-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[rust] Added support for text/plain to reqwest clients #20643
Merged
wing328
merged 8 commits into
OpenAPITools:master
from
ranger-ross:support-text-content
Feb 17, 2025
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e129d23
[rust] Added support for text/plain to reqwest-trait client
ranger-ross c7e87fa
Updated samples
ranger-ross 560fd60
[rust] Added support for text/plain to reqwest client
ranger-ross 83c6260
Updated samples
ranger-ross 413310f
cleanup
ranger-ross ec2606a
reduced compiler warnings
ranger-ross 59195ac
fixed text/plain content with charset
ranger-ross 149eaa4
Only deserialize text/plain if the API produces it
ranger-ross 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 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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,27 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String | |
unimplemented!("Only objects are supported with style=deepObject") | ||
} | ||
|
||
/// Internal use only | ||
/// A content type supported by this client. | ||
#[allow(dead_code)] | ||
enum ContentType { | ||
Json, | ||
Text, | ||
Unsupported(String) | ||
} | ||
|
||
impl From<&str> for ContentType { | ||
fn from(content_type: &str) -> Self { | ||
if content_type.starts_with("application") && content_type.contains("json") { | ||
return Self::Json; | ||
} else if content_type.starts_with("text/plain") { | ||
return Self::Text; | ||
} else { | ||
return Self::Unsupported(content_type.to_string()); | ||
} | ||
Comment on lines
+148
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rational for this logic is to be able to support both custom JSON variants and charset extensions.
as well as
|
||
} | ||
} | ||
|
||
{{#apiInfo}} | ||
{{#apis}} | ||
pub mod {{{classFilename}}}; | ||
|
This file contains 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 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 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 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 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 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 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
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 would not call this a vendor extension since its not meant for the API spec to set
x-supports-plain-text
.I just needed a way to set attach some arbitrary metadata to an operation and this was the easiest way that I found to do it.
If there is a better way to do this, please let me know.
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.
in java client codegen, we've something similar:
openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java
Line 825 in 9ed15a1
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 i remember correctly, there was a use case before which the content type is application/json and the return type is string (e.g.
"something here"
) so I think we will need to check the content type (produce
) as wellThere 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.
sure that makes sense. I extracted the logic that the
JavaClientCodegen
into a re-useable function inCodegenOperation
in 149eaa4