-
Notifications
You must be signed in to change notification settings - Fork 5
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
draft proposal for how we might add the x-rust-type extension #47
base: main
Are you sure you want to change the base?
Conversation
"format": "uuid", | ||
"x-rust-type": { | ||
"crate": "newtype-uuid", | ||
"parameters": [ | ||
{ | ||
"not": true, | ||
"x-rust-type": { | ||
"crate": "my-crate", | ||
"path": "my_crate::MyKind", | ||
"version": "0.1.0" | ||
} | ||
} | ||
], | ||
"path": "newtype_uuid::TypedUuid", | ||
"version": "1.2.0" | ||
} |
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.
this might be the most relevant portion to review
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.
This is awesome!
fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { | ||
schemars::schema::SchemaObject { | ||
subschemas: Some( | ||
schemars::schema::SubschemaValidation { | ||
not: Some(schemars::schema::Schema::Bool(true).into()), | ||
..Default::default() | ||
} | ||
.into(), | ||
), | ||
extensions: [( | ||
"x-rust-type".to_string(), | ||
serde_json::json!({ | ||
"crate": "my-crate", | ||
"version": "0.1.0", | ||
"path": "my_crate::MyKind", | ||
}), | ||
)] | ||
.into_iter() | ||
.collect(), | ||
..Default::default() | ||
} | ||
.into() | ||
} | ||
} |
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.
This makes sense. Is there a plan to make this easier to define? Wonder if we should revive @hawkw's proc macro.
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.
That's something I wanted to talk about. I could imagine a derive macro, but it might be less rope for consumers to instead export something like the impl_typed_uuid_kind
macro you suggest people write. As you noted, the derive macro requires a few inputs; this change would require more (crate name, path to the type)--I think that as derive macros grow mandatory attributes they start feeling like they should be function-style macros instead.
Updating this: Rain's suggestion for a macro to define these types was something along these lines: impl_typed_uuid_kind! {
json_schema_settings = {
crate = "my-crate",
path = "my_crate",
};
Collection => { version = "0.1.0", tag = "collection", kind = CollectionKind, short = CollectionUuid },
Downstairs => { version = "0.1.0", tag = "downstairs", kind = DownstairsKind, short = DownstairsUuid },
// ...
} We might simplify that a bit to make it easier to parse with |
This would still be wonderful. |
@sunshowers I'm posting this as an artifact for us to discuss next week as your time permits.
It depends on the version of typify that's still unreleased so obviously would need to wait for that.