Normalize¶
- ocdskit.normalize.convert_from_oas3(schema, *, get_only=False)[source]¶
Convert from OpenAPI Specification 3.0 to JSON Schema draft 4.
Warning
Modifies schema
$refvalues in-place.Limitations
Unsupported:
Schema Objects not under
#/components/schemasExternal
$refto Schema ObjectsAny
$refto Response ObjectsAny
$refto Path Item Objects
- ocdskit.normalize.remove_private_fields(value)¶
Remove
propertiesmembers that start with underscores.Warning
Assumes
propertiesis never a direct member of thepropertiesvalidation keyword.- Parameters:
value (dict) – a JSON schema
- ocdskit.normalize.remove_fields(schema, fields)[source]¶
Remove the given fields from the
propertiesmapping.Warning
Assumes
propertiesis never a direct member of thepropertiesvalidation keyword.
- ocdskit.normalize.remove_unreachable_definitions(schema, pattern)[source]¶
Remove any definitions that are unreachable from definitions whose names contain
pattern.Performs a breadth-first search from the root definitions, following
$refedges.
- ocdskit.normalize.fix_validation_errors(schema, normalizer=None)[source]¶
Fix validation errors in a JSON Schema.
Changes
anyOffrom an object to an array, deduplicating values based on their normalized form.Warning
Assumes
anyOfis never a direct member of thepropertiesvalidation keyword.- Parameters:
schema (dict) – a JSON schema
normalizer – a function that accepts a JSON Schema and returns a JSON Schema, with all structurally-irrelevant properties removed, for deduplication
- ocdskit.normalize.get_normal_schema(value, *, remove_nontype_keywords=False, remove_x_keywords=False, remove_fields=())[source]¶
Remove metadata and validation keywords,
x-*keywords and/or specific fields.Warning
Assumes
propertiesis never a direct member of thepropertiesvalidation keyword.
- ocdskit.normalize.hoist_deep_properties(schema, normalizer)[source]¶
Move any sub-schema with a
propertieskeyword to the definitions location.If neither
$defsnordefinitionsexists,$defsis used.The schema is named using its
titlekeyword, or its parent property.Warning
Assumes
propertiesis never a direct member of thepropertiesvalidation keyword.Limitations
The schema is named after an earlier ancestor if the parent property has the same name as an applicator keyword.
- Parameters:
schema (dict) – a JSON schema
normalizer – a function that accepts a JSON Schema and returns a JSON Schema, with all structurally-irrelevant properties removed
- ocdskit.normalize.normalize_schema(schema, normalizer, get_base_classes)[source]¶
Extract base classes from a schema’s definitions. Rewrite definitions to use
allOfinheritance.Hashes each
propertiesmember usingnormalizer, callsget_base_classes, then performs greedy set-cover to determine multiple inheritance for both base classes and original definitions.Warning
Modifies
schemain-place.Limitations
All
propertiesmappings must be at each definition’s top-level. Seehoist_deep_properties().- Parameters:
schema (dict) – a JSON schema
normalizer – a function that accepts a JSON Schema and returns a JSON Schema, with all structurally-irrelevant properties removed
get_base_classes –
a function that accepts the schema’s definitions as a mapping of definition names to sets of
{prop}:{hash}strings, and returns base classes as a list of dicts with the keys:nameThe name of the base class
membersA sequence of child classes
propsA set of
{prop}:{hash}strings