Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kotlin-spring] use spring resource for file handling #2455

Merged
merged 9 commits into from
Mar 27, 2019
Merged

[kotlin-spring] use spring resource for file handling #2455

merged 9 commits into from
Mar 27, 2019

Conversation

sylvainmoindron
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Using spring ResponseEntity<Resource> for handling file when generating an API who return a file with

schema:  
  type: string
  format: binary

before it was ResponseEntity<File> which only responded filename

@jimschubert @dr4ke616

@auto-labeler
Copy link

auto-labeler bot commented Mar 19, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Copy link
Member

@jimschubert jimschubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used spring resource in this way. What's in the PR looks good side from the import of that full type.

Let me know if you need a hand looking into fixing it.

@sylvainmoindron
Copy link
Contributor Author

with the correct sample the CI check are OK

@@ -56,7 +56,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
@RequestMapping(
value = ["/pet/{petId}"],
method = [RequestMethod.DELETE])
fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: Long,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: String?): ResponseEntity<Unit> {
fun deletePet(@ApiParam(value = "Pet id to delete", required=true, defaultValue="null") @PathVariable("petId") petId: Long,@ApiParam(value = "" , defaultValue="null") @RequestHeader(value="api_key", required=false) apiKey: String): ResponseEntity<Unit> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the default should be null (without double quotes) or should be omitted.

I don't think it's related to this change so we will need to fix it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw lot of change in the gérérated code (last time it was générated was 3.3.9 on Sep 2018).
i alsa saw a change in the body parameter name
(@Valid @RequestBody pet: Pet
changed to
@Valid @RequestBody body: Pet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 This looks like it's probably an issue with the spec document? An id path parameter, by definition, can't be null otherwise the request won't match the path definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is another PR for this problem i think
#2487

@sylvainmoindron
Copy link
Contributor Author

there is a problem at the moment for a binary body, the API use Resource, the interface ApiService use multipart. i'm looking for the problem

@sylvainmoindron
Copy link
Contributor Author

i fixed the multipart problem

@wing328 wing328 added this to the 4.0.0 milestone Mar 25, 2019
@@ -78,7 +78,7 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
@RequestMapping(
value = ["/user/{username}"],
method = [RequestMethod.DELETE])
fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: String): ResponseEntity<Unit> {
fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true, defaultValue="null") @PathVariable("username") username: String): ResponseEntity<Unit> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unrelated to this PR, but I don't think passing a null from Spring's internals to a Kotlin String will work. We may be missing nullable type work on the input parameter.

@@ -56,7 +56,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
@RequestMapping(
value = ["/pet/{petId}"],
method = [RequestMethod.DELETE])
fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: Long,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: String?): ResponseEntity<Unit> {
fun deletePet(@ApiParam(value = "Pet id to delete", required=true, defaultValue="null") @PathVariable("petId") petId: Long,@ApiParam(value = "" , defaultValue="null") @RequestHeader(value="api_key", required=false) apiKey: String): ResponseEntity<Unit> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 This looks like it's probably an issue with the spec document? An id path parameter, by definition, can't be null otherwise the request won't match the path definition.

@Service
{{#operations}}
class {{classname}}ServiceImpl : {{classname}}Service {
{{#operation}}

override fun {{operationId}}({{#allParams}}{{paramName}}: {{^isFile}}{{>optionalDataType}}{{/isFile}}{{#isFile}}org.springframework.web.multipart.MultipartFile{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}}): {{>returnTypes}} {
override fun {{operationId}}({{#allParams}}{{paramName}}: {{#isFormParam}}{{#isFile}}org.springframework.web.multipart.MultipartFile{{/isFile}}{{^isFile}}{{{dataType}}}{{/isFile}}{{/isFormParam}}{{^isFormParam}}{{{dataType}}}{{/isFormParam}}{{#hasMore}},{{/hasMore}}{{/allParams}}): {{>returnTypes}} {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to change org.springframework.web.multipart.MultipartFile to {{{dataType}}} to use Resource as well, otherwise it's hard-coded and the file type mapping will only work for models. I could be wrong as I've not used Resource, and jcenter is giving me 502 bad gateways so I can't download plugins required to build a sample.

Same issue in service.mustache and formParams.mustache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I wanted to treat all file as Resource, but after watching other générator I thought that keeping Multipart for form was a better idea (i was inspired by the spring-java générator).
Maybe i'm wrong ,it's my first job on openapi-genrator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm doing a POC where I remove all instance of MultipartFile; if i'm confident i break nothing, i will commit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed your recommendations and did a push

# Conflicts:
#	samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApi.kt
#	samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApi.kt
#	samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApi.kt
@jimschubert jimschubert self-assigned this Mar 26, 2019
@jimschubert
Copy link
Member

I tested this against the petstore simple yaml and looks like Resource is working as expected for file input.

I restarted Shippable (failed on Elm client tests), but I think this is good to go once checks have completed.

@wing328
Copy link
Member

wing328 commented Mar 27, 2019

Resolved the merge conflicts via 4f8a555

I'll update the Kotlin server samples later after merging the PR into master.

@wing328 wing328 merged commit 74fbd34 into OpenAPITools:master Mar 27, 2019
@wing328
Copy link
Member

wing328 commented Mar 27, 2019

Samples updated via 1313cff

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