Search code examples
swaggerswagger-uiswagger-2.0swagger-editor

Swagger editor is throwing error while specifying the response "Not a valid response definition"


I am trying to generate the API documentation using swagger editor. I specified my API specification as follow

paths:
  /opendata/v1/{index}:
    get:
      tags: [verification]
      description: Verify the person information
      parameters:
        - name: index
          in: path
          description: specific data index
          required: true
          type: string
        - name: name
          in: query
          description: name of a person
          required: false
          type: string
        - name: company name
          in: query
          description: name of a company
          required: false
          type: string

      responses:
        '200':
          description: Success
          content:
            application/json:
              schemas:
                $ref: '#/responses/200'



responses:
    '200':
      description: Success
      schema:
        type: object
        properties:
          verification:
            type: string

But its always showing error in the editor that "Not a valid response definition". I checked the specification for response from here. What changes I should do so that error will not come.

Note: I want the response in the json form like below:

{
    verification:string
}

Solution

  • You are mixing OpenAPI/Swagger 2.0 and OpenAPI 3.0 syntax. Your spec seems to be swagger: '2.0', so you should use:

    paths:
      /opendata/v1/{index}:
        get:
          ...
    
          produces:
            - application/json
          responses:
            200:
              $ref: '#/responses/200'
    

    Here's a related OpenAPI/Swagger 2.0 guide: Describing Responses