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

Object composition with allOf and required #108

Open
bobh66 opened this issue Oct 8, 2018 · 0 comments
Open

Object composition with allOf and required #108

bobh66 opened this issue Oct 8, 2018 · 0 comments

Comments

@bobh66
Copy link

bobh66 commented Oct 8, 2018

I have found an issue with object composition where swagger-spec-validator works one way and openapi-spec-validator (--schema 2.0) works a different way, and I'm not entirely sure which one is "wrong".

If I compose an object like this:

NameObject:
  properties:
    name:
      type: string

NameRequiredObject:
    allOf:
    - $ref: '#/definitions/NameObject'
    - properties:
        id:
          minLength: 1
          type: string
      type: object
    required:
    - id
    - name

it validates fine in swagger-spec-validator but openapi-spec-validator complains that it cannot find the required field 'name'.

If I change the definition of NameRequiredObject to:

NameRequiredObject:
    allOf:
    - $ref: '#/definitions/NameObject'
    - properties:
        id:
          minLength: 1
          type: string
      type: object
      required:
       - id
       - name

so that required is now part of the allOf object composition, swagger-spec-validator fails because it cannot find the name field, but openapi-spec-validator passes.

It's not clear from the Swagger2.0 spec whether the required attribute should be a property of the NameRequiredObject, or if it should be included in the allOf object composition, and clearly the two projects have implemented it differently.

I'm looking for a reference that will "decide" which format is "correct", and thus which tool is "correct". so my specs will pass validation by both tools.

Thanks,

Bob

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