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

OAS 3.0 Model Type Validation Not Accurate

Open kand617 opened this issue 7 years ago • 8 comments

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 :(

kand617 avatar Sep 23 '18 14:09 kand617

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?

kand617 avatar Sep 23 '18 14:09 kand617

Yes, I plan to implement validation for OpenAPI 3.0 too. PRs are always welcome, of course. 😉

JamesMessinger avatar Sep 23 '18 19:09 JamesMessinger

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.

kand617 avatar Sep 24 '18 04:09 kand617

@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 avatar Oct 29 '18 18:10 lexishanson

@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 avatar Oct 30 '18 09:10 JamesMessinger

@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!

mauriedo avatar Aug 21 '19 00:08 mauriedo

@JamesMessinger any update on when OpenApi 3 spec validation might be added?

derekherman avatar Jun 13 '20 04:06 derekherman

I don't currently have time to work on that, but would be happy to review a PR (with tests)

JamesMessinger avatar Jun 24 '20 10:06 JamesMessinger