[BUG][core] Normalize OAS 3.1 type: null map value (additionalProperties) under NORMALIZE_31SPEC#23967
Open
seonwooj0810 wants to merge 1 commit into
Conversation
A nullable map whose `additionalProperties` value schema is `type: "null"` (or `type: [array, "null"]`) was not normalized to a usable OAS 3.0 value type. Generators emitted a fictional `Null` / `ModelNull` value type that fails to compile (e.g. `Map<String, ModelNull>` with no `ModelNull` model). A pure `type: "null"` value schema is short-circuited by `ModelUtils.isNullTypeSchema` before normalization, so it kept its OAS 3.1 null type. A `type: [array, "null"]` value was converted to a new array schema whose result was then discarded by the map branch. When NORMALIZE_31SPEC is enabled, rewrite a pure-null map value to an any-type nullable schema and capture the normalized value schema for the array case. Behavior is unchanged unless NORMALIZE_31SPEC is enabled. Fixes OpenAPITools#23945 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
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.
Fixes #23945
Problem
With
--openapi-normalizer NORMALIZE_31SPEC=true, a nullable map whoseadditionalPropertiesvalue schema still contains JSON Schemanullwas not normalized to a usable OAS 3.0 value type. Generators emitted a fictionalNull/ModelNullvalue type that fails to compile, e.g.Map<String, ModelNull>(Java) with noModelNullmodel generated,Dictionary<string, Null>(csharp, CS0246), etc.Two value-schema shapes from the report:
Root cause
In
OpenAPINormalizer#normalizeSchema, the map branch recurses intoadditionalPropertiesbut:type: "null"value schema is short-circuited byModelUtils.isNullTypeSchema(...)at the top ofnormalizeSchemaand returned unchanged, so it keeps its OAS 3.1nulltype.type: [array, "null"]value schema is converted byprocessNormalize31Specinto a newArraySchema, but the map branch discarded the return value (normalizeSchema(...)was called without reassigningadditionalProperties), leaving the value half-converted.This is the remaining gap after #22056 (which covered
additionalProperties: falseon closed objects, not nullable map values).Fix
In the map branch, when
NORMALIZE_31SPECis enabled:additionalPropertiesvalue to an any-type nullable schema, so the map value generates as a normal (nullable) object; and[array, "null"]rewrite is not lost).The change is fully gated behind
NORMALIZE_31SPEC; behavior is unchanged when the rule is off. No committed sample config usesNORMALIZE_31SPEC, so no generated samples change.Test evidence
Added
OpenAPINormalizerTest#testOpenAPINormalizer31SpecNullMapAdditionalProperties(specsrc/test/resources/3_1/issue_23945.yaml) asserting thestringMapvalue loses itsnulltype (becomes any-type nullable) and theerrorsByKeyvalue becomes a nullable array.Verification done: (1) confirmed no in-flight PR (
gh pr listsearch for NORMALIZE_31SPEC/23945 returned none); (2) no self-claim — issue has 0 comments; (3) code-only change to.java+ test; (4) reproduced the bug on master with a failing assertion before the fix (stringMapvalue stayedtypes=[null],errorsByKeyvalue stayedtype=null/types=[array]); (5) fullOpenAPINormalizerTest(61 tests) green.🤖 Generated with Claude Code
Summary by cubic
Fixes normalization of nullable map values in OAS 3.1 under
NORMALIZE_31SPECso generators no longer emit fictionalNull/ModelNulltypes and maps compile correctly.OpenAPINormalizer#normalizeSchema, whenadditionalPropertiesistype: "null", rewrite to an any-type nullable schema.type: [array, "null"]so it becomes a nullable array.NORMALIZE_31SPEC; default behavior unchanged.OpenAPINormalizerTest#testOpenAPINormalizer31SpecNullMapAdditionalPropertiesand3_1/issue_23945.yamlto cover both shapes.Written for commit ed90132. Summary will update on new commits.