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][jaxrs-cxf] Option disallowAdditionalPropertiesIfNotPresent has no effect #10645

Open
5 of 6 tasks
ssiegler opened this issue Oct 20, 2021 · 3 comments
Open
5 of 6 tasks

Comments

@ssiegler
Copy link

ssiegler commented Oct 20, 2021

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

When setting disallowAdditionalPropertiesIfNotPresent to false, the generator should add support for additional properties to model classes for schemas that have no additionalProperties attribute. This is explicitly stated in the documentation of the generator:

If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.

Instead, the generated code is the same, independent of the value for disallowAdditionalPropertiesIfNotPresent.

openapi-generator version

5.2.1

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  version: "v1"
  title: Example
paths: {}
components:
  schemas:
    Example:
      type: object
      properties:
        a:
          type: integer
Generation Details
openapi-generator-cli generate \
-i openapi.yaml \
--additional-properties=disallowAdditionalPropertiesIfNotPresent=false \
-g jaxrs-cxf \
-o output
Steps to reproduce
  1. Generate Code from the example above with the cli command.
  2. Check the generated file src/gen/java/org/openapitools/model/Example.java in the output path

Expected result: The class supports additional properties. As described in #1466 this means it extends from HashMap
Actual result: The class has no support for additional properties.

Related issues/PRs

A similar issue was mentioned in #10306.

Without a fix for #1466 this might be less helpful, as the generated Code will not work as expected.

Suggest a fix

When checking for additionalProperties, the flag disallowAdditionalPropertiesIfNotPresent needs to be considered. Maybe ModelUtils#isMapSchema should return true in this case, as it does when additionalProperties is set explicitly.

@MargieMo
Copy link

MargieMo commented Dec 4, 2021

Do you try:

openapi: 3.0.3
info:
version: "v1"
title: Example
paths: {}
components:
schemas:
Example:
type: object
properties:
a:
type: integer
additionalProperties: true

@MargieMo
Copy link

MargieMo commented Dec 4, 2021

openapi: 3.0.3
info:
  version: "v1"
  title: Example
paths: {}
components:
  schemas:
    Example:
      type: object
      properties:
        a:
          type: integer
          additionalProperties: true

@askuri
Copy link

askuri commented Sep 20, 2023

Our workaround is to set additionalModelTypeAnnotations in configOptions to @com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true). If you're using Maven, you'll find it in your pom.xml.

Source: this comment on a related issue: #11776 (comment)

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

3 participants