kevindew / openapi3_parser

Open API 3 Parser/Validator for Ruby
MIT License
90 stars 12 forks source link

Schema property.required is not set #3

Closed lewisnyman closed 6 years ago

lewisnyman commented 6 years ago

Hello, With a schema like this:

NewPet:
      required:
        - name
      properties:
        name:
          type: string
        tag:
          type: string

When I access the name property, required returns nil. I can write a helper function that checks the required array, it would be useful to set required for properties as it exists.

kevindew commented 6 years ago

Hello. Hmm yeah I can see how that could trip you up.

The presence of required on a property is because it is a type of schema object as per: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#schema-object and it's presence only really becomes relevant when you're dealing with a type of object. So it's not actually intended to show whether that property is required in the parent schema context but to show what properties are required in it's own context.

e.g.

NewPet:
  required:
    - name
  properties:
    name:
      type: object
      required:
        - last_name
      properties:
        first_name:
          type: string
        last_name:
          type: string
lewisnyman commented 6 years ago

Oh of course! It's a schema object within a schema object. Thanks for the guidance. Looks like the best thing to do is to write a helper method.