Invoice Schema Models API
Purpose
This module defines validator models used in RDEToolKit's invoice schema (invoice.schema.json). It provides functionality for invoice data structure validation and schema compliance verification.
Key Features
Schema Models
- Schema definition for entire invoice
- Schema validation for basic information
- Schema validation for sample information
- Custom field management
Data Validation
- JSONSchema-based validation
- Type safety assurance
- Multilingual label management
src.rdetoolkit.models.invoice_schema.InvoiceSchemaJson
Bases: BaseModel
Invoice schema class.
Example
To generate invoice.schema.json from the model, do as follows:
1 2 3 4 5 6 7 8 |
|
description: str | None = Field(default=None)
class-attribute
instance-attribute
model_config: Incomplete = ConfigDict(populate_by_name=True)
class-attribute
instance-attribute
properties: Properties
instance-attribute
required: list[Literal['custom', 'sample']] | None = Field(default=None)
class-attribute
instance-attribute
schema_id: str = Field(default='https://rde.nims.go.jp/rde/dataset-templates/', validation_alias='$id', serialization_alias='$id')
class-attribute
instance-attribute
value_type: Literal['object'] = Field(default='object', alias='type')
class-attribute
instance-attribute
version: str = Field(default='https://json-schema.org/draft/2020-12/schema', validation_alias='$schema', serialization_alias='$schema')
class-attribute
instance-attribute
__check_custom_fields()
__check_required_fields()
__check_smaple_field()
src.rdetoolkit.models.invoice_schema.Properties
Bases: BaseModel
Represents the properties of an invoice.
properties
is an instance of this class.
Attributes:
Name | Type | Description |
---|---|---|
custom |
Optional[CustomField]
|
The custom field of the invoice. |
sample |
Optional[str]
|
A sample field of the invoice. |
custom: CustomField | None = Field(default=None)
class-attribute
instance-attribute
sample: SampleField | None = Field(default=None)
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.DatasetId
Bases: BaseModel
Represents the dataset ID for an invoice.
properties.datasetId
is an instance of this class.
value_type: str = Field(default='string', alias='type')
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.BasicItems
Bases: BaseModel
Represents the basic items of an invoice.
properties.basic
is an instance of this class.
dataOwnerId: BasicItemsValue = Field(default=BasicItemsValue(type='string', pattern='^([0-9a-zA-Z]{56})$'))
class-attribute
instance-attribute
dateName: BasicItemsValue = Field(default=BasicItemsValue(type='string', pattern='^([0-9a-zA-Z]{56})$'))
class-attribute
instance-attribute
dateSubmitted: BasicItemsValue = Field(default=BasicItemsValue(type='string', format='date'))
class-attribute
instance-attribute
description: BasicItemsValue | None = Field(default=None)
class-attribute
instance-attribute
experimentId: BasicItemsValue | None = Field(default=None)
class-attribute
instance-attribute
instrumentId: BasicItemsValue | None = Field(default=BasicItemsValue(type='string', pattern='^$|^([0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12})$'))
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.BasicItemsValue
Bases: BaseModel
description: str | None = Field(default=None)
class-attribute
instance-attribute
format: Literal['date'] | None = Field(default=None)
class-attribute
instance-attribute
pattern: str | None = Field(default=None)
class-attribute
instance-attribute
value_type: str | list | None = Field(default=None, alias='type')
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.SampleField
Bases: BaseModel
Represents a sample field in the invoice schema.
properties.sample
is an instance of this class.
label: LangLabels
instance-attribute
obj_type: Literal['object'] = Field(..., alias='type')
class-attribute
instance-attribute
properties: SampleProperties
instance-attribute
required: list[Literal['names', 'sampleId']] = Field(default=['names', 'sampleId'])
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.SampleProperties
Bases: BaseModel
Represents the properties of a sample.
properties.sample.properties
is an instance of this class.
generalAttributes: GeneralAttribute | None = Field(default=None, alias='generalAttributes')
class-attribute
instance-attribute
specificAttributes: SpecificAttribute | None = Field(default=None, alias='specificAttributes')
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.SamplePropertiesWhenAdding
Bases: BaseModel
Represents the properties of a sample.
properties.sample.properties
is an instance of this class.
composition: str | None = Field(default=None, alias='composition')
class-attribute
instance-attribute
description: str | None = Field(default=None, alias='description')
class-attribute
instance-attribute
generalAttributes: GeneralAttribute | None = Field(default=None, alias='generalAttributes')
class-attribute
instance-attribute
ownerId: str = Field(pattern='^([0-9a-zA-Z]{56})$', description='sample ownere id', alias='ownerId')
class-attribute
instance-attribute
referenceUrl: str | None = Field(default=None, alias='referenceUrl')
class-attribute
instance-attribute
sample_id: str | None = Field(default=None, alias='sampleId')
class-attribute
instance-attribute
specificAttributes: SpecificAttribute | None = Field(default=None, alias='specificAttributes')
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.SpecificAttribute
Bases: BaseModel
Represents a specific attribute in the invoice schema.
properties.sample.properties.specificAttribute
is an instance of this class.
items: SampleSpecificItems
instance-attribute
obj_type: Literal['array'] = Field(..., alias='type')
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.SampleSpecificItems
Bases: RootModel
Represents a specificAttirbutes child property.
properties.sample.properties.specificAttributes.itemss
is an instance of this class.
root: list[SpecificProperty]
instance-attribute
src.rdetoolkit.models.invoice_schema.SpecificProperty
Bases: BaseModel
Represents a specificAttirbutes child property.
properties.sample.properties.specificAttributes.itemss
is an instance of this class.
object_type: Literal['object'] = Field(..., alias='type')
class-attribute
instance-attribute
properties: SpecificChildProperty
instance-attribute
required: list[Literal['classId', 'termId', 'value']]
instance-attribute
src.rdetoolkit.models.invoice_schema.SpecificChildProperty
Bases: BaseModel
Represents a specificAttirbutes child property.
properties.sample.properties.specificAttributes.items.properties
is an instance of this class.
class_id: ClassId = Field(..., alias='classId')
class-attribute
instance-attribute
term_id: TermId = Field(..., alias='termId')
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.GeneralAttribute
Bases: BaseModel
Represents a general attribute in the invoice schema.
properties.sample.properties.generalAttribute
is an instance of this class.
items: SampleGeneralItems
instance-attribute
obj_type: Literal['array'] = Field(..., alias='type')
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.SampleGeneralItems
Bases: RootModel
Represents a sample general item.
This class is used as the instance for properties.sample.properties.generalAtttirbutes.items
.
Attributes:
Name | Type | Description |
---|---|---|
root |
Optional[list[GeneralProperty]]
|
The list of general properties. Defaults to None. |
root: list[GeneralProperty] | None = Field(default=None)
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.GeneralProperty
Bases: BaseModel
Represents a general property in the invoice schema.
properties.sample.properties.generalAtttirbutes.items
is an instance of this class.
object_type: Literal['object'] = Field(..., alias='type')
class-attribute
instance-attribute
properties: GeneralChildProperty
instance-attribute
required: list[Literal['termId', 'value']]
instance-attribute
src.rdetoolkit.models.invoice_schema.GeneralChildProperty
Bases: BaseModel
Represents a general child property.
properties.sample.properties.generalAtttirbutes.items.properties
is an instance of this class.
term_id: TermId = Field(..., alias='termId')
class-attribute
instance-attribute
src.rdetoolkit.models.invoice_schema.ClassId
Bases: BaseModel
Represents the ClassId for an invoice.
properties.sample.properties.specificAttributes.items.properties.classId
is an instance of this class.
const: str
instance-attribute
src.rdetoolkit.models.invoice_schema.TermId
Bases: BaseModel
Represents a term identifier.
properties.sample.properties.generalAtttirbutes.items.properties.termId
is an instance of this class.
const: str
instance-attribute
src.rdetoolkit.models.invoice_schema.CustomField
Bases: BaseModel
Represents a custom field in an invoice schema.
properties.custom.
is an instance of this class.
label: LangLabels
instance-attribute
obj_type: Literal['object'] = Field(..., alias='type')
class-attribute
instance-attribute
properties: CustomItems
instance-attribute
required: list[str]
instance-attribute
src.rdetoolkit.models.invoice_schema.CustomItems
Bases: RootModel
A class representing custom items in an invoice schema.
properties.custom.properties.<custom key>
is an instance of this class.
Attributes:
Name | Type | Description |
---|---|---|
root |
dict[str, MetaProperty]
|
A dictionary containing the custom items. |
root: dict[str, MetaProperty]
instance-attribute
__getitem__(item)
__iter__()
src.rdetoolkit.models.invoice_schema.MetaProperty
Bases: BaseModel
Represents a meta property in the invoice schema.
Attributes:
Name | Type | Description |
---|---|---|
label |
LangLabels
|
The label of the meta property. |
value_type |
Literal['boolean', 'integer', 'number', 'string']
|
The type of the value for the meta property. |
description |
Optional[str]
|
The description of the meta property. |
examples |
Optional[str]
|
Examples of the meta property. |
default |
Optional[Union[bool, int, float, str]]
|
The default value for the meta property. |
const: bool | int | float | str | None = Field(default=None)
class-attribute
instance-attribute
default: bool | int | float | str | None = Field(default=None)
class-attribute
instance-attribute
description: str | None = Field(default=None)
class-attribute
instance-attribute
enum: list[bool | int | float | str] | None = Field(default=None)
class-attribute
instance-attribute
examples: list[bool | int | float | str] | None = Field(default=None)
class-attribute
instance-attribute
exclusiveMaximum: int | None = Field(default=None, description='Declare that the number is less than the specified value. Only applicable when the type is a numeric type (integer, number).')
class-attribute
instance-attribute
exclusiveMinimum: int | None = Field(default=None, description='Declare that the number is greater than the specified value. Only applicable when the type is a numeric type (integer, number).')
class-attribute
instance-attribute
format: Literal['date', 'time', 'uri', 'uuid', 'markdown'] | None = Field(default=None, description='Specify the format of the string. Refer to date, time, uri, uuid, markdown for possible values.')
class-attribute
instance-attribute
label: LangLabels
instance-attribute
maxLength: int | None = Field(default=None, description='Specify the maximum length of the string.')
class-attribute
instance-attribute
maximum: int | None = Field(default=None, description='Declare that the number is less than or equal to the specified value. Only applicable when the type is a numeric type (integer, number).')
class-attribute
instance-attribute
minLength: int | None = Field(default=None, description='Specify the minimum length of the string. Must be 0 or more.')
class-attribute
instance-attribute
minimum: int | None = Field(default=None, description='Declare that the number is greater than or equal to the specified value. Only applicable when the type is a numeric type (integer, number).')
class-attribute
instance-attribute
model_config: Incomplete = ConfigDict(extra='allow')
class-attribute
instance-attribute
pattern: str | None = Field(default=None, description='Declare that it has a pattern specified by a regular expression.')
class-attribute
instance-attribute
value_type: Literal['boolean', 'integer', 'number', 'string'] = Field(..., alias='type')
class-attribute
instance-attribute
__check_const_type()
__check_numeric_type()
__check_string_type()
src.rdetoolkit.models.invoice_schema.Options
Bases: BaseModel
Represents the options for a widget in the invoice schema.
properties.custom.properties.<custom key>.options
is an instance of this class.
Attributes:
Name | Type | Description |
---|---|---|
widget |
Optional[Literal['textarea']]
|
The type of widget. Defaults to None. |
rows |
Optional[int]
|
The number of rows for a textarea widget. Defaults to None. |
unit |
Optional[str]
|
The unit of measurement for the widget. Defaults to None. |
placeholder |
Optional[Placeholder]
|
The placeholder text for the widget. Defaults to None. |
placeholder: Placeholder | None = Field(default=None)
class-attribute
instance-attribute
rows: int | None = Field(default=None)
class-attribute
instance-attribute
unit: str | None = Field(default=None)
class-attribute
instance-attribute
widget: Literal['textarea'] | None = Field(default=None)
class-attribute
instance-attribute
__check_row_for_widget_textarea()
Validates that the 'row' field is set when the 'widget' field is set to 'textarea'.
Raises:
Type | Description |
---|---|
ValueError
|
If the widget is set to 'textarea' and the 'row' is not set (None or not provided). |
Returns:
Name | Type | Description |
---|---|---|
Options |
Options
|
The validated value of the 'row' field. Returns the input value (v) if there are no issues. |
src.rdetoolkit.models.invoice_schema.Placeholder
Bases: BaseModel
A class representing placeholders in different languages.
This class inherits from BaseModel
, and the ja
and en
attributes hold the placeholders in Japanese and English, respectively.
properties.custom.properties.<custom key>.options.placeholder
is an instance of this class.
en: str
instance-attribute
ja: str
instance-attribute
src.rdetoolkit.models.invoice_schema.LangLabels
Bases: BaseModel
A class representing labels in different languages.
en: str
instance-attribute
ja: str
instance-attribute
Practical Usage
Basic Schema Validation
basic_schema_validation.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Custom Field Management
custom_fields.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
Attribute and Property Management
attributes_properties.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|