OpenAPITools / OpenAPITools/openapi-generator

[BUG] [java] [spring] Type-less parameters in generated model method

Open
#20,271 1 comment 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

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'

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

Run ./gradlew build in the linked reproducer and inspect src/main/resources/swagger-testing.yaml alongside the generated UserNew.java output. Trace the Spring generator's model-method parameter handling for the allOf Role definition; done means the generated methods include valid Java parameter types and the project compiles successfully.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.