2

I want to represent custom object as parameter of an api in swagger-editor. Lets say we are calling an api /postInfo/data

@RequestMapping(value = "/postInfo/data", method = RequestMethod.POST)
public Info requestProcessing(@RequestBody Info info)
{
    // Implementation
}

Above method contains Info model class as a parameter :

class Info
{
    private String id;
    private String name;
    private String desc;
}

How can this be represented in swagger editor as yaml document?

1 Answer 1

3

In Swagger 2.0, object schemas can be defined in the global definitions section:

definitions:
  Info:
    type: object
    properties:
      id:
        type: string
      name:
        type: string
      desc:
        type: string

and then $ref'ed from other parts of the spec.

If an object is used an input for an operation, the operation needs to define a body parameter with a schema that corresponds to that object's schema.

paths:
  /postInfo/data:
    post:
      consumes:
        - application/json
      parameters:
        - in: body
          name: body
          required: true
          schema:
            $ref: '#/definitions/Info'
      responses:
        200:
          description: OK
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.