Skip to content
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

date-time with default panics #539

Closed
ahl opened this issue Mar 28, 2024 · 0 comments · Fixed by #540
Closed

date-time with default panics #539

ahl opened this issue Mar 28, 2024 · 0 comments · Fixed by #540

Comments

@ahl
Copy link
Collaborator

ahl commented Mar 28, 2024

This schema causes a panic:

    {
      "type": "object",
      "properties": {
        "when": {
          "type": "string",
          "format": "date-time",
          "default": "1970-01-01T00:00:00Z"
        }
      }
    }

"DateTime<chrono" is not a valid Ident

If we remove the default, it's fine. Why? This:

let text = value.to_string();
let type_path = type_name
.split("::")
.map(|component| format_ident!("{}", component));
// Deserialize the string to the type; the unwrap() is
// unfortunate, but unavoidable without getting in the
// underpants of the serialized form of these built-in types.
quote! {
serde_json::from_str::< #( #type_path )::* >(#text).unwrap()
}

Instead we need to do what's done here:

TypeEntryDetails::Native(TypeEntryNative {
type_name: name, ..
})
| TypeEntryDetails::Integer(name)
| TypeEntryDetails::Float(name) => syn::parse_str::<syn::TypePath>(name)
.unwrap()
.to_token_stream(),

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 a pull request may close this issue.

1 participant