JSON::Schema::Definitions
Inherits Reference < Object
Collects the definitions of the types referenced while introspecting.
Passing an instance as refs to json_schema or JSON::Schema.introspect emits
nested JSON::Serializable types and enums as $refs, instead of inlining them,
and builds each referenced type's definition once:
refs = JSON::Schema::Definitions.new
MyType.json_schema(refs: refs) # nested types are {"$ref": "#/$defs/Nested"}
refs.resolve # => {"Nested" => {type: "object", ...}}
Types are named by type, never by shape, so two enums with the same members remain distinct definitions.
Constructors
Class methods
converts a type name into a definition name, using only the characters that OpenAPI
allows in component names ([a-zA-Z0-9._-]).
The conversion is reversible, so distinct types never share a name. . and -
never appear in a type name, they encode its separators: :: is ., (, ), ,
and | are -o, -c, -n and -p, and any other character is -u followed by
its six digit hex code point.
normalise("Api::User") # => "Api.User"
normalise("Page(Api::User)") # => "Page-oApi.User-c"
Instance methods
registers the type, returning a reference to its definition
A description sits beside the $ref in JSON Schema 2020-12. OpenAPI 3.0 ignores
siblings of a $ref, so there the reference is wrapped in an allOf along with
nullable and the type of the definition (3.0.3 only applies nullable with a type)