Field Types

justobjects provides support for: - standard library types - custom justobjects type arguments - custom justonjects classes that can be used as typed annotations

Standard Library Types

Standard library types can be used to annotated properties in data objects

Types

justobjects provides multiple types that can be used to annotated fields

StringType

Generates a jsonschema with type = "string"

justobjects.decorators.all_of(types: Iterable[Type], default: Optional[Any] = None, required: bool = False, description: Optional[str] = None) attr._make.Attribute

JSON schema allOf

justobjects.decorators.any_of(types: Iterable[Type], default: Optional[Any] = None, required: bool = False, description: Optional[str] = None) attr._make.Attribute

JSON schema anyOf

justobjects.decorators.array(item: Type, contains: bool = False, min_items: Optional[int] = 1, max_items: Optional[int] = None, required: bool = False, unique_items: bool = False, description: Optional[str] = None) attr._make.Attribute

Array schema data type

If item is the class type of another data object, it will be converted to a reference

Parameters
  • item – data object class type used as items in the array

  • contains – schema only needs to validate against one or more items in the array.

  • min_items – positive integer representing the minimum number of items that can be on the array

  • max_items – positive integer representing the maximum number of items that can be on the array

  • required – True if field is required

  • unique_items – disallow duplicates

  • description – field description

Returns

A array attribute wrapper

justobjects.decorators.boolean(default: Optional[bool] = None, required: Optional[bool] = None, description: Optional[str] = None) attr._make.Attribute

Boolean schema data type

Parameters
  • default – default boolean value

  • required (bool) –

  • description (str) – summary/description

Returns

boolean schema wrapper

justobjects.decorators.integer(default: Optional[int] = None, minimum: Optional[int] = None, maximum: Optional[int] = None, multiple_of: Optional[int] = None, exclusive_min: Optional[int] = None, exclusive_max: Optional[int] = None, required: Optional[bool] = None, description: Optional[str] = None) attr._make.Attribute

The integer type is used for integral numbers

Parameters
  • default – default value used for instances

  • minimum – a number denoting the minimum allowed value for instances

  • maximum – a number denoting the maximum allowed value for instances

  • multiple_of – must be a positive value, restricts values to be multiples of the given number

  • exclusive_max – a number denoting maximum allowed value should be less that the given value

  • exclusive_min – a number denoting minimum allowed value should be greater that the given value

  • required – True if field should be a required field

  • description – Comments describing the field

Returns

A wrapped IntegerType

justobjects.decorators.numeric(default: Optional[float] = None, minimum: Optional[float] = None, maximum: Optional[float] = None, multiple_of: Optional[int] = None, exclusive_min: Optional[float] = None, exclusive_max: Optional[float] = None, required: Optional[bool] = None, description: Optional[str] = None) attr._make.Attribute

The number type is used for any numeric type, either integers or floating point numbers.

Parameters
  • default – default value used for instances

  • minimum – a number denoting the minimum allowed value for instances

  • maximum – a number denoting the maximum allowed value for instances

  • multiple_of – must be a positive value, restricts values to be multiples of the given number

  • exclusive_max – a number denoting maximum allowed value should be less that the given value

  • exclusive_min – a number denoting minimum allowed value should be greater that the given value

  • required – True if field should be a required field

  • description – Comments describing the field

Returns

A wrapped NumericType

justobjects.decorators.one_of(types: Iterable[Type], default: Optional[Any] = None, required: bool = False, description: Optional[str] = None) attr._make.Attribute

Applies to properties and complies with JSON schema oneOf property :param types: list of types that will be allowed :type types: list[type] :param default: default object instance that must be one of the allowed types :type default: object :param required: True if property is required :param description: field comments/description

Returns

field instance

Return type

attr.ib

justobjects.decorators.ref(ref_type: Type, required: bool = False, description: Optional[str] = None, default: Optional[Type] = None) attr._make.Attribute

Creates a json reference to another json object

Parameters
  • ref_type – class type referenced

  • required – True if field is required

  • description – ref specific documentation/comments

  • default – default value

Returns

a schema reference attribute wrapper