-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
fix(kotlin): set content type on ktor-jvm library #15812
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
Closed
bcmedeiros
wants to merge
1
commit into
OpenAPITools:master
from
bcmedeiros:fix-kotlin-ktor-content-type
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
thanks for the PR.
instead of hard coding to applicaiton/json, what about updating api.mustache to use content-type defined in the sepc instead similar to what we've done in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache#L222 ?
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 My first try was:
I also just tried:
Both result in an empty value:
Also, even if I get this correctly, I'm pretty sure we would need some conditionals to add the correct gradle dependencies in the template.
At this point I know very little about Mustache and the project layout overall.
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.
can you please share your spec? or a minimal spec to reproduce the issue?
did you do it in api.mustache inside the
operation
mustache tag?I would suggest plotting the fix in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache#L222 to the api.mustache for
ktor-jvm
library.Uh oh!
There was an error while loading. Please reload this page.
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 see I need to be in the scope of the
operation
now, but anyway, I cannot set the content type there due to the current design of the operation and thejsonRequest
andrequest
abstractions inApiClient
.The current fix is done in a method called
request
, whose only caller isjsonRequest
, so I highly doubt that "making this right" and set the dynamic Content Type will actually work.I'll try a little bit longer, though.
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.
You can use this fix with customized template (e.g. -t option CLI) if you need this fix urgently for your use case.
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.
If you look at https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/api.mustache#L222, the content-type header is set there instead of ApiClient.
can we not do the same? or you saying jvm-okhttp has the issue for your use case?
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 not without a major redesign. We need to do it inside the
client.request {
block, which the current design chose to abstract in theApiClient
.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 is it time for a big redesign? should I give it a try?
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 don't think I fully understand the problem/limitation that requires the redesign.
Can you please PM me via Slack to further discuss this when you've time?
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.
It's not easy to understand the problem without looking at the code. Basically, the content type is being set in a super class method that has no access to the config, IIRC.
The issue ended up being fixed by #16843, so I'll close this PR.
That solution ended up getting the content type from the header, or a hardcoded value as a fallback, BTW, so we still haven't "fixed" this properly as you suggested.