swagger-api / swagger-api/swagger-codegen

[JAVA] "accept" parameter conflicts with internal "accept" variable during generated APIs...

Open
#11,888 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Thanks for this time saving library :)
I was using it to generate some Java code from a Json Schema and it works, but it fails generating an API object, because of a conflict between a parameter and an internal variable. They are both named as accept.
Here the code snippet:

    public ResponseEntity<TermsAndConditionsResponse> termsAndConditionsUsingPOSTWithHttpInfo(OrderData body, String accept) throws RestClientException {
        Object postBody = body;
        // verify the required parameter 'body' is set
        if (body == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling termsAndConditionsUsingPOST");
        }
        // verify the required parameter 'accept' is set
        if (accept == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'accept' when calling termsAndConditionsUsingPOST");
        }
        String path = UriComponentsBuilder.fromPath("/rs/api/v1/termsAndConditions").build().toUriString();
        
        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
        if (accept != null)
            headerParams.add("Accept", apiClient.parameterToString(accept));

        final String[] accepts = { 
            "text/html;charset&#x3D;UTF-8", "text/plain"
         };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { 
            "application/json"
         };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] {  };

        ParameterizedTypeReference<TermsAndConditionsResponse> returnType = new ParameterizedTypeReference<TermsAndConditionsResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
Swagger-codegen version

3.0.35
It happens also with previous versions.

Swagger declaration file content or url

Here the URL

Command line used for generation

Used the maven plugin with this configuration:

        <plugin>
                <groupId>io.swagger.codegen.v3</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>3.0.35</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/api-docs.json</inputSpec>
                            <language>java</language>
                            <library>resttemplate</library>
                            <apiPackage>com.lastminute.rsimoni.flightcatalog</apiPackage>
                            <modelPackage>com.lastminute.rsimoni.flightcatalog.model</modelPackage>
                            <invokerPackage>com.lastminute.rsimoni.flightcatalog.handler</invokerPackage>
                            <generateApis>true</generateApis>
                            <generateApiTests>false</generateApiTests>
                            <generateApiDocumentation>false</generateApiDocumentation>
                            <generateModelTests>false</generateModelTests>
                            <generateModelDocumentation>false</generateModelDocumentation>
                            <generateSupportingFiles>true</generateSupportingFiles>
                            <configOptions>
                                <interfaceOnly>true</interfaceOnly>
                                <dateLibrary>java8</dateLibrary>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Simply running the plugin

Related issues/PRs

I searched similar issue, but didn't find anything

Suggest a fix/enhancement

Probably a check for conflicting names? But I didn't check the code...

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

Reproduce the failure by running the Maven plugin with the supplied OpenAPI URL and Java/resttemplate configuration. Inspect the generated Java API method where the parameter and internal variable are both named accept; done means generation completes with compilable Java code and no duplicate local name.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.