Model Adapter

class spectree.model_adapter.ModelAdapter[source]

The protocol of model adapter.

  • check the model type

  • validate the model

  • dump model instance to a JSON

  • generate the JSON schema

  • check the validation errors

__init__(*args, **kwargs)
is_model_instance(value: Any, model) bool[source]

Check if the value is the instance of the model under this adapter.

If it’s already an instance, we could skip the validation.

is_model_type(value: Any) bool[source]

Check if the value can be used to generate a schema.

class spectree.model_adapter.pydantic_adapter.BaseFile[source]

An uploaded file, will be assigned as the corresponding web framework’s file object.

class spectree.model_adapter.pydantic_adapter.PydanticModelAdapter[source]

pydantic model adapter.

__init__() None[source]
basefile

alias of BaseFile

is_model_instance(value: Any, model) bool[source]

Check if the value is the instance of the model under this adapter.

If it’s already an instance, we could skip the validation.

is_model_type(value: type) bool[source]

Check if the value can be used to generate a schema.

class spectree.model_adapter.pydantic_adapter.ValidationErrorType[source]

Model of a validation error response.

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class spectree.model_adapter.msgspec_adapter.MsgspecModelAdapter[source]

msgspec model adapter.

__init__() None[source]
is_model_instance(value: Any, model) bool[source]

Check if the value is the instance of the model under this adapter.

If it’s already an instance, we could skip the validation.

is_model_type(value: type) bool[source]

All kinds of types are treated the same.

json_schema(model: type[Any], *, ref_template: str, mode: Literal['validation', 'serialization'] = 'validation') dict[str, Any][source]

mode is not supported by msgspec.

See https://github.com/jcrist/msgspec/issues/686

make_root_model(root_type: type[Any], *, name: str = 'GeneratedRootModel', module: str | None = None) type[Struct][source]

All the types are treated the same in msgspec.

See: https://github.com/jcrist/msgspec/issues/484

validation_error

alias of ValidationError

validation_errors(err: ValidationError)[source]

Expect a list[ValidationErrorElement]