schemas¶
- justobjects.schemas.get_schema(cls: Union[Type[justobjects.types.JustSchema], justobjects.types.RefType, justobjects.types.BasicType]) Union[justobjects.types.JustSchema, justobjects.types.SchemaType] ¶
Retrieves a justschema representation for the class or object instance
- Parameters
cls – a class type which is expected to be a pre-defined data object or an instance of json type
- justobjects.schemas.show_schema(model: Any) Dict ¶
Converts a data object class type into a valid json schema
- Parameters
model – data object class type or instance
- Returns
a json schema dictionary
Examples
Creating and getting the schema associated with a simple integer type
import justobjects as jo s = jo.IntegerType(minimum=3) jo.show_schema(s) # {'minimum': 3, 'type': 'integer'}
- justobjects.schemas.transform(cls: Type) justobjects.types.JustSchema ¶
“Attempts to transform any object class type into an appropriate schema type
- justobjects.schemas.validate(schema: justobjects.types.JustSchema, instance: Any) None ¶
- justobjects.schemas.validate(schema: Type, instance: Any) None
- justobjects.schemas.validate(schema: Any, instance: Any = None) None
Validates an object instance against its associated json schema
- Parameters
schema – a data object schema instance
instance – data object instance
- Raises
ValidationException – when there errors
Examples
import justobjects as jo @jo.data() class Model: a = jo.integer(minimum=18) b = jo.boolean() jo.validate(Model(a=4, b=True)