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
  • #11579
Closed
Open
Issue created Feb 11, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] Java RestTemplate Mustache template doesn't use reserved words for local variables

Created by: amra

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

Java generator defines list reserved words, part of them are for local variables. These are not used for java resttemplate. And local variable name can collide with parameter name (as it happened in my case). Code will not compile because of it.

Examples:

resttemplate snippet from openapi-generator\Java\libraries\resttemplate\api.mustache (with wrong local variable name):

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();{{#hasQueryParams}}

resteasy snippet from openapi-generator\Java\libraries\resteasy\api.mustache (with local variable name using reserved word):

    {{javaUtilPrefix}}List<Pair> localVarQueryParams = new {{javaUtilPrefix}}ArrayList<Pair>();
    {{javaUtilPrefix}}Map<String, String> localVarHeaderParams = new {{javaUtilPrefix}}HashMap<String, String>();
    {{javaUtilPrefix}}Map<String, String> localVarCookieParams = new {{javaUtilPrefix}}HashMap<String, String>();
    {{javaUtilPrefix}}Map<String, Object> localVarFormParams = new {{javaUtilPrefix}}HashMap<String, Object>();
openapi-generator version

5.4

OpenAPI declaration file content or url
inputSpec: spec/openapi.json
generatorName: java
library: resttemplate
outputDir: generated
java8: true

invokerPackage: com.project.client
modelPackage: com.project.model
apiPackage: com.project.api
groupId: com.api
artifactId: project
artifactVersion: 1.0-SNAPSHOT
Generation Details

./bin/openapi-generator-cli generate --config opslog.yaml

Steps to reproduce
  1. Create a openapi.json spec, where a parameter name will be queryParams.
  2. Generate code using java resttemplate.
  3. Code will not compile because method parameter name collide with local variable name.

Example:

        "/api/v1/project/commands": {
            "put": {
                "operationId": "commands",
                "parameters": [
                    {
                        "in": "query",
                        "name": "queryParams",
                        "required": true,
                        "schema": {
                            "$ref": "#/components/schemas/ProjectCommonQueryParameters"
                        }
                    }
                ],
Related issues/PRs
Suggest a fix

Use reserved names local* for local variables for resttemplate as it's used for other libraries, e.g. resteasy.

List of reserved words for java: https://openapi-generator.tech/docs/generators/java#reserved-words

Assignee
Assign to
Time tracking