Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
4 of 6 tasks
ncelerier opened this issue Nov 19, 2024 · 4 comments
Open
4 of 6 tasks

Comments

@ncelerier
Copy link

ncelerier commented Nov 19, 2024

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.

@wing328
Copy link
Member

wing328 commented Nov 21, 2024

did you try setting disallowAdditionalPropertiesIfNotPresent to false? (e.g. --additional-properties disallowAdditionalPropertiesIfNotPresent=false in CLI)

https://openapi-generator.tech/docs/generators/java/

@ncelerier
Copy link
Author

Hi @wing328, I have this property in the pom.xml :

<configOptions>
  <disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
</configOptions>

Could it be that it is not taken into account ?

@wing328
Copy link
Member

wing328 commented Nov 21, 2024

I think there might be a bug in the Java spring generator.

Ah. I can only assure this option works for java client generator (jersey2, jersey3, okhttp-gson) but not the spring generator. Sorry.

One way to check is to remove the option or set the option to true to see if there's any change in the output

@ncelerier
Copy link
Author

For the java client generator, I tried with this and indeed the Map is generated:

<generatorName>java</generatorName>
<configOptions>
  <disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
</configOptions>

However, if I set additionalProperties: false in my schema, the Map is still generated whereas it shouldn't.

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

No branches or pull requests

2 participants