Skip to content

Detect $dynamicRef in OpenAPI 3.0 documents (DynamicRefIn30 rule) - #203

Merged
geemus merged 4 commits into
ota42y:masterfrom
takayamaki:pr17-dynamic-ref
Aug 27, 2026
Merged

Detect $dynamicRef in OpenAPI 3.0 documents (DynamicRefIn30 rule)#203
geemus merged 4 commits into
ota42y:masterfrom
takayamaki:pr17-dynamic-ref

Conversation

@takayamaki

Copy link
Copy Markdown
Contributor

Continuing the OpenAPI 3.1 work from #152.

OpenAPI 3.1 adopts JSON Schema 2020-12, which brings the $dynamicRef referencing mechanism.
3.0 only knows $ref.

This PR adds detection of that version mismatch.
A 3.0 document using $dynamicRef is relying on a keyword its declared version does not define, and SpecValidator should be able to say so.

SpecValidator rule

DynamicRefIn30 reports a violation for each schema in a 3.0 document that uses $dynamicRef:

OpenAPIParser.load(
  'spec.yaml',
  strict_specification_version: :warn,
)
# [DynamicRefIn30] #/components/schemas/Node — `$dynamicRef` is a 3.1 addition (from JSON Schema 2020-12); 3.0 only knows `$ref`

Detection inspects raw_schema key presence,
so it fires regardless of whether the referenced anchor exists.

Scope

This PR does not make $dynamicRef resolvable.
$dynamicRef has to branch its reference dynamically while the schema is being evaluated, which likely means redesigning SchemaValidator in this gem.
Resolving it is a TODO beyond this series of PRs.

Parse layer keeps $dynamicRef as raw schema data; reference expansion
support is left for a follow-up. The rule reports the version mismatch
so 3.0 documents that smuggle the keyword in get flagged.
$dynamicRef on a 3.0 document warns and raises (JSON Schema 2020-12
dynamic referencing; 3.0 only knows $ref); the same keyword on a 3.1
document stays clean.
@takayamaki
takayamaki marked this pull request as ready for review August 19, 2026 17:53

@geemus geemus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@geemus
geemus merged commit f62003f into ota42y:master Aug 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants