ts_ids_core.base.ids_element module¶
- Model IdsElement[source]¶
Bases:
BaseModelBase class for IDS models.
Show JSON schema
{ "description": "Base class for IDS models.", "type": "object", "properties": {}, "additionalProperties": false }
- Validators:
all_abstract_fields_implemented»all fields
- validator all_abstract_fields_implemented » all fields[source]¶
Assert no fields are abstract before being populated, i.e. they have all been implemented.
- Validates:
all fields
- dict(*, include: IncEx = None, exclude: IncEx = None, by_alias: bool = True, exclude_unset: bool = True, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny[source]¶
Return the model instance as a dictionary.
This is an alias of the model_dump method which is Pydantic’s default name for this functionality.
- model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx = None, exclude: IncEx = None, by_alias: bool = True, exclude_unset: bool = True, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: bool = True) DictStrAny[source]¶
Export to a Python dictionary, excluding any fields whose values are not defined.
For the other parameters, see
pydantic.main.BaseModel.model_dump().- Parameters:
exclude_unset – This parameter is not used but is maintained in order to preserve the parent class’ API.
- Raises:
NotImplementedError – If any value other than the default is passed to
exclude_unset. Theexclude_unsetparameter is only to keep the API consistent with the parent class’ method,pydantic.BaseModel.model_dump().
- model_dump_json(*, indent: int | None = None, include: IncEx = None, exclude: IncEx = None, by_alias: bool = True, exclude_unset: bool = True, exclude_defaults: bool = False, exclude_none: bool = False, round_trip: bool = False, warnings: bool = True) str[source]¶
Export to JSON.
For the other parameters, see
pydantic.main.BaseModel.model_dump_json().Note exclude_unset may not be used, IDS models always have to exclude unset values so that IDS_UNDEFINED is handled correctly.
- Parameters:
exclude_unset – This parameter is not used but is maintained in order to preserve the parent class’ API.
- Raises:
NotImplementedError – If any value other than the default is passed to
exclude_unset. Theexclude_unsetparameter is only to keep the API consistent with the parent class’ method,pydantic.BaseModel.model_dump_json().
- classmethod model_json_schema(by_alias: bool = True, ref_template: str = '#/definitions/{model}', schema_generator: ~typing.Type[~pydantic.json_schema.GenerateJsonSchema] = <class 'ts_ids_core.base.ids_element.IdsSchemaGenerator'>, mode: typing_extensions.Literal[validation, serialization] = 'validation') Dict[str, Any][source]¶
Generates a JSON schema for a model class.
- Parameters:
by_alias – Whether to use field aliases in the JSON Schema. Defaults to True.
ref_template – The
$reftemplate. Defaults to ‘#/definitions/{model}’, wheremodelis replaced with thets_ids_core.base.ids_element.IdsElement’s class name.
- Returns:
The JSON Schema, as described above.
- Raises:
UnimplementedAbstractField – One or more abstract field(s) are not implemented.
InvalidSchemaMetadata – One or more of the schema metadata fields specified in
ts_ids_core.base.ids_element.schema_extra_metadataare invalid values.
- classmethod schema(by_alias: bool = True, ref_template: str = '#/definitions/{model}') Dict[str, Any][source]¶
Return the JSON Schema as a Python object.
This is an alias of the model_json_schema method which is Pydantic’s default name for this functionality.
- classmethod schema_json(*, by_alias: bool = True, ref_template: str = '#/definitions/{model}', **dumps_kwargs: Any) str[source]¶
Dump schema to json string. This method preserves Pydantic’s v1 BaseModel.schema_json functionality.
- Parameters:
by_alias – Whether to use field aliases in the JSON Schema. Defaults to True.
ref_template – The
$reftemplate. Defaults to ‘#/definitions/{model}’, wheremodelis replaced with thets_ids_core.base.ids_element.IdsElement’s class name.dumps_kwargs – Key word arguments passed to IdsElement.model_json_schema
- Returns:
IdsElement schema as string
- schema_extra_metadata: ClassVar[SchemaExtraMetadataType] = {}¶
Key/value pairs to add to the JSON Schema. These values will not be in the output of method
dict()norjson(). That is, they won’t be in the IDS instance. To indicate that the key/value pair is abstract and thus expected to be overridden by the child class, set the value toNotImplemented. Note that in child classes thetyping.ClassVartype hint must be provided in order to indicate thatschema_extra_metadatais not an IDS Field.
- class IdsSchemaGenerator(by_alias: bool = True, ref_template: str = '#/$defs/{model}')[source]¶
Bases:
GenerateJsonSchemaJSON Schema generation which follows TetraScience IDS conventions.
- default_schema(schema: WithDefaultSchema) Dict[str, Any][source]¶
Generates a JSON schema that matches a schema with a default value.
- Args:
schema: The core schema.
- Returns:
The generated JSON schema.
- enum_schema(schema: EnumSchema) Dict[str, Any][source]¶
Generates a JSON schema that matches an Enum value.
This is a modification of Pydantic’s built-in enum schema, to allow the type to be nullable, e.g. “type”: [“string”, “null”] for an enum containing strings and null values. Pydantic’s default is to omit the “type” in this case.
- generate(schema: InvalidSchema | AnySchema | NoneSchema | BoolSchema | IntSchema | FloatSchema | DecimalSchema | StringSchema | BytesSchema | DateSchema | TimeSchema | DatetimeSchema | TimedeltaSchema | LiteralSchema | EnumSchema | IsInstanceSchema | IsSubclassSchema | CallableSchema | ListSchema | TupleSchema | SetSchema | FrozenSetSchema | GeneratorSchema | DictSchema | AfterValidatorFunctionSchema | BeforeValidatorFunctionSchema | WrapValidatorFunctionSchema | PlainValidatorFunctionSchema | WithDefaultSchema | NullableSchema | UnionSchema | TaggedUnionSchema | ChainSchema | LaxOrStrictSchema | JsonOrPythonSchema | TypedDictSchema | ModelFieldsSchema | ModelSchema | DataclassArgsSchema | DataclassSchema | ArgumentsSchema | CallSchema | CustomErrorSchema | JsonSchema | UrlSchema | MultiHostUrlSchema | DefinitionsSchema | DefinitionReferenceSchema | UuidSchema | ComplexSchema, mode: typing_extensions.Literal[validation, serialization] = 'validation') Dict[str, Any][source]¶
Generates a JSON schema for a specified schema in a specified mode.
- Args:
schema: A Pydantic model. mode: The mode in which to generate the schema. Defaults to ‘validation’.
- Returns:
A JSON schema representing the specified schema.
- Raises:
PydanticUserError: If the JSON schema generator has already been used to generate a JSON schema.
- handle_ref_overrides(json_schema: Dict[str, Any]) Dict[str, Any][source]¶
When a $ref appears next to other JSON Schema metadata, do nothing.
In the default handle_ref_overrides, Pydantic moves $ref into an allOf if if appears next to sibling metadata. However, typically in IDS JSON Schemas, we want to avoid using allOf and just allow $ref with sibling metadata (i.e. this method should do nothing).
For example, this is allowed: {“description”: “My quantity description”, “$ref”: “#/definitions/ValueUnit”}.
Note this is also supported by jsonref.replace_refs with merge_props=True: https://jsonref.readthedocs.io/en/latest/#the-replace-refs-function for any downstream handling of definitions.
- literal_schema(schema: LiteralSchema) Dict[str, Any][source]¶
Generates a JSON schema that matches a literal value.
This is a modification of Pydantic’s built-in literal schema, to define a type for const values, where Pydantic excludes the “type”.
- nullable_schema(schema: NullableSchema) Dict[str, Any][source]¶
Generates a JSON schema that matches a schema that allows null values.
- Args:
schema: The core schema.
- Returns:
The generated JSON schema.
- ref_template = '#/definitions/{model}'¶
- schema_dialect = 'http://json-schema.org/draft-07/schema#'¶