Skip to content

feat: add schemas for time crate ^0.3 - #472

Open
fwfurtado wants to merge 4 commits into
GREsau:masterfrom
fwfurtado:feat/add-time03-crate
Open

fwfurtado wants to merge 4 commits into
GREsau:masterfrom
fwfurtado:feat/add-time03-crate

Conversation

@fwfurtado

Copy link
Copy Markdown

This pull request adds support for the time crate version 0.3 (as the optional time03 feature) to Schemars, allowing types from time (such as Date, Time, PrimitiveDateTime, and OffsetDateTime) to implement JsonSchema. It also includes tests and documentation updates for this new feature.

Support for the time03 feature:

  • Added time03 as an optional dependency in schemars/Cargo.toml, with and without the serde feature for normal and testing builds. [1] [2]
  • Updated the documentation in README.md to mention the new time03 feature flag.

Implementation for time03 types:

  • Added a new module time03.rs implementing JsonSchema for Date, Time, PrimitiveDateTime, and OffsetDateTime, mapping them to appropriate JSON Schema string formats.
  • Registered the new module behind the time03 feature flag in mod.rs.

Testing:

  • Added integration tests for the new time03 types in time.rs, including snapshot testing and roundtrip checks.
  • Added a corresponding snapshot file for the expected JSON Schema output.
  • Registered the new test module in the integration test harness.

@marcelotozzi

Copy link
Copy Markdown

👍

Comment thread schemars/src/json_schema_impls/time03.rs

@clementwanjau clementwanjau left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good.

@gpluscb gpluscb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is an issue with this that needs consideration: the default serialization format of time's types is not rfc3339 (see time-rs/time#672). Without external solutions like the serde_with crate, only OffsetDateTime supports an rfc3339 format by using #[serde(with = time::serde::rfc3339)]. Therefore by default there would be a discrepancy between the generated schema and the serialized data.

For OffsetDateTime the required serde attribute could be documented, for other types such as Time, PrimitiveDateTime, and Date the correct approach is not so clear.

Also if a solution is found that includes Time, PrimitiveDateTime and Date, then UtcDateTime should be added as well.

@matthiasbeyer

matthiasbeyer commented Aug 13, 2026

Copy link
Copy Markdown

I am interested in this (or #257) and would like to see it implemented. What can I do to help move this forward?

@matthiasbeyer

Copy link
Copy Markdown

@GREsau what is needed to drive this to completion?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants