swagger-api / swagger-api/swagger-codegen
[Java] Wrong form parameters
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Something seems to have broken since version 3.0.20 with regards to form parameters because they are no longer generated as arguments to the api methods. Here is an example using petstore.yaml, comparing the java client SDK form method updatePetWithForm generated with version 3.0.20 to a java client SDK form method updatePetWithForm generated with the latest commit
/**
* Build call for updatePetWithForm
* @param petId ID of pet that needs to be updated (required)
- * @param name (optional)
- * @param status (optional)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
- public com.squareup.okhttp.Call updatePetWithFormCall(Long petId, String name, String status, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
+ public com.squareup.okhttp.Call updatePetWithFormCall(Long petId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
As you can see, the form variables name and status have been ignored.
The corresponding method in petstore.yaml file looks like this:
https://github.com/swagger-api/swagger-codegen/blob/3c955d7ce9055eb17084bbf0bec97d0c83c119af/modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml#L181-L208
Swagger-codegen version
I am using the latest version of swagger-codegen as of today
For the comparison diff above, I compared it to the homebrew swagger-codegen command line tool, which is version 3.0.20.
Steps to reproduce
It is quick and easy to reproduce by comparing to version 3.0.19 instead of comparing to version 3.0.20 (will have the same result)
After clone and building the 3.0.0 branch repo,
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml -o samples/client/petstore/java/okhttp-gson -l java
git diff samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java
This works because the latest version of PetApi.java in the repository is from version 3.0.19
Related issues/PRs
This PR #671 seems to fix this issue for typescript angular. A similar fix may be needed for java (and all it's respective libraries).
Edit: Upon further investigations, I believe the error actually lies somewhere in the transition from v1.0.20 to v1.0.21 in swagger-codegen-generators. I checked out the 3.0.20 version of this repo, and modified the pom.xml file here:
Changing from version 1.0.20 to 1.0.21-SNAPSHOT and this results in the form parameters error described above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Build the 3.0.0 branch and run the documented swagger-codegen-cli command against modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml. Compare the generated samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java with the repository version, then inspect the generator dependency change in pom.xml and the related generators transition. Done means generated Java form methods retain the name and status parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100