Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update openapi json schema to fit json-schema draft 6 #42

Closed
nicolas-bonnel opened this issue Nov 30, 2017 · 2 comments
Closed

Update openapi json schema to fit json-schema draft 6 #42

nicolas-bonnel opened this issue Nov 30, 2017 · 2 comments

Comments

@nicolas-bonnel
Copy link

Hi,

I'm building a service that has an API catalog. To make the CRUD on API entities, I'm using schema validation with latest version of AJV, which support last JSON schema draft (v6).

I didn't found an official JSON schema for openapi 3.0 spec (I suscribed to this issue to get notified when one is available: OAI/OpenAPI-Specification#1032), so I'm using the one in this repository which seems to be the last up to date.

However, my validator complain and this schema does not seem to be draft v6 compatible. Is it possible to :

  • replace "format": "uriref" with "format": "uri-reference"
  • add a $id property at the root of the schema
  • replace "exclusiveMinimum": true with "exclusiveMinimum": 0 and remove "minimum": 0

I can also make a PR if you want, but I have no idea of the $id to use.

And 👍 for the great work you're doing on the openapi 3 spec !

@MikeRalphson
Copy link
Contributor

Hmm, this is complicated. OpenAPI 3.0.0 specifies the use of JSON Schema Draft 5, so it makes sense that the schemas which validate it should also be Draft 5, not Draft 6 or (the latest) Draft 7.

It is possible to manipulate ajv into working in Draft 5 mode, here's how it's done in validate.js:

var ajv = require('ajv')({
    allErrors: true,
    verbose: true,
    jsonPointers: true,
    patternGroups: true,
    extendRefs: true // optional, current default is to 'fail', spec behaviour is to 'ignore'
});
//meta: false, // optional, to prevent adding draft-06 meta-schema

var ajvFormats = require('ajv/lib/compile/formats.js');
ajv.addFormat('uriref', ajvFormats.full['uri-reference']);
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
ajv._refs['http://json-schema.org/schema'] = 'http://json-schema.org/draft-04/schema'; // optional, using unversioned URI is out of spec
var metaSchema = require('ajv/lib/refs/json-schema-v5.json');
ajv.addMetaSchema(metaSchema);
ajv._opts.defaultMeta = metaSchema.id;

@nicolas-bonnel
Copy link
Author

Ok, I understand.

Thanks for the answer !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants