Hilzu / express-openapi-validate

Express middleware to validate requests based on an OpenAPI 3 document
Apache License 2.0
75 stars 12 forks source link

allOf nesting not being validated? #45

Closed scampiuk closed 5 years ago

scampiuk commented 5 years ago

Hi,

We have complex object roughly like:

    SearchResponseObject:
      description: "Combination response object for search"
      allOf:
        - $ref: "#/components/schemas/ApiResponseCommonValues"
        - type: object
          required:
            - details
          properties:
            details:
              type: object
              required:
                - xRequestId
                - result
              properties:
                xRequestId:
                  $ref: "#/components/schemas/xRequestId"
                result:
                  allOf:
                    - $ref: "#/components/schemas/StandardSearchResponseObject"
                      type: object
                      required:
                        - results
                      properties:
                        results:
                          type: array
                          items:
                            $ref: "#/components/schemas/SearchResultsItem"
    SearchResultsItem:
      description: "Individual Search Result"
      type: object
      required:
        - id
        - score
        - name
      properties:
        id:
          type: integer
          description: 'Id'
        score:
          type: number
          description: 'Search result score'
        name:
          type: string
          description: 'Name of the thing'
    200SearchResponse:
      description: "Search success response."
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/SearchResponseObject"
 "/search":
    get:
      description: Search
      parameters:
        - name: "q"
          in: "query"
          required: false
          schema:
            type: string
      responses:
        200:
          $ref: "#/components/responses/200SearchResponse"
        400:
          $ref: "#/components/responses/400BadRequestResponse"

What we're finding is that the validator is not finding issues when the criteria in SearchResponseObject is not met. Are there any known issues with this kind of structure, or limitations on the depth that the validator will travel?

Thanks,

scampiuk commented 5 years ago

Never mind, I'm a clown, I've just re-read it and spotted for formatting mistake :)

                result:
                  allOf:
                    - $ref: "#/components/schemas/StandardSearchResponseObject"
                      type: object
                      required:
                        - results
                result:
                  allOf:
                    - $ref: "#/components/schemas/StandardSearchResponseObject"
                    - type: object
                      required:
                        - results