openapi-semantic-validator
v0.8.0
Published
Perform structural and semantic validation on an OpenAPI specification, just like Swagger Editor!
Downloads
1,045
Readme
OpenAPI Semantic Validator
Perform structural and semantic validation on an OpenAPI specification, just like Swagger Editor!
Purpose
Swagger Editor performs both structural (schema) and semantic (spec) validation of OpenAPI specifications.
This package performs structural and semantic validation by executing the validators from the swagger-editor package.
Validation Examples
Structural
- should always have a 'X'
- Object includes not allowed fields
- etc.
Semantic
- operationId' must be unique among all operations
- parameter is not defined within path template
- etc.
Installation
yarn add openapi-semantic-validator
Usage
const { readFile } = require('fs/promises')
const { validateOpenapiSpec } = require('openapi-semantic-validator')
const spec = await readFile('openapi.yml', 'utf8')
// validate structure and semantics
try {
await validateOpenapiSpec(spec)
log('no structural or semantic errors!')
} catch (err) {
log(`structural or semantic errors: ${JSON.stringify(err.validationErrors)}`)
}API
validateOpenapiSpec(spec)- Validates an OpenAPI specification
- Inputs:
spec: OpenAPI specification string
- Returns:
Promise- If no structural or semantic errors are found, resolves
- If structural or semantic errors are found, rejects with an
Errorobject containing avalidationErrorsproperty; this is an array of objects containing:level: 'error' | 'warning'message: string
Development
yarn
yarn build
yarn testLicense
MIT
