swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
786 stars 531 forks source link

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

Open tgtshanika opened 2 years ago

tgtshanika commented 2 years ago

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 commented 1 year ago

Any update on this?

ajax-hospodarysko-a commented 4 months ago

Facing the same issue . I need these errors as well

ajax-hospodarysko-a commented 4 months ago

@tgtshanika Did You managed to resolve this problem?