apib2swagger icon indicating copy to clipboard operation
apib2swagger copied to clipboard

Hard-coded query parameters are wrongly extracted as path parameters

Open MikeRalphson opened this issue 7 years ago • 4 comments

Given the following from http://docs.icons8.apiary.io/api-description-document

# Search [/api/iconsets]

## By Keyword [GET /api/iconsets/v3/search?term={term}&amout={amount}&offset={offset}&platform={platform}&language={language}]

+ Parameters
    + term: `home` (string, required) - the name or tag of the icon or any other phrase.
        e.g. use "@home" to find icons with the tag "home" and "=home" to find icons with the name "home"
    + amount (number, optional) - the maximum number of icons which you'd like to receive
        + Default: 25
    + offset (number, optional) - the offset from the first received result
        + Default: 0
    + platform (enum[string], optional) - the style of the icons
        + Default: `all`
        + Members
            + `all`
            + `ios7`
            + `win8`
            + `win10`
            + `android`
            + `androidL`
            + `color`
            + `office`
    + language: `en-US` (enum[string], required) - the language code to get localized result
        + Members
            + `en-US`
            + `fr-FR`
            + `de-DE`
            + `it-IT`
            + `pt-BR`
            + `pl-PL`
            + `ru-RU`
            + `es-ES`

The generated swagger looks like:

  '/api/iconsets/v3/search?term={term}&amout={amount}&offset={offset}&platform={platform}&language={language}':
    get:
      description: ''
      parameters:
        - description: |
            the name or tag of the icon or any other phrase.
            e.g. use "@home" to find icons with the tag "home" and "=home" to find icons with the name "home"
          in: path
          name: term
          required: true
          type: string
        - default: 25
          description: the maximum number of icons which you'd like to receive
          in: path
          name: amount
          required: true
          type: number
        - description: the offset from the first received result
          in: path
          name: offset
          required: true
          type: number
        - default: all
          description: the style of the icons
          enum:
            - all
            - ios7
            - win8
            - win10
            - android
            - androidL
            - color
            - office
          in: path
          name: platform
          required: true
          type: string
        - description: the language code to get localized result
          enum:
            - en-US
            - fr-FR
            - de-DE
            - it-IT
            - pt-BR
            - pl-PL
            - ru-RU
            - es-ES
          in: path
          name: language
          required: true
          type: string

Whereas I would expect something like:

  '/api/iconsets/v3/search':
    get:
      description: ''
      parameters:
        - description: |
            the name or tag of the icon or any other phrase.
            e.g. use "@home" to find icons with the tag "home" and "=home" to find icons with the name "home"
          in: query
          name: term
          required: true
          type: string
        - default: 25
          description: the maximum number of icons which you'd like to receive
          in: query
          name: amount
          required: true
          type: number
        - description: the offset from the first received result
          in: query
          name: offset
          required: true
          type: number
        - default: all
          description: the style of the icons
          enum:
            - all
            - ios7
            - win8
            - win10
            - android
            - androidL
            - color
            - office
          in: query
          name: platform
          required: true
          type: string
        - description: the language code to get localized result
          enum:
            - en-US
            - fr-FR
            - de-DE
            - it-IT
            - pt-BR
            - pl-PL
            - ru-RU
            - es-ES
          in: query
          name: language
          required: true
          type: string

MikeRalphson avatar Jun 28 '17 09:06 MikeRalphson

I think this URI format is invalid. see https://github.com/apiaryio/api-blueprint/blob/master/API%20Blueprint%20Specification.md#def-uri-templates

kminami avatar Jun 28 '17 21:06 kminami

I may be reading the API Blueprint spec wrongly, but it seems to specify

To define variables for a form-style query use the question mark (?) operator

MikeRalphson avatar Jun 28 '17 22:06 MikeRalphson

To indicate a form-style parameter, you should add the question mark (?) operator IN a variable expression, I think.

https://tools.ietf.org/html/rfc6570#section-1.1

   For example, the following URI Template includes a form-style
   parameter expression, as indicated by the "?" operator appearing
   before the variable names.
    http://www.example.com/foo{?query,number}

kminami avatar Jun 28 '17 22:06 kminami

@visualpharm do you agree, the parameter definitions in the API Blueprint definition may not be correct?

MikeRalphson avatar Jun 28 '17 22:06 MikeRalphson