swagger-parser
swagger-parser copied to clipboard
OAS 3.0 Model Type Validation Not Accurate
There seems to be quite a few differences between the validation on editor.swagger.io and this library. One such issue is as follows
SPEC:
openapi: "3.0.0"
info:
version: 1.0.0
title: My API
description: The API for everything
servers:
- url: http://localhost:8080/api
paths:
/applications:
get:
summary: List all applications
operationId: get-all-applications
tags:
- Applications
responses:
'200':
description: A list of applications
content:
application/json:
schema:
$ref: '#/components/schemas/Application'
components:
schemas:
Application:
required:
- name
- email
properties:
applicationId:
type: string
description: Unique application reference
name:
type: string
description: Name of the application
email:
type: invalidtype
description: Email address of the main contact
See how the type of email is invalidtype. This spec seems to pass validation :(
Oh man! I just read through the source code to see there is no validation for open api 3.0...... Any plans to support this?
Yes, I plan to implement validation for OpenAPI 3.0 too. PRs are always welcome, of course. 😉
I have been looking through the code and see that the validate function takes in a parsed object, the information about column and line are lost......
Would you consider an approach where line and column numbers are present too? This would be useful for text editors, it would be able to highlight a particular line/column combination.
@JamesMessinger Can you confirm the status of OAI 3.0 validation? The docs say "Validates against the Swagger 2.0 schema or OpenAPI 3.0 Schema." We're looking to specifically parse and validate against the 3.0 schema so we'd like to be aware of the maturity and any known nuances.
@lexishanson - Swagger Parser does two types of validation:
Schema Validation This ensures that your API definition is well-formed by validating it against the OpenAPI JSON Schema. This will catch most problems, including illegal structure, missing required parts, data type mismatches, and some typos.
Schema validation supported for both Swagger 2.0 and OpenAPI 3.0.
Spec Validation This is more akin to linting. It consists of custom rules to check for common mistakes, such as something that's never used, two parameters with the same name, etc.
Spec validation is currently only supported for Swagger 2.0. I do plan to eventually support it for OpenAPI 3.0 as well, and I'd be happy to accept a PR if you feel like contributing.
@JamesMessinger any updates on the plan to support OpenApi 3 spec validation? Swagger Parser is so useful with Swagger 2.0 specs, but our internal teams are moving to OpenApi 3 and losing that valuable safety net.
Any updates will be very much appreciated, and thanks for the useful library!
@JamesMessinger any update on when OpenApi 3 spec validation might be added?
I don't currently have time to work on that, but would be happy to review a PR (with tests)