Skip to content

Validate if its result is indeed a OAS3 schema #8

Closed
@sebas2day

Description

@sebas2day

First off: thanks a lot for the effort being put into this.

I have a situation where I had a JSON schema converted to OAS3 schema but it didn't match the oas3 json schema spec. It took me some time to figure out what was causing the issue because I was expecting a oas3 compliant schema. Apparently it were some extra properties that were in the json schema that were directly translated to the oas3 schema but aren't allowed.

Would it be an idea to always validate whether the transformed result is always oas3 compliant?
e.g.:

import Ajv from 'ajv';
import draft4 from 'ajv/lib/refs/json-schema-draft-04.json';
import oas3schema from './refs/schema.oas3.json'; 

function validateOAS3Schema(schema) {
  let ajv = new Ajv({
    schemaId: 'id', // draft-04 support requirment.
    allErrors: true,
    jsonPointers: true
  });
  ajv.addMetaSchema(draft4);
  ajv.addSchema(oas3schema);
  let valid = ajv.validate({ $ref: 'https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema' }, schema);
  if (!valid) {
    throw new Error(ajv.errorsText());
  }
}

Let me know your ideas :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions