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

Changing schemars' generation settings #32

Open
svix-andor opened this issue Jan 13, 2023 · 1 comment
Open

Changing schemars' generation settings #32

svix-andor opened this issue Jan 13, 2023 · 1 comment

Comments

@svix-andor
Copy link
Contributor

While using aide I'd like to change schemars' settings, specifically I'd like to disable making Options being turned into anyOfs with nulls. Schemars supports this by setting option_nullable = true and option_add_null_type = false on its settings struct which I can do by doing something like this:

aide::gen::in_context(|ctx| {
    ctx.schema = schemars::gen::SchemaGenerator::new(schemars::gen::SchemaSettings::draft07().with(|s| {
        s.option_nullable = true;
        s.option_add_null_type = false;
    }));
});

But if I want to use other aide features such as schema extraction then this isn't going to work because that also modifies the schema generator. I worked around this for now by just looking at the source and making the same modifications on the schema settings as extract_schemas does, but this is not optimal as it requires me to know internals of aide. Would you consider exposing these settings through aide so this is not required?

@tamasfe
Copy link
Owner

tamasfe commented Jan 15, 2023

After some brief thinking I believe your approach is the way to go here. By default aide aims to conform to the OpenAPI spec during schema generation with sensible defaults. If you need to alter this in any way and you know what you're looking for, the schema generator is exposed and it's possible to do so.

I would rather not expose individual features of schemars one by one. The extract_schemas setting is an exception; I exposed it as a high-level switch because it's a behaviour people generally expect from doc generators but is disabled by default because schemars doesn't handle name conflicts.

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