draft proposal for how we might add the x-rust-type extension#47
draft proposal for how we might add the x-rust-type extension#47
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.
this might be the most relevant portion to review
| 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.
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.
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.