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
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.
[1] Sample