-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
There was a problem hiding this 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.
.../server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt
Outdated
Show resolved
Hide resolved
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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 |
i fixed the multipart problem |
@@ -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> { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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}} { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
I tested this against the petstore simple yaml and looks like I restarted Shippable (failed on Elm client tests), but I think this is good to go once checks have completed. |
Resolved the merge conflicts via 4f8a555 I'll update the Kotlin server samples later after merging the PR into master. |
Samples updated via 1313cff |
PR checklist
./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\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
Using spring ResponseEntity<Resource> for handling file when generating an API who return a file with
before it was ResponseEntity<File> which only responded filename
@jimschubert @dr4ke616