Defining multiple schemas/mime types for a single path/operation

1,379 views
Skip to first unread message

David Biesack

unread,
Oct 20, 2014, 2:52:40 PM10/20/14
to swagger-sw...@googlegroups.com
I have a path /a/b/c and the POST method supports several different mime types.

How do I encode this in Swagger 2.0? If I use just one path/operation,
I can list multiple mime-types under the consumes: block, but 
I can only specify one parameter with in: body and corresponding schema

  /a/b/c:
    post
:
       consumes
:
         
- mime-type-1
         
- mime-type-2
       parameters
:
         
- name: body
           
in: body
           required
: true
           schema
:
             $ref
: ICanNameOneTypeHere



If I list the post method twice, each with the mime-type and corresponding
in: body parameter and schema, the swagger-ui only shows
the first of the two methods.  I suppose this is because 
the JSON path object for /a/b/c cannot have two different objects named "post".

How can I achieve what I want? Do I need to use a disciminator ?
Are there any examples of that? Note that these are discrete types,
not different subtypes of a common base type. The API uses the
Content-Type header to handle these two different POST requests.

Can I define a schema that is really defined as one of several?

   schema-1 | schema-2 | schema-3

if so, how do I associate the different schemas with their
corresponding mime-types?

This same question applies to supporting XML and JSON 
request bodies to the same path/method.

Ron

unread,
Oct 20, 2014, 3:02:47 PM10/20/14
to swagger-sw...@googlegroups.com
There's an open issue to add support for it in a future version of the spec.
You can find it here https://github.com/wordnik/swagger-spec/issues/146 and of course voice your opinion.

As for XML and JSON, as long as they are the same model which can be simply transformed, it can be supported.
The "xml" property of the schema can help with fine tuning such transformations (https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#xmlObject).

--
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.

Reply all
Reply to author
Forward
0 new messages