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

If minProperties is greater than or equal to the number of declared properties and additionalProperties is false, all properties should be required #565

Open
andreww2012 opened this issue Dec 25, 2023 · 2 comments

Comments

@andreww2012
Copy link

Hello, I think the following schema should produce the object type with all the properties required:

{
  "type": "object",
  "additionalProperties": false,
  "minProperties": 2,
  "properties": {
    "a": {
      "type": "number"
    },
    "b": {
      "type": "string"
    }
  }
}

The current output:

export interface Demo {
  a?: number;
  b?: string;
}

The expected output:

export interface Demo {
  a: number;
  b: string;
}
@GabenGar
Copy link

GabenGar commented Jan 1, 2024

What is the usecase? "minProperties" is used for various types of hash tables or when only a subset of any properties listed is required (in which case all properties are optional as far as types concerned). The example above can be expressed as declaring "required" array and it will result in a more readable schema and most likely more performant validation function.

@andreww2012
Copy link
Author

It (kind of) prevents fields duplication problem if all fields are required (I wish JSON schema had an easy and safe way to express this). Kind of, because if new ones are added, one may still forget to update minProperties.

And, well, technically the current behaviour is incorrect.

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