gemseo / core / grammars

json_schema module

JSON schema handler.

Classes:

MutableMappingSchemaBuilder([schema_uri])

A mutable genson SchemaBuilder with a dictionary-like interface.

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

Bases: genson.schema.builder.SchemaBuilder

A mutable genson SchemaBuilder with a dictionary-like interface.

The mutability is 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.

Attributes:

DEFAULT_URI

EXTRA_STRATEGIES

NULL_URI

STRATEGIES

Classes:

NODE_CLASS

alias of genson.schema.builder.MutableMappingSchemaBuilderSchemaNode

Methods:

add_object(obj)

Modify the schema to accommodate an object.

add_schema(schema)

Merge in a JSON schema.

get(key[, default])

Implement the standard mapping getter.

items()

Return the pairs of key and mapped value.

keys()

Return the keys.

to_dict()

Generate a schema based on previous inputs.

to_json(*args, **kwargs)

Generate a schema and convert it directly to serialized JSON.

to_schema()

Generate a schema based on previous inputs.

values()

Return the values.

DEFAULT_URI = 'http://json-schema.org/schema#'
EXTRA_STRATEGIES = (<class 'gemseo.core.grammars.json_schema._MergeRequiredStrategy'>,)
NODE_CLASS

alias of genson.schema.builder.MutableMappingSchemaBuilderSchemaNode Attributes:

STRATEGIES

Methods:

add_object(obj)

Modify the schema to accommodate an object.

add_schema(schema)

Merges in an existing schema.

to_schema()

Convert the current schema to a dict.

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'>)
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(key, default=None)[source]

Implement the standard mapping getter.

Parameters
  • key – A key whose mapped value shall be returned.

  • default – The default value returned if the key is missing.

Returns

The value mapped to key if it exists, default otherwise.

items()[source]

Return the pairs of key and mapped value.

Returns

The pairs of key and mapped value.

keys()[source]

Return the keys.

Returns

The keys.

to_dict()

Generate a schema based on previous inputs.

Return type

dict

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()[source]

Return the values.

Returns

The values.