Skip to content

[Java][Feign] Fix a bug in API template using paramName#8800

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
nitschy:patch-1
Feb 27, 2021
Merged

[Java][Feign] Fix a bug in API template using paramName#8800
wing328 merged 1 commit intoOpenAPITools:masterfrom
nitschy:patch-1

Conversation

@nitschy
Copy link
Copy Markdown
Contributor

@nitschy nitschy commented Feb 22, 2021

When a GET/PUT/POST operations includes queryParams, then the feign generator wrongly generates the Basename instead of the paramName. That leads to
a java.illegalstateException ("Body parameters cannot be used with form parameters") in Feign Contract when attempting to invoke the Method.
i.e: a generated feign client:
public interface PersonClientTest extends RestApi {
@RequestLine("GET /personen/{kundenNummer}?mitUnterstruktur={mitUnterstruktur}")
@headers({
"Accept: application/json",
"If-None-Match: {ifNoneMatch}"
})
PersonOut getPersonByKundenNummer(@param(value="kundenNummer", expander=ParamExpander.class) String kundenNummer, @param(value="If-None-Match", expander=ParamExpander.class) String ifNoneMatch, @param(value="mitUnterstruktur", expander=ParamExpander.class) Boolean mitUnterstruktur);
}

in the headers:
"If-None-Match: {ifNoneMatch}"
but in the method:
@param(value="If-None-Match", expander=ParamExpander.class) String ifNoneMatch
the value should be ifNoneMatch instead of "If-None-Match"

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

When a GET/PUT/POST operations includes queryParams, then the feign generator wrongly generates the Basename instead of the paramName. That leads to
a java.illegalstateException ("Body parameters cannot be used with form parameters") in Feign Contract when attempting to invoke the Method.
i.e: a generated feign client:
public interface PersonClientTest extends RestApi {
    @RequestLine("GET /personen/{kundenNummer}?mitUnterstruktur={mitUnterstruktur}")
    @headers({
            "Accept: application/json",
            "If-None-Match: {ifNoneMatch}"
    })
    PersonOut getPersonByKundenNummer(@param(value="kundenNummer", expander=ParamExpander.class) String kundenNummer, @param(value="If-None-Match", expander=ParamExpander.class) String ifNoneMatch, @param(value="mitUnterstruktur", expander=ParamExpander.class) Boolean mitUnterstruktur);
}

in the headers:
 "If-None-Match: {ifNoneMatch}"
but in the method:
 @param(value="If-None-Match", expander=ParamExpander.class) String ifNoneMatch
the value should be ifNoneMatch instead of "If-None-Match"
@nitschy nitschy changed the title FIX: Error in mustache.api FIX: [Java Feign Generator]- Error in mustache.api Feb 22, 2021
@nitschy nitschy changed the title FIX: [Java Feign Generator]- Error in mustache.api FIX: [Java Feign Generator]- Error in api.mustache template Feb 23, 2021
@Zomzog
Copy link
Copy Markdown
Contributor

Zomzog commented Feb 24, 2021

Hi,
I reproduce the behavior with this OAS and Feign generator with legacy dates:

paths:
  /ponies:
    get:
      summary: List all ponies
      operationId: ListAll
      parameters:
        - schema:
            type: string
          in: query
          name: pony-type
      responses:
        '200':
          description: All ponies
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pony'

LGTM

@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 27, 2021

@nitschy thanks for the PR.

@Zomzog thanks for reviewing the change.

PR merged.

@wing328 wing328 merged commit a8b74d1 into OpenAPITools:master Feb 27, 2021
@wing328 wing328 changed the title FIX: [Java Feign Generator]- Error in api.mustache template [Java Feign Generator]- Error in api.mustache template Feb 27, 2021
@wing328 wing328 changed the title [Java Feign Generator]- Error in api.mustache template [Java][Feign] Error in api.mustache template Feb 27, 2021
@wing328 wing328 changed the title [Java][Feign] Error in api.mustache template [Java][Feign] Fix a bug in api.mustache template Feb 27, 2021
@wing328 wing328 changed the title [Java][Feign] Fix a bug in api.mustache template [Java][Feign] Fix a bug in API template using paramName Feb 27, 2021
@nitschy nitschy deleted the patch-1 branch March 1, 2021 12:50
@wing328
Copy link
Copy Markdown
Member

wing328 commented Mar 22, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants