fix: recurse into OpenAPI 3.1 fields in transformOpenAPIToJSONSchema#1121
Closed
reuvenharrison wants to merge 14 commits intogetkin:masterfrom
Closed
fix: recurse into OpenAPI 3.1 fields in transformOpenAPIToJSONSchema#1121reuvenharrison wants to merge 14 commits intogetkin:masterfrom
reuvenharrison wants to merge 14 commits intogetkin:masterfrom
Conversation
The implementation provides complete OpenAPI 3.1 specification compliance while maintaining 100% backward compatibility with OpenAPI 3.0. ## What Was Implemented ### 1. Schema Object Extensions (openapi3/schema.go) Added full JSON Schema 2020-12 support with new fields: - **`Const`** - Constant value validation - **`Examples`** - Array of examples (replaces singular `example`) - **`PrefixItems`** - Tuple validation for arrays - **`Contains`, `MinContains`, `MaxContains`** - Array containment validation - **`PatternProperties`** - Pattern-based property matching - **`DependentSchemas`** - Conditional schema dependencies - **`PropertyNames`** - Property name validation - **`UnevaluatedItems`, `UnevaluatedProperties`** - Unevaluated keyword support - **Type arrays** - Support for `["string", "null"]` notation ### 2. Document-Level Features (openapi3/openapi3.go) - **`Webhooks`** - New field for defining webhook callbacks (OpenAPI 3.1) - **`JSONSchemaDialect`** - Specifies default JSON Schema dialect - **Version detection methods**: - `IsOpenAPI3_0()` - Returns true for 3.0.x documents - `IsOpenAPI3_1()` - Returns true for 3.1.x documents - `Version()` - Returns major.minor version string ### 3. License Object (openapi3/license.go) - **`Identifier`** - SPDX license expression (alternative to URL) ### 4. Info Object (openapi3/info.go) - **`Summary`** - Short summary of the API (OpenAPI 3.1) ### 5. Types Helper Methods (openapi3/schema.go) New methods for working with type arrays: - `IncludesNull()` - Checks if null type is included - `IsMultiple()` - Detects type arrays (OpenAPI 3.1 feature) - `IsSingle()` - Checks for single type - `IsEmpty()` - Checks for unspecified types ### 6. JSON Schema 2020-12 Validator (openapi3/schema_jsonschema_validator.go) A new opt-in validator using [santhosh-tekuri/jsonschema/v6](https://github.com/santhosh-tekuri/jsonschema): - Full JSON Schema Draft 2020-12 compliance - Automatic OpenAPI → JSON Schema transformation - Converts OpenAPI 3.0 `nullable` to type arrays - Handles `exclusiveMinimum`/`exclusiveMaximum` conversion - Comprehensive error formatting - Fallback to built-in validator on compilation errors
…d formatting and correcting the version logic
The ResolveRefsIn function was not resolving $ref references inside webhooks, causing Schema.Value to be nil when a webhook operation referenced a component schema. This adds webhook ref resolution after the paths loop, using the same resolvePathItemRef function since webhooks contain PathItem objects. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
In OpenAPI 3.0 (JSON Schema draft-04), exclusiveMinimum/exclusiveMaximum are booleans that modify minimum/maximum values. In OpenAPI 3.1 (JSON Schema 2020-12), they are numbers representing the actual exclusive bounds. This change introduces ExclusiveBound type that can hold either: - Bool: for OpenAPI 3.0 style boolean modifier - Value: for OpenAPI 3.1 style numeric bound The validation and marshaling logic handles both formats correctly. Co-Authored-By: Claude Opus 4.5 <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>
40 tasks
Contributor
Author
|
Superseded by #1125 which consolidates all OpenAPI 3.1 PRs into a single PR. |
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
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
transformOpenAPIToJSONSchemato recurse into OpenAPI 3.1 / JSON Schema 2020-12 schema fieldsProblem
When using the JSON Schema 2020-12 validator (
EnableJSONSchema2020()), thetransformOpenAPIToJSONSchemafunction converts OpenAPI 3.0-isms (likenullable: true) into JSON Schema 2020-12 equivalents (like type arrays). However, it only recursed into pre-3.1 fields:properties,additionalProperties,items,notoneOf,anyOf,allOfSchemas nested inside OpenAPI 3.1 fields were not transformed, so an OpenAPI 3.0-style
nullable: trueinside e.g.prefixItemswould not be converted, causing incorrect validation results.Solution
Add recursion into all OpenAPI 3.1 / JSON Schema 2020-12 fields:
contains,propertyNames,unevaluatedItems,unevaluatedPropertiesprefixItemspatternProperties,dependentSchemasAlso consolidated the
propertiesmap iteration withpatternPropertiesanddependentSchemasinto a single loop to reduce duplication.Related
Follow-up to PR #1114 (OpenAPI 3.1 support).
Test plan
TestJSONSchema2020Validator_TransformRecursesInto31Fieldswith 7 sub-tests covering each field typenullable: truein a nested schema to verify the transform recurses correctly🤖 Generated with Claude Code