swagger-api / swagger-api/swagger-parser
[Swagger 2.0] Missing definitions are not validated by Swagger Parser
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at SwaggerParser.parse using the Swagger 2.0 sample in the issue, which references the missing Pet definition from a response schema. Trace how referenced definitions are resolved and validated; done means parsing this sample reports the missing schema instead of succeeding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100