SVN600
SVN600

Reputation: 385

Swagger Model Schema does not include variable name for body parameter

In the Swagger UI for my application I have POST and PUT methods that both take in a POJO as a body parameter in the REST call. When I look at the UI and click on the Model Schema to automatically fill the parameter box (just to save time on typing the whole JSON out) it does not include the name of the parameter so the request fails. Example:

Model Schema:

{ 
   "first": "string",
   "last": "string",
   "address": "string",
   "email": "string",
   .
   .
   .
}

However, to make the request I need to include the parameter name entry as so:

{ "entry": {
   "first": "string",
   "last": "string",
   "address": "string",
   "email": "string",
   .
   .
   .
}}

While it is not too inconvenient to do this myself before making a request, it has caused issues with other developers using the Swagger UI for my application and not realizing that they need to add entry. Is there a way to modify the Model Schema?

Upvotes: 0

Views: 1048

Answers (1)

Wilson
Wilson

Reputation: 11637

The name of the parameter is not used as a property in body parameter. In order to describe your model, you can define a entry property with object type as follow:

definitions:
  Entry:
    type: object
    properties:
      entry:
        type: object
        properties:
          first: 
            type: string
          last:
            type: string
          address:
            type: string
          email:
            type: string

and you can use it as body schema like follows:

post:
  produces:
    - application/json
  parameters:
    - name: body
      in: body
      schema:
        $ref: '#/definitions/Entry'

Upvotes: 2

Related Questions