OpenAPITools / OpenAPITools/openapi-generator

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

Open
#20,139 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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 (2b891f6da9db9cf24fe0186f5635d550c958c657)

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/main/resources/swagger/swagger.yaml and reproduce with mvn clean install using the mentioned pom.xml. Inspect the Java Spring generator behavior for an object without additionalProperties, then check target/generated-sources/openapi-server/src/main/java/com/example/models/JsonWebKey.java; done means the generated class contains the additional-properties Map and its get/put methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.