Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-schema-validation

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-schema-validation - npm Package Compare versions

Comparing version 0.2.1 to 0.4.0

schema/openapi-3.0.json

20

index.js

@@ -6,6 +6,8 @@ var loggingKey = require('./package.json').name;

var jsonSchema = require('jsonschema-draft4');
var swaggerSchema = require('swagger-schema-official/schema.json');
var swagger2Schema = require('swagger-schema-official/schema.json');
var swagger3Schema = require('./schema/openapi-3.0.json');
v.addSchema(jsonSchema);
v.addSchema(swaggerSchema);
v.addSchema(swagger2Schema);
v.addSchema(swagger3Schema);

@@ -16,4 +18,14 @@ module.exports = {

function validate(openapiDoc) {
return v.validate(openapiDoc, swaggerSchema);
/**
* Runs specified validator against the provided openapiDocument and returns the results.
* Previously the second param was unused. To maintain backward compatibility, if anything other than a
* Number is passed, the v2 validator will be used.
*
* @param openapiDoc {object} to be validated
* @param version {Number} defaults to 2 if unspecified or invalid type is passed
* @returns {object} results from the validator
*/
function validate(openapiDoc, version) {
version = parseInt(version, 10) || 2; // default to swagger 2.0 validation
return v.validate(openapiDoc, version === 2 ? swagger2Schema : swagger3Schema);
}

13

package.json
{
"name": "openapi-schema-validation",
"version": "0.2.1",
"version": "0.4.0",
"description": "Validate openapi documents.",
"scripts": {
"cover": "istanbul cover _mocha -- ./test/*.js",
"coveralls": "cat ./coverage/lcov.info | coveralls -v",
"test-watch": "mocha -w ./test/*.js ./test/**/*.js",
"test": "mocha ./test/*.js"
"test": "mocha ./test/*.js",
"travis-test": "npm run cover"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kogosoftwarellc/openapi-schema-validation.git"
"url": "git+https://github.com/kogosoftwarellc/open-api.git"
},

@@ -23,8 +23,7 @@ "keywords": [

"bugs": {
"url": "https://github.com/kogosoftwarellc/openapi-schema-validation/issues"
"url": "https://github.com/kogosoftwarellc/open-api/issues"
},
"homepage": "https://github.com/kogosoftwarellc/openapi-schema-validation#readme",
"homepage": "https://github.com/kogosoftwarellc/open-api/tree/master/packages/openapi-schema-validation#readme",
"devDependencies": {
"chai": "^3.4.1",
"coveralls": "^2.11.6",
"glob": "^6.0.3",

@@ -31,0 +30,0 @@ "istanbul": "^0.4.1",

# openapi-schema-validation [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url]
> Validate openapi documents.
For OpenAPI v2.0 (a.k.a. swagger 2.0) document examples and documentation, view
[the official docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#itemsObject).
##For OpenAPI v2.0 (a.k.a. swagger 2.0) and OpenAPI v3.0.0
####Document examples and full specs:
* [Official 2.0 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#itemsObject)
* [Official 3.0.0 docs](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md)
## Highlights
* Validate openapi documents against official openapi schema documents.
* Validate openapi documents against openapi schema documents.
* Uses [jsonschema](https://github.com/tdegrunt/jsonschema) under the hood.

@@ -16,22 +18,22 @@ * Performant.

* Small footprint.
* Currently supports openapi 2.0 (a.k.a. swagger 2.0) documents.
* Supports openapi 2.0 (a.k.a. swagger 2.0) documents and openapi 3.0.0
## Example
**Huge thank you to the [gnostic](https://github.com/googleapis/gnostic) project for building up a 3.0.0 JSON schema.**
See `./test/data-driven/*.js` for more examples.
## Example
```javascript
var validateSchema = require('openapi-schema-validation').validate;
console.log(validateSchema({/* openapi doc */}, {version: 'swagger-2.0'});
console.log(validateSchema(apiDoc, version));
```
[see here](https://github.com/tdegrunt/jsonschema#results) for example results.
## API
### .validate(apiDoc [, args])
### .validate(apiDoc, version)
* `apiDoc` _object_ is any api document you wish to validate.
* `version` _optional number_ openapi document schema version to use (2 or 3).
* 2 - `swagger-2.0` (default)
* 3 - `openapi-3.0.0`
`apiDoc` is any api document you wish to validate.
`[args]` is an optional object the accepts the following arguments:
* `version` - The openapi document schema version to use. Currently the only supported
version is `swagger-2.0` (the default).
## LICENSE

@@ -66,6 +68,6 @@ ``````

[travis-url]: https://travis-ci.org/kogosoftwarellc/openapi-schema-validation
[travis-image]: http://img.shields.io/travis/kogosoftwarellc/openapi-schema-validation.svg
[travis-url]: https://travis-ci.org/kogosoftwarellc/open-api
[travis-image]: http://img.shields.io/travis/kogosoftwarellc/open-api.svg
[coveralls-url]: https://coveralls.io/r/kogosoftwarellc/openapi-schema-validation
[coveralls-image]: http://img.shields.io/coveralls/kogosoftwarellc/openapi-schema-validation/master.svg
[coveralls-url]: https://coveralls.io/r/kogosoftwarellc/open-api
[coveralls-image]: http://img.shields.io/coveralls/kogosoftwarellc/open-api/master.svg

@@ -12,5 +12,4 @@ var expect = require('chai').expect;

fixture = require(path.resolve(baseDir, fixture));
it('should ' + testName, function() {
var errors = sut.validate(fixture.apiDoc).errors;
var errors = sut.validate(fixture.apiDoc, fixture.validator).errors;
expect(JSON.stringify(errors, null, ' '))

@@ -17,0 +16,0 @@ .to.equal(JSON.stringify(fixture.errors, null, ' '));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc