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] 7.1.0 generates broken APIs for models consisting only of additionalProperties #17258

Closed
bonii-xx opened this issue Nov 30, 2023 · 2 comments · Fixed by #17490
Closed

Comments

@bonii-xx
Copy link

Description

Updating the openapi-generator-maven-plugin to 7.1.0 breaks all APIs which use models consisting only of additionalProperties. It looks like model generation is skipped for those models, however the API still uses them, and they're also beneficial for the code in general since they serve as an anti-corruption layer.

openapi-generator version

7.1.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: bug
  version: 1.0.0

paths:
  /test:
    post:
      responses:
        default:
          description: dummy response
          content:
            application/json:
              schema:
                type: object
      requestBody:
        description: additional properties only
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TestRequestBody'
      operationId: getQuestionnaire

components:
  schemas:
    TestRequestBody:
      type: object
      description: A schema consisting only of additional properties
      additionalProperties: true
Generation Details
            <!-- OpenAPI code generators -->
            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.1.0</version>
                <executions>
                    <execution>
                        <id>test</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/openapi/openapi-bug.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <configOptions>
                                <library>spring-boot</library>
                                <interfaceOnly>true</interfaceOnly>
                                <serializableModel>true</serializableModel>
                                <useSpringBoot3>true</useSpringBoot3>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Generate the provided api-specification using the provided configuration.

The generator logs:

[INFO] Model TestRequestBody not generated since it's a free-form object

while the generated DefaultApi.java class uses:

default ResponseEntity<Object> getQuestionnaire(
        @Parameter(name = "TestRequestBody", description = "additional properties only") @Valid @RequestBody(required = false) TestRequestBody testRequestBody
    ) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

    }

which doesn't compile, since the TestRequestBody class wasn't generated.

Related issues/PRs
Suggest a fix

Don't skip generation of free-form objects. There's a reason why the api-specification uses a separate schema with title to define the model, instead of using an inline object.

@ignacioel
Copy link

Hi,
I facing same issue after updating to 7.1.0.
I think I have tracked the specific change to this PR: #16613

@martin-mfg
Copy link
Contributor

Hi @ignacioel, thanks for taking the time to track down the relevant commit for this issue.

wing328 pushed a commit that referenced this issue Jan 5, 2024
* fix  #16797 and #15796 spring child constructor missing parent params

* root cause and update the DefaultCodegen.java to add missing property when with multi inheritance

* rollback SpringCodegen.java

* update samples

* rollback with master cause #16992 fixed this issue too

* still using orignal design

* catchup master

* catchup master

* catchup master

* fix

* add tests

---------

Co-authored-by: dabdirb <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants