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

allOf with additional required fields doesn't make them required #157

Closed
thejuan opened this issue Apr 4, 2018 · 4 comments
Closed

allOf with additional required fields doesn't make them required #157

thejuan opened this issue Apr 4, 2018 · 4 comments

Comments

@thejuan
Copy link

thejuan commented Apr 4, 2018

You should be able to specify a reference to a type and a set of required fields using allOf.
At the moment the specified required fields are not required in the typescript (i.e. generated wtih a ? on the property)

{
  type: 'object',
  required: [ 'name', 'location' ],
  additionalProperties: false,
  properties: {
    location: {
      allOf: [
        { $ref: 'location' },
        { required: [ 'postalCode' ] }
      ]
    },
    name: { type: 'string' },
    website: { type: 'string' }
  }
}

In above postalCode should be marked as required, but it's not ATM
https://stackoverflow.com/questions/41958392/extending-ref-with-additional-required-fields

@thejuan thejuan changed the title allOf with additional required fields doesn't include them allOf with additional required fields doesn't make them required Apr 4, 2018
@bcherny
Copy link
Owner

bcherny commented Apr 4, 2018

@handrews @schani Do you know if this is kosher - { required: [ 'postalCode' ] } should make postalCode required in { $ref: 'location' }?

@schani
Copy link

schani commented Apr 4, 2018

Yes, that is correct. This is also a bug in quicktype that I just discovered ;-)

@bcherny
Copy link
Owner

bcherny commented Apr 4, 2018

Related: #96

@thejuan
Copy link
Author

thejuan commented Apr 4, 2018

I work around this by pre-processing the schemas with
https://github.com/bojand/json-schema-deref
and
https://github.com/mokkabonna/json-schema-merge-allof?files=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants