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

Values set in custom Schema Processor are overwritten during schema generation #1681

Open
jstrawther opened this issue Mar 14, 2024 · 0 comments

Comments

@jstrawther
Copy link

jstrawther commented Mar 14, 2024

Hi, this is likely just a misunderstanding on my part, but I've noticed that my custom ISchemaProcessor is invoked before the rest of the schema is generated, so in some cases, values that I set in the Process method are overwritten by the JsonSchemaGenerator. As an example, let's say I do the following:

    internal class MyJsonSchemaProcessor : ISchemaProcessor
    {
        public void Process(SchemaProcessorContext context)
        {
            context.Schema.MinLength = 42;
        }

What I would expect is that all properties will have minLength: 42 in the generated schema, but what I observe is that the default schema generation behavior runs after the ISchemaProcessor and overwrites values set here. Is there a way to force the values set in the ISchemaProcessor to take precedence?

I'm setting the processor as follows:

settings.SchemaProcessors.Add(new MyJsonSchemaProcessor());

Note, this is just a silly contrived example. What i'm actually trying to do is null out the minLength: 1 that is generated automatically for required string properties, and happened to notice that context.Schema.MinLength has not yet been set to 1 yet when the ISchemaProcessor runs, so I am unable to set it to null and override the default behavior. But my question here is more about clarifying my general understanding of what i'm supposed to be able to accomplish with a custom ISchemaProcessor.

Thank you for your time and input.

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