schemars
schemars copied to clipboard
support extension attribute
trafficstars
It would be useful to be able to annotate a container with something like #[schemars(extension = "x-foo-bar")] and have those values appear in SchemaObject::extensions. I'd be happy to submit a PR if you'd be interested in it.
This makes sense to me, except that extension values would need both a name and a value, so I imagine it would be more like #[schemars(extension("x-foo-bar" = "baz"))].
I'd just need to decide two main things:
- Whether the keys should be quoted, i.e.
"x-foo-bar" = "baz"vsx-foo-bar = "baz". I think they would need to be quoted, mainly because parsing something likex-fooin syn would be quite difficult as it's not a valid rust identifier Whilex-prefixes aren't required in JSON schema extension attributes, they do seem to be fairly common in practice, so they'll need to be supported. - What would a valid value be - a string literal, or any literal, or maybe any expression? Allowing an expression would be nice, so you could pass it a global variable or a function that returns anything implementing
serde::Serialize- this would look like:#[schemars(extension("x-foo-bar" = something()))].
- Agreed on quotes
- I like the idea of specifying an expression
I'd be happy to submit a PR if you'd be interested