Repository navigation
Conversation
03c70d5 to
e7c73b3
Compare
|
I haven't looked at this closely, but first:
|
Actually I haven't, feature flag was my initial gut feeling. But you may be right. As chrono is only a dev dependency it wouldn't pollute consumer code when the generated code doesn't need it. I'll change it to a generation input setting.
schemars has an open PR GREsau/schemars#547 for adding jiff support, but this would only work if we update schemars to 1.x (as far as I can see), which has its own difficulties. |
| (format, _) => { | ||
| self.convert_format(type_name, original_schema, metadata, format, validation) |
There was a problem hiding this comment.
this seems a bit odd. convert_format is convert_string minus date and date-time?
There was a problem hiding this comment.
That was the easy way to catch date and date-time early. I can move it into the convert_string function i think.
| .into_iter() | ||
| .collect::<TypespaceTraitSet>(), | ||
| ), | ||
| TypeEntry::new_native(date_path(format, library), date_traits(library)), |
There was a problem hiding this comment.
perhaps date_path and date_traits and be in the same function that just returns the TypeEntry
There was a problem hiding this comment.
Yes, I'll move that into a single generation function.
| value_parser = ["chrono", "jiff", "string"], | ||
| default_value = "chrono" | ||
| )] | ||
| date_library: String, |
There was a problem hiding this comment.
I bet this could be the enum rather than a string
There was a problem hiding this comment.
I thought about that at first. Could have used the DateLibrary enum from typify-impl, but would have needed to add clap to it, so I went with String. I'll duplicate it add a conversion, makes it more clean. The other option would be to add a feature cli feature to typify-impl to reuse those types, maybe something to consider for the future.
| /// The crates needed for native types: `uuid` and the date library | ||
| /// (`chrono` or `jiff`) for the string formats they map to, and each crate an `x-rust-type` extension | ||
| /// names, at the version [`TypeSpaceSettings::with_crate`] declared for | ||
| /// it. Recorded on the `TypespaceBuilder` so the finalized typespace | ||
| /// reports them with the crates of what typespace renders itself. |
| /// Plain `String`s. Length and pattern constraints still apply; the format | ||
| /// itself is not validated. | ||
| String, |
There was a problem hiding this comment.
explain that the benefit is no dependency
| @@ -0,0 +1,176 @@ | |||
| #![deny(warnings)] | |||
There was a problem hiding this comment.
let's not make a new subdirectory; follow an existing pattern for this
There was a problem hiding this comment.
I extracted the date-defaults into its own file now, which reduces duplicate code. Also flattened the subdir into its own two files with a jiff suffix.
Co-authored-by: Adam Leventhal <adam.leventhal@gmail.com>
|
@ahl I hope I resolved all your findings. Feel free to review again and resolve the comments. |
resolves #1111
dateanddate-timestring formats are now mapped to a date library chosen by Cargo feature.chronostays the default, so existing output is unchanged.jiffis available as an alternative, and it takes precedence when both are enabled. With neither feature, dates are plain Strings.Changes:
typify-implhaschrono(default) andjiffmarker features. typify emits the paths and never links either crate, so these only select which path is generatedtypify,typify-macro, andcargo-typifyforward the features.typify,typify-impl, andtypify-macronow setdefault-features = false. Cargo doesn't allow a member to override default-features on an inherited dependency, so this is the only way to let each crate choose.Remarks:
jifftypes omitJsonSchema.schemars0.8, which typify uses, has nojiffimpl.JsonSchemaand holds ajiffdateis refused when rendered, with an error naming::jiff::Timestamp.chronogolden files only run under chronojiffsTimestampis notchronosDateTime, API differs