Skip to content

[BUG][core] OAS 3.1 normalizer makes any-type map values (additionalProperties: {} / true) nullable #25811

Backlog

Description

@Robuske

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Since #23967 (7.24.0), OpenAPINormalizer rewrites additionalProperties to a nullable any-type schema whenever ModelUtils.isNullTypeSchema matches. That helper also matches a type-less 3.1 schema ({} or true), so a map of "any value" becomes a map of "nullable any value". Generators then emit optional map values.

Actual: additionalProperties: {} and additionalProperties: true come out as {nullable: true}. With swift6 the map becomes [String: JSONValue?], and with kotlin Map<String, JsonElement?>.

Expected: {} and true stay non-nullable any-type, as before 7.24.0. Only an explicit type: "null" should become nullable any-type, which is what #23945 asked for.

openapi-generator version

7.24.0 and later (verified on 7.27.0 and master). 7.22.0 is not affected, so this is a regression.

OpenAPI declaration file content or url
openapi: 3.1.1
info: {title: Repro, version: 1.0.0}
paths: {}
components:
  schemas:
    Maps:
      type: object
      properties:
        a: {type: object, additionalProperties: {}}
        b: {type: object, additionalProperties: true}
Generation Details

NORMALIZE_31SPEC is enabled automatically for OAS 3.1 specs, so no extra options are needed.

Steps to reproduce

Run openapi-generator-cli generate -g openapi-yaml -i spec.yaml -o out. Both a and b come out with additionalProperties: {nullable: true}.

Related issues/PRs

#23945, #23967

Suggest a fix

Only rewrite when the map value schema explicitly declares the null type. PR to follow.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions