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

support extension attribute #50

Closed
ahl opened this issue Aug 29, 2020 · 3 comments
Closed

support extension attribute #50

ahl opened this issue Aug 29, 2020 · 3 comments

Comments

@ahl
Copy link
Contributor

ahl commented Aug 29, 2020

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.

@GREsau
Copy link
Owner

GREsau commented Apr 11, 2021

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:

  1. Whether the keys should be quoted, i.e. "x-foo-bar" = "baz" vs x-foo-bar = "baz". I think they would need to be quoted, mainly because parsing something like x-foo in syn would be quite difficult as it's not a valid rust identifier While x- 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.
  2. 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()))].

@ahl
Copy link
Contributor Author

ahl commented Aug 19, 2021

  1. Agreed on quotes
  2. I like the idea of specifying an expression

I'd be happy to submit a PR if you'd be interested

@GREsau
Copy link
Owner

GREsau commented Jun 5, 2024

This is (finally) implemented in 1.0.0-alpha.2 as #[schemars(extend("key" = value))]!

Please be aware this version contains breaking changes (see changelog), and further breaking changes are possible until 1.0.0 proper is released

@GREsau GREsau closed this as completed Jun 5, 2024
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

No branches or pull requests

2 participants