@kubb/oas 2.16.0 → 2.16.1

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.
@@ -24,7 +24,7 @@ var __privateMethod = (obj, member, method) => {
24
24
  // src/utils.ts
25
25
  import { isRef, isSchema } from "oas/types";
26
26
  import openapiFormat from "openapi-format";
27
- import { isObject, mergeDeep } from "remeda";
27
+ import { isObject } from "remeda";
28
28
  function isOpenApiV2Document(doc) {
29
29
  return doc && isObject(doc) && !("openapi" in doc);
30
30
  }
@@ -44,33 +44,38 @@ function isRequired(schema) {
44
44
  return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required;
45
45
  }
46
46
  async function filterAndSort(data, options = {}) {
47
- const mergedOptions = mergeDeep(
48
- {
49
- sort: true,
50
- sortSet: {
51
- root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
52
- get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
53
- post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
54
- put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
55
- patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
56
- delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
57
- parameters: ["name", "in", "description", "required", "schema"],
58
- requestBody: ["description", "required", "content"],
59
- responses: ["description", "headers", "content", "links"],
60
- content: [],
61
- components: ["parameters", "schemas"],
62
- schema: ["description", "type", "items", "properties", "format", "example", "default"],
63
- schemas: ["description", "type", "items", "properties", "format", "example", "default"],
64
- properties: ["description", "type", "items", "format", "example", "default", "enum"]
65
- },
66
- sortComponentsSet: {},
67
- filterSet: {
68
- unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : []
69
- },
70
- casingSet: {}
47
+ const mergedOptions = {
48
+ sort: options.sort ?? true,
49
+ ["no-sort"]: options["no-sort"] ?? false,
50
+ sortSet: {
51
+ root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
52
+ get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
53
+ post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
54
+ put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
55
+ patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
56
+ delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
57
+ parameters: ["name", "in", "description", "required", "schema"],
58
+ requestBody: ["description", "required", "content"],
59
+ responses: ["description", "headers", "content", "links"],
60
+ content: [],
61
+ components: ["parameters", "schemas"],
62
+ schema: ["description", "type", "items", "properties", "format", "example", "default"],
63
+ schemas: ["description", "type", "items", "properties", "format", "example", "default"],
64
+ properties: ["description", "type", "items", "format", "example", "default", "enum"],
65
+ ...options.sortSet
66
+ },
67
+ sortComponentsSet: {
68
+ ...options.sortComponentsSet
71
69
  },
72
- options
73
- );
70
+ filterSet: {
71
+ inverseMethods: ["get", "put", "post", "delete", "patch", "head", "options", "trace"],
72
+ unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : [],
73
+ ...options.filterSet
74
+ },
75
+ casingSet: {
76
+ ...options.casingSet
77
+ }
78
+ };
74
79
  const restFilter = await openapiFormat.openapiFilter(data, mergedOptions);
75
80
  data = restFilter.data;
76
81
  const resFormat = await openapiFormat.openapiSort(data, mergedOptions);
@@ -236,4 +241,4 @@ export {
236
241
  filterAndSort,
237
242
  Oas
238
243
  };
239
- //# sourceMappingURL=chunk-ADBW4NBH.js.map
244
+ //# sourceMappingURL=chunk-77RG7VLQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport openapiFormat from 'openapi-format'\nimport { isObject } 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 && isObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isObject(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 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'],\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,gBAAgB;AAMlB,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,SAAS,GAAG,KAAK,EAAE,aAAa;AAChD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,SAAS,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AACjF;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;AAEA,eAAsB,cAAc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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"]}
@@ -44,33 +44,38 @@ function isRequired(schema) {
44
44
  return Array.isArray(schema.required) ? !!_optionalChain([schema, 'access', _ => _.required, 'optionalAccess', _2 => _2.length]) : !!schema.required;
45
45
  }
46
46
  async function filterAndSort(data, options = {}) {
47
- const mergedOptions = _remeda.mergeDeep.call(void 0,
48
- {
49
- sort: true,
50
- sortSet: {
51
- root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
52
- get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
53
- post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
54
- put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
55
- patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
56
- delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
57
- parameters: ["name", "in", "description", "required", "schema"],
58
- requestBody: ["description", "required", "content"],
59
- responses: ["description", "headers", "content", "links"],
60
- content: [],
61
- components: ["parameters", "schemas"],
62
- schema: ["description", "type", "items", "properties", "format", "example", "default"],
63
- schemas: ["description", "type", "items", "properties", "format", "example", "default"],
64
- properties: ["description", "type", "items", "format", "example", "default", "enum"]
65
- },
66
- sortComponentsSet: {},
67
- filterSet: {
68
- unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : []
69
- },
70
- casingSet: {}
47
+ const mergedOptions = {
48
+ sort: _nullishCoalesce(options.sort, () => ( true)),
49
+ ["no-sort"]: _nullishCoalesce(options["no-sort"], () => ( false)),
50
+ sortSet: {
51
+ root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
52
+ get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
53
+ post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
54
+ put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
55
+ patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
56
+ delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
57
+ parameters: ["name", "in", "description", "required", "schema"],
58
+ requestBody: ["description", "required", "content"],
59
+ responses: ["description", "headers", "content", "links"],
60
+ content: [],
61
+ components: ["parameters", "schemas"],
62
+ schema: ["description", "type", "items", "properties", "format", "example", "default"],
63
+ schemas: ["description", "type", "items", "properties", "format", "example", "default"],
64
+ properties: ["description", "type", "items", "format", "example", "default", "enum"],
65
+ ...options.sortSet
66
+ },
67
+ sortComponentsSet: {
68
+ ...options.sortComponentsSet
71
69
  },
72
- options
73
- );
70
+ filterSet: {
71
+ inverseMethods: ["get", "put", "post", "delete", "patch", "head", "options", "trace"],
72
+ unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : [],
73
+ ...options.filterSet
74
+ },
75
+ casingSet: {
76
+ ...options.casingSet
77
+ }
78
+ };
74
79
  const restFilter = await _openapiformat2.default.openapiFilter(data, mergedOptions);
75
80
  data = restFilter.data;
76
81
  const resFormat = await _openapiformat2.default.openapiSort(data, mergedOptions);
@@ -236,4 +241,4 @@ getResponseBodyFactory_fn = function(responseBody) {
236
241
 
237
242
 
238
243
  exports.isOpenApiV2Document = isOpenApiV2Document; exports.isOpenApiV3_1Document = isOpenApiV3_1Document; exports.isParameterObject = isParameterObject; exports.isReference = isReference; exports.isRequired = isRequired; exports.filterAndSort = filterAndSort; exports.Oas = Oas;
239
- //# sourceMappingURL=chunk-XYGNER5L.cjs.map
244
+ //# sourceMappingURL=chunk-IBBEFRQ2.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings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BAAgB,MAAM,cAAqC;AAClE,WAAO,CAAC,CAAC;AAAA,EACX;AAEA,SAAO,CAAC,gBAAgB;AACtB,QAAI,CAAC,gBAAgB,YAAY,GAAG;AAClC,aAAO;AAAA,IACT;AAEA,QAAI,YAAY,YAAY,GAAG;AAG7B,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,aAAa,SAAS;AACzB,aAAO;AAAA,IACT;AAEA,QAAI,aAAa;AACf,UAAI,EAAE,eAAe,aAAa,UAAU;AAC1C,eAAO;AAAA,MACT;AAEA,aAAO,aAAa,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 { isObject } 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 && isObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isObject(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 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'],\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"]}
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkXYGNER5Lcjs = require('./chunk-XYGNER5L.cjs');
7
+ var _chunkIBBEFRQ2cjs = require('./chunk-IBBEFRQ2.cjs');
8
8
 
9
9
  // src/types.ts
10
10
  var HttpMethods = {
@@ -29,5 +29,5 @@ var _utils = require('oas/utils');
29
29
 
30
30
 
31
31
 
32
- exports.HttpMethods = HttpMethods; exports.Oas = _chunkXYGNER5Lcjs.Oas; exports.findSchemaDefinition = _utils.findSchemaDefinition; exports.isOpenApiV3_1Document = _chunkXYGNER5Lcjs.isOpenApiV3_1Document; exports.isParameterObject = _chunkXYGNER5Lcjs.isParameterObject; exports.isReference = _chunkXYGNER5Lcjs.isReference; exports.isRequired = _chunkXYGNER5Lcjs.isRequired; exports.matchesMimeType = _utils.matchesMimeType;
32
+ exports.HttpMethods = HttpMethods; exports.Oas = _chunkIBBEFRQ2cjs.Oas; exports.findSchemaDefinition = _utils.findSchemaDefinition; exports.isOpenApiV3_1Document = _chunkIBBEFRQ2cjs.isOpenApiV3_1Document; exports.isParameterObject = _chunkIBBEFRQ2cjs.isParameterObject; exports.isReference = _chunkIBBEFRQ2cjs.isReference; exports.isRequired = _chunkIBBEFRQ2cjs.isRequired; exports.matchesMimeType = _utils.matchesMimeType;
33
33
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -35,8 +35,8 @@ declare module 'openapi-format' {
35
35
  properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
36
36
  }
37
37
  filterSet?: {
38
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>
39
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>
38
+ methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>
39
+ inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>
40
40
  tags?: Array<string>
41
41
  inverseTags?: Array<string>
42
42
  operationIds?: Array<string>
package/dist/index.d.ts CHANGED
@@ -35,8 +35,8 @@ declare module 'openapi-format' {
35
35
  properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
36
36
  }
37
37
  filterSet?: {
38
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>
39
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>
38
+ methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>
39
+ inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>
40
40
  tags?: Array<string>
41
41
  inverseTags?: Array<string>
42
42
  operationIds?: Array<string>
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  isParameterObject,
5
5
  isReference,
6
6
  isRequired
7
- } from "./chunk-ADBW4NBH.js";
7
+ } from "./chunk-77RG7VLQ.js";
8
8
 
9
9
  // src/types.ts
10
10
  var HttpMethods = {
package/dist/parser.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkXYGNER5Lcjs = require('./chunk-XYGNER5L.cjs');
5
+ var _chunkIBBEFRQ2cjs = require('./chunk-IBBEFRQ2.cjs');
6
6
 
7
7
  // src/parser/index.ts
8
8
  var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
@@ -18,13 +18,13 @@ async function parse(pathOrApi, options = {}) {
18
18
  } catch (e) {
19
19
  document = await oasNormalize.load();
20
20
  }
21
- if (_chunkXYGNER5Lcjs.isOpenApiV2Document.call(void 0, document)) {
21
+ if (_chunkIBBEFRQ2cjs.isOpenApiV2Document.call(void 0, document)) {
22
22
  const { openapi } = await _swagger2openapi2.default.convertObj(document, { anchors: true });
23
- const oas2 = await _chunkXYGNER5Lcjs.filterAndSort.call(void 0, openapi, options);
24
- return new (0, _chunkXYGNER5Lcjs.Oas)({ oas: oas2 });
23
+ const oas2 = await _chunkIBBEFRQ2cjs.filterAndSort.call(void 0, openapi, options);
24
+ return new (0, _chunkIBBEFRQ2cjs.Oas)({ oas: oas2 });
25
25
  }
26
- const oas = await _chunkXYGNER5Lcjs.filterAndSort.call(void 0, document, options);
27
- return new (0, _chunkXYGNER5Lcjs.Oas)({ oas });
26
+ const oas = await _chunkIBBEFRQ2cjs.filterAndSort.call(void 0, document, options);
27
+ return new (0, _chunkIBBEFRQ2cjs.Oas)({ oas });
28
28
  }
29
29
 
30
30
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parser/index.ts"],"names":["oas"],"mappings":";;;;;;;AAAA,OAAO,kBAAkB;AACzB,OAAO,qBAAqB;AAkD5B,eAAsB,MAAM,WAAiC,UAAyB,CAAC,GAAiB;AACtG,QAAM,eAAe,IAAI,aAAa,WAAW;AAAA,IAC/C,aAAa;AAAA,IACb,gBAAgB;AAAA,EAClB,CAAC;AACD,MAAI;AAEJ,MAAI;AAEF,eAAW,MAAM,aAAa,OAAO;AAAA,EACvC,SAAS,GAAG;AACV,eAAY,MAAM,aAAa,KAAK;AAAA,EACtC;AAEA,MAAI,oBAAoB,QAAQ,GAAG;AACjC,UAAM,EAAE,QAAQ,IAAI,MAAM,gBAAgB,WAAW,UAAU,EAAE,SAAS,KAAK,CAAC;AAEhF,UAAMA,OAAM,MAAM,cAAc,SAAwB,OAAO;AAE/D,WAAO,IAAI,IAAI,EAAE,KAAKA,KAAmB,CAAC;AAAA,EAC5C;AAEA,QAAM,MAAM,MAAM,cAAc,UAAyB,OAAO;AAEhE,SAAO,IAAI,IAAI,EAAE,IAAI,CAAC;AACxB","sourcesContent":["import OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { filterAndSort, isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport type FormatOptions = {\n verbose?: boolean\n 'no-sort'?: boolean\n sort?: boolean\n output?: string\n sortSet?: {\n root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>\n get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>\n requestBody?: Array<'description' | 'required' | 'content'>\n responses?: Array<'description' | 'headers' | 'content' | 'links'>\n content?: Array<string>\n components?: Array<'parameters' | 'schemas'>\n schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>\n }\n filterSet?: {\n methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>\n inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>\n tags?: Array<string>\n inverseTags?: Array<string>\n operationIds?: Array<string>\n inverseOperationIds?: Array<string>\n operations?: Array<string>\n flags?: Array<string>\n inverseFlags?: Array<string>\n flagValues?: Array<string>\n inverseFlagValues?: Array<string>\n stripFlags?: Array<string>\n responseContent?: Array<string>\n inverseResponseContent?: Array<string>\n unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>\n }\n sortComponentsSet?: {}\n casingSet?: {}\n}\n\nexport async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}): Promise<Oas> {\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n let document: OpenAPI.Document\n\n try {\n // resolve external refs\n document = await oasNormalize.bundle()\n } catch (e) {\n document = (await oasNormalize.load()) as OpenAPI.Document\n }\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, { anchors: true })\n\n const oas = await filterAndSort(openapi as OASDocument, options)\n\n return new Oas({ oas: oas as OASDocument })\n }\n\n const oas = await filterAndSort(document as OASDocument, options)\n\n return new Oas({ oas })\n}\n"]}
1
+ {"version":3,"sources":["../src/parser/index.ts"],"names":["oas"],"mappings":";;;;;;;AAAA,OAAO,kBAAkB;AACzB,OAAO,qBAAqB;AAkD5B,eAAsB,MAAM,WAAiC,UAAyB,CAAC,GAAiB;AACtG,QAAM,eAAe,IAAI,aAAa,WAAW;AAAA,IAC/C,aAAa;AAAA,IACb,gBAAgB;AAAA,EAClB,CAAC;AACD,MAAI;AAEJ,MAAI;AAEF,eAAW,MAAM,aAAa,OAAO;AAAA,EACvC,SAAS,GAAG;AACV,eAAY,MAAM,aAAa,KAAK;AAAA,EACtC;AAEA,MAAI,oBAAoB,QAAQ,GAAG;AACjC,UAAM,EAAE,QAAQ,IAAI,MAAM,gBAAgB,WAAW,UAAU,EAAE,SAAS,KAAK,CAAC;AAEhF,UAAMA,OAAM,MAAM,cAAc,SAAwB,OAAO;AAE/D,WAAO,IAAI,IAAI,EAAE,KAAKA,KAAmB,CAAC;AAAA,EAC5C;AAEA,QAAM,MAAM,MAAM,cAAc,UAAyB,OAAO;AAEhE,SAAO,IAAI,IAAI,EAAE,IAAI,CAAC;AACxB","sourcesContent":["import OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { filterAndSort, isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport type FormatOptions = {\n verbose?: boolean\n 'no-sort'?: boolean\n sort?: boolean\n output?: string\n sortSet?: {\n root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>\n get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>\n requestBody?: Array<'description' | 'required' | 'content'>\n responses?: Array<'description' | 'headers' | 'content' | 'links'>\n content?: Array<string>\n components?: Array<'parameters' | 'schemas'>\n schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>\n }\n filterSet?: {\n methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>\n inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>\n tags?: Array<string>\n inverseTags?: Array<string>\n operationIds?: Array<string>\n inverseOperationIds?: Array<string>\n operations?: Array<string>\n flags?: Array<string>\n inverseFlags?: Array<string>\n flagValues?: Array<string>\n inverseFlagValues?: Array<string>\n stripFlags?: Array<string>\n responseContent?: Array<string>\n inverseResponseContent?: Array<string>\n unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>\n }\n sortComponentsSet?: {}\n casingSet?: {}\n}\n\nexport async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}): Promise<Oas> {\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n let document: OpenAPI.Document\n\n try {\n // resolve external refs\n document = await oasNormalize.bundle()\n } catch (e) {\n document = (await oasNormalize.load()) as OpenAPI.Document\n }\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, { anchors: true })\n\n const oas = await filterAndSort(openapi as OASDocument, options)\n\n return new Oas({ oas: oas as OASDocument })\n }\n\n const oas = await filterAndSort(document as OASDocument, options)\n\n return new Oas({ oas })\n}\n"]}
package/dist/parser.d.cts CHANGED
@@ -25,8 +25,8 @@ type FormatOptions = {
25
25
  properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>;
26
26
  };
27
27
  filterSet?: {
28
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>;
29
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>;
28
+ methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>;
29
+ inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>;
30
30
  tags?: Array<string>;
31
31
  inverseTags?: Array<string>;
32
32
  operationIds?: Array<string>;
package/dist/parser.d.ts CHANGED
@@ -25,8 +25,8 @@ type FormatOptions = {
25
25
  properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>;
26
26
  };
27
27
  filterSet?: {
28
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>;
29
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>;
28
+ methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>;
29
+ inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>;
30
30
  tags?: Array<string>;
31
31
  inverseTags?: Array<string>;
32
32
  operationIds?: Array<string>;
package/dist/parser.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  Oas,
3
3
  filterAndSort,
4
4
  isOpenApiV2Document
5
- } from "./chunk-ADBW4NBH.js";
5
+ } from "./chunk-77RG7VLQ.js";
6
6
 
7
7
  // src/parser/index.ts
8
8
  import OASNormalize from "oas-normalize";
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parser/index.ts"],"sourcesContent":["import OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { filterAndSort, isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport type FormatOptions = {\n verbose?: boolean\n 'no-sort'?: boolean\n sort?: boolean\n output?: string\n sortSet?: {\n root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>\n get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>\n requestBody?: Array<'description' | 'required' | 'content'>\n responses?: Array<'description' | 'headers' | 'content' | 'links'>\n content?: Array<string>\n components?: Array<'parameters' | 'schemas'>\n schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>\n }\n filterSet?: {\n methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>\n inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>\n tags?: Array<string>\n inverseTags?: Array<string>\n operationIds?: Array<string>\n inverseOperationIds?: Array<string>\n operations?: Array<string>\n flags?: Array<string>\n inverseFlags?: Array<string>\n flagValues?: Array<string>\n inverseFlagValues?: Array<string>\n stripFlags?: Array<string>\n responseContent?: Array<string>\n inverseResponseContent?: Array<string>\n unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>\n }\n sortComponentsSet?: {}\n casingSet?: {}\n}\n\nexport async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}): Promise<Oas> {\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n let document: OpenAPI.Document\n\n try {\n // resolve external refs\n document = await oasNormalize.bundle()\n } catch (e) {\n document = (await oasNormalize.load()) as OpenAPI.Document\n }\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, { anchors: true })\n\n const oas = await filterAndSort(openapi as OASDocument, options)\n\n return new Oas({ oas: oas as OASDocument })\n }\n\n const oas = await filterAndSort(document as OASDocument, options)\n\n return new Oas({ oas })\n}\n"],"mappings":";;;;;;;AAAA,OAAO,kBAAkB;AACzB,OAAO,qBAAqB;AAkD5B,eAAsB,MAAM,WAAiC,UAAyB,CAAC,GAAiB;AACtG,QAAM,eAAe,IAAI,aAAa,WAAW;AAAA,IAC/C,aAAa;AAAA,IACb,gBAAgB;AAAA,EAClB,CAAC;AACD,MAAI;AAEJ,MAAI;AAEF,eAAW,MAAM,aAAa,OAAO;AAAA,EACvC,SAAS,GAAG;AACV,eAAY,MAAM,aAAa,KAAK;AAAA,EACtC;AAEA,MAAI,oBAAoB,QAAQ,GAAG;AACjC,UAAM,EAAE,QAAQ,IAAI,MAAM,gBAAgB,WAAW,UAAU,EAAE,SAAS,KAAK,CAAC;AAEhF,UAAMA,OAAM,MAAM,cAAc,SAAwB,OAAO;AAE/D,WAAO,IAAI,IAAI,EAAE,KAAKA,KAAmB,CAAC;AAAA,EAC5C;AAEA,QAAM,MAAM,MAAM,cAAc,UAAyB,OAAO;AAEhE,SAAO,IAAI,IAAI,EAAE,IAAI,CAAC;AACxB;","names":["oas"]}
1
+ {"version":3,"sources":["../src/parser/index.ts"],"sourcesContent":["import OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { filterAndSort, isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport type FormatOptions = {\n verbose?: boolean\n 'no-sort'?: boolean\n sort?: boolean\n output?: string\n sortSet?: {\n root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>\n get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>\n requestBody?: Array<'description' | 'required' | 'content'>\n responses?: Array<'description' | 'headers' | 'content' | 'links'>\n content?: Array<string>\n components?: Array<'parameters' | 'schemas'>\n schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>\n }\n filterSet?: {\n methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>\n inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>\n tags?: Array<string>\n inverseTags?: Array<string>\n operationIds?: Array<string>\n inverseOperationIds?: Array<string>\n operations?: Array<string>\n flags?: Array<string>\n inverseFlags?: Array<string>\n flagValues?: Array<string>\n inverseFlagValues?: Array<string>\n stripFlags?: Array<string>\n responseContent?: Array<string>\n inverseResponseContent?: Array<string>\n unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>\n }\n sortComponentsSet?: {}\n casingSet?: {}\n}\n\nexport async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}): Promise<Oas> {\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n let document: OpenAPI.Document\n\n try {\n // resolve external refs\n document = await oasNormalize.bundle()\n } catch (e) {\n document = (await oasNormalize.load()) as OpenAPI.Document\n }\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, { anchors: true })\n\n const oas = await filterAndSort(openapi as OASDocument, options)\n\n return new Oas({ oas: oas as OASDocument })\n }\n\n const oas = await filterAndSort(document as OASDocument, options)\n\n return new Oas({ oas })\n}\n"],"mappings":";;;;;;;AAAA,OAAO,kBAAkB;AACzB,OAAO,qBAAqB;AAkD5B,eAAsB,MAAM,WAAiC,UAAyB,CAAC,GAAiB;AACtG,QAAM,eAAe,IAAI,aAAa,WAAW;AAAA,IAC/C,aAAa;AAAA,IACb,gBAAgB;AAAA,EAClB,CAAC;AACD,MAAI;AAEJ,MAAI;AAEF,eAAW,MAAM,aAAa,OAAO;AAAA,EACvC,SAAS,GAAG;AACV,eAAY,MAAM,aAAa,KAAK;AAAA,EACtC;AAEA,MAAI,oBAAoB,QAAQ,GAAG;AACjC,UAAM,EAAE,QAAQ,IAAI,MAAM,gBAAgB,WAAW,UAAU,EAAE,SAAS,KAAK,CAAC;AAEhF,UAAMA,OAAM,MAAM,cAAc,SAAwB,OAAO;AAE/D,WAAO,IAAI,IAAI,EAAE,KAAKA,KAAmB,CAAC;AAAA,EAC5C;AAEA,QAAM,MAAM,MAAM,cAAc,UAAyB,OAAO;AAEhE,SAAO,IAAI,IAAI,EAAE,IAAI,CAAC;AACxB;","names":["oas"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/oas",
3
- "version": "2.16.0",
3
+ "version": "2.16.1",
4
4
  "description": "Oas helpers",
5
5
  "keywords": [
6
6
  "typescript",
@@ -29,8 +29,8 @@ export type FormatOptions = {
29
29
  properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
30
30
  }
31
31
  filterSet?: {
32
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>
33
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>
32
+ methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>
33
+ inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>
34
34
  tags?: Array<string>
35
35
  inverseTags?: Array<string>
36
36
  operationIds?: Array<string>
package/src/typings.d.ts CHANGED
@@ -21,8 +21,8 @@ declare module 'openapi-format' {
21
21
  properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
22
22
  }
23
23
  filterSet?: {
24
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>
25
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete'>
24
+ methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>
25
+ inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head'>
26
26
  tags?: Array<string>
27
27
  inverseTags?: Array<string>
28
28
  operationIds?: Array<string>
package/src/utils.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { isRef, isSchema } from 'oas/types'
2
2
  import openapiFormat from 'openapi-format'
3
- import { isObject, mergeDeep } from 'remeda'
3
+ import { isObject } from 'remeda'
4
4
 
5
5
  import type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'
6
6
  import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
7
+ import type { FormatOptions } from './parser/index.ts'
7
8
 
8
9
  export function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {
9
10
  return doc && isObject(doc) && !('openapi' in doc)
@@ -36,34 +37,39 @@ export function isRequired(schema?: SchemaObject): boolean {
36
37
  return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required
37
38
  }
38
39
 
39
- export async function filterAndSort(data: OASDocument, options: openapiFormat.Options = {}): Promise<OASDocument> {
40
- const mergedOptions = mergeDeep(
41
- {
42
- sort: true,
43
- sortSet: {
44
- root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],
45
- get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
46
- post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
47
- put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
48
- patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
49
- delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
50
- parameters: ['name', 'in', 'description', 'required', 'schema'],
51
- requestBody: ['description', 'required', 'content'],
52
- responses: ['description', 'headers', 'content', 'links'],
53
- content: [],
54
- components: ['parameters', 'schemas'],
55
- schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],
56
- schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],
57
- properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],
58
- },
59
- sortComponentsSet: {},
60
- filterSet: {
61
- unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],
62
- },
63
- casingSet: {},
40
+ export async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {
41
+ const mergedOptions: FormatOptions = {
42
+ sort: options.sort ?? true,
43
+ ['no-sort']: options['no-sort'] ?? false,
44
+ sortSet: {
45
+ root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],
46
+ get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
47
+ post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
48
+ put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
49
+ patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
50
+ delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
51
+ parameters: ['name', 'in', 'description', 'required', 'schema'],
52
+ requestBody: ['description', 'required', 'content'],
53
+ responses: ['description', 'headers', 'content', 'links'],
54
+ content: [],
55
+ components: ['parameters', 'schemas'],
56
+ schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],
57
+ schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],
58
+ properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],
59
+ ...options.sortSet,
64
60
  },
65
- options as Record<string, unknown>,
66
- ) as openapiFormat.Options
61
+ sortComponentsSet: {
62
+ ...options.sortComponentsSet,
63
+ },
64
+ filterSet: {
65
+ inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace'],
66
+ unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],
67
+ ...options.filterSet,
68
+ },
69
+ casingSet: {
70
+ ...options.casingSet,
71
+ },
72
+ }
67
73
 
68
74
  const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)
69
75
  data = restFilter.data
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport openapiFormat from 'openapi-format'\nimport { isObject, mergeDeep } from 'remeda'\n\nimport type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isObject(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 async function filterAndSort(data: OASDocument, options: openapiFormat.Options = {}): Promise<OASDocument> {\n const mergedOptions = mergeDeep(\n {\n sort: true,\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 },\n sortComponentsSet: {},\n filterSet: {\n unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],\n },\n casingSet: {},\n },\n options as Record<string, unknown>,\n ) as openapiFormat.Options\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,UAAU,iBAAiB;AAK7B,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,SAAS,GAAG,KAAK,EAAE,aAAa;AAChD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,SAAS,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AACjF;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,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,aAAa,SAAS;AAAA,EAC9B;AACF;AAtLE;AA4BA;AAAA,4BAAuB,SAAC,cAAoI;AAC1J,WAAS,gBAAgB,MAAM,cAAqC;AAClE,WAAO,CAAC,CAAC;AAAA,EACX;AAEA,SAAO,CAAC,gBAAgB;AACtB,QAAI,CAAC,gBAAgB,YAAY,GAAG;AAClC,aAAO;AAAA,IACT;AAEA,QAAI,YAAY,YAAY,GAAG;AAG7B,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,aAAa,SAAS;AACzB,aAAO;AAAA,IACT;AAEA,QAAI,aAAa;AACf,UAAI,EAAE,eAAe,aAAa,UAAU;AAC1C,eAAO;AAAA,MACT;AAEA,aAAO,aAAa,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 { isObject, mergeDeep } from 'remeda'\n\nimport type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isObject(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 async function filterAndSort(data: OASDocument, options: openapiFormat.Options = {}): Promise<OASDocument> {\n const mergedOptions = mergeDeep(\n {\n sort: true,\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 },\n sortComponentsSet: {},\n filterSet: {\n unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],\n },\n casingSet: {},\n },\n options as Record<string, unknown>,\n ) as openapiFormat.Options\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"]}