-
-
Notifications
You must be signed in to change notification settings - Fork 489
feat: add OpenAPI 3.1 support #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
reuvenharrison
wants to merge
13
commits into
getkin:master
Choose a base branch
from
oasdiff:feat/openapi-3.1-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+4,071
−104
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add comprehensive OpenAPI 3.1 / JSON Schema 2020-12 support: - Type arrays with null support (e.g., ["string", "null"]) - JSON Schema 2020-12 keywords: const, examples, prefixItems, contains, minContains, maxContains, patternProperties, dependentSchemas, propertyNames, unevaluatedItems, unevaluatedProperties - Conditional keywords: if/then/else, dependentRequired - ExclusiveBound union type for 3.0 (boolean) and 3.1 (numeric) exclusive bounds - Webhooks support with $ref resolution - Version detection helpers: IsOpenAPI3_0(), IsOpenAPI3_1() - Info.Summary and License.Identifier fields - JSON Schema 2020-12 validator via EnableJSONSchema2020() - Document-level validation option: EnableJSONSchema2020Validation() - Allow $ref alongside other keywords in 3.1 schemas - Handle "null" type in schema validation - Auto-detect 3.1 in cmd/validate Co-Authored-By: Chance Kirsch <> Co-Authored-By: RobbertDM <> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…, etc.) The loader's resolveSchemaRef only resolved $ref in pre-3.1 fields (items, properties, additionalProperties, not, allOf, anyOf, oneOf). References inside the new OpenAPI 3.1 / JSON Schema 2020-12 fields were silently left unresolved, causing nil Value pointers. This adds ref resolution for: prefixItems, contains, patternProperties, dependentSchemas, propertyNames, unevaluatedItems, unevaluatedProperties. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The OpenAPI-to-JSON-Schema transformation only recursed into pre-3.1 fields (properties, additionalProperties, items, not, oneOf, anyOf, allOf). Nested schemas inside 3.1 fields with OpenAPI 3.0-isms like nullable:true were not converted, causing incorrect validation. This adds recursion into: prefixItems, contains, patternProperties, dependentSchemas, propertyNames, unevaluatedItems, unevaluatedProperties. Also consolidates the properties/patternProperties/dependentSchemas map iteration into a single loop. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Schema.Validate() (used by doc.Validate()) recursively validates sub-schemas in Items, Properties, AdditionalProperties, etc. but did not recurse into the new OpenAPI 3.1 / JSON Schema 2020-12 fields. Invalid sub-schemas nested inside these fields went undetected. This adds validation for: prefixItems, contains, patternProperties, dependentSchemas, propertyNames, unevaluatedItems, unevaluatedProperties. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 9, 2026
- Make paths optional in 3.1 (required only in 3.0) - Add mutualTLS security scheme type validation - Validate license url/identifier mutual exclusivity - Enable JSON Schema 2020-12 validation in openapi3filter for 3.1 docs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add $id, $anchor, $dynamicRef, $dynamicAnchor identity keywords - Add contentMediaType, contentEncoding, contentSchema vocabulary - Add discriminator support for anyOf (was only oneOf) - Validate jsonSchemaDialect as valid URI Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4 tasks
- IsEmpty(): add missing checks for PrefixItems, Contains, MinContains, MaxContains, PatternProperties, DependentSchemas, PropertyNames, UnevaluatedItems, UnevaluatedProperties, Examples - JSONLookup(): add all 23 missing JSON Schema 2020-12 field cases - validate(): relax items requirement for arrays when in 3.1 mode or when prefixItems is present - transformOpenAPIToJSONSchema: clean up exclusiveMinimum/Maximum false, handle nullable:true without type field - MarshalYAML: only emit paths when non-nil (valid in 3.1) - visitConstOperation: use reflect.DeepEqual for json.Number comparison - Webhooks validation: use componentNames() for deterministic ordering Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rephrase text to not contain literal json struct tag syntax that triggers the json/yaml tag consistency check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Open issues are tracked in the PR getkin#1125 description instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add $comment keyword to Schema struct (MarshalYAML, UnmarshalJSON, IsEmpty, JSONLookup) - Fix PrefixItems type from []*SchemaRef to SchemaRefs for consistency with OneOf/AnyOf/AllOf and JSON Pointer support - Fix exclusiveBoundToBool data loss: preserve numeric bound value when converting OAS 3.1 exclusive bounds to OAS 2.0 - Auto-enable JSON Schema 2020-12 validation for OpenAPI 3.1 documents in doc.Validate() so library users don't need explicit opt-in - Add ref resolution tests for if/then/else and contentSchema - Add transform test for contentSchema with nullable nested schema - Add validate test for contentSchema with invalid sub-schema - Document breaking API changes in README (ExclusiveBound, PrefixItems) - Regenerate docs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add $schema keyword to Schema struct for per-schema dialect declaration - Add $defs keyword (Schemas map) for local reusable schema definitions, with full support: struct, marshal, unmarshal, IsEmpty, JSONLookup, validate (recurse), loader (resolve refs), transform (recurse) - Fix jsonSchemaDialect URI validation to require a scheme - Refactor discriminator resolution into shared helper to eliminate code duplication between oneOf and anyOf paths - Regenerate docs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Open Issues Status Update22 of 30 issues resolved across commits 9–11. Resolved issues (22)Bugs / correctness (11 fixed)
Missing features (3 added)
Code quality (2 fixed)
Breaking API changes (2 documented)
Test coverage (4 added)
Remaining open issues (8)These are larger-scope items for follow-up PRs:
|
Contributor
Author
Coverage vs Pierre Fenoll's Task ListAssessment of this PR against the tasks outlined by Pierre for complete OpenAPI 3.1 support:
What this PR delivers (~60-70% of the full task list)
Remaining items for follow-up PRs
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Comprehensive OpenAPI 3.1 / JSON Schema 2020-12 support. This consolidates and supersedes PRs #1102, #1114, #1118–#1124.
Core features
["string", "null"])const,examples,prefixItems,contains,minContains,maxContains,patternProperties,dependentSchemas,propertyNames,unevaluatedItems,unevaluatedPropertiesif/then/else,dependentRequired$id,$anchor,$dynamicRef,$dynamicAnchorcontentMediaType,contentEncoding,contentSchema$schema,$comment,$defs$refresolutionIsOpenAPI3_0(),IsOpenAPI3_1()Validation
EnableJSONSchema2020()(per-field) andEnableJSONSchema2020Validation()(document-level)doc.Validate()automatically enables JSON Schema 2020-12 mode for OpenAPI 3.1 documentsconstkeyword enforcement,IsEmpty()awareness of all new fields$refresolution in loader for all new schema fields (including$defs)$defs)$refalongside other keywords (legal in 3.1)"null"type in schema validationBackward compatibility
ExclusiveBoundtransparently handles both boolean and numeric formsopenapi2convupdated to convert betweenExclusiveBoundand boolean, preserving numeric bound valuesCommit history
Open issues for complete 3.1 support
The following items are known gaps that can be addressed in follow-up PRs:
Missing features
— Added per-schema dialect declaration.$schemakeyword— Added with full support (struct, marshal, unmarshal, IsEmpty, JSONLookup, validate, loader, transform).$defskeyword— Added as first-class field.$commentkeyword$dynamicRef/$dynamicAnchornot resolved — Parsed and serialized but the loader does not resolve them. Schemas using$dynamicReffor recursive references will not work.const. Other 3.1 keywords are silently ignored withoutEnableJSONSchema2020().contentMediaType/contentEncodingnot validated at runtime — Spec-compliant (annotation-only in 2020-12), but some users may expect validation.pathItemsin Components struct — OAS 3.1 addedcomponents/pathItems. Completely absent — silently dropped during parsing.Bugs / correctness
— All fields added.Schema.JSONLookup()missing all new 3.1 fields— All fields added.IsEmpty()missing checks for most new 3.1 fields— Relaxed.validate()requiresitemsfor typearrayeven in 3.1— Fixed.transformOpenAPIToJSONSchemadoes not clean upexclusiveMinimum: false— Fixed.transformOpenAPIToJSONSchemadropsnullable: truewithouttype— Fixed.MarshalYAMLunconditionally emits"paths": nullfor 3.1 docs— Fixed.visitConstOperationuses==forjson.NumberWebhooks validation iterates non-deterministically— Fixed.— Fixed.exclusiveBoundToBoolloses constraint data— Fixed.doc.Validate()does not auto-enable 3.1 mode— Now requires scheme.jsonSchemaDialectURI validation is a no-opitemsto ALL array elements, ignoringprefixItems— In 3.1,itemsapplies only beyond theprefixItemstuple.patternPropertiesomission changesadditionalPropertiessemantics —additionalProperties: falseincorrectly rejects properties matching pattern properties.visitJSONWithJSONSchema— Silently falls back to built-in validator when JSON Schema compilation fails.Const: nilcannot express "value must be null" — Gonilis the zero value forany.Breaking API changes
— Documented in README.ExclusiveMin/ExclusiveMaxtype changed— Documented in README.PrefixItemstype changedCode quality
— Changed toPrefixItemstype inconsistencySchemaRefs.Discriminator logic duplicated for— Refactored intoanyOfresolveDiscriminatorRefhelper.Test coverage
No ref resolution test for— Added.ContentSchemaNo ref resolution test for— Added.If/Then/ElseNo— Added.transformOpenAPIToJSONSchematest forContentSchemaNo— Added.Schema.validate()test forContentSchemaTest plan
go test ./...)Supersedes
Closes #1102, closes #1114, closes #1118, closes #1119, closes #1120, closes #1121, closes #1122, closes #1123, closes #1124
🤖 Generated with Claude Code
Co-Authored-By: Chance Kirsch <>
Co-Authored-By: RobbertDM <>