Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Validation fails with schema polymorphic schema examples #72

Closed Klaus-Nji-sp closed 4 years ago

Klaus-Nji-sp commented 4 years ago

Please run the following schema through the Enforcer with all default settings:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
paths: 
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: A pet
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Dog'
                  - $ref: '#/components/schemas/Cat'
                discriminator:
                  propertyName: petType
                  mapping:
                    dog: "#/components/schemas/Dog"
                    cat: "#/components/schemas/Cat"
              examples:
                cat: 
                  #$ref: "nina-kitty.yml"
                  summary: A dog example
                  value: {"id": 0, "name": "nina", "petType": "dog"}
                dog:
              #    $ref: "bullet-bull-dog.yml"
                  summary: A dog example
                  value: {"id": 0, "name": "nina", "petType": "dog"}

components:
  schemas:
    Dog:
      type: object
      required:
        - id
        - name
        - petType
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        petType:
          type: string
    Cat:
      type: object
      required:
        - id
        - name
        - petType
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        petType:
          type: string

Validation result to the following error:

Unexpected error encountered: TypeError: Cannot read property 'staticData' of undefined

Last line in stack trace indicates error is coming from

deserialize.js:110:47

If I get some time, I will attempt to troubleshoot.

if does not matter if the examples are represented in JSON or YAML or if the examples are specified outside of the spec. If we have no examples, however, spec passes validation.

Thank you for looking into these issues. I'll jump in and try to help out.

Gi60s commented 4 years ago

Awesome bug find. I'll see what I can figure out. Thank you.

Gi60s commented 4 years ago

I've provided a fix and published to NPM as version 1.10.2.

Thanks again for the easily repeatable bug report.

Klaus-Nji-sp commented 4 years ago

Awesome, thank you for the speedy response.