Body Param or Response Schema as Array of Strings

5,074 views
Skip to first unread message

Eric Hemesath

unread,
Dec 5, 2014, 5:45:41 PM12/5/14
to swagger-sw...@googlegroups.com
I cannot seem to set an array with strings as either a PUT body schema or Response schema (e.g. ["test","test2","test3"\

      responses:
       
200:
          description
: Sequence of Steps to perform
          schema
:
            title
: sequence
            type
: array
            items
:
              type
: string
            example
: ["idofstep1","idofstep2","idofstep3"]

OR

      parameters:
       
- name: sequence
         
in: body
          required
: true
          schema
:
            type
: array
            items
:
              type
: string




Background....

Our API has an endpoint that deals with the sequence of sub objects.

/Instructions/{ID}/Steps/ -> Returns an [ ] of Steps associated with a specific Instruction object

/Instructions/{ID}/Steps/sequence -> Returns & Accepts an [ ] of Step IDs to be used as the sequence of those steps



I believe the following is a valid json-schema...

schema:
{
  "type": "array",
  "items": {
    "type": "string"
  }
}

json:
["idofstep1","idofstep2","idofstep3"]

Ron

unread,
Dec 5, 2014, 11:33:24 PM12/5/14
to swagger-sw...@googlegroups.com

Hi Eric,

I'm not really sure what you mean. What problem do you experience? The snippets you provided are valid.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ron

unread,
Dec 5, 2014, 11:33:26 PM12/5/14
to swagger-sw...@googlegroups.com

Hi Eric,

I'm not really sure what you mean. What problem do you experience? The snippets you provided are valid.

On Dec 6, 2014 12:45 AM, "Eric Hemesath" <eric.h...@funnelwise.com> wrote:
--

Eric Hemesath

unread,
Dec 6, 2014, 9:06:38 AM12/6/14
to swagger-sw...@googlegroups.com
Sorry. The resulting swagger-ui does not show the appropriate parameters or response schema.

PUT body parameter should be an array of strings:


GET response should be an array of strings:


Thanks for the reply Ron.

Ron

unread,
Dec 6, 2014, 9:44:22 AM12/6/14
to swagger-sw...@googlegroups.com
Which version of the UI do you use? It's a known issue that should have been resolved with https://github.com/swagger-api/swagger-ui/issues/713.

--

Eric Hemesath

unread,
Dec 7, 2014, 9:51:35 PM12/7/14
to swagger-sw...@googlegroups.com
Latest on master...

Squashed 'subtrees/swagger-ui/' changes from 2c4f4a6..886145b


I should probably say... my swagger files are not auto generated. I'm currently writing them in YAML and converting them. Here is my process.

  1. Write Documentation in YAML
  2. Convert the YAML docs to JSON using gulp-yaml
  3. Validate the json files using swagger-tools
  4. Copy all swagger-ui files from /dist/ to my build dir
  5. Copy swagger-ui/dist/index.html
    • Modify it to look locally for the swagger json spec files
  6. Deploy to nginx docker

Ron

unread,
Dec 8, 2014, 12:06:14 AM12/8/14
to swagger-sw...@googlegroups.com
Any chance you can share your spec (preferably the JSON)? That would make it easier to test.

--

Ron

unread,
Dec 8, 2014, 2:43:58 AM12/8/14
to swagger-sw...@googlegroups.com
Hi Eric,

Thanks for sharing the spec (in private, which is perfectly ok). I'm replying here for the benefit of the community.

There are two distinct issues here. The first is documenting the param and the second is the response.

For the body parameter (or any other type), the issue should be resolved with issue #713.
If you follow this comment - https://github.com/swagger-api/swagger-ui/issues/713#issuecomment-64740733 - and replace your swagger-client.js, it should render properly.
If it works for you and looks fine, please add a comment to the issue.

The response documentation is different though. It seems the whole rendering of primitive arrays is broken.
If you have either a primitive or an array of models, it renders fine, but once it's an array of primitives, it renders 'name' for some reason and that certainly shouldn't be the case.
To resolve that, you'd need to open an issue directly on swagger-ui. Try to give there as many details as possible, and a snippet could really help in showing the problem.

Thanks for bringing it up to our attention!
Reply all
Reply to author
Forward
0 new messages