Feat: (Rust) Added chrono (date/date-time) support for Rust Generator [resolves #19319]#23451
Feat: (Rust) Added chrono (date/date-time) support for Rust Generator [resolves #19319]#23451richy1623 wants to merge 8 commits intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
8 issues found across 111 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/rust/hyper/petstore/src/models/order.rs">
<violation number="1" location="samples/client/petstore/rust/hyper/petstore/src/models/order.rs:24">
P2: `ship_date` uses timezone-naive `NaiveDateTime` for an OpenAPI `date-time` field, risking RFC3339 offset incompatibility and loss of timezone semantics.</violation>
</file>
<file name="samples/client/petstore/rust/reqwest/petstore-avoid-box/docs/Order.md">
<violation number="1" location="samples/client/petstore/rust/reqwest/petstore-avoid-box/docs/Order.md:10">
P1: `date-time` is mapped to timezone-naive `chrono::NaiveDateTime`, which can drop or reject RFC3339 offset information for `ship_date`.</violation>
</file>
<file name="samples/client/petstore/rust/reqwest/petstore-no-chrono/git_push.sh">
<violation number="1" location="samples/client/petstore/rust/reqwest/petstore-no-chrono/git_push.sh:57">
P2: `git push` is piped through `grep`, which can hide the real push exit code and return incorrect script success/failure.</violation>
</file>
<file name="samples/client/petstore/rust/reqwest/petstore-no-chrono/src/apis/testing_api.rs">
<violation number="1" location="samples/client/petstore/rust/reqwest/petstore-no-chrono/src/apis/testing_api.rs:81">
P2: `Result<String, ...>` success handling incorrectly rejects `text/plain` responses instead of returning the response text.</violation>
</file>
<file name="samples/client/petstore/rust/reqwest/petstore-no-chrono/docs/TestingApi.md">
<violation number="1" location="samples/client/petstore/rust/reqwest/petstore-no-chrono/docs/TestingApi.md:54">
P2: Dead markdown link: `std::path::PathBuf` is linked to `std::path::PathBuf.md`, but that file is not present in the docs directory.</violation>
</file>
<file name="samples/client/petstore/rust/hyper/petstore/docs/Order.md">
<violation number="1" location="samples/client/petstore/rust/hyper/petstore/docs/Order.md:10">
P2: `date-time` is documented and modeled as `chrono::NaiveDateTime`, which is timezone-naive and can break or degrade RFC3339 offset semantics.</violation>
</file>
<file name="samples/client/petstore/rust/reqwest/petstore-no-chrono/src/apis/mod.rs">
<violation number="1" location="samples/client/petstore/rust/reqwest/petstore-no-chrono/src/apis/mod.rs:104">
P2: Content-Type detection is case-sensitive, so valid mixed-case JSON/text media types can be misclassified as unsupported and break response parsing.</violation>
</file>
<file name="samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/order.rs">
<violation number="1" location="samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/order.rs:24">
P2: `shipDate` uses `NaiveDateTime`, which is timezone-naive and can break RFC3339 `date-time` compatibility (offset parsing/round-tripping).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
samples/client/petstore/rust/reqwest/petstore-avoid-box/docs/Order.md
Outdated
Show resolved
Hide resolved
samples/client/petstore/rust/hyper/petstore/src/models/order.rs
Outdated
Show resolved
Hide resolved
| let content = resp.text()?; | ||
| match content_type { | ||
| ContentType::Json => serde_json::from_str(&content).map_err(Error::from), | ||
| ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `String`"))), |
There was a problem hiding this comment.
P2: Result<String, ...> success handling incorrectly rejects text/plain responses instead of returning the response text.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/rust/reqwest/petstore-no-chrono/src/apis/testing_api.rs, line 81:
<comment>`Result<String, ...>` success handling incorrectly rejects `text/plain` responses instead of returning the response text.</comment>
<file context>
@@ -0,0 +1,225 @@
+ let content = resp.text()?;
+ match content_type {
+ ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
+ ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `String`"))),
+ ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
+ }
</file context>
There was a problem hiding this comment.
this is generated by the generate-samples.sh script
samples/client/petstore/rust/reqwest/petstore-no-chrono/docs/TestingApi.md
Show resolved
Hide resolved
|
|
||
| impl From<&str> for ContentType { | ||
| fn from(content_type: &str) -> Self { | ||
| if content_type.starts_with("application") && content_type.contains("json") { |
There was a problem hiding this comment.
P2: Content-Type detection is case-sensitive, so valid mixed-case JSON/text media types can be misclassified as unsupported and break response parsing.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/rust/reqwest/petstore-no-chrono/src/apis/mod.rs, line 104:
<comment>Content-Type detection is case-sensitive, so valid mixed-case JSON/text media types can be misclassified as unsupported and break response parsing.</comment>
<file context>
@@ -0,0 +1,120 @@
+
+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") {
</file context>
There was a problem hiding this comment.
this is generated by the generate-samples.sh script
samples/client/petstore/rust/reqwest/petstore-async-middleware/src/models/order.rs
Outdated
Show resolved
Hide resolved
…o::FixedOffset> ``
…o::FixedOffset>`
…tor into fix_issue_19319
Current issue:
The rust generator does not use a typed Date/DateTime object, it uses a type String [resolves #19319]
Proposed solution
Use a common date time library
chronoto represent these typesImplementation
useChrono) which defaults to truechronotypes for the fieldstypeMappingchronoas a dependency in theCargo.tomlTesting
chronowhere relevantuseChrono=falseand the expected behaviour is using String typesRequesting a review from one of the Rust technical comittee:
PR checklist
Commit all changed files.
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*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Adds typed date/time support in the Rust generator using
chrono. By default,datemaps tochrono::NaiveDateanddate-timemaps tochrono::DateTime<chrono::FixedOffset>to improve type safety and RFC3339 serialization. Resolves #19319.New Features
date->chrono::NaiveDate,date-time->chrono::DateTime<chrono::FixedOffset>whenuseChrono=true.useChrono(CLI/config), defaulttrue;falsekeepsString.chronoin generatedCargo.tomlonly when date fields are present.useChronoin Rust generator docs; addedrust-reqwest-petstore-no-chronoconfig and sample.Migration
chronois added automatically when models use dates.Stringdates, setuseChrono=false(e.g.,-p useChrono=false).Written for commit a522e3e. Summary will update on new commits.