membrane-php / membrane-core

Membrane is a general purpose input validation library, supports both PHP Attributes and OpenAPI specifications
Other
3 stars 3 forks source link

Handle required fields on all of #137

Open carnage opened 1 year ago

carnage commented 1 year ago

Check first to see if this is compliant with the spec but the following open API spec doesn't add the required fields validator that should be added:

components:
    SpecObject:
      required:
        - prop1
      allOf:
        -
          $ref: '#/components/schemas/OtherSpecObject'
        -
          type: object
          properties:
            prop1:
              type: string
charjr commented 1 year ago

I don't know currently if it's valid.

As a quick fix I believe it would add a required fields validator if the spec looked like this:

components:
    SpecObject:
      allOf:
        -
          $ref: '#/components/schemas/OtherSpecObject'
        -
          type: object
          required: 
            - prop1
          properties:
            prop1:
              type: string
charjr commented 1 year ago

The following is considered valid using this validator

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
paths:
  /path:
    get:
      responses:
        200:
          description: Successful Response

components:
  schemas:
    SpecObject:
      required:
        - prop1
      allOf:
        -
          $ref: '#/components/schemas/OtherSpecObject'
        -
          type: object
          properties:
            prop1:
              type: string
    OtherSpecObject:
      type: object