oas-normalize 5.0.0 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +14 -0
  2. package/index.js +14 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -83,3 +83,17 @@ For security reasons, you need to opt into allowing fetching by a local path. To
83
83
  ```js
84
84
  const oas = new OASNormalize('./petstore.json', { enablePaths: true })
85
85
  ```
86
+
87
+ ### Colorized errors
88
+
89
+ If you wish errors from `.validate()` to be styled and colorized, supply `colorizeErrors: true` to your instance of `OASNormalize`:
90
+
91
+ ```js
92
+ const oas = new OASNormalize('https://example.com/petstore.json', {
93
+ colorizeErrors: true,
94
+ })
95
+ ```
96
+
97
+ Error messages will look like such:
98
+
99
+ <img src="https://user-images.githubusercontent.com/33762/137796648-7e1157c2-cee4-466e-9129-dd2a743dd163.png" width="600" />
package/index.js CHANGED
@@ -7,7 +7,12 @@ const utils = require('./lib/utils');
7
7
  class oasNormalize {
8
8
  constructor(file, opts) {
9
9
  this.file = file;
10
- this.opts = { enablePaths: false, ...opts };
10
+ this.opts = {
11
+ colorizeErrors: false,
12
+ enablePaths: false,
13
+ ...opts,
14
+ };
15
+
11
16
  this.type = utils.type(this.file);
12
17
 
13
18
  this.cache = {
@@ -69,7 +74,9 @@ class oasNormalize {
69
74
  });
70
75
  }
71
76
 
72
- async validate(convertToLatest) {
77
+ async validate(convertToLatest = false) {
78
+ const colorizeErrors = this.opts.colorizeErrors;
79
+
73
80
  return this.load().then(async schema => {
74
81
  const baseVersion = parseInt(utils.version(schema), 10);
75
82
 
@@ -84,7 +91,11 @@ class oasNormalize {
84
91
  const clonedSchema = JSON.parse(JSON.stringify(schema));
85
92
 
86
93
  return openapiParser
87
- .validate(clonedSchema)
94
+ .validate(clonedSchema, {
95
+ validate: {
96
+ colorizeErrors,
97
+ },
98
+ })
88
99
  .then(() => {
89
100
  if (!convertToLatest) {
90
101
  return schema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas-normalize",
3
- "version": "5.0.0",
3
+ "version": "5.0.4",
4
4
  "description": "OpenAPI 3.x or Swagger 2.0? YAML or JSON? URL, path, string or object? Who cares! It just works.",
5
5
  "main": "index.js",
6
6
  "engines": {