oas-normalize
Advanced tools
Comparing version 5.0.0 to 5.0.1
17
index.js
@@ -10,3 +10,8 @@ const fetch = require('node-fetch'); | ||
this.file = file; | ||
this.opts = { enablePaths: false, ...opts }; | ||
this.opts = { | ||
colorizeErrors: false, | ||
enablePaths: false, | ||
...opts, | ||
}; | ||
this.type = utils.type(this.file); | ||
@@ -73,3 +78,5 @@ | ||
async validate(convertToLatest) { | ||
async validate(convertToLatest = false) { | ||
const colorizeErrors = this.opts.colorizeErrors; | ||
return this.load().then(async schema => { | ||
@@ -89,3 +96,7 @@ const baseVersion = parseInt(utils.version(schema), 10); | ||
return openapiParser | ||
.validate(clonedSchema) | ||
.validate(clonedSchema, { | ||
validate: { | ||
colorizeErrors, | ||
}, | ||
}) | ||
.then(() => { | ||
@@ -92,0 +103,0 @@ if (!convertToLatest) { |
{ | ||
"name": "oas-normalize", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "OpenAPI 3.x or Swagger 2.0? YAML or JSON? URL, path, string or object? Who cares! It just works.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -86,1 +86,15 @@ OpenAPI 3.x or Swagger 2.0? YAML or JSON? URL, path, string or object? Who cares! It just works. | ||
``` | ||
### Colorized errors | ||
If you wish errors from `.validate()` to be styled and colorized, supply `colorizeErrors: true` to your instance of `OASNormalize`: | ||
```js | ||
const oas = new OASNormalize('https://example.com/petstore.json', { | ||
colorizeErrors: true, | ||
}) | ||
``` | ||
Error messages will look like such: | ||
<img src="https://user-images.githubusercontent.com/33762/137796648-7e1157c2-cee4-466e-9129-dd2a743dd163.png" width="600" /> |
15774
138
100