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] [spring] Type-less parameters in generated model method #20271

Open
5 of 6 tasks
flozano opened this issue Dec 8, 2024 · 1 comment
Open
5 of 6 tasks

Comments

@flozano
Copy link
Contributor

flozano commented Dec 8, 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

Generated models omit type in a method parameter:

> Task :compileJava FAILED
/Users/flozano/Projects/java/reproduce-openapi-issue/build/generated/src/main/java/io/github/flozano/openapireproduce/model/UserNew.java:102: error: <identifier> expected
  public UserNew putRoleItem(String key,  roleItem) {
                                                  ^
/Users/flozano/Projects/java/reproduce-openapi-issue/build/generated/src/main/java/io/github/flozano/openapireproduce/model/UserNew.java:150: error: <identifier> expected
  public UserNew putAlertMethodItem(String key,  alertMethodItem) {
                                                                ^
2 errors

full reproducer project in https://github.com/flozano/reproduce-openapi-spring-issue/

openapi-generator version

7.10.0

OpenAPI declaration file content or url

https://github.com/flozano/reproduce-openapi-spring-issue/blob/master/src/main/resources/swagger-testing.yaml

Generation Details

most simple gradle configuration possible:

plugins {
    id "org.openapi.generator" version "${openApiGeneratorVersion}"
    id 'java'
}

openApiGenerate {
    generatorName = "spring"
    inputSpec = "${project.projectDir}/src/main/resources/swagger-testing.yaml".toString()
    outputDir = "${project.buildDir}/generated".toString()
    skipOverwrite = false
}
Steps to reproduce

just run ./gradlew build in the reproducer project https://github.com/flozano/reproduce-openapi-spring-issue/

Incorrect output details

A method like this is generated in the model:

  private Object role;

// ...
  public UserNew putRoleItem(String key,  roleItem) {
    if (this.role == null) {
      this.role = new HashMap<>();
    }
    this.role.put(key, roleItem);
    return this;
  }

role is in a definition like this:

  Role:
    type: string
    enum:
      - admin
      - technician
      - observer

and used like this in the definition that generates the offending class:

      role:
        allOf:
          - description: if role is omitted, `"technician"` is used as default.
          - $ref: '#/definitions/Role'
@flozano flozano changed the title [BUG] [java] [spring] Type-less parameters in method [BUG] [java] [spring] Type-less parameters in generated model method Dec 8, 2024
@jpfinne
Copy link
Contributor

jpfinne commented Dec 14, 2024

There are some normalizers for the first element in an allOf.
Try putting the $ref up.

See also the normalizer options in https://openapi-generator.tech/docs/customization

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