[BUG][core] Normalize OAS 3.1 type: null map value (additionalProperties) under NORMALIZE_31SPEC - #23967
Conversation
should the normalizer simply remove this ? |
|
Yes, that is essentially the intent for the pure I chose that because there is no OAS 3.0 For the mixed
If you would prefer the pure-null case to remove |
|
thanks for the explanation please resolve the merge conflicts when you've time. |
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>
ed90132 to
6b8ab05
Compare
|
@wing328 Thanks! I've rebased onto the latest |
|
Friendly ping, @wing328. Following up on the rebase you requested — the branch is still |
|
did a test locally with java client generator and the result looks good: - private Map<String, ModelNull> stringMap = new HashMap<>();
+ private Map<String, Object> stringMap = new HashMap<>(); |
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 OAS 3.1 nullable map value schemas under
NORMALIZE_31SPECso generators stop emitting fictionalNull/ModelNulltypes and maps compile.additionalPropertiesistype: "null", rewrite to an any-type nullable schema.type: [array, "null"]→ nullable array) so the rewrite isn’t lost.NORMALIZE_31SPEC; default behavior unchanged.OpenAPINormalizerTest#testOpenAPINormalizer31SpecNullMapAdditionalPropertiesand3_1/issue_23945.yamlto cover both shapes.Written for commit 6b8ab05. Summary will update on new commits.