Created by: sburnicki
These commits add support for two things:
- fix #8080 (closed) by only generating
@RequestParam
annotation, if the query param is not a model. - add support for parsing date and date-time parameters (corresponds to #2053 (closed) in java/spring, applies also for kotlin/spring)
I added test cases adopted from the java spring codegen, which had the same issues (see linked issues and PRs in #8080 (closed)) and tested the changes locally.
Manually test changes
Tests for model object params
Generate code based on one of the existing examples before the PR:
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g kotlin-spring \
-i modules/openapi-generator/src/test/resources/3_0/objectQueryParam.yaml \
-o /tmp/openapi/8080/ \
--skip-validate-spec
and make /tmp/openapi/8080/src/main/kotlin/org/openapitools/api/PonyApi.kt
return the following:
return ResponseEntity(pageQuery, HttpStatus.OK)
also modify the return type and test to compile. After running mvn spring-boot:run
, you can query via curl:
curl -X GET \
'http://localhost:8080/pony?offset=1&limit=2' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache'
which won't return anything, as pageQuery
is null
.
After this PR, run the same steps again. Executing the curl command will correctly return {"offset":1,"limit":2}
, since
spring was able to parse the parameters as a valid pageQuery
object.
Steps for date-time params
Same procedure as above:
Generate code for src/test/resources/3_0/issue_2053.yaml
:
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g kotlin-spring \
-i modules/openapi-generator/src/test/resources/3_0/issue_2053.yaml \
-o /tmp/openapi/datetime/ \
--skip-validate-spec
Test with curl:
curl -vX GET \
'http://localhost:8080/elephants?startDate=2020-12-22' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache
curl -vX GET \
'http://localhost:8080/zebras?startDateTime=2020-12-22T08:00:12.345Z' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache'
Both requests fail with HTTP 400, since Spring cannot parse the parameters.
After the PR, repeat the same steps, both requests will return HTTP 501 (not implemented) and not fail anymore.
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. -
If contributing template-only or documentation-only changes which will change sample output, build the project beforehand. -
Run the shell script ./bin/generate-samples.sh
to update all Petstore samples related to your fix. 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
-
Copy the technical committee to review the pull request if your PR is targeting a particular programming language.
Please review: @jimschubert (2017/09), @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03)