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

Swagger lint failed because of wrong allOf in system/propertiesy/{key}/get #34

Closed
CPtung opened this issue Nov 25, 2019 · 0 comments
Closed
Assignees

Comments

@CPtung
Copy link
Contributor

CPtung commented Nov 25, 2019

Got error message from #33 travis log

Swagger schema validation failed. 
  Data does not match any schemas from 'oneOf' at #/paths//system/properties/{key}/get/responses/200
    Additional properties not allowed: example at #/paths//system/properties/{key}/get/responses/200
    Missing required property: $ref at #/paths//system/properties/{key}/get/responses/200

Look into the swagger file, /system/properties/{key}/get will return a response of the union of gps and aliasName. However, the error told us data does not match any schema from oneOf.
According to swagger document, to validate an union payload from multi schemas, we should use allOf in definition of schemas where an example shown as below

components:
  schemas:
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
    Dog:     # "Dog" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Dog`-specific properties 
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: boolean
            breed:
              type: string
              enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:     # "Cat" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Cat`-specific properties 
        - $ref: '#/components/schemas/Pet'
        - type: object
          # all other properties specific to a `Cat`
          properties:
            hunts:
              type: boolean
            age:
              type: integer

but in oapi-tp-gateway/schema/system/index.yaml.

 '/system/properties/{key}':
    parameters:
      - name: key
        in: path
        type: string
        required: true
    get:
      description: Get specific system property
      responses:
        '200':
          description: success
          schema:
            allOf:
              - '$ref': '#/definitions/SystemProperties/properties/aliasName'
              - '$ref': '#/definitions/SystemProperties/properties/gps'
          example:
            application/json:
              lat: 121.123
              lng: 22.456
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

2 participants