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

Schema customization #173

Open
MikailBag opened this issue Sep 4, 2022 · 0 comments
Open

Schema customization #173

MikailBag opened this issue Sep 4, 2022 · 0 comments

Comments

@MikailBag
Copy link

Sometimes user wants not to override schema generation, but to post-process it.
One possible case is to add non-standard extensions, e.g. x-kubernetes-validations extension can be used to CustomResourceDefinition-s to add programmatic validation rules.

Proposed solution: add a new customize_with attribute which can be applied to the whole derive-ing container, e.g.

#[derive(JsonSchema)]
#[schemars(customize_with = "customize")]
struct Foo {
   // ...
}

// this function will be called after schema for Foo is generated, and it can modify returned schema
fn customize(schema: &mut schemars::schema::Schema) {
    // something like schema.extensions.insert("x-my-custom-extension", ...) here.
}
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

1 participant