cyprieng / swagger-parser

Give useful informations about your swagger files
MIT License
62 stars 59 forks source link

allow x-example #25

Closed ghost closed 7 years ago

ghost commented 7 years ago

the acutal code is searching for 'example' in the parameters. When using the example field like this...

  /users/{uid}:
    get:
      summary: Returns a user
      operationId: swagger.api.read_user_by_uid
      produces:
        - application/json
      parameters:
        - name: uid
          in: path
          description: UID of user that needs to be fetched
          required: true
          type: string
#          default: myuuid
          example: myuuid
      responses:
        "200":
          description: One User
          schema:
            $ref: "#/definitions/UserRead"

...it fails . The only way to get {uid} populated with 'myuuid' is by using the 'default' property but it is not intended to be used for setting a default value in such a scenario.

As x-vendor properties are permitted by the spec, let use them:

 /users/{uid}:
    get:
      summary: Returns a user
      operationId: swagger.api.read_user_by_uid
      produces:
        - application/json
      parameters:
        - name: uid
          in: path
          description: UID of user that needs to be fetched
          required: true
          type: string
          x-example: myuuid
      responses:
        "200":
          description: One User
          schema:
            $ref: "#/definitions/UserRead"
beanqueen commented 7 years ago

i don't fully understand the problem, but i'm ok with the solution anyway. the if / if / elif / .. / else should be refactored to be consistent.

cyprieng commented 7 years ago

I don't see why the 'example' field wouldn't work in your example, neither why x-example would improve this (even if I am completly agree to support it). Can you provide the code that fails ?

beanqueen commented 7 years ago

we can close this PR, i added the x-example support and cleaned up the if/elif block

cyprieng commented 7 years ago

Done in #26