aind_behavior_services.schema package

Module contents

class aind_behavior_services.schema.BonsaiSgenSerializers(*values)[source]

Bases: Enum

JSON = 'json'[source]
NONE = 'None'[source]
YAML = 'yaml'[source]
class aind_behavior_services.schema.CustomGenerateJsonSchema(*args, **kwargs)[source]

Bases: GenerateJsonSchema

Custom JSON Schema generator to modify the way certain schemas are generated.

enum_schema(schema)[source]

Generates a JSON schema that matches an Enum value.

Parameters:

schema (EnumSchema) – The core schema.

Returns:

The generated JSON schema.

Return type:

dict[str, Any]

get_flattened_oneof(schemas)[source]
Parameters:

schemas (list[dict[str, Any]])

Return type:

dict[str, Any]

literal_schema(schema)[source]

Generates a JSON schema that matches a literal value.

Parameters:

schema (LiteralSchema) – The core schema.

Returns:

The generated JSON schema.

Return type:

dict[str, Any]

nullable_schema(schema)[source]

Generates a JSON schema that matches a schema that allows null values.

Parameters:

schema (NullableSchema) – The core schema.

Returns:

The generated JSON schema.

Return type:

dict[str, Any]

union_schema(schema)[source]

Generates a JSON schema that matches a schema that allows values matching any of the given schemas.

Parameters:

schema (UnionSchema) – The core schema.

Returns:

The generated JSON schema.

Return type:

dict[str, Any]

aind_behavior_services.schema.bonsai_sgen(schema_path, output_path, namespace=None, root_element=None, serializer=None)[source]

Runs Bonsai.SGen to generate a Bonsai-compatible schema from a json-schema model For more information run bonsai.sgen –help in the command line.

Returns:

The result of running the command.

Return type:

CompletedProcess

Parameters:
  • schema_path (PathLike) – Target Json Schema file

  • output_path (PathLike) – Specifies the name of the file containing the generated code.

  • namespace (Optional[str], optional) – Specifies the namespace to use for all generated serialization classes. Defaults to DataSchema.

  • root_element (Optional[str], optional) – Specifies the name of the class used to represent the schema root element. If None, it will use the json schema root element. Defaults to None.

  • serializer (Optional[List[BonsaiSgenSerializers]], optional) – Specifies the serializer data annotations to include in the generated classes. Defaults to None.

aind_behavior_services.schema.convert_pydantic_to_bonsai(model, *, model_name=None, json_schema_output_dir=PosixPath('src/DataSchemas'), cs_output_dir=PosixPath('src/Extensions'), cs_namespace='DataSchema', cs_serializer=None, json_schema_export_kwargs=None, root_element=None)[source]
Parameters:
  • model (Type[BaseModel])

  • model_name (str | None)

  • json_schema_output_dir (PathLike)

  • cs_output_dir (PathLike | None)

  • cs_namespace (str)

  • cs_serializer (List[BonsaiSgenSerializers] | None)

  • json_schema_export_kwargs (Dict[str, Any] | None)

  • root_element (str | None)

Return type:

CompletedProcess | None

aind_behavior_services.schema.export_schema(model, schema_generator=<class 'aind_behavior_services.schema.CustomGenerateJsonSchema'>, mode='serialization', remove_root=True)[source]

Export the schema of a model to a json file

Parameters:
  • model (Type[BaseModel])

  • schema_generator (Type[GenerateJsonSchema])

  • mode (Literal['validation', 'serialization'])

  • remove_root (bool)