Skip to content

[BUG][JAVA] Not specifying additionalProperties should generate the Map #20139

Open
@ncelerier

Description

@ncelerier

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Hello,

Regarding additionalProperties and the specification here: https://json-schema.org/understanding-json-schema/reference/object#additionalproperties, I think there might be a bug in the Java spring generator.

I'm not specifying the additionalProperties property and in this case, because of the specification mentioning:

By default any additional properties are allowed.

I would expect the JsonWebKey generated class to contain the Map<String, Object> additionalProperties (and get/put methods) to be generated. But it is not !

It seems the only way to generate this map is to use either:

additionalProperties: true

Or:

additionalProperties:
  type: string

Which I would like to avoid and shouldn't be necessary.

Am I missing something ?

Thank you for your help !

openapi-generator version

7.10.0 (current latest)
7.11.0-SNAPSHOT (2b891f6)

OpenAPI declaration file content or url

My src/main/resources/swagger/swagger.yaml file:

swagger: '2.0'
info:
  version: '1.0'
  title: FooBar
paths:
  /jwks:
    get:
      operationId: getJwks
      responses:
        200:
          description: "Success"
          schema:
            type: "array"
            items:
              $ref: "#/definitions/JsonWebKey"
definitions:
  JsonWebKey:
    title: JSON Web Key
    type: object
    properties:
      kid:
        type: string
    # No additionalProperties specified
Generation Details

I'm using this pom.xml:
https://gist.github.com/ncelerier/1729b37b6f9d37aefc8af33926fed07b

Steps to reproduce

Running mvn clean install, then looking at the generated file if the Map is generated or not:
target/generated-sources/openapi-server/src/main/java/com/example/models/JsonWebKey.java

Related issues/PRs
Suggest a fix

I can suggest something but I would like to know first if this is really a bug or if I am missing something.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions