Description
Motivation
These keywords are defined in the JSON Schema 2020-12 dialect.
Release notes: https://json-schema.org/draft/2020-12/release-notes
These are useful for representing generics: https://json-schema.org/blog/posts/dynamicref-and-generics
Specification of dynamic scope rules: https://json-schema.org/draft/2020-12/json-schema-core#name-lexical-scope-and-dynamic-s
Proposed solution
Schemas containing $defs
generate types that include the defs as members. If the schemas contain $dynamicAnchor
, they create protocols with associated types instead of concrete types with type aliases. The schema of the dynamic-anchored types are used as the type constraint for the associated types.
Dynamic reference schemas (those containing the $dynamicRef
keyword) refer to associated types and may supply generic parameters using their own $defs
and $dynamicAnchor
keywords.
Alternatives considered
Avoid generating protocols / associated types, and instead always generate concrete types, treating dynamic refs/anchors as template instantiation.
Additional information
This would depend on support in OpenAPIKit. Upstream issue filed: mattpolzin/OpenAPIKit#359