Skip to content

Schema properties with default considered required #664

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

Closed
agualis opened this issue Jun 24, 2021 · 1 comment
Closed

Schema properties with default considered required #664

agualis opened this issue Jun 24, 2021 · 1 comment

Comments

@agualis
Copy link

agualis commented Jun 24, 2021

This line assumes that a property is required when it has a default value.

According to the specification:

default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, if type is string, then default can be "foo" but cannot be 1.

So, my understanding is that:

  • When the consumer is reading the value will always have a value (required)
  • But, when the consumer is writing the value can be provided or not so that the generated type should also be optional instead of required

Am I missing something?

Thanks for your great library!

@drwpow
Copy link
Contributor

drwpow commented Jun 26, 2021

This is no longer true! Now we give you the option. The default command will only treat required as non-nullable. But if you specify the --default-non-nullable flag as well, then it will treat either required or default as non-nullable. That’s the options.defaultNonNullable && part). Hopefully this clarifies things!

@drwpow drwpow closed this as completed Jun 26, 2021
@drwpow drwpow mentioned this issue Nov 6, 2023
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