oas-normalize 15.2.0 → 15.4.0

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.
package/README.md CHANGED
@@ -128,10 +128,12 @@ If you also wish to treat certain errors as warnings you can do so by supplying
128
128
  ```ts
129
129
  try {
130
130
  const result = await oas.validate({
131
- validate: {
132
- rules: {
133
- openapi: {
134
- 'path-parameters-not-in-path': 'warning',
131
+ parser: {
132
+ validate: {
133
+ rules: {
134
+ openapi: {
135
+ 'path-parameters-not-in-path': 'warning',
136
+ },
135
137
  },
136
138
  },
137
139
  },
@@ -148,7 +150,26 @@ try {
148
150
  }
149
151
  ```
150
152
 
151
- For full documentation on the available rulesets, as well as tooling to transform the the `.validate()` responses into a human-readable strings, check out the documentation for [`@readme/openapi-parser`](https://npm.im/@readme/openapi-parser).
153
+ If you want to always receive a `ValidationResult` object back (which includes a flag that indicates if the supplied API definition is valid or not), you can set the `shouldThrowIfInvalid` option to `false`:
154
+
155
+ ```ts
156
+ const result = await oas.validate({ shouldThrowIfInvalid: false });
157
+ console.log(result);
158
+
159
+ /*
160
+ {
161
+ valid: false,
162
+ errors: [
163
+ { message: 'REQUIRED must have required property "url"' },
164
+ ],
165
+ warnings: [],
166
+ additionalErrors: 0,
167
+ specification: 'OpenAPI',
168
+ } */
169
+ ```
170
+
171
+ > [!NOTE]
172
+ > For full documentation on the available rulesets, as well as tooling to transform `ValidateResult` objects into a human-readable strings, check out the documentation for [`@readme/openapi-parser`](https://npm.im/@readme/openapi-parser).
152
173
 
153
174
  ### `.version()`
154
175
 
@@ -0,0 +1,19 @@
1
+ // src/lib/errors.ts
2
+ var ValidationError = class extends Error {
3
+ errors;
4
+ warnings;
5
+ constructor(message, {
6
+ errors,
7
+ warnings
8
+ } = {}) {
9
+ super(message);
10
+ this.name = "ValidationError";
11
+ this.errors = errors || [];
12
+ this.warnings = warnings || [];
13
+ }
14
+ };
15
+
16
+ export {
17
+ ValidationError
18
+ };
19
+ //# sourceMappingURL=chunk-45XXAYDL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/errors.ts"],"sourcesContent":["import type { ErrorDetails, WarningDetails } from '@readme/openapi-parser';\n\nexport class ValidationError extends Error {\n errors: ErrorDetails[];\n warnings: WarningDetails[];\n\n constructor(\n message: string,\n {\n errors,\n warnings,\n }: {\n errors?: ErrorDetails[];\n warnings?: WarningDetails[];\n } = {},\n ) {\n super(message);\n this.name = 'ValidationError';\n this.errors = errors || [];\n this.warnings = warnings || [];\n }\n}\n"],"mappings":";AAEO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EAEA,YACE,SACA;AAAA,IACE;AAAA,IACA;AAAA,EACF,IAGI,CAAC,GACL;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS,UAAU,CAAC;AACzB,SAAK,WAAW,YAAY,CAAC;AAAA,EAC/B;AACF;","names":[]}
@@ -1,12 +1,19 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/lib/errors.ts
2
2
  var ValidationError = class extends Error {
3
- constructor(message) {
3
+
4
+
5
+ constructor(message, {
6
+ errors,
7
+ warnings
8
+ } = {}) {
4
9
  super(message);
5
10
  this.name = "ValidationError";
11
+ this.errors = errors || [];
12
+ this.warnings = warnings || [];
6
13
  }
7
14
  };
8
15
 
9
16
 
10
17
 
11
18
  exports.ValidationError = ValidationError;
12
- //# sourceMappingURL=chunk-SI6PKQOL.cjs.map
19
+ //# sourceMappingURL=chunk-AKXTCPGM.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas-normalize/dist/chunk-AKXTCPGM.cjs","../src/lib/errors.ts"],"names":[],"mappings":"AAAA;ACEO,IAAM,gBAAA,EAAN,MAAA,QAA8B,MAAM;AAAA,EACzC;AAAA,EACA;AAAA,EAEA,WAAA,CACE,OAAA,EACA;AAAA,IACE,MAAA;AAAA,IACA;AAAA,EACF,EAAA,EAGI,CAAC,CAAA,EACL;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,KAAA,EAAO,iBAAA;AACZ,IAAA,IAAA,CAAK,OAAA,EAAS,OAAA,GAAU,CAAC,CAAA;AACzB,IAAA,IAAA,CAAK,SAAA,EAAW,SAAA,GAAY,CAAC,CAAA;AAAA,EAC/B;AACF,CAAA;ADPA;AACA;AACE;AACF,0CAAC","file":"/Users/erunion/code/readme/oas/packages/oas-normalize/dist/chunk-AKXTCPGM.cjs","sourcesContent":[null,"import type { ErrorDetails, WarningDetails } from '@readme/openapi-parser';\n\nexport class ValidationError extends Error {\n errors: ErrorDetails[];\n warnings: WarningDetails[];\n\n constructor(\n message: string,\n {\n errors,\n warnings,\n }: {\n errors?: ErrorDetails[];\n warnings?: WarningDetails[];\n } = {},\n ) {\n super(message);\n this.name = 'ValidationError';\n this.errors = errors || [];\n this.warnings = warnings || [];\n }\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkSI6PKQOLcjs = require('./chunk-SI6PKQOL.cjs');
3
+ var _chunkAKXTCPGMcjs = require('./chunk-AKXTCPGM.cjs');
4
4
 
5
5
 
6
6
 
@@ -159,6 +159,7 @@ var OASNormalize = class _OASNormalize {
159
159
  *
160
160
  */
161
161
  async validate(opts = {}) {
162
+ const shouldThrowIfInvalid = _nullishCoalesce(opts.shouldThrowIfInvalid, () => ( true));
162
163
  const parserOptions = opts.parser || this.opts.parser || {};
163
164
  if (!parserOptions.validate) parserOptions.validate = {};
164
165
  if (!parserOptions.validate.errors) parserOptions.validate.errors = {};
@@ -167,17 +168,38 @@ var OASNormalize = class _OASNormalize {
167
168
  return _chunkHIUYACR6cjs.isPostman.call(void 0, schema) ? _OASNormalize.convertPostmanToOpenAPI(schema) : schema;
168
169
  }).then(async (schema) => {
169
170
  if (!_chunkHIUYACR6cjs.isSwagger.call(void 0, schema) && !_chunkHIUYACR6cjs.isOpenAPI.call(void 0, schema)) {
170
- throw new (0, _chunkSI6PKQOLcjs.ValidationError)("The supplied API definition is unsupported.");
171
+ if (shouldThrowIfInvalid) {
172
+ throw new (0, _chunkAKXTCPGMcjs.ValidationError)("The supplied API definition is unsupported.");
173
+ }
174
+ return {
175
+ valid: false,
176
+ errors: [{ message: "The supplied API definition is unsupported." }],
177
+ warnings: [],
178
+ additionalErrors: 0,
179
+ specification: null
180
+ };
171
181
  } else if (_chunkHIUYACR6cjs.isSwagger.call(void 0, schema)) {
172
182
  const baseVersion = parseInt(schema.swagger, 10);
173
183
  if (baseVersion === 1) {
174
- throw new (0, _chunkSI6PKQOLcjs.ValidationError)("Swagger v1.2 is unsupported.");
184
+ if (shouldThrowIfInvalid) {
185
+ throw new (0, _chunkAKXTCPGMcjs.ValidationError)("Swagger v1.2 is unsupported.");
186
+ }
187
+ return {
188
+ valid: false,
189
+ errors: [{ message: "Swagger v1.2 is unsupported." }],
190
+ warnings: [],
191
+ additionalErrors: 0,
192
+ specification: "Swagger"
193
+ };
175
194
  }
176
195
  }
177
196
  const clonedSchema = JSON.parse(JSON.stringify(schema));
178
197
  const result = await _openapiparser.validate.call(void 0, clonedSchema, parserOptions);
179
- if (!result.valid) {
180
- throw new (0, _chunkSI6PKQOLcjs.ValidationError)(_openapiparser.compileErrors.call(void 0, result));
198
+ if (!result.valid && shouldThrowIfInvalid) {
199
+ throw new (0, _chunkAKXTCPGMcjs.ValidationError)(_openapiparser.compileErrors.call(void 0, result), {
200
+ errors: result.errors,
201
+ warnings: result.warnings
202
+ });
181
203
  }
182
204
  return result;
183
205
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas-normalize/dist/index.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAAA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAAA;AACA;AACA;ACTA,gEAAe;AAEf,uDAA6D;AAC7D,kIAA6B;AAC7B,oHAAsB;AActB,IAAqB,aAAA,EAArB,MAAqB,cAAa;AAAA,EAChC;AAAA;AAAA,EAQA;AAAA,EAEA;AAAA,EAEA;AAAA;AAAA,EAGA,WAAA,CAAY,IAAA,EAAW,IAAA,EAAgB;AACrC,IAAA,IAAA,CAAK,KAAA,EAAO,IAAA;AACZ,IAAA,IAAA,CAAK,KAAA,EAAO;AAAA,MACV,cAAA,EAAgB,KAAA;AAAA,MAChB,WAAA,EAAa,KAAA;AAAA,MACb,MAAA,EAAQ,CAAC,CAAA;AAAA,MACT,GAAG;AAAA,IACL,CAAA;AAEA,IAAA,GAAA,CAAI,CAAC,IAAA,CAAK,IAAA,CAAK,WAAA,EAAa;AAC1B,MAAA,GAAA,CAAI,CAAC,IAAA,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QAEF,OAAA;AACE,UAAA,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA;AAAA,MAC5C;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF,CAAA;AD/FA;AACE;AACF,+BAAA","file":"/Users/erunion/code/readme/oas/packages/oas-normalize/dist/index.cjs","sourcesContent":[null,"import type { ParserOptions, ValidationResult } from '@readme/openapi-parser';\nimport type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';\nimport type { Options } from './lib/types.js';\n\nimport fs from 'node:fs';\n\nimport { bundle, compileErrors, dereference, validate } from '@readme/openapi-parser';\nimport postmanToOpenAPI from '@readme/postman-to-openapi';\nimport converter from 'swagger2openapi';\n\nimport { ValidationError } from './lib/errors.js';\nimport {\n getAPIDefinitionType,\n getType,\n isOpenAPI,\n isPostman,\n isSwagger,\n prepareURL,\n stringToJSON,\n} from './lib/utils.js';\n\n// biome-ignore lint/style/noDefaultExport: This is fine for now.\nexport default class OASNormalize {\n cache: {\n bundle?: OpenAPI.Document | false;\n convert?: OpenAPI.Document | false;\n deref?: OpenAPI.Document | false;\n load?: Record<string, unknown> | false;\n };\n\n // biome-ignore lint/suspicious/noExplicitAny: Intentionally loose because this library supports a wide variety of inputs.\n file: any;\n\n opts: Options;\n\n type: ReturnType<typeof getType>;\n\n // biome-ignore lint/suspicious/noExplicitAny: Intentionally loose because this library supports a wide variety of inputs.\n constructor(file: any, opts?: Options) {\n this.file = file;\n this.opts = {\n colorizeErrors: false,\n enablePaths: false,\n parser: {},\n ...opts,\n };\n\n if (!this.opts.enablePaths) {\n if (!this.opts.parser) this.opts.parser = {};\n if (!this.opts.parser.resolve) this.opts.parser.resolve = {};\n this.opts.parser.resolve = { file: false };\n }\n\n this.type = getType(this.file);\n\n this.cache = {\n load: false,\n bundle: false,\n deref: false,\n };\n }\n\n /**\n * Load and return the API definition that `oas-normalize` was initialized with.\n *\n */\n async load(): Promise<Record<string, unknown>> {\n if (this.cache.load) return this.cache.load;\n\n const resolve = (obj: Parameters<typeof stringToJSON>[0]) => {\n const ret = stringToJSON(obj);\n this.cache.load = ret;\n return ret;\n };\n\n switch (this.type) {\n case 'json':\n case 'string-json':\n case 'string-yaml':\n return resolve(this.file);\n\n case 'buffer':\n return resolve(this.file.toString());\n\n case 'url': {\n const { url, options } = prepareURL(this.file);\n const resp = await fetch(url, options).then(res => res.text());\n return resolve(resp);\n }\n\n case 'path': {\n // Load a local file\n if (!this.opts.enablePaths) {\n throw new Error('Use `opts.enablePaths` to enable accessing local files.');\n }\n\n const contents = fs.readFileSync(this.file).toString();\n if (!contents.trim()) {\n throw new Error('No file contents found.');\n }\n return resolve(contents);\n }\n\n default:\n throw new Error('Could not load this file.');\n }\n }\n\n private static async convertPostmanToOpenAPI(schema: Record<string, unknown>) {\n return postmanToOpenAPI(JSON.stringify(schema), undefined, {\n outputFormat: 'json',\n replaceVars: true,\n }).then(JSON.parse);\n }\n\n /**\n * Bundle up the given API definition, resolving any external `$ref` pointers in the process.\n *\n */\n async bundle(): Promise<OpenAPI.Document> {\n if (this.cache.bundle) return this.cache.bundle;\n const parserOptions = this.opts.parser || {};\n\n return this.load()\n .then(schema => {\n // Though Postman collections don't support `$ref` pointers for us to bundle we'll still\n // upconvert it to an OpenAPI definition file so our returned dataset is always one of\n // those for a Postman dataset.\n if (isPostman(schema)) {\n return OASNormalize.convertPostmanToOpenAPI(schema);\n }\n\n return schema;\n })\n .then(schema => bundle(schema, parserOptions))\n .then(bundled => {\n this.cache.bundle = bundled;\n return bundled;\n });\n }\n\n /**\n * Dereference the given API definition.\n *\n */\n async dereference(): Promise<OpenAPI.Document> {\n if (this.cache.deref) return this.cache.deref;\n const parserOptions = this.opts.parser || {};\n\n return this.load()\n .then(schema => {\n // Though Postman collections don't support `$ref` pointers for us to dereference we'll\n // still upconvert it to an OpenAPI definition file so our returned dataset is always one\n // of those for a Postman dataset.\n if (isPostman(schema)) {\n return OASNormalize.convertPostmanToOpenAPI(schema);\n }\n\n return schema;\n })\n .then(schema => dereference(schema, parserOptions))\n .then(dereferenced => {\n this.cache.deref = dereferenced;\n return dereferenced;\n });\n }\n\n /**\n * Dereference the given API definition.\n *\n * This method is deprecated in favor of `dereference`. It will be removed in a future release.\n *\n * @deprecated\n */\n async deref(): Promise<OpenAPI.Document> {\n return this.dereference();\n }\n\n /**\n * Convert a given API definition to OpenAPI if it is not already.\n *\n */\n async convert(): Promise<OpenAPI.Document> {\n if (this.cache.convert) return this.cache.convert;\n\n return this.load()\n .then(async schema => {\n // If we have a Postman collection we need to convert it to OpenAPI.\n return isPostman(schema) ? OASNormalize.convertPostmanToOpenAPI(schema) : schema;\n })\n .then(async schema => {\n if (!isSwagger(schema) && !isOpenAPI(schema)) {\n throw new Error('The supplied API definition is unsupported.');\n } else if (isOpenAPI(schema)) {\n return schema;\n }\n\n const baseVersion = parseInt(schema.swagger, 10);\n if (baseVersion === 1) {\n throw new Error('Swagger v1.2 is unsupported.');\n }\n\n return converter\n .convertObj(schema, { anchors: true })\n .then((options: { openapi: OpenAPI.Document }) => options.openapi);\n });\n }\n\n /**\n * Validate a given API definition.\n *\n * If supplied a Postman collection it will be converted to OpenAPI first and then run through\n * standard OpenAPI validation.\n *\n */\n async validate(\n opts: {\n /**\n * Options to supply to our OpenAPI parser. See `@readme/openapi-parser` for documentation.\n * This option is deprecated in favor of the `parser` option on the constructor. It will be\n * removed in a future release.\n *\n * @see {@link https://npm.im/@readme/openapi-parser}\n * @deprecated\n */\n parser?: ParserOptions;\n } = {},\n ): Promise<ValidationResult> {\n const parserOptions = opts.parser || this.opts.parser || {};\n if (!parserOptions.validate) parserOptions.validate = {};\n if (!parserOptions.validate.errors) parserOptions.validate.errors = {};\n\n parserOptions.validate.errors.colorize = this.opts.colorizeErrors;\n\n return this.load()\n .then(async schema => {\n // Because we don't have something akin to `openapi-parser` for Postman collections we just\n // always convert them to OpenAPI.\n return isPostman(schema) ? OASNormalize.convertPostmanToOpenAPI(schema) : schema;\n })\n .then(async schema => {\n if (!isSwagger(schema) && !isOpenAPI(schema)) {\n throw new ValidationError('The supplied API definition is unsupported.');\n } else if (isSwagger(schema)) {\n const baseVersion = parseInt(schema.swagger, 10);\n if (baseVersion === 1) {\n throw new ValidationError('Swagger v1.2 is unsupported.');\n }\n }\n\n /**\n * `OpenAPIParser.validate()` dereferences schemas at the same time as validation, mutating\n * the supplied parameter in the process, and does not give us an option to disable this.\n * As we already have a dereferencing method on this library, and this method just needs to\n * tell us if the API definition is valid or not, we need to clone the schema before\n * supplying it to `openapi-parser`.\n */\n const clonedSchema = JSON.parse(JSON.stringify(schema));\n\n const result = await validate(clonedSchema, parserOptions);\n if (!result.valid) {\n throw new ValidationError(compileErrors(result));\n }\n\n // The API definition, whatever its format or specification, is valid.\n return result;\n });\n }\n\n /**\n * Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition.\n *\n */\n async version(): Promise<{\n specification: 'openapi' | 'postman' | 'swagger';\n version: string | 'unknown';\n }> {\n return this.load().then(schema => {\n switch (getAPIDefinitionType(schema)) {\n case 'openapi':\n return {\n specification: 'openapi',\n version: (schema as unknown as OpenAPIV3.Document).openapi,\n };\n\n case 'postman': {\n let version = 'unknown';\n if ((schema?.info as Record<string, string>)?.schema) {\n // Though `info.schema` is required by the Postman spec there's no strictness to its\n // contents so we'll do our best to extract a version out of this schema URL that they\n // seem to usually match. If not we'll fallback to treating it as an `unknown` version.\n const match = (schema?.info as Record<string, string>).schema.match(\n /http(s?):\\/\\/schema.getpostman.com\\/json\\/collection\\/v([0-9.]+)\\//,\n );\n\n if (match) {\n version = match[2];\n }\n }\n\n return {\n specification: 'postman',\n version,\n };\n }\n\n case 'swagger':\n return {\n specification: 'swagger',\n version: (schema as unknown as OpenAPIV2.Document).swagger,\n };\n\n default:\n throw new Error('Unknown file detected.');\n }\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas-normalize/dist/index.cjs","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAAA;AACA;AACE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AAe,SAAA;AAAA,YACf,OAAA,EAAU,MAAA,CAAyC;AAAA,UACrD,CAAA;AAAA,QAEF,OAAA;AACE,UAAA,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAAA;AAAA,MAC5C;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF,CAAA;AD3GA;AACE;AACF,+BAAA","file":"/Users/erunion/code/readme/oas/packages/oas-normalize/dist/index.cjs","sourcesContent":[null,"import type { ParserOptions, ValidationResult } from '@readme/openapi-parser';\nimport type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';\nimport type { Options } from './lib/types.js';\n\nimport fs from 'node:fs';\n\nimport { bundle, compileErrors, dereference, validate } from '@readme/openapi-parser';\nimport postmanToOpenAPI from '@readme/postman-to-openapi';\nimport converter from 'swagger2openapi';\n\nimport { ValidationError } from './lib/errors.js';\nimport {\n getAPIDefinitionType,\n getType,\n isOpenAPI,\n isPostman,\n isSwagger,\n prepareURL,\n stringToJSON,\n} from './lib/utils.js';\n\n// biome-ignore lint/style/noDefaultExport: This is fine for now.\nexport default class OASNormalize {\n cache: {\n bundle?: OpenAPI.Document | false;\n convert?: OpenAPI.Document | false;\n deref?: OpenAPI.Document | false;\n load?: Record<string, unknown> | false;\n };\n\n // biome-ignore lint/suspicious/noExplicitAny: Intentionally loose because this library supports a wide variety of inputs.\n file: any;\n\n opts: Options;\n\n type: ReturnType<typeof getType>;\n\n // biome-ignore lint/suspicious/noExplicitAny: Intentionally loose because this library supports a wide variety of inputs.\n constructor(file: any, opts?: Options) {\n this.file = file;\n this.opts = {\n colorizeErrors: false,\n enablePaths: false,\n parser: {},\n ...opts,\n };\n\n if (!this.opts.enablePaths) {\n if (!this.opts.parser) this.opts.parser = {};\n if (!this.opts.parser.resolve) this.opts.parser.resolve = {};\n this.opts.parser.resolve = { file: false };\n }\n\n this.type = getType(this.file);\n\n this.cache = {\n load: false,\n bundle: false,\n deref: false,\n };\n }\n\n /**\n * Load and return the API definition that `oas-normalize` was initialized with.\n *\n */\n async load(): Promise<Record<string, unknown>> {\n if (this.cache.load) return this.cache.load;\n\n const resolve = (obj: Parameters<typeof stringToJSON>[0]) => {\n const ret = stringToJSON(obj);\n this.cache.load = ret;\n return ret;\n };\n\n switch (this.type) {\n case 'json':\n case 'string-json':\n case 'string-yaml':\n return resolve(this.file);\n\n case 'buffer':\n return resolve(this.file.toString());\n\n case 'url': {\n const { url, options } = prepareURL(this.file);\n const resp = await fetch(url, options).then(res => res.text());\n return resolve(resp);\n }\n\n case 'path': {\n // Load a local file\n if (!this.opts.enablePaths) {\n throw new Error('Use `opts.enablePaths` to enable accessing local files.');\n }\n\n const contents = fs.readFileSync(this.file).toString();\n if (!contents.trim()) {\n throw new Error('No file contents found.');\n }\n return resolve(contents);\n }\n\n default:\n throw new Error('Could not load this file.');\n }\n }\n\n private static async convertPostmanToOpenAPI(schema: Record<string, unknown>) {\n return postmanToOpenAPI(JSON.stringify(schema), undefined, {\n outputFormat: 'json',\n replaceVars: true,\n }).then(JSON.parse);\n }\n\n /**\n * Bundle up the given API definition, resolving any external `$ref` pointers in the process.\n *\n */\n async bundle(): Promise<OpenAPI.Document> {\n if (this.cache.bundle) return this.cache.bundle;\n const parserOptions = this.opts.parser || {};\n\n return this.load()\n .then(schema => {\n // Though Postman collections don't support `$ref` pointers for us to bundle we'll still\n // upconvert it to an OpenAPI definition file so our returned dataset is always one of\n // those for a Postman dataset.\n if (isPostman(schema)) {\n return OASNormalize.convertPostmanToOpenAPI(schema);\n }\n\n return schema;\n })\n .then(schema => bundle(schema, parserOptions))\n .then(bundled => {\n this.cache.bundle = bundled;\n return bundled;\n });\n }\n\n /**\n * Dereference the given API definition.\n *\n */\n async dereference(): Promise<OpenAPI.Document> {\n if (this.cache.deref) return this.cache.deref;\n const parserOptions = this.opts.parser || {};\n\n return this.load()\n .then(schema => {\n // Though Postman collections don't support `$ref` pointers for us to dereference we'll\n // still upconvert it to an OpenAPI definition file so our returned dataset is always one\n // of those for a Postman dataset.\n if (isPostman(schema)) {\n return OASNormalize.convertPostmanToOpenAPI(schema);\n }\n\n return schema;\n })\n .then(schema => dereference(schema, parserOptions))\n .then(dereferenced => {\n this.cache.deref = dereferenced;\n return dereferenced;\n });\n }\n\n /**\n * Dereference the given API definition.\n *\n * This method is deprecated in favor of `dereference`. It will be removed in a future release.\n *\n * @deprecated\n */\n async deref(): Promise<OpenAPI.Document> {\n return this.dereference();\n }\n\n /**\n * Convert a given API definition to OpenAPI if it is not already.\n *\n */\n async convert(): Promise<OpenAPI.Document> {\n if (this.cache.convert) return this.cache.convert;\n\n return this.load()\n .then(async schema => {\n // If we have a Postman collection we need to convert it to OpenAPI.\n return isPostman(schema) ? OASNormalize.convertPostmanToOpenAPI(schema) : schema;\n })\n .then(async schema => {\n if (!isSwagger(schema) && !isOpenAPI(schema)) {\n throw new Error('The supplied API definition is unsupported.');\n } else if (isOpenAPI(schema)) {\n return schema;\n }\n\n const baseVersion = parseInt(schema.swagger, 10);\n if (baseVersion === 1) {\n throw new Error('Swagger v1.2 is unsupported.');\n }\n\n return converter\n .convertObj(schema, { anchors: true })\n .then((options: { openapi: OpenAPI.Document }) => options.openapi);\n });\n }\n\n /**\n * Validate a given API definition.\n *\n * If supplied a Postman collection it will be converted to OpenAPI first and then run through\n * standard OpenAPI validation.\n *\n */\n async validate(\n opts: {\n /**\n * Options to supply to our OpenAPI parser. See `@readme/openapi-parser` for documentation.\n * This option is deprecated in favor of the `parser` option on the constructor. It will be\n * removed in a future release.\n *\n * @see {@link https://npm.im/@readme/openapi-parser}\n * @deprecated\n */\n parser?: ParserOptions;\n\n /**\n * Determines if `.validate()` should throw a `ValidationError` if the API definition is\n * invalid.\n *\n * By default this will always happen however if you want to always instead receive a\n * `ValidationResult` object back, which will still allow you to determine if the supplied\n * API definition is valid or not, you can set this to `false`.\n */\n shouldThrowIfInvalid?: boolean;\n } = {},\n ): Promise<ValidationResult> {\n const shouldThrowIfInvalid = opts.shouldThrowIfInvalid ?? true;\n const parserOptions = opts.parser || this.opts.parser || {};\n if (!parserOptions.validate) parserOptions.validate = {};\n if (!parserOptions.validate.errors) parserOptions.validate.errors = {};\n\n parserOptions.validate.errors.colorize = this.opts.colorizeErrors;\n\n return this.load()\n .then(async schema => {\n // Because we don't have something akin to `openapi-parser` for Postman collections we just\n // always convert them to OpenAPI.\n return isPostman(schema) ? OASNormalize.convertPostmanToOpenAPI(schema) : schema;\n })\n .then(async schema => {\n if (!isSwagger(schema) && !isOpenAPI(schema)) {\n if (shouldThrowIfInvalid) {\n throw new ValidationError('The supplied API definition is unsupported.');\n }\n\n return {\n valid: false,\n errors: [{ message: 'The supplied API definition is unsupported.' }],\n warnings: [],\n additionalErrors: 0,\n specification: null,\n };\n } else if (isSwagger(schema)) {\n const baseVersion = parseInt(schema.swagger, 10);\n if (baseVersion === 1) {\n if (shouldThrowIfInvalid) {\n throw new ValidationError('Swagger v1.2 is unsupported.');\n }\n\n return {\n valid: false,\n errors: [{ message: 'Swagger v1.2 is unsupported.' }],\n warnings: [],\n additionalErrors: 0,\n specification: 'Swagger',\n };\n }\n }\n\n /**\n * `OpenAPIParser.validate()` dereferences schemas at the same time as validation, mutating\n * the supplied parameter in the process, and does not give us an option to disable this.\n * As we already have a dereferencing method on this library, and this method just needs to\n * tell us if the API definition is valid or not, we need to clone the schema before\n * supplying it to `openapi-parser`.\n */\n const clonedSchema = JSON.parse(JSON.stringify(schema));\n\n const result = await validate(clonedSchema, parserOptions);\n if (!result.valid && shouldThrowIfInvalid) {\n throw new ValidationError(compileErrors(result), {\n errors: result.errors,\n warnings: result.warnings,\n });\n }\n\n // The API definition, whatever its format or specification, is valid.\n return result;\n });\n }\n\n /**\n * Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition.\n *\n */\n async version(): Promise<{\n specification: 'openapi' | 'postman' | 'swagger';\n version: string | 'unknown';\n }> {\n return this.load().then(schema => {\n switch (getAPIDefinitionType(schema)) {\n case 'openapi':\n return {\n specification: 'openapi',\n version: (schema as unknown as OpenAPIV3.Document).openapi,\n };\n\n case 'postman': {\n let version = 'unknown';\n if ((schema?.info as Record<string, string>)?.schema) {\n // Though `info.schema` is required by the Postman spec there's no strictness to its\n // contents so we'll do our best to extract a version out of this schema URL that they\n // seem to usually match. If not we'll fallback to treating it as an `unknown` version.\n const match = (schema?.info as Record<string, string>).schema.match(\n /http(s?):\\/\\/schema.getpostman.com\\/json\\/collection\\/v([0-9.]+)\\//,\n );\n\n if (match) {\n version = match[2];\n }\n }\n\n return {\n specification: 'postman',\n version,\n };\n }\n\n case 'swagger':\n return {\n specification: 'swagger',\n version: (schema as unknown as OpenAPIV2.Document).swagger,\n };\n\n default:\n throw new Error('Unknown file detected.');\n }\n });\n }\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -60,6 +60,15 @@ declare class OASNormalize {
60
60
  * @deprecated
61
61
  */
62
62
  parser?: ParserOptions;
63
+ /**
64
+ * Determines if `.validate()` should throw a `ValidationError` if the API definition is
65
+ * invalid.
66
+ *
67
+ * By default this will always happen however if you want to always instead receive a
68
+ * `ValidationResult` object back, which will still allow you to determine if the supplied
69
+ * API definition is valid or not, you can set this to `false`.
70
+ */
71
+ shouldThrowIfInvalid?: boolean;
63
72
  }): Promise<ValidationResult>;
64
73
  /**
65
74
  * Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition.
package/dist/index.d.ts CHANGED
@@ -60,6 +60,15 @@ declare class OASNormalize {
60
60
  * @deprecated
61
61
  */
62
62
  parser?: ParserOptions;
63
+ /**
64
+ * Determines if `.validate()` should throw a `ValidationError` if the API definition is
65
+ * invalid.
66
+ *
67
+ * By default this will always happen however if you want to always instead receive a
68
+ * `ValidationResult` object back, which will still allow you to determine if the supplied
69
+ * API definition is valid or not, you can set this to `false`.
70
+ */
71
+ shouldThrowIfInvalid?: boolean;
63
72
  }): Promise<ValidationResult>;
64
73
  /**
65
74
  * Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "./chunk-KGEOPSPH.js";
3
+ } from "./chunk-45XXAYDL.js";
4
4
  import {
5
5
  getAPIDefinitionType,
6
6
  getType,
@@ -159,6 +159,7 @@ var OASNormalize = class _OASNormalize {
159
159
  *
160
160
  */
161
161
  async validate(opts = {}) {
162
+ const shouldThrowIfInvalid = opts.shouldThrowIfInvalid ?? true;
162
163
  const parserOptions = opts.parser || this.opts.parser || {};
163
164
  if (!parserOptions.validate) parserOptions.validate = {};
164
165
  if (!parserOptions.validate.errors) parserOptions.validate.errors = {};
@@ -167,17 +168,38 @@ var OASNormalize = class _OASNormalize {
167
168
  return isPostman(schema) ? _OASNormalize.convertPostmanToOpenAPI(schema) : schema;
168
169
  }).then(async (schema) => {
169
170
  if (!isSwagger(schema) && !isOpenAPI(schema)) {
170
- throw new ValidationError("The supplied API definition is unsupported.");
171
+ if (shouldThrowIfInvalid) {
172
+ throw new ValidationError("The supplied API definition is unsupported.");
173
+ }
174
+ return {
175
+ valid: false,
176
+ errors: [{ message: "The supplied API definition is unsupported." }],
177
+ warnings: [],
178
+ additionalErrors: 0,
179
+ specification: null
180
+ };
171
181
  } else if (isSwagger(schema)) {
172
182
  const baseVersion = parseInt(schema.swagger, 10);
173
183
  if (baseVersion === 1) {
174
- throw new ValidationError("Swagger v1.2 is unsupported.");
184
+ if (shouldThrowIfInvalid) {
185
+ throw new ValidationError("Swagger v1.2 is unsupported.");
186
+ }
187
+ return {
188
+ valid: false,
189
+ errors: [{ message: "Swagger v1.2 is unsupported." }],
190
+ warnings: [],
191
+ additionalErrors: 0,
192
+ specification: "Swagger"
193
+ };
175
194
  }
176
195
  }
177
196
  const clonedSchema = JSON.parse(JSON.stringify(schema));
178
197
  const result = await validate(clonedSchema, parserOptions);
179
- if (!result.valid) {
180
- throw new ValidationError(compileErrors(result));
198
+ if (!result.valid && shouldThrowIfInvalid) {
199
+ throw new ValidationError(compileErrors(result), {
200
+ errors: result.errors,
201
+ warnings: result.warnings
202
+ });
181
203
  }
182
204
  return result;
183
205
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ParserOptions, ValidationResult } from '@readme/openapi-parser';\nimport type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';\nimport type { Options } from './lib/types.js';\n\nimport fs from 'node:fs';\n\nimport { bundle, compileErrors, dereference, validate } from '@readme/openapi-parser';\nimport postmanToOpenAPI from '@readme/postman-to-openapi';\nimport converter from 'swagger2openapi';\n\nimport { ValidationError } from './lib/errors.js';\nimport {\n getAPIDefinitionType,\n getType,\n isOpenAPI,\n isPostman,\n isSwagger,\n prepareURL,\n stringToJSON,\n} from './lib/utils.js';\n\n// biome-ignore lint/style/noDefaultExport: This is fine for now.\nexport default class OASNormalize {\n cache: {\n bundle?: OpenAPI.Document | false;\n convert?: OpenAPI.Document | false;\n deref?: OpenAPI.Document | false;\n load?: Record<string, unknown> | false;\n };\n\n // biome-ignore lint/suspicious/noExplicitAny: Intentionally loose because this library supports a wide variety of inputs.\n file: any;\n\n opts: Options;\n\n type: ReturnType<typeof getType>;\n\n // biome-ignore lint/suspicious/noExplicitAny: Intentionally loose because this library supports a wide variety of inputs.\n constructor(file: any, opts?: Options) {\n this.file = file;\n this.opts = {\n colorizeErrors: false,\n enablePaths: false,\n parser: {},\n ...opts,\n };\n\n if (!this.opts.enablePaths) {\n if (!this.opts.parser) this.opts.parser = {};\n if (!this.opts.parser.resolve) this.opts.parser.resolve = {};\n this.opts.parser.resolve = { file: false };\n }\n\n this.type = getType(this.file);\n\n this.cache = {\n load: false,\n bundle: false,\n deref: false,\n };\n }\n\n /**\n * Load and return the API definition that `oas-normalize` was initialized with.\n *\n */\n async load(): Promise<Record<string, unknown>> {\n if (this.cache.load) return this.cache.load;\n\n const resolve = (obj: Parameters<typeof stringToJSON>[0]) => {\n const ret = stringToJSON(obj);\n this.cache.load = ret;\n return ret;\n };\n\n switch (this.type) {\n case 'json':\n case 'string-json':\n case 'string-yaml':\n return resolve(this.file);\n\n case 'buffer':\n return resolve(this.file.toString());\n\n case 'url': {\n const { url, options } = prepareURL(this.file);\n const resp = await fetch(url, options).then(res => res.text());\n return resolve(resp);\n }\n\n case 'path': {\n // Load a local file\n if (!this.opts.enablePaths) {\n throw new Error('Use `opts.enablePaths` to enable accessing local files.');\n }\n\n const contents = fs.readFileSync(this.file).toString();\n if (!contents.trim()) {\n throw new Error('No file contents found.');\n }\n return resolve(contents);\n }\n\n default:\n throw new Error('Could not load this file.');\n }\n }\n\n private static async convertPostmanToOpenAPI(schema: Record<string, unknown>) {\n return postmanToOpenAPI(JSON.stringify(schema), undefined, {\n outputFormat: 'json',\n replaceVars: true,\n }).then(JSON.parse);\n }\n\n /**\n * Bundle up the given API definition, resolving any external `$ref` pointers in the process.\n *\n */\n async bundle(): Promise<OpenAPI.Document> {\n if (this.cache.bundle) return this.cache.bundle;\n const parserOptions = this.opts.parser || {};\n\n return this.load()\n .then(schema => {\n // Though Postman collections don't support `$ref` pointers for us to bundle we'll still\n // upconvert it to an OpenAPI definition file so our returned dataset is always one of\n // those for a Postman dataset.\n if (isPostman(schema)) {\n return OASNormalize.convertPostmanToOpenAPI(schema);\n }\n\n return schema;\n })\n .then(schema => bundle(schema, parserOptions))\n .then(bundled => {\n this.cache.bundle = bundled;\n return bundled;\n });\n }\n\n /**\n * Dereference the given API definition.\n *\n */\n async dereference(): Promise<OpenAPI.Document> {\n if (this.cache.deref) return this.cache.deref;\n const parserOptions = this.opts.parser || {};\n\n return this.load()\n .then(schema => {\n // Though Postman collections don't support `$ref` pointers for us to dereference we'll\n // still upconvert it to an OpenAPI definition file so our returned dataset is always one\n // of those for a Postman dataset.\n if (isPostman(schema)) {\n return OASNormalize.convertPostmanToOpenAPI(schema);\n }\n\n return schema;\n })\n .then(schema => dereference(schema, parserOptions))\n .then(dereferenced => {\n this.cache.deref = dereferenced;\n return dereferenced;\n });\n }\n\n /**\n * Dereference the given API definition.\n *\n * This method is deprecated in favor of `dereference`. It will be removed in a future release.\n *\n * @deprecated\n */\n async deref(): Promise<OpenAPI.Document> {\n return this.dereference();\n }\n\n /**\n * Convert a given API definition to OpenAPI if it is not already.\n *\n */\n async convert(): Promise<OpenAPI.Document> {\n if (this.cache.convert) return this.cache.convert;\n\n return this.load()\n .then(async schema => {\n // If we have a Postman collection we need to convert it to OpenAPI.\n return isPostman(schema) ? OASNormalize.convertPostmanToOpenAPI(schema) : schema;\n })\n .then(async schema => {\n if (!isSwagger(schema) && !isOpenAPI(schema)) {\n throw new Error('The supplied API definition is unsupported.');\n } else if (isOpenAPI(schema)) {\n return schema;\n }\n\n const baseVersion = parseInt(schema.swagger, 10);\n if (baseVersion === 1) {\n throw new Error('Swagger v1.2 is unsupported.');\n }\n\n return converter\n .convertObj(schema, { anchors: true })\n .then((options: { openapi: OpenAPI.Document }) => options.openapi);\n });\n }\n\n /**\n * Validate a given API definition.\n *\n * If supplied a Postman collection it will be converted to OpenAPI first and then run through\n * standard OpenAPI validation.\n *\n */\n async validate(\n opts: {\n /**\n * Options to supply to our OpenAPI parser. See `@readme/openapi-parser` for documentation.\n * This option is deprecated in favor of the `parser` option on the constructor. It will be\n * removed in a future release.\n *\n * @see {@link https://npm.im/@readme/openapi-parser}\n * @deprecated\n */\n parser?: ParserOptions;\n } = {},\n ): Promise<ValidationResult> {\n const parserOptions = opts.parser || this.opts.parser || {};\n if (!parserOptions.validate) parserOptions.validate = {};\n if (!parserOptions.validate.errors) parserOptions.validate.errors = {};\n\n parserOptions.validate.errors.colorize = this.opts.colorizeErrors;\n\n return this.load()\n .then(async schema => {\n // Because we don't have something akin to `openapi-parser` for Postman collections we just\n // always convert them to OpenAPI.\n return isPostman(schema) ? OASNormalize.convertPostmanToOpenAPI(schema) : schema;\n })\n .then(async schema => {\n if (!isSwagger(schema) && !isOpenAPI(schema)) {\n throw new ValidationError('The supplied API definition is unsupported.');\n } else if (isSwagger(schema)) {\n const baseVersion = parseInt(schema.swagger, 10);\n if (baseVersion === 1) {\n throw new ValidationError('Swagger v1.2 is unsupported.');\n }\n }\n\n /**\n * `OpenAPIParser.validate()` dereferences schemas at the same time as validation, mutating\n * the supplied parameter in the process, and does not give us an option to disable this.\n * As we already have a dereferencing method on this library, and this method just needs to\n * tell us if the API definition is valid or not, we need to clone the schema before\n * supplying it to `openapi-parser`.\n */\n const clonedSchema = JSON.parse(JSON.stringify(schema));\n\n const result = await validate(clonedSchema, parserOptions);\n if (!result.valid) {\n throw new ValidationError(compileErrors(result));\n }\n\n // The API definition, whatever its format or specification, is valid.\n return result;\n });\n }\n\n /**\n * Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition.\n *\n */\n async version(): Promise<{\n specification: 'openapi' | 'postman' | 'swagger';\n version: string | 'unknown';\n }> {\n return this.load().then(schema => {\n switch (getAPIDefinitionType(schema)) {\n case 'openapi':\n return {\n specification: 'openapi',\n version: (schema as unknown as OpenAPIV3.Document).openapi,\n };\n\n case 'postman': {\n let version = 'unknown';\n if ((schema?.info as Record<string, string>)?.schema) {\n // Though `info.schema` is required by the Postman spec there's no strictness to its\n // contents so we'll do our best to extract a version out of this schema URL that they\n // seem to usually match. If not we'll fallback to treating it as an `unknown` version.\n const match = (schema?.info as Record<string, string>).schema.match(\n /http(s?):\\/\\/schema.getpostman.com\\/json\\/collection\\/v([0-9.]+)\\//,\n );\n\n if (match) {\n version = match[2];\n }\n }\n\n return {\n specification: 'postman',\n version,\n };\n }\n\n case 'swagger':\n return {\n specification: 'swagger',\n version: (schema as unknown as OpenAPIV2.Document).swagger,\n };\n\n default:\n throw new Error('Unknown file detected.');\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAIA,OAAO,QAAQ;AAEf,SAAS,QAAQ,eAAe,aAAa,gBAAgB;AAC7D,OAAO,sBAAsB;AAC7B,OAAO,eAAe;AActB,IAAqB,eAArB,MAAqB,cAAa;AAAA,EAChC;AAAA;AAAA,EAQA;AAAA,EAEA;AAAA,EAEA;AAAA;AA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C,cAAM,IAAI,gBAAgB,6CAA6C;AAAA,MACzE,WAAW,UAAU,MAAM,GAAG;AAC5B,cAAM,cAAc,SAAS,OAAO,SAAS,EAAE;AAC/C,YAAI,gBAAgB,GAAG;AACrB,gBAAM,IAAI,gBAAgB,8BAA8B;AAAA,QAC1D;AAAA,MACF;AASA,YAAM,eAAe,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC;AAEtD,YAAM,SAAS,MAAM,SAAS,cAAc,aAAa;AACzD,UAAI,CAAC,OAAO,OAAO;AACjB,cAAM,IAAI,gBAAgB,cAAc,MAAM,CAAC;AAAA,MACjD;AAGA,aAAO;AAAA,IACT,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,UAGH;AACD,WAAO,KAAK,KAAK,EAAE,KAAK,YAAU;AAChC,cAAQ,qBAAqB,MAAM,GAAG;AAAA,QACpC,KAAK;AACH,iBAAO;AAAA,YACL,eAAe;AAAA,YACf,SAAU,OAAyC;AAAA,UACrD;AAAA,QAEF,KAAK,WAAW;AACd,cAAI,UAAU;AACd,cAAK,QAAQ,MAAiC,QAAQ;AAIpD,kBAAM,SAAS,QAAQ,MAAgC,OAAO;AAAA,cAC5D;AAAA,YACF;AAEA,gBAAI,OAAO;AACT,wBAAU,MAAM,CAAC;AAAA,YACnB;AAAA,UACF;AAEA,iBAAO;AAAA,YACL,eAAe;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,QAEA,KAAK;AACH,iBAAO;AAAA,YACL,eAAe;AAAA,YACf,SAAU,OAAyC;AAAA,UACrD;AAAA,QAEF;AACE,gBAAM,IAAI,MAAM,wBAAwB;AAAA,MAC5C;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { ParserOptions, ValidationResult } from '@readme/openapi-parser';\nimport type { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';\nimport type { Options } from './lib/types.js';\n\nimport fs from 'node:fs';\n\nimport { bundle, compileErrors, dereference, validate } from '@readme/openapi-parser';\nimport postmanToOpenAPI from '@readme/postman-to-openapi';\nimport converter from 'swagger2openapi';\n\nimport { ValidationError } from './lib/errors.js';\nimport {\n getAPIDefinitionType,\n getType,\n isOpenAPI,\n isPostman,\n isSwagger,\n prepareURL,\n stringToJSON,\n} from './lib/utils.js';\n\n// biome-ignore lint/style/noDefaultExport: This is fine for now.\nexport default class OASNormalize {\n cache: {\n bundle?: OpenAPI.Document | false;\n convert?: OpenAPI.Document | false;\n deref?: OpenAPI.Document | false;\n load?: Record<string, unknown> | false;\n };\n\n // biome-ignore lint/suspicious/noExplicitAny: Intentionally loose because this library supports a wide variety of inputs.\n file: any;\n\n opts: Options;\n\n type: ReturnType<typeof getType>;\n\n // biome-ignore lint/suspicious/noExplicitAny: Intentionally loose because this library supports a wide variety of inputs.\n constructor(file: any, opts?: Options) {\n this.file = file;\n this.opts = {\n colorizeErrors: false,\n enablePaths: false,\n parser: {},\n ...opts,\n };\n\n if (!this.opts.enablePaths) {\n if (!this.opts.parser) this.opts.parser = {};\n if (!this.opts.parser.resolve) this.opts.parser.resolve = {};\n this.opts.parser.resolve = { file: false };\n }\n\n this.type = getType(this.file);\n\n this.cache = {\n load: false,\n bundle: false,\n deref: false,\n };\n }\n\n /**\n * Load and return the API definition that `oas-normalize` was initialized with.\n *\n */\n async load(): Promise<Record<string, unknown>> {\n if (this.cache.load) return this.cache.load;\n\n const resolve = (obj: Parameters<typeof stringToJSON>[0]) => {\n const ret = stringToJSON(obj);\n this.cache.load = ret;\n return ret;\n };\n\n switch (this.type) {\n case 'json':\n case 'string-json':\n case 'string-yaml':\n return resolve(this.file);\n\n case 'buffer':\n return resolve(this.file.toString());\n\n case 'url': {\n const { url, options } = prepareURL(this.file);\n const resp = await fetch(url, options).then(res => res.text());\n return resolve(resp);\n }\n\n case 'path': {\n // Load a local file\n if (!this.opts.enablePaths) {\n throw new Error('Use `opts.enablePaths` to enable accessing local files.');\n }\n\n const contents = fs.readFileSync(this.file).toString();\n if (!contents.trim()) {\n throw new Error('No file contents found.');\n }\n return resolve(contents);\n }\n\n default:\n throw new Error('Could not load this file.');\n }\n }\n\n private static async convertPostmanToOpenAPI(schema: Record<string, unknown>) {\n return postmanToOpenAPI(JSON.stringify(schema), undefined, {\n outputFormat: 'json',\n replaceVars: true,\n }).then(JSON.parse);\n }\n\n /**\n * Bundle up the given API definition, resolving any external `$ref` pointers in the process.\n *\n */\n async bundle(): Promise<OpenAPI.Document> {\n if (this.cache.bundle) return this.cache.bundle;\n const parserOptions = this.opts.parser || {};\n\n return this.load()\n .then(schema => {\n // Though Postman collections don't support `$ref` pointers for us to bundle we'll still\n // upconvert it to an OpenAPI definition file so our returned dataset is always one of\n // those for a Postman dataset.\n if (isPostman(schema)) {\n return OASNormalize.convertPostmanToOpenAPI(schema);\n }\n\n return schema;\n })\n .then(schema => bundle(schema, parserOptions))\n .then(bundled => {\n this.cache.bundle = bundled;\n return bundled;\n });\n }\n\n /**\n * Dereference the given API definition.\n *\n */\n async dereference(): Promise<OpenAPI.Document> {\n if (this.cache.deref) return this.cache.deref;\n const parserOptions = this.opts.parser || {};\n\n return this.load()\n .then(schema => {\n // Though Postman collections don't support `$ref` pointers for us to dereference we'll\n // still upconvert it to an OpenAPI definition file so our returned dataset is always one\n // of those for a Postman dataset.\n if (isPostman(schema)) {\n return OASNormalize.convertPostmanToOpenAPI(schema);\n }\n\n return schema;\n })\n .then(schema => dereference(schema, parserOptions))\n .then(dereferenced => {\n this.cache.deref = dereferenced;\n return dereferenced;\n });\n }\n\n /**\n * Dereference the given API definition.\n *\n * This method is deprecated in favor of `dereference`. It will be removed in a future release.\n *\n * @deprecated\n */\n async deref(): Promise<OpenAPI.Document> {\n return this.dereference();\n }\n\n /**\n * Convert a given API definition to OpenAPI if it is not already.\n *\n */\n async convert(): Promise<OpenAPI.Document> {\n if (this.cache.convert) return this.cache.convert;\n\n return this.load()\n .then(async schema => {\n // If we have a Postman collection we need to convert it to OpenAPI.\n return isPostman(schema) ? OASNormalize.convertPostmanToOpenAPI(schema) : schema;\n })\n .then(async schema => {\n if (!isSwagger(schema) && !isOpenAPI(schema)) {\n throw new Error('The supplied API definition is unsupported.');\n } else if (isOpenAPI(schema)) {\n return schema;\n }\n\n const baseVersion = parseInt(schema.swagger, 10);\n if (baseVersion === 1) {\n throw new Error('Swagger v1.2 is unsupported.');\n }\n\n return converter\n .convertObj(schema, { anchors: true })\n .then((options: { openapi: OpenAPI.Document }) => options.openapi);\n });\n }\n\n /**\n * Validate a given API definition.\n *\n * If supplied a Postman collection it will be converted to OpenAPI first and then run through\n * standard OpenAPI validation.\n *\n */\n async validate(\n opts: {\n /**\n * Options to supply to our OpenAPI parser. See `@readme/openapi-parser` for documentation.\n * This option is deprecated in favor of the `parser` option on the constructor. It will be\n * removed in a future release.\n *\n * @see {@link https://npm.im/@readme/openapi-parser}\n * @deprecated\n */\n parser?: ParserOptions;\n\n /**\n * Determines if `.validate()` should throw a `ValidationError` if the API definition is\n * invalid.\n *\n * By default this will always happen however if you want to always instead receive a\n * `ValidationResult` object back, which will still allow you to determine if the supplied\n * API definition is valid or not, you can set this to `false`.\n */\n shouldThrowIfInvalid?: boolean;\n } = {},\n ): Promise<ValidationResult> {\n const shouldThrowIfInvalid = opts.shouldThrowIfInvalid ?? true;\n const parserOptions = opts.parser || this.opts.parser || {};\n if (!parserOptions.validate) parserOptions.validate = {};\n if (!parserOptions.validate.errors) parserOptions.validate.errors = {};\n\n parserOptions.validate.errors.colorize = this.opts.colorizeErrors;\n\n return this.load()\n .then(async schema => {\n // Because we don't have something akin to `openapi-parser` for Postman collections we just\n // always convert them to OpenAPI.\n return isPostman(schema) ? OASNormalize.convertPostmanToOpenAPI(schema) : schema;\n })\n .then(async schema => {\n if (!isSwagger(schema) && !isOpenAPI(schema)) {\n if (shouldThrowIfInvalid) {\n throw new ValidationError('The supplied API definition is unsupported.');\n }\n\n return {\n valid: false,\n errors: [{ message: 'The supplied API definition is unsupported.' }],\n warnings: [],\n additionalErrors: 0,\n specification: null,\n };\n } else if (isSwagger(schema)) {\n const baseVersion = parseInt(schema.swagger, 10);\n if (baseVersion === 1) {\n if (shouldThrowIfInvalid) {\n throw new ValidationError('Swagger v1.2 is unsupported.');\n }\n\n return {\n valid: false,\n errors: [{ message: 'Swagger v1.2 is unsupported.' }],\n warnings: [],\n additionalErrors: 0,\n specification: 'Swagger',\n };\n }\n }\n\n /**\n * `OpenAPIParser.validate()` dereferences schemas at the same time as validation, mutating\n * the supplied parameter in the process, and does not give us an option to disable this.\n * As we already have a dereferencing method on this library, and this method just needs to\n * tell us if the API definition is valid or not, we need to clone the schema before\n * supplying it to `openapi-parser`.\n */\n const clonedSchema = JSON.parse(JSON.stringify(schema));\n\n const result = await validate(clonedSchema, parserOptions);\n if (!result.valid && shouldThrowIfInvalid) {\n throw new ValidationError(compileErrors(result), {\n errors: result.errors,\n warnings: result.warnings,\n });\n }\n\n // The API definition, whatever its format or specification, is valid.\n return result;\n });\n }\n\n /**\n * Retrieve OpenAPI, Swagger, or Postman version information about the supplied API definition.\n *\n */\n async version(): Promise<{\n specification: 'openapi' | 'postman' | 'swagger';\n version: string | 'unknown';\n }> {\n return this.load().then(schema => {\n switch (getAPIDefinitionType(schema)) {\n case 'openapi':\n return {\n specification: 'openapi',\n version: (schema as unknown as OpenAPIV3.Document).openapi,\n };\n\n case 'postman': {\n let version = 'unknown';\n if ((schema?.info as Record<string, string>)?.schema) {\n // Though `info.schema` is required by the Postman spec there's no strictness to its\n // contents so we'll do our best to extract a version out of this schema URL that they\n // seem to usually match. If not we'll fallback to treating it as an `unknown` version.\n const match = (schema?.info as Record<string, string>).schema.match(\n /http(s?):\\/\\/schema.getpostman.com\\/json\\/collection\\/v([0-9.]+)\\//,\n );\n\n if (match) {\n version = match[2];\n }\n }\n\n return {\n specification: 'postman',\n version,\n };\n }\n\n case 'swagger':\n return {\n specification: 'swagger',\n version: (schema as unknown as OpenAPIV2.Document).swagger,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AK,KAAK,EAAE,KAAK,YAAU;AAChC,cAAQ,qBAAqB,MAAM,GAAG;AAAA,QACpC,KAAK;AACH,iBAAO;AAAA,YACL,eAAe;AAAA,YACf,SAAU,OAAyC;AAAA,UACrD;AAAA,QAEF,KAAK,WAAW;AACd,cAAI,UAAU;AACd,cAAK,QAAQ,MAAiC,QAAQ;AAIpD,kBAAM,SAAS,QAAQ,MAAgC,OAAO;AAAA,cAC5D;AAAA,YACF;AAEA,gBAAI,OAAO;AACT,wBAAU,MAAM,CAAC;AAAA,YACnB;AAAA,UACF;AAEA,iBAAO;AAAA,YACL,eAAe;AAAA,YACf;AAAA,UACF;AAAA,QACF;AAAA,QAEA,KAAK;AACH,iBAAO;AAAA,YACL,eAAe;AAAA,YACf,SAAU,OAAyC;AAAA,UACrD;AAAA,QAEF;AACE,gBAAM,IAAI,MAAM,wBAAwB;AAAA,MAC5C;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkSI6PKQOLcjs = require('../chunk-SI6PKQOL.cjs');
3
+ var _chunkAKXTCPGMcjs = require('../chunk-AKXTCPGM.cjs');
4
4
 
5
5
 
6
- exports.ValidationError = _chunkSI6PKQOLcjs.ValidationError;
6
+ exports.ValidationError = _chunkAKXTCPGMcjs.ValidationError;
7
7
  //# sourceMappingURL=errors.cjs.map
@@ -1,5 +1,12 @@
1
+ import { ErrorDetails, WarningDetails } from '@readme/openapi-parser';
2
+
1
3
  declare class ValidationError extends Error {
2
- constructor(message: string);
4
+ errors: ErrorDetails[];
5
+ warnings: WarningDetails[];
6
+ constructor(message: string, { errors, warnings, }?: {
7
+ errors?: ErrorDetails[];
8
+ warnings?: WarningDetails[];
9
+ });
3
10
  }
4
11
 
5
12
  export { ValidationError };
@@ -1,5 +1,12 @@
1
+ import { ErrorDetails, WarningDetails } from '@readme/openapi-parser';
2
+
1
3
  declare class ValidationError extends Error {
2
- constructor(message: string);
4
+ errors: ErrorDetails[];
5
+ warnings: WarningDetails[];
6
+ constructor(message: string, { errors, warnings, }?: {
7
+ errors?: ErrorDetails[];
8
+ warnings?: WarningDetails[];
9
+ });
3
10
  }
4
11
 
5
12
  export { ValidationError };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ValidationError
3
- } from "../chunk-KGEOPSPH.js";
3
+ } from "../chunk-45XXAYDL.js";
4
4
  export {
5
5
  ValidationError
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas-normalize",
3
- "version": "15.2.0",
3
+ "version": "15.4.0",
4
4
  "description": "Tooling for converting, validating, and parsing OpenAPI, Swagger, and Postman API definitions",
5
5
  "type": "module",
6
6
  "exports": {
@@ -67,21 +67,21 @@
67
67
  },
68
68
  "license": "MIT",
69
69
  "dependencies": {
70
- "@readme/openapi-parser": "^5.2.0",
70
+ "@readme/openapi-parser": "^5.2.1",
71
71
  "@readme/postman-to-openapi": "^4.1.0",
72
72
  "js-yaml": "^4.1.0",
73
73
  "openapi-types": "^12.1.3",
74
74
  "swagger2openapi": "^7.0.8"
75
75
  },
76
76
  "devDependencies": {
77
- "@readme/oas-examples": "^7.0.3",
77
+ "@readme/oas-examples": "^7.0.4",
78
78
  "@types/js-yaml": "^4.0.9",
79
79
  "@types/swagger2openapi": "^7.0.4",
80
80
  "nock": "^14.0.2",
81
81
  "tsup": "^8.5.0",
82
82
  "typescript": "^5.1.6",
83
- "vitest": "^3.2.1"
83
+ "vitest": "^4.0.8"
84
84
  },
85
85
  "prettier": "@readme/standards/prettier",
86
- "gitHead": "9eadd18c66ad97646c8340204dbcf76bef96c02f"
86
+ "gitHead": "b70b4a84401b1e91bd0aa7e8416536082927f0b1"
87
87
  }
@@ -1,12 +0,0 @@
1
- // src/lib/errors.ts
2
- var ValidationError = class extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = "ValidationError";
6
- }
7
- };
8
-
9
- export {
10
- ValidationError
11
- };
12
- //# sourceMappingURL=chunk-KGEOPSPH.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/errors.ts"],"sourcesContent":["export class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n"],"mappings":";AAAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas-normalize/dist/chunk-SI6PKQOL.cjs","../src/lib/errors.ts"],"names":[],"mappings":"AAAA;ACAO,IAAM,gBAAA,EAAN,MAAA,QAA8B,MAAM;AAAA,EACzC,WAAA,CAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,KAAA,EAAO,iBAAA;AAAA,EACd;AACF,CAAA;ADEA;AACA;AACE;AACF,0CAAC","file":"/Users/erunion/code/readme/oas/packages/oas-normalize/dist/chunk-SI6PKQOL.cjs","sourcesContent":[null,"export class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n"]}