apiaryio / fury-adapter-swagger

Swagger 2.0 parser adapter for Fury.js
MIT License
11 stars 12 forks source link

{variable*} URI template isn't expanded as a comma-separated list by the uri-template Node.js library #123

Closed honzajavorek closed 7 years ago

honzajavorek commented 7 years ago

When Swagger contains array URI parameter:

paths:
  /honey:
    get:
      parameters:
        - name: flavour
          in: query
          type: array
          items:
            type: string
          collectionFormat: multi
          x-example:
            - sweet
            - spicy

Then the adapter creates an URI template, which looks like this:

/honey{?flavour*}

If the uri-template library is provided with such template and with [ 'sweet', 'spicy' ] as a value for flavour, it produces following URI:

/honey?flavour=sweet&flavour=spicy

If the uri-template library is provided with template /honey{?flavour} and with [ 'sweet', 'spicy' ] as a value for flavour, it produces following URI:

/honey?flavour=sweet,spicy

That made me read the RFC and it looks like the interpretation of how a variable should get expanded in this case is quite vague. The spec says it depends on a context. IMHO this is a problem, because user clearly specified collectionFormat: multi, which is a comma-separated list of strings. The Swagger adapter's interpretation of this in form of URI template is more vague though and allows subsequent tooling (uri-template library) to expand it in a different way. Also, if I wanted to manually take care of this in Dredd, I'm out of luck, because I have no access to anything else then the vague template.

I looked up tests of the uri-template library and found this, which looks like both templates should end up as comma-separated lists. However, when I try this in REPL, it consistently works as described above, not as written in the test.

honzajavorek commented 7 years ago

Please notice this comment from the authors of the uri-template library: https://github.com/grncdr/uri-template/issues/17#issuecomment-324020852

honzajavorek commented 7 years ago

I'm sorry for the mess, multi is correctly interpreted as foo=bar&foo=bar. I confused it with csv. This issue is irrelevant.