swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

[Swagger 2.0] Missing definitions are not validated by Swagger Parser

Open tgtshanika opened this issue 2 years ago • 3 comments

Swagger Parser does not detect or validate swagger 2.0 definitions with missing response schema definitions. The following code snippet has been used to validate the swagger definition and it fails to identify validation errors in any Swagger 2.0 definitions with missing schemas. A sample definition can be found here [1]. But the swagger editor successfully validates these definitions and points out the error.

SwaggerParser parser = new SwaggerParser();
parser.parse(swaggerDefinition);

[1] Sample

swagger: '2.0'
info:
  version: 1.0.0
  title: Swagger Petstore
  description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
  termsOfService: http://swagger.io/terms/
  contact:
    name: Swagger API Team
  license:
    name: MIT
host: petstore.swagger.io
basePath: /api
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /pets:
    post:
      description: Creates a new pet in the store.  Duplicates are allowed
      operationId: addPet
      produces:
        - application/json
      parameters:
        - name: pet
          in: body
          description: Pet to add to the store
          required: true
          schema:
            $ref: '#/definitions/NewPet'
      responses:
        '200':
          description: pet response
          schema:
            $ref: '#/definitions/Pet'
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/ErrorModel'
definitions:
  NewPet:
    type: object
    required:
      - name
    properties:
      name:
        type: string
      tag:
        type: string
  ErrorModel:
    type: object
    required:
      - code
      - message
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string

tgtshanika avatar Nov 21 '22 11:11 tgtshanika

Any update on this?

tgtshanika avatar Feb 08 '23 07:02 tgtshanika

Facing the same issue . I need these errors as well

ajax-hospodarysko-a avatar Jun 28 '24 16:06 ajax-hospodarysko-a

@tgtshanika Did You managed to resolve this problem?

ajax-hospodarysko-a avatar Jun 28 '24 16:06 ajax-hospodarysko-a