Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1831
Closed
Open
Issue created Jan 06, 2019 by Administrator@rootContributor

[BUG] Java codegen does not check classVarName against reserved keywords

Created by: spacether

Description

The java client codegen does not check the classVarName variables agains the reserved list of keywords. Because of this, when I built the java rest-assured client sample, it generated a class method with the name default, which is a reserved keyword in java. My CircleCI test failure is here: https://circleci.com/gh/OpenAPITools/openapi-generator/4075#tests/containers/1 Generated ApiClient.java code

    public DefaultApi default() {
        return DefaultApi.default(config.baseReqSpec.get());
    }

This is invalid Java code because default is a reserved keyword. Mustache file is here: modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/ApiClient.mustache

    public {{classname}} {{classVarName}}() {
        return {{classname}}.{{classVarName}}(config.baseReqSpec.get());
    }

Java clients DO know about reserved keywords per here: modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java

openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url

openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml

Command line used for generation

./bin/java-petstore-rest-assured.sh

Steps to reproduce

Generate the above java rest-assured client. Then run the circleCi tests for node 1 from: CI/circle_parallel.sh

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/13

Suggest a fix

Note: I see a hard-coded in naming fix in the google-api-client mustache file: modules/openapi-generator/src/main/resources/Java/libraries/google-api-client/ApiClient.mustache

    public {{classname}} {{classVarName}}Api() {
        return new {{classname}}(this);
    }

I will put in a hard coded fix, but adding a classVarName check against reserved keywords is a more robust way to fix this.

Assignee
Assign to
Time tracking