user3310115
user3310115

Reputation: 1460

how to generate getter on boolean using swagger-codegen-maven plugin

I'm using swagger-codegen-maven(3.0.29) plugin to generate code. However, I see that boolean is generated with isXXX instead of getXXX. Is there a way to generate getXXX.

swagger code

 Data:
    required:
      - id
    properties:
      verified:
        description: >-
          Id
        example: true
        pattern: ^true|false$
        type: boolean

generated code

  @NotNull
  @Schema(example = "true", required = true)
  public Boolean isVerified() {
    return verified;
  }

  public void setVerified(Boolean verified) {
    this.verified = verified;
  }

}

Upvotes: 1

Views: 4031

Answers (2)

padisah
padisah

Reputation: 41

The author of the question asked a solution for "swagger-codegen-maven" which is not the openAPI generator. Actually, the openAPI variation for code generation fixed this specific issue, while swagger codegen still did not:

https://github.com/swagger-api/swagger-codegen-generators/pull/599

I used a shell script command on the generated files:

sed -i'' -e 's/Boolean is/Boolean get/g' $(find generated-sources/src/main/java/com/company//module/openapi/ -type f)

Upvotes: 0

André
André

Reputation: 60

According to their github issues, that enhancement is available on 3.1.x of OpenAPI-generator and that will have to be implemented on swagger-codegen-maven which currently seems to be not implemented.

Version 3.1.0 is the first minor version of OpenAPI-Generator, in comparison to 3.0.3 it contains some breaking changes, but with the possibility to fallback to the old behavior. The default value of some options might change. Projects relying on generated code might need to be adapted.

Please, check out the issues.

  1. https://github.com/swagger-api/swagger-codegen/issues/7764
  2. https://github.com/OpenAPITools/openapi-generator/pull/432
  3. https://github.com/jmini/openapi-generator/blob/6fca5f5aa0d863fbe9ec013448c5f4f24206397d/docs/migration-guide.adoc

Upvotes: 1

Related Questions