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 = Field(default=None)
class-attribute
instance-attribute
model_config = ConfigDict(populate_by_name=True)
class-attribute
instance-attribute
properties
instance-attribute
required = Field(default=None)
class-attribute
instance-attribute
schema_id = Field(default='https://rde.nims.go.jp/rde/dataset-templates/', validation_alias='$id', serialization_alias='$id')
class-attribute
instance-attribute
value_type = Field(default='object', alias='type')
class-attribute
instance-attribute
version = 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()
find_field(key, custom_only=False)
Find and return field definition for the specified key.
Searches for a field definition by key, either in custom properties only or throughout the entire schema structure using recursive traversal.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
key
|
str
|
The field key to search for. |
必須 |
custom_only
|
bool
|
If True, search only in custom properties. If False, search the entire schema structure. Defaults to False. |
False
|
戻り値:
| タイプ | デスクリプション |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: The field definition as a dictionary if found, None otherwise. The dictionary contains the field's metadata serialized in JSON mode with aliases. |
Note
When custom_only is True, the method only searches within self.properties.custom.properties.root. When False, it performs a recursive search through the entire model structure.
src.rdetoolkit.models.invoice_schema.Properties
Bases: BaseModel
Represents the properties of an invoice.
properties is an instance of this class.
属性:
| 名前 | タイプ | デスクリプション |
|---|---|---|
custom |
Optional[CustomField]
|
The custom field of the invoice. |
sample |
Optional[str]
|
A sample field of the invoice. |
custom = Field(default=None)
class-attribute
instance-attribute
sample = 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 = 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 = Field(default=(BasicItemsValue(type='string', pattern='^([0-9a-zA-Z]{56})$')))
class-attribute
instance-attribute
dateName = Field(default=(BasicItemsValue(type='string', pattern='^([0-9a-zA-Z]{56})$')))
class-attribute
instance-attribute
dateSubmitted = Field(default=(BasicItemsValue(type='string', format='date')))
class-attribute
instance-attribute
description = Field(default=None)
class-attribute
instance-attribute
experimentId = Field(default=None)
class-attribute
instance-attribute
instrumentId = 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 = Field(default=None)
class-attribute
instance-attribute
format = Field(default=None)
class-attribute
instance-attribute
pattern = Field(default=None)
class-attribute
instance-attribute
value_type = 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
instance-attribute
obj_type = Field(..., alias='type')
class-attribute
instance-attribute
properties
instance-attribute
required = 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 = Field(default=None, alias='generalAttributes')
class-attribute
instance-attribute
specificAttributes = 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 = Field(default=None, alias='composition')
class-attribute
instance-attribute
description = Field(default=None, alias='description')
class-attribute
instance-attribute
generalAttributes = Field(default=None, alias='generalAttributes')
class-attribute
instance-attribute
ownerId = Field(pattern='^([0-9a-zA-Z]{56})$', description='sample ownere id', alias='ownerId')
class-attribute
instance-attribute
referenceUrl = Field(default=None, alias='referenceUrl')
class-attribute
instance-attribute
sample_id = Field(default=None, alias='sampleId')
class-attribute
instance-attribute
specificAttributes = 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
instance-attribute
obj_type = 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
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 = Field(..., alias='type')
class-attribute
instance-attribute
properties
instance-attribute
required
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 = Field(..., alias='classId')
class-attribute
instance-attribute
term_id = 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
instance-attribute
obj_type = 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.
属性:
| 名前 | タイプ | デスクリプション |
|---|---|---|
root |
Optional[list[GeneralProperty]]
|
The list of general properties. Defaults to None. |
root = 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 = Field(..., alias='type')
class-attribute
instance-attribute
properties
instance-attribute
required
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 = 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
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
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
instance-attribute
obj_type = Field(..., alias='type')
class-attribute
instance-attribute
properties
instance-attribute
required
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.
属性:
| 名前 | タイプ | デスクリプション |
|---|---|---|
root |
dict[str, MetaProperty]
|
A dictionary containing the custom items. |
root
instance-attribute
__getitem__(item)
__iter__()
src.rdetoolkit.models.invoice_schema.MetaProperty
Bases: BaseModel
Represents a meta property in the invoice schema.
属性:
| 名前 | タイプ | デスクリプション |
|---|---|---|
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 = Field(default=None)
class-attribute
instance-attribute
default = Field(default=None)
class-attribute
instance-attribute
description = Field(default=None)
class-attribute
instance-attribute
enum = Field(default=None)
class-attribute
instance-attribute
examples = Field(default=None)
class-attribute
instance-attribute
exclusiveMaximum = 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 = 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 = 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
instance-attribute
maxLength = Field(default=None, description='Specify the maximum length of the string.')
class-attribute
instance-attribute
maximum = 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 = Field(default=None, description='Specify the minimum length of the string. Must be 0 or more.')
class-attribute
instance-attribute
minimum = 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 = ConfigDict(extra='allow')
class-attribute
instance-attribute
pattern = Field(default=None, description='Declare that it has a pattern specified by a regular expression.')
class-attribute
instance-attribute
value_type = 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.
属性:
| 名前 | タイプ | デスクリプション |
|---|---|---|
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 = Field(default=None)
class-attribute
instance-attribute
rows = Field(default=None)
class-attribute
instance-attribute
unit = Field(default=None)
class-attribute
instance-attribute
widget = 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'.
発生:
| タイプ | デスクリプション |
|---|---|
ValueError
|
If the widget is set to 'textarea' and the 'row' is not set (None or not provided). |
戻り値:
| 名前 | タイプ | デスクリプション |
|---|---|---|
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
instance-attribute
ja
instance-attribute
src.rdetoolkit.models.invoice_schema.LangLabels
Bases: BaseModel
A class representing labels in different languages.
en
instance-attribute
ja
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 | |