apple / apple/swift-openapi-generator

Support `$dynamicAnchor` and `$dynamicRef`

Open
#547 19 comments 0 reactions 0 assignees View on GitHub
kind/feature status/blocked status/needs-design
Dominant language
Swift
Stars
2k
Forks
182
Avg merge
13h 28m
Merged PRs (30d)
5

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: https://github.com/mattpolzin/OpenAPIKit/issues/359

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the JSON Schema 2020-12 dynamic scope specification and the linked OpenAPIKit issue #359, since the proposed implementation depends on upstream support. Done means schemas using $dynamicAnchor and $dynamicRef generate the described protocols, associated types, and dynamic references in Swift.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, swift
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.