Wednesday 26 April 2017

What is the schema type for JSON object in swagger 2.0

I am writing a API document with the help of Swagger 2.0. I have generated one API where response is in array of books which is working fine.

[{
    "id": 1,
    "book_name": "The Complete Reference Java8",
    "author": "Herbert Schidt",
    "genre": "Technology"
}, {
    "id": 2,
    "book_name": "C Programming",
    "author": "Dennis Ritchie",
    "genre": "Technology"
}]

Swagger

/fetchBooks:
get:
  description: |
    Returns an array of book objects.

  responses:
    200:
      description: Successful response
      schema:
        title: ArrayOfBooks
        type: array
        items:
          type: object
          properties:
            id:
              type: integer
            book_name:
              type: string
            author:
              type: string
            genre:
              type: string

Well, I want to send only one book details in one API in JSONObject what schema type should I take for it as I tried object is not working.

{
    "id": 1,
    "book_name": "The Complete Reference Java8",
    "author": "Herbert Schidt",
    "genre": "Technology"
}

Swagger

/fetchBook:
get:
  description: |
    Returns a book object

  parameters:
    - name: id
      in: query
      description: Books Id's
      reqrequired: true
      type: integer
      format: int

  responses:  
    200:
      description: Successful response
      schema:
        type: object <-- What type should I specify for JSONObject here
        items:
          type: object
          properties:
            id:
              type: integer
            book_name:
              type: string
            author:
              type: string
            genre:
              type: string

As object is not working, swagger is not showing JSON format.

Current State :

enter image description here

Expected State :

enter image description here



via Williams

No comments:

Post a Comment