-
Notifications
You must be signed in to change notification settings - Fork 22
Home
James Speirs edited this page Oct 9, 2018
·
2 revisions
Tools for validating and using the Open API Specification (OAS).
Supports OAS 2.0 (formerly Swagger) and OAS 3.x
Features
- Validate your OAS definition.
- Serialize, deserialize, and validate values against OAS schemas.
- Identify the operation associated with a request.
- Request parsing and validating.
- Facilitated response building with automated serialization and validating.
- Generate random valid values from a schema.
- Plugin environment for custom document validation and extended object functionality.
npm install openapi-enforcer
const Enforcer = require('openapi-enforcer');
const errors = Enforcer.errors({
openapi: '3.0.0',
info: {
title: "My API"
}
});
console.log(errors);
// One or more errors exist in the OpenAPI definition
// at: info
// Missing required property: version
// Missing required property: paths
This example shows how to deserialize and validate a request and then how to validate and serialize the response.
const enforcer = Enforcer({
openapi: '3.0.0',
info: {
version: "1.0.0"
title: "My API"
},
paths: {
"/pet/{petId}": {
}
});