gemseo / core / grammars

json_schema module

JSON schema handler.

class gemseo.core.grammars.json_schema.MutableMappingSchemaBuilder(schema_uri='DEFAULT')[source]

Bases: Mapping, SchemaBuilder

A mutable genson SchemaBuilder with a dictionary-like interface.

The SchemaBuilder does not provide a way to mutate directly the properties of a schema (these are stored deeply). For ease of usage, this class brings the properties closer to the surface, and the mutability is only provided by the ability to delete a property.

Parameters:

schema_uri

value of the $schema keyword. If not given, it will use the value of the first available $schema keyword on an added schema or else the default: 'http://json-schema.org/schema#'. A value of False or None will direct GenSON to leave out the "$schema" keyword.

By default it is set to “DEFAULT”.

NODE_CLASS

alias of MutableMappingSchemaBuilderSchemaNode

add_object(obj)

Modify the schema to accommodate an object.

Parameters:

obj – any object or scalar that can be serialized in JSON

add_schema(schema)

Merge in a JSON schema. This can be a dict or another SchemaBuilder

Parameters:

schema – a JSON Schema

Note

There is no schema validation. If you pass in a bad schema, you might get back a bad schema.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.
items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
to_json(*args, **kwargs)

Generate a schema and convert it directly to serialized JSON.

Return type:

str

to_schema()

Generate a schema based on previous inputs.

Return type:

dict

values() an object providing a view on D's values
DEFAULT_URI = 'http://json-schema.org/schema#'
EXTRA_STRATEGIES = (<class 'gemseo.core.grammars.json_schema._MergeRequiredStrategy'>,)
NULL_URI = 'NULL'
STRATEGIES = (<class 'gemseo.core.grammars.json_schema._MergeRequiredStrategy'>, <class 'genson.schema.strategies.scalar.Null'>, <class 'genson.schema.strategies.scalar.Boolean'>, <class 'genson.schema.strategies.scalar.Number'>, <class 'genson.schema.strategies.scalar.String'>, <class 'genson.schema.strategies.array.List'>, <class 'genson.schema.strategies.array.Tuple'>, <class 'genson.schema.strategies.object.Object'>)
property properties: dict[str, Any]

Return the properties.

Returns:

The existing properties, otherwise an empty dictionary.

property required: set[str]

Return the required properties.

Returns:

The required properties, otherwise an empty set.