-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
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
If an enum request parameter with a default value is specified as a separate model (see TestParameter1 in the provided gist) then generated spring code doesn't have this default value. If it's specified right away (like with TestParameter2) then it works as expected.
openapi-generator version
v5.2.1
OpenAPI declaration file content or URL
https://gist.github.com/MikhailovNikita/fb4aa00211146b0faf082e9d95ff09c1
Generation Details
I generate code in a way that is specified in readme here. For example:
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
git checkout 5.2.x
mvn clean package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i ~/petstore-test.yml \
-g spring \
-o /var/tmp/petstore_spring
petstore-test.yml is provided as a gist.
Let me know If any more details are required.
Steps to reproduce
Generate code like described in the previous step. Check org.openapitools.api.GetApi java class.
Actual result:
Get method signature is generated as:
default ResponseEntity<Void> getPet(@ApiParam(value = "Type of token ", allowableValues = "FOO, BAR") @Valid @RequestParam(value = "testParameter1", required = false) TestParameter1 testParameter1,@ApiParam(value = "", allowableValues = "FOO, BAR", defaultValue = "BAR") @Valid @RequestParam(value = "TestParameter2", required = false, defaultValue="BAR") String testParameter2)
As you can see there is a defaultValue parameter specified for testParameter2, but not for testParameter1.
The same happens if code is generated using the current master branch.
Expected result:
However, if I generate it using the v4.3.1 generator (change the checkout to git checkout v4.3.1 step in generation details) this method has the following signature:
default ResponseEntity<Void> getPet(@ApiParam(value = "Type of token ", allowableValues = "FOO, BAR", defaultValue = "BAR") @Valid @RequestParam(value = "testParameter1", required = false, defaultValue="BAR") TestParameter1 testParameter1,@ApiParam(value = "", allowableValues = "FOO, BAR", defaultValue = "BAR") @Valid @RequestParam(value = "TestParameter2", required = false, defaultValue="BAR") String testParameter2)
Now both testParameter1 and testParameter2 have default values specified, that's why I assume this is a bug.