@kubb/oas 2.19.5 → 2.19.6

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.
@@ -1,25 +1,11 @@
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; }var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
- var __privateMethod = (obj, member, method) => {
20
- __accessCheck(obj, member, "access private method");
21
- return method;
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; }var __typeError = (msg) => {
2
+ throw TypeError(msg);
22
3
  };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
23
9
 
24
10
  // src/utils.ts
25
11
  var _types = require('oas/types');
@@ -92,17 +78,14 @@ async function filterAndSort(data, options = {}) {
92
78
  var _oas = require('oas'); var _oas2 = _interopRequireDefault(_oas);
93
79
  var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
94
80
  var _utils = require('oas/utils');
95
- var _options, _getResponseBodyFactory, getResponseBodyFactory_fn;
81
+ var _options, _Oas_instances, getResponseBodyFactory_fn;
96
82
  var Oas = class extends _oas2.default {
97
83
  constructor({ oas, user }, options = {}) {
98
84
  if (typeof oas === "string") {
99
85
  oas = JSON.parse(oas);
100
86
  }
101
87
  super(oas, user);
102
- /**
103
- * Oas does not have a getResponseBody(contentType)
104
- */
105
- __privateAdd(this, _getResponseBodyFactory);
88
+ __privateAdd(this, _Oas_instances);
106
89
  __privateAdd(this, _options, {});
107
90
  this.document = void 0;
108
91
  this.document = oas;
@@ -127,7 +110,7 @@ var Oas = class extends _oas2.default {
127
110
  }
128
111
  });
129
112
  }
130
- const getResponseBody = __privateMethod(this, _getResponseBodyFactory, getResponseBodyFactory_fn).call(this, operation.getResponseByStatusCode(statusCode));
113
+ const getResponseBody = __privateMethod(this, _Oas_instances, getResponseBodyFactory_fn).call(this, operation.getResponseByStatusCode(statusCode));
131
114
  const { contentType } = __privateGet(this, _options);
132
115
  const responseBody = getResponseBody(contentType);
133
116
  if (responseBody === false) {
@@ -193,7 +176,10 @@ var Oas = class extends _oas2.default {
193
176
  }
194
177
  };
195
178
  _options = new WeakMap();
196
- _getResponseBodyFactory = new WeakSet();
179
+ _Oas_instances = new WeakSet();
180
+ /**
181
+ * Oas does not have a getResponseBody(contentType)
182
+ */
197
183
  getResponseBodyFactory_fn = function(responseBody) {
198
184
  function hasResponseBody(res = responseBody) {
199
185
  return !!res;
@@ -245,4 +231,4 @@ getResponseBodyFactory_fn = function(responseBody) {
245
231
 
246
232
 
247
233
  exports.isOpenApiV2Document = isOpenApiV2Document; exports.isOpenApiV3_1Document = isOpenApiV3_1Document; exports.isParameterObject = isParameterObject; exports.isReference = isReference; exports.isRequired = isRequired; exports.isOptional = isOptional; exports.filterAndSort = filterAndSort; exports.Oas = Oas;
248
- //# sourceMappingURL=chunk-Y6TRLK3L.cjs.map
234
+ //# sourceMappingURL=chunk-BBEAIQFK.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings":";;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAMvB,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,cAAc,GAAG,KAAK,EAAE,aAAa;AACrD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,cAAoC,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AAC5G;AAMO,SAAS,kBAAkB,KAA6D;AAC7F,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,YAAY,KAA+E;AACzG,SAAO,CAAC,CAAC,OAAO,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Aa,QAAQ,WAAW;AAAA,IACzC;AAIA,QAAI,uBAA2C;AAC/C,UAAM,eAAe,OAAO,KAAK,aAAa,OAAO;AACrD,iBAAa,QAAQ,CAAC,OAAe;AACnC,UAAI,CAAC,wBAAwB,gBAAgB,KAAK,EAAE,GAAG;AACrD,+BAAuB;AAAA,MACzB;AAAA,IACF,CAAC;AAED,QAAI,CAAC,sBAAsB;AACzB,mBAAa,QAAQ,CAAC,OAAe;AACnC,YAAI,CAAC,sBAAsB;AACzB,iCAAuB;AAAA,QACzB;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,sBAAsB;AACxB,aAAO,CAAC,sBAAsB,aAAa,QAAQ,oBAAoB,GAAI,GAAI,aAAa,cAAc,CAAC,aAAa,WAAW,IAAI,CAAC,CAAE;AAAA,IAC5I;AAEA,WAAO;AAAA,EACT;AACF","sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport openapiFormat from 'openapi-format'\nimport { isPlainObject } from 'remeda'\n\nimport type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\nimport type { FormatOptions } from './parser/index.ts'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n\nexport async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {\n const mergedOptions: FormatOptions = {\n sort: options.sort ?? true,\n ['no-sort']: options['no-sort'] ?? false,\n sortSet: {\n root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],\n get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n parameters: ['name', 'in', 'description', 'required', 'schema'],\n requestBody: ['description', 'required', 'content'],\n responses: ['description', 'headers', 'content', 'links'],\n content: [],\n components: ['parameters', 'schemas'],\n schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],\n ...options.sortSet,\n },\n sortComponentsSet: {\n ...options.sortComponentsSet,\n },\n filterSet: {\n inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace', 'parameters'],\n unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],\n ...options.filterSet,\n },\n casingSet: {\n ...options.casingSet,\n },\n }\n\n const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)\n data = restFilter.data\n\n const resFormat = await openapiFormat.openapiSort(data, mergedOptions)\n data = resFormat.data\n\n const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions)\n data = resChangeCase.data\n\n return data\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...findSchemaDefinition(schema.$ref, this.api),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = findSchemaDefinition($ref, this.api)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate()\n }\n}\n"]}
@@ -1,25 +1,11 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
18
- };
19
- var __privateMethod = (obj, member, method) => {
20
- __accessCheck(obj, member, "access private method");
21
- return method;
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
22
3
  };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
23
9
 
24
10
  // src/utils.ts
25
11
  import { isRef, isSchema } from "oas/types";
@@ -92,17 +78,14 @@ async function filterAndSort(data, options = {}) {
92
78
  import BaseOas from "oas";
93
79
  import OASNormalize from "oas-normalize";
94
80
  import { findSchemaDefinition, matchesMimeType } from "oas/utils";
95
- var _options, _getResponseBodyFactory, getResponseBodyFactory_fn;
81
+ var _options, _Oas_instances, getResponseBodyFactory_fn;
96
82
  var Oas = class extends BaseOas {
97
83
  constructor({ oas, user }, options = {}) {
98
84
  if (typeof oas === "string") {
99
85
  oas = JSON.parse(oas);
100
86
  }
101
87
  super(oas, user);
102
- /**
103
- * Oas does not have a getResponseBody(contentType)
104
- */
105
- __privateAdd(this, _getResponseBodyFactory);
88
+ __privateAdd(this, _Oas_instances);
106
89
  __privateAdd(this, _options, {});
107
90
  this.document = void 0;
108
91
  this.document = oas;
@@ -127,7 +110,7 @@ var Oas = class extends BaseOas {
127
110
  }
128
111
  });
129
112
  }
130
- const getResponseBody = __privateMethod(this, _getResponseBodyFactory, getResponseBodyFactory_fn).call(this, operation.getResponseByStatusCode(statusCode));
113
+ const getResponseBody = __privateMethod(this, _Oas_instances, getResponseBodyFactory_fn).call(this, operation.getResponseByStatusCode(statusCode));
131
114
  const { contentType } = __privateGet(this, _options);
132
115
  const responseBody = getResponseBody(contentType);
133
116
  if (responseBody === false) {
@@ -193,7 +176,10 @@ var Oas = class extends BaseOas {
193
176
  }
194
177
  };
195
178
  _options = new WeakMap();
196
- _getResponseBodyFactory = new WeakSet();
179
+ _Oas_instances = new WeakSet();
180
+ /**
181
+ * Oas does not have a getResponseBody(contentType)
182
+ */
197
183
  getResponseBodyFactory_fn = function(responseBody) {
198
184
  function hasResponseBody(res = responseBody) {
199
185
  return !!res;
@@ -245,4 +231,4 @@ export {
245
231
  filterAndSort,
246
232
  Oas
247
233
  };
248
- //# sourceMappingURL=chunk-TOY2KSNY.js.map
234
+ //# sourceMappingURL=chunk-XMMCJRIW.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport openapiFormat from 'openapi-format'\nimport { isPlainObject } from 'remeda'\n\nimport type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\nimport type { FormatOptions } from './parser/index.ts'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n\nexport async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {\n const mergedOptions: FormatOptions = {\n sort: options.sort ?? true,\n ['no-sort']: options['no-sort'] ?? false,\n sortSet: {\n root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],\n get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n parameters: ['name', 'in', 'description', 'required', 'schema'],\n requestBody: ['description', 'required', 'content'],\n responses: ['description', 'headers', 'content', 'links'],\n content: [],\n components: ['parameters', 'schemas'],\n schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],\n ...options.sortSet,\n },\n sortComponentsSet: {\n ...options.sortComponentsSet,\n },\n filterSet: {\n inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace', 'parameters'],\n unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],\n ...options.filterSet,\n },\n casingSet: {\n ...options.casingSet,\n },\n }\n\n const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)\n data = restFilter.data\n\n const resFormat = await openapiFormat.openapiSort(data, mergedOptions)\n data = resFormat.data\n\n const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions)\n data = resChangeCase.data\n\n return data\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...findSchemaDefinition(schema.$ref, this.api),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = findSchemaDefinition($ref, this.api)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAMvB,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,cAAc,GAAG,KAAK,EAAE,aAAa;AACrD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,cAAoC,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AAC5G;AAMO,SAAS,kBAAkB,KAA6D;AAC7F,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,YAAY,KAA+E;AACzG,SAAO,CAAC,CAAC,OAAO,MAAM,GAAG;AAC3B;AAEO,SAAS,WAAW,QAAgC;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,uBAA2C;AAC/C,UAAM,eAAe,OAAO,KAAK,aAAa,OAAO;AACrD,iBAAa,QAAQ,CAAC,OAAe;AACnC,UAAI,CAAC,wBAAwB,gBAAgB,KAAK,EAAE,GAAG;AACrD,+BAAuB;AAAA,MACzB;AAAA,IACF,CAAC;AAED,QAAI,CAAC,sBAAsB;AACzB,mBAAa,QAAQ,CAAC,OAAe;AACnC,YAAI,CAAC,sBAAsB;AACzB,iCAAuB;AAAA,QACzB;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,sBAAsB;AACxB,aAAO,CAAC,sBAAsB,aAAa,QAAQ,oBAAoB,GAAI,GAAI,aAAa,cAAc,CAAC,aAAa,WAAW,IAAI,CAAC,CAAE;AAAA,IAC5I;AAEA,WAAO;AAAA,EACT;AACF;","names":["schema"]}
1
+ {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport openapiFormat from 'openapi-format'\nimport { isPlainObject } from 'remeda'\n\nimport type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\nimport type { FormatOptions } from './parser/index.ts'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n\nexport async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {\n const mergedOptions: FormatOptions = {\n sort: options.sort ?? true,\n ['no-sort']: options['no-sort'] ?? false,\n sortSet: {\n root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],\n get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n parameters: ['name', 'in', 'description', 'required', 'schema'],\n requestBody: ['description', 'required', 'content'],\n responses: ['description', 'headers', 'content', 'links'],\n content: [],\n components: ['parameters', 'schemas'],\n schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],\n ...options.sortSet,\n },\n sortComponentsSet: {\n ...options.sortComponentsSet,\n },\n filterSet: {\n inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace', 'parameters'],\n unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],\n ...options.filterSet,\n },\n casingSet: {\n ...options.casingSet,\n },\n }\n\n const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)\n data = restFilter.data\n\n const resFormat = await openapiFormat.openapiSort(data, mergedOptions)\n data = resFormat.data\n\n const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions)\n data = resChangeCase.data\n\n return data\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...findSchemaDefinition(schema.$ref, this.api),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = findSchemaDefinition($ref, this.api)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate()\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAMvB,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,cAAc,GAAG,KAAK,EAAE,aAAa;AACrD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,cAAoC,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AAC5G;AAMO,SAAS,kBAAkB,KAA6D;AAC7F,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,YAAY,KAA+E;AACzG,SAAO,CAAC,CAAC,OAAO,MAAM,GAAG;AAC3B;AAEO,SAAS,WAAW,QAAgC;AACzD,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,QAAQ,OAAO,QAAQ,IAAI,CAAC,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,OAAO;AAC/E;AAEO,SAAS,WAAW,QAAgC;AACzD,SAAO,CAAC,WAAW,MAAM;AAC3B;AAEA,eAAsB,cAAc,MAAmB,UAAyB,CAAC,GAAyB;AACxG,QAAM,gBAA+B;AAAA,IACnC,MAAM,QAAQ,QAAQ;AAAA,IACtB,CAAC,SAAS,GAAG,QAAQ,SAAS,KAAK;AAAA,IACnC,SAAS;AAAA,MACP,MAAM,CAAC,WAAW,QAAQ,WAAW,SAAS,cAAc,QAAQ,eAAe,cAAc;AAAA,MACjG,KAAK,CAAC,eAAe,WAAW,eAAe,cAAc,eAAe,WAAW;AAAA,MACvF,MAAM,CAAC,eAAe,WAAW,eAAe,cAAc,eAAe,WAAW;AAAA,MACx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s = require('./chunk-Y6TRLK3L.cjs');
8
+ var _chunkBBEAIQFKcjs = require('./chunk-BBEAIQFK.cjs');
9
9
 
10
10
  // src/types.ts
11
11
  var HttpMethods = {
@@ -31,5 +31,5 @@ var _utils = require('oas/utils');
31
31
 
32
32
 
33
33
 
34
- exports.HttpMethods = HttpMethods; exports.Oas = _chunkY6TRLK3Lcjs.Oas; exports.findSchemaDefinition = _utils.findSchemaDefinition; exports.isOpenApiV3_1Document = _chunkY6TRLK3Lcjs.isOpenApiV3_1Document; exports.isOptional = _chunkY6TRLK3Lcjs.isOptional; exports.isParameterObject = _chunkY6TRLK3Lcjs.isParameterObject; exports.isReference = _chunkY6TRLK3Lcjs.isReference; exports.isRequired = _chunkY6TRLK3Lcjs.isRequired; exports.matchesMimeType = _utils.matchesMimeType;
34
+ exports.HttpMethods = HttpMethods; exports.Oas = _chunkBBEAIQFKcjs.Oas; exports.findSchemaDefinition = _utils.findSchemaDefinition; exports.isOpenApiV3_1Document = _chunkBBEAIQFKcjs.isOpenApiV3_1Document; exports.isOptional = _chunkBBEAIQFKcjs.isOptional; exports.isParameterObject = _chunkBBEAIQFKcjs.isParameterObject; exports.isReference = _chunkBBEAIQFKcjs.isReference; exports.isRequired = _chunkBBEAIQFKcjs.isRequired; exports.matchesMimeType = _utils.matchesMimeType;
35
35
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  isParameterObject,
6
6
  isReference,
7
7
  isRequired
8
- } from "./chunk-TOY2KSNY.js";
8
+ } from "./chunk-XMMCJRIW.js";
9
9
 
10
10
  // src/types.ts
11
11
  var HttpMethods = {
package/dist/parser.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkY6TRLK3Lcjs = require('./chunk-Y6TRLK3L.cjs');
5
+ var _chunkBBEAIQFKcjs = require('./chunk-BBEAIQFK.cjs');
6
6
 
7
7
  // src/parser/index.ts
8
8
  var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
@@ -19,15 +19,15 @@ async function parse(pathOrApi, options = {}) {
19
19
  colorizeErrors: true
20
20
  });
21
21
  const document = await oasNormalize.load();
22
- if (_chunkY6TRLK3Lcjs.isOpenApiV2Document.call(void 0, document)) {
22
+ if (_chunkBBEAIQFKcjs.isOpenApiV2Document.call(void 0, document)) {
23
23
  const { openapi } = await _swagger2openapi2.default.convertObj(document, {
24
24
  anchors: true
25
25
  });
26
- const oas2 = await _chunkY6TRLK3Lcjs.filterAndSort.call(void 0, openapi, options);
27
- return new (0, _chunkY6TRLK3Lcjs.Oas)({ oas: oas2 });
26
+ const oas2 = await _chunkBBEAIQFKcjs.filterAndSort.call(void 0, openapi, options);
27
+ return new (0, _chunkBBEAIQFKcjs.Oas)({ oas: oas2 });
28
28
  }
29
- const oas = await _chunkY6TRLK3Lcjs.filterAndSort.call(void 0, document, options);
30
- return new (0, _chunkY6TRLK3Lcjs.Oas)({ oas });
29
+ const oas = await _chunkBBEAIQFKcjs.filterAndSort.call(void 0, document, options);
30
+ return new (0, _chunkBBEAIQFKcjs.Oas)({ oas });
31
31
  }
32
32
 
33
33
 
package/dist/parser.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  Oas,
3
3
  filterAndSort,
4
4
  isOpenApiV2Document
5
- } from "./chunk-TOY2KSNY.js";
5
+ } from "./chunk-XMMCJRIW.js";
6
6
 
7
7
  // src/parser/index.ts
8
8
  import OASNormalize from "oas-normalize";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/oas",
3
- "version": "2.19.5",
3
+ "version": "2.19.6",
4
4
  "description": "Oas helpers",
5
5
  "keywords": [
6
6
  "typescript",
@@ -48,14 +48,14 @@
48
48
  "!/**/__tests__/**"
49
49
  ],
50
50
  "dependencies": {
51
- "@redocly/openapi-core": "^1.14.0",
51
+ "@redocly/openapi-core": "^1.15.0",
52
52
  "hotscript": "^1.0.13",
53
53
  "json-schema-to-ts": "^3.1.0",
54
- "oas": "^24.3.6",
55
- "oas-normalize": "^11.1.0",
56
- "openapi-format": "^1.17.1",
54
+ "oas": "^24.4.1",
55
+ "oas-normalize": "^11.1.1",
56
+ "openapi-format": "^1.19.0",
57
57
  "openapi-types": "^12.1.3",
58
- "remeda": "^2.0.0",
58
+ "remeda": "^2.0.10",
59
59
  "swagger2openapi": "^7.0.8",
60
60
  "ts-toolbelt": "^9.6.0"
61
61
  },
@@ -63,11 +63,11 @@
63
63
  "@stoplight/yaml": "^4.3.0",
64
64
  "@types/swagger2openapi": "^7.0.4",
65
65
  "expect-type": "^0.19.0",
66
- "tsup": "^8.0.2",
66
+ "tsup": "^8.1.0",
67
67
  "typescript": "^5.4.5",
68
- "@kubb/config-biome": "2.19.5",
69
- "@kubb/config-ts": "2.19.5",
70
- "@kubb/config-tsup": "2.19.5"
68
+ "@kubb/config-biome": "2.19.6",
69
+ "@kubb/config-ts": "2.19.6",
70
+ "@kubb/config-tsup": "2.19.6"
71
71
  },
72
72
  "engines": {
73
73
  "node": ">=18"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAMvB,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,cAAc,GAAG,KAAK,EAAE,aAAa;AACrD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,cAAoC,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AAC5G;AAMO,SAAS,kBAAkB,KAA6D;AAC7F,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,YAAY,KAA+E;AACzG,SAAO,CAAC,CAAC,OAAO,MAAM,GAAG;AAC3B;AAEO,SAAS,WAAW,QAAgC;AACzD,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EAC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a,OAAO;AACrD,iBAAa,QAAQ,CAAC,OAAe;AACnC,UAAI,CAAC,wBAAwB,gBAAgB,KAAK,EAAE,GAAG;AACrD,+BAAuB;AAAA,MACzB;AAAA,IACF,CAAC;AAED,QAAI,CAAC,sBAAsB;AACzB,mBAAa,QAAQ,CAAC,OAAe;AACnC,YAAI,CAAC,sBAAsB;AACzB,iCAAuB;AAAA,QACzB;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,sBAAsB;AACxB,aAAO,CAAC,sBAAsB,aAAa,QAAQ,oBAAoB,GAAI,GAAI,aAAa,cAAc,CAAC,aAAa,WAAW,IAAI,CAAC,CAAE;AAAA,IAC5I;AAEA,WAAO;AAAA,EACT;AACF","sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport openapiFormat from 'openapi-format'\nimport { isPlainObject } from 'remeda'\n\nimport type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\nimport type { FormatOptions } from './parser/index.ts'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n\nexport async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {\n const mergedOptions: FormatOptions = {\n sort: options.sort ?? true,\n ['no-sort']: options['no-sort'] ?? false,\n sortSet: {\n root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],\n get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n parameters: ['name', 'in', 'description', 'required', 'schema'],\n requestBody: ['description', 'required', 'content'],\n responses: ['description', 'headers', 'content', 'links'],\n content: [],\n components: ['parameters', 'schemas'],\n schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],\n ...options.sortSet,\n },\n sortComponentsSet: {\n ...options.sortComponentsSet,\n },\n filterSet: {\n inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace', 'parameters'],\n unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],\n ...options.filterSet,\n },\n casingSet: {\n ...options.casingSet,\n },\n }\n\n const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)\n data = restFilter.data\n\n const resFormat = await openapiFormat.openapiSort(data, mergedOptions)\n data = resFormat.data\n\n const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions)\n data = resChangeCase.data\n\n return data\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...findSchemaDefinition(schema.$ref, this.api),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = findSchemaDefinition($ref, this.api)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate()\n }\n}\n"]}