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

Add #[schemars(extend("key" = value))] attribute #297

Merged
merged 2 commits into from
Jun 5, 2024
Merged

Add #[schemars(extend("key" = value))] attribute #297

merged 2 commits into from
Jun 5, 2024

Conversation

GREsau
Copy link
Owner

@GREsau GREsau commented Jun 5, 2024

Implements #50

  • this attribute can be used to add properties (or replace existing properties) in a generated schema
  • can be set on a struct, enum, or enum variant
  • can have multiple key/value pairs and/or be specified multiple times - but if so, every key must be unique (otherwise, a compile error is emitted)
  • key must be quoted but can be any string
  • value can be any expression that produces a value implementing Serialize
  • value can also be a JSON literal which can interpolate other values, e.g. #[schemars(extend("obj" = {"array": [null, ()]}))]
    • this follows the same rules as arguments to the serde_json::json!(...) macro (which this attribute uses under the hood)

@GREsau GREsau merged commit 840315b into v1 Jun 5, 2024
8 checks passed
@GREsau GREsau deleted the extend branch June 5, 2024 20:09
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 this pull request may close these issues.

None yet

1 participant