@kubb/oas 3.0.0-alpha.6 → 3.0.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-7D7ASOLY.js → chunk-LVZACNUG.js} +51 -64
- package/dist/{chunk-7D7ASOLY.js.map → chunk-LVZACNUG.js.map} +1 -1
- package/dist/{chunk-UIWP4KHB.cjs → chunk-WZOC4WVK.cjs} +55 -68
- package/dist/chunk-WZOC4WVK.cjs.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/parser.cjs +5 -5
- package/dist/parser.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-UIWP4KHB.cjs.map +0 -1
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __typeError = (msg) => {
|
|
2
|
-
throw TypeError(msg);
|
|
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);
|
|
9
|
-
|
|
10
1
|
// src/utils.ts
|
|
11
2
|
import { isRef, isSchema } from "oas/types";
|
|
12
3
|
import openapiFormat from "openapi-format";
|
|
@@ -78,18 +69,16 @@ async function filterAndSort(data, options = {}) {
|
|
|
78
69
|
import BaseOas from "oas";
|
|
79
70
|
import OASNormalize from "oas-normalize";
|
|
80
71
|
import { findSchemaDefinition, matchesMimeType } from "oas/utils";
|
|
81
|
-
var _options, _Oas_instances, getResponseBodyFactory_fn;
|
|
82
72
|
var Oas = class extends BaseOas {
|
|
73
|
+
#options = {};
|
|
74
|
+
document = void 0;
|
|
83
75
|
constructor({ oas, user }, options = {}) {
|
|
84
76
|
if (typeof oas === "string") {
|
|
85
77
|
oas = JSON.parse(oas);
|
|
86
78
|
}
|
|
87
79
|
super(oas, user);
|
|
88
|
-
__privateAdd(this, _Oas_instances);
|
|
89
|
-
__privateAdd(this, _options, {});
|
|
90
|
-
this.document = void 0;
|
|
91
80
|
this.document = oas;
|
|
92
|
-
|
|
81
|
+
this.#options = options;
|
|
93
82
|
}
|
|
94
83
|
dereferenceWithRef(schema) {
|
|
95
84
|
if (isReference(schema)) {
|
|
@@ -100,6 +89,49 @@ var Oas = class extends BaseOas {
|
|
|
100
89
|
}
|
|
101
90
|
return schema;
|
|
102
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Oas does not have a getResponseBody(contentType)
|
|
94
|
+
*/
|
|
95
|
+
#getResponseBodyFactory(responseBody) {
|
|
96
|
+
function hasResponseBody(res = responseBody) {
|
|
97
|
+
return !!res;
|
|
98
|
+
}
|
|
99
|
+
return (contentType) => {
|
|
100
|
+
if (!hasResponseBody(responseBody)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (isReference(responseBody)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (!responseBody.content) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (contentType) {
|
|
110
|
+
if (!(contentType in responseBody.content)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return responseBody.content[contentType];
|
|
114
|
+
}
|
|
115
|
+
let availablecontentType = void 0;
|
|
116
|
+
const contentTypes = Object.keys(responseBody.content);
|
|
117
|
+
contentTypes.forEach((mt) => {
|
|
118
|
+
if (!availablecontentType && matchesMimeType.json(mt)) {
|
|
119
|
+
availablecontentType = mt;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (!availablecontentType) {
|
|
123
|
+
contentTypes.forEach((mt) => {
|
|
124
|
+
if (!availablecontentType) {
|
|
125
|
+
availablecontentType = mt;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (availablecontentType) {
|
|
130
|
+
return [availablecontentType, responseBody.content[availablecontentType], ...responseBody.description ? [responseBody.description] : []];
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
103
135
|
getResponseSchema(operation, statusCode) {
|
|
104
136
|
if (operation.schema.responses) {
|
|
105
137
|
Object.keys(operation.schema.responses).forEach((key) => {
|
|
@@ -110,8 +142,8 @@ var Oas = class extends BaseOas {
|
|
|
110
142
|
}
|
|
111
143
|
});
|
|
112
144
|
}
|
|
113
|
-
const getResponseBody =
|
|
114
|
-
const { contentType } =
|
|
145
|
+
const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode));
|
|
146
|
+
const { contentType } = this.#options;
|
|
115
147
|
const responseBody = getResponseBody(contentType);
|
|
116
148
|
if (responseBody === false) {
|
|
117
149
|
return {};
|
|
@@ -123,7 +155,7 @@ var Oas = class extends BaseOas {
|
|
|
123
155
|
return this.dereferenceWithRef(schema);
|
|
124
156
|
}
|
|
125
157
|
getRequestSchema(operation) {
|
|
126
|
-
const { contentType } =
|
|
158
|
+
const { contentType } = this.#options;
|
|
127
159
|
if (operation.schema.requestBody) {
|
|
128
160
|
operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody);
|
|
129
161
|
}
|
|
@@ -138,7 +170,7 @@ var Oas = class extends BaseOas {
|
|
|
138
170
|
return this.dereferenceWithRef(schema);
|
|
139
171
|
}
|
|
140
172
|
getParametersSchema(operation, inKey) {
|
|
141
|
-
const { contentType = operation.getContentType() } =
|
|
173
|
+
const { contentType = operation.getContentType() } = this.#options;
|
|
142
174
|
const params = operation.getParameters().map((schema) => {
|
|
143
175
|
return this.dereferenceWithRef(schema);
|
|
144
176
|
}).filter((v) => v.in === inKey);
|
|
@@ -183,51 +215,6 @@ var Oas = class extends BaseOas {
|
|
|
183
215
|
});
|
|
184
216
|
}
|
|
185
217
|
};
|
|
186
|
-
_options = new WeakMap();
|
|
187
|
-
_Oas_instances = new WeakSet();
|
|
188
|
-
/**
|
|
189
|
-
* Oas does not have a getResponseBody(contentType)
|
|
190
|
-
*/
|
|
191
|
-
getResponseBodyFactory_fn = function(responseBody) {
|
|
192
|
-
function hasResponseBody(res = responseBody) {
|
|
193
|
-
return !!res;
|
|
194
|
-
}
|
|
195
|
-
return (contentType) => {
|
|
196
|
-
if (!hasResponseBody(responseBody)) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
if (isReference(responseBody)) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
if (!responseBody.content) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
if (contentType) {
|
|
206
|
-
if (!(contentType in responseBody.content)) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
return responseBody.content[contentType];
|
|
210
|
-
}
|
|
211
|
-
let availablecontentType = void 0;
|
|
212
|
-
const contentTypes = Object.keys(responseBody.content);
|
|
213
|
-
contentTypes.forEach((mt) => {
|
|
214
|
-
if (!availablecontentType && matchesMimeType.json(mt)) {
|
|
215
|
-
availablecontentType = mt;
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
if (!availablecontentType) {
|
|
219
|
-
contentTypes.forEach((mt) => {
|
|
220
|
-
if (!availablecontentType) {
|
|
221
|
-
availablecontentType = mt;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
if (availablecontentType) {
|
|
226
|
-
return [availablecontentType, responseBody.content[availablecontentType], ...responseBody.description ? [responseBody.description] : []];
|
|
227
|
-
}
|
|
228
|
-
return false;
|
|
229
|
-
};
|
|
230
|
-
};
|
|
231
218
|
|
|
232
219
|
export {
|
|
233
220
|
isOpenApiV2Document,
|
|
@@ -239,4 +226,4 @@ export {
|
|
|
239
226
|
filterAndSort,
|
|
240
227
|
Oas
|
|
241
228
|
};
|
|
242
|
-
//# sourceMappingURL=chunk-
|
|
229
|
+
//# sourceMappingURL=chunk-LVZACNUG.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 parser: {\n validate: {\n colorizeErrors: true,\n schema: false,\n spec: false,\n },\n },\n })\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,OAAO,mBAA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QACR;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AA9LE;AADK;AAAA;AAAA;AAAA;AA6BL,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;","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 parser: {\n validate: {\n colorizeErrors: true,\n schema: false,\n spec: false,\n },\n },\n })\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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AAA,UACnB,SAAS,OAAO;AAAA,UAChB;AAAA,UACA,YAAY;AAAA,YACV,GAAG,OAAO;AAAA,YACV,CAAC,eAAe,IAAI,GAAG;AAAA,cACrB,aAAa,eAAe;AAAA,cAC5B,GAAG;AAAA,YACL;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,EAAE,MAAM,UAAU,UAAU,CAAC,GAAG,YAAY,CAAC,EAAE;AAAA,IACjD;AAAA,EACF;AAAA,EAEA,MAAM,WAAW;AACf,UAAM,eAAe,IAAI,aAAa,KAAK,KAAK;AAAA,MAC9C,aAAa;AAAA,MACb,gBAAgB;AAAA,IAClB,CAAC;AAED,UAAM,aAAa,SAAS;AAAA,MAC1B,QAAQ;AAAA,QACN,UAAU;AAAA,UACR,gBAAgB;AAAA,UAChB,QAAQ;AAAA,UACR,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["schema"]}
|
|
@@ -1,13 +1,4 @@
|
|
|
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
|
|
2
|
-
throw TypeError(msg);
|
|
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);
|
|
9
|
-
|
|
10
|
-
// src/utils.ts
|
|
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 _class;// src/utils.ts
|
|
11
2
|
var _types = require('oas/types');
|
|
12
3
|
var _openapiformat = require('openapi-format'); var _openapiformat2 = _interopRequireDefault(_openapiformat);
|
|
13
4
|
var _remeda = require('remeda');
|
|
@@ -78,18 +69,16 @@ async function filterAndSort(data, options = {}) {
|
|
|
78
69
|
var _oas = require('oas'); var _oas2 = _interopRequireDefault(_oas);
|
|
79
70
|
var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
|
|
80
71
|
var _utils = require('oas/utils');
|
|
81
|
-
var
|
|
82
|
-
|
|
72
|
+
var Oas = (_class = class extends _oas2.default {
|
|
73
|
+
#options = {};
|
|
74
|
+
__init() {this.document = void 0}
|
|
83
75
|
constructor({ oas, user }, options = {}) {
|
|
84
76
|
if (typeof oas === "string") {
|
|
85
77
|
oas = JSON.parse(oas);
|
|
86
78
|
}
|
|
87
|
-
super(oas, user);
|
|
88
|
-
__privateAdd(this, _Oas_instances);
|
|
89
|
-
__privateAdd(this, _options, {});
|
|
90
|
-
this.document = void 0;
|
|
79
|
+
super(oas, user);_class.prototype.__init.call(this);;
|
|
91
80
|
this.document = oas;
|
|
92
|
-
|
|
81
|
+
this.#options = options;
|
|
93
82
|
}
|
|
94
83
|
dereferenceWithRef(schema) {
|
|
95
84
|
if (isReference(schema)) {
|
|
@@ -100,6 +89,49 @@ var Oas = class extends _oas2.default {
|
|
|
100
89
|
}
|
|
101
90
|
return schema;
|
|
102
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Oas does not have a getResponseBody(contentType)
|
|
94
|
+
*/
|
|
95
|
+
#getResponseBodyFactory(responseBody) {
|
|
96
|
+
function hasResponseBody(res = responseBody) {
|
|
97
|
+
return !!res;
|
|
98
|
+
}
|
|
99
|
+
return (contentType) => {
|
|
100
|
+
if (!hasResponseBody(responseBody)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (isReference(responseBody)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (!responseBody.content) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (contentType) {
|
|
110
|
+
if (!(contentType in responseBody.content)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return responseBody.content[contentType];
|
|
114
|
+
}
|
|
115
|
+
let availablecontentType = void 0;
|
|
116
|
+
const contentTypes = Object.keys(responseBody.content);
|
|
117
|
+
contentTypes.forEach((mt) => {
|
|
118
|
+
if (!availablecontentType && _utils.matchesMimeType.json(mt)) {
|
|
119
|
+
availablecontentType = mt;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (!availablecontentType) {
|
|
123
|
+
contentTypes.forEach((mt) => {
|
|
124
|
+
if (!availablecontentType) {
|
|
125
|
+
availablecontentType = mt;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (availablecontentType) {
|
|
130
|
+
return [availablecontentType, responseBody.content[availablecontentType], ...responseBody.description ? [responseBody.description] : []];
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
103
135
|
getResponseSchema(operation, statusCode) {
|
|
104
136
|
if (operation.schema.responses) {
|
|
105
137
|
Object.keys(operation.schema.responses).forEach((key) => {
|
|
@@ -110,8 +142,8 @@ var Oas = class extends _oas2.default {
|
|
|
110
142
|
}
|
|
111
143
|
});
|
|
112
144
|
}
|
|
113
|
-
const getResponseBody =
|
|
114
|
-
const { contentType } =
|
|
145
|
+
const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode));
|
|
146
|
+
const { contentType } = this.#options;
|
|
115
147
|
const responseBody = getResponseBody(contentType);
|
|
116
148
|
if (responseBody === false) {
|
|
117
149
|
return {};
|
|
@@ -123,7 +155,7 @@ var Oas = class extends _oas2.default {
|
|
|
123
155
|
return this.dereferenceWithRef(schema);
|
|
124
156
|
}
|
|
125
157
|
getRequestSchema(operation) {
|
|
126
|
-
const { contentType } =
|
|
158
|
+
const { contentType } = this.#options;
|
|
127
159
|
if (operation.schema.requestBody) {
|
|
128
160
|
operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody);
|
|
129
161
|
}
|
|
@@ -138,7 +170,7 @@ var Oas = class extends _oas2.default {
|
|
|
138
170
|
return this.dereferenceWithRef(schema);
|
|
139
171
|
}
|
|
140
172
|
getParametersSchema(operation, inKey) {
|
|
141
|
-
const { contentType = operation.getContentType() } =
|
|
173
|
+
const { contentType = operation.getContentType() } = this.#options;
|
|
142
174
|
const params = operation.getParameters().map((schema) => {
|
|
143
175
|
return this.dereferenceWithRef(schema);
|
|
144
176
|
}).filter((v) => v.in === inKey);
|
|
@@ -182,52 +214,7 @@ var Oas = class extends _oas2.default {
|
|
|
182
214
|
}
|
|
183
215
|
});
|
|
184
216
|
}
|
|
185
|
-
};
|
|
186
|
-
_options = new WeakMap();
|
|
187
|
-
_Oas_instances = new WeakSet();
|
|
188
|
-
/**
|
|
189
|
-
* Oas does not have a getResponseBody(contentType)
|
|
190
|
-
*/
|
|
191
|
-
getResponseBodyFactory_fn = function(responseBody) {
|
|
192
|
-
function hasResponseBody(res = responseBody) {
|
|
193
|
-
return !!res;
|
|
194
|
-
}
|
|
195
|
-
return (contentType) => {
|
|
196
|
-
if (!hasResponseBody(responseBody)) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
if (isReference(responseBody)) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
if (!responseBody.content) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
if (contentType) {
|
|
206
|
-
if (!(contentType in responseBody.content)) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
return responseBody.content[contentType];
|
|
210
|
-
}
|
|
211
|
-
let availablecontentType = void 0;
|
|
212
|
-
const contentTypes = Object.keys(responseBody.content);
|
|
213
|
-
contentTypes.forEach((mt) => {
|
|
214
|
-
if (!availablecontentType && _utils.matchesMimeType.json(mt)) {
|
|
215
|
-
availablecontentType = mt;
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
if (!availablecontentType) {
|
|
219
|
-
contentTypes.forEach((mt) => {
|
|
220
|
-
if (!availablecontentType) {
|
|
221
|
-
availablecontentType = mt;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
if (availablecontentType) {
|
|
226
|
-
return [availablecontentType, responseBody.content[availablecontentType], ...responseBody.description ? [responseBody.description] : []];
|
|
227
|
-
}
|
|
228
|
-
return false;
|
|
229
|
-
};
|
|
230
|
-
};
|
|
217
|
+
}, _class);
|
|
231
218
|
|
|
232
219
|
|
|
233
220
|
|
|
@@ -239,4 +226,4 @@ getResponseBodyFactory_fn = function(responseBody) {
|
|
|
239
226
|
|
|
240
227
|
|
|
241
228
|
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;
|
|
242
|
-
//# sourceMappingURL=chunk-
|
|
229
|
+
//# sourceMappingURL=chunk-WZOC4WVK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/oas/dist/chunk-WZOC4WVK.cjs","../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings":"AAAA;ACAA,kCAAgC;AAChC,6GAA0B;AAC1B,gCAA8B;AAMvB,SAAS,mBAAA,CAAoB,GAAA,EAAqC;AACvE,EAAA,OAAO,IAAA,GAAO,mCAAA,GAAiB,EAAA,GAAK,CAAA,CAAE,UAAA,GAAa,GAAA,CAAA;AACrD;AAKO,SAAS,qBAAA,CAAsB,GAAA,EAAuC;AAC3E,EAAA,OAAO,IAAA,GAAO,mCAAA,GAAuC,EAAA,GAAK,UAAA,GAAa,IAAA,GAAO,GAAA,CAAI,OAAA,CAAQ,UAAA,CAAW,KAAK,CAAA;AAC5G;AAMO,SAAS,iBAAA,CAAkB,GAAA,EAA6D;AAC7F,EAAA,OAAO,IAAA,GAAO,KAAA,GAAQ,GAAA;AACxB;AAEO,SAAS,WAAA,CAAY,GAAA,EAA+E;AACzG,EAAA,OAAO,CAAC,CAAC,IAAA,GAAO,0BAAA,GAAS,CAAA;AAC3B;AAEO,SAAS,UAAA,CAAW,MAAA,EAAgC;AACzD,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,QAAQ,EAAA,EAAI,CAAC,iBAAC,MAAA,mBAAO,QAAA,6BAAU,SAAA,EAAS,CAAC,CAAC,MAAA,CAAO,QAAA;AAC/E;AAEO,SAAS,UAAA,CAAW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MAAA,EAAQ;AAAA,QACN,QAAA,EAAU;AAAA,UACR,cAAA,EAAgB,IAAA;AAAA,UAChB,MAAA,EAAQ,KAAA;AAAA,UACR,IAAA,EAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AACF,UAAA;AFYA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uTAAC","file":"/home/runner/work/kubb/kubb/packages/oas/dist/chunk-WZOC4WVK.cjs","sourcesContent":[null,"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 parser: {\n validate: {\n colorizeErrors: true,\n schema: false,\n spec: false,\n },\n },\n })\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkWZOC4WVKcjs = require('./chunk-WZOC4WVK.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 =
|
|
34
|
+
exports.HttpMethods = HttpMethods; exports.Oas = _chunkWZOC4WVKcjs.Oas; exports.findSchemaDefinition = _utils.findSchemaDefinition; exports.isOpenApiV3_1Document = _chunkWZOC4WVKcjs.isOpenApiV3_1Document; exports.isOptional = _chunkWZOC4WVKcjs.isOptional; exports.isParameterObject = _chunkWZOC4WVKcjs.isParameterObject; exports.isReference = _chunkWZOC4WVKcjs.isReference; exports.isRequired = _chunkWZOC4WVKcjs.isRequired; exports.matchesMimeType = _utils.matchesMimeType;
|
|
35
35
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
package/dist/parser.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkWZOC4WVKcjs = require('./chunk-WZOC4WVK.cjs');
|
|
6
6
|
|
|
7
7
|
// src/parser/index.ts
|
|
8
8
|
var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
|
|
9
9
|
var _swagger2openapi = require('swagger2openapi'); var _swagger2openapi2 = _interopRequireDefault(_swagger2openapi);
|
|
10
10
|
var _openapicore = require('@redocly/openapi-core');
|
|
11
|
-
async function parse(pathOrApi, options = {}, oasClass =
|
|
11
|
+
async function parse(pathOrApi, options = {}, oasClass = _chunkWZOC4WVKcjs.Oas) {
|
|
12
12
|
if (typeof pathOrApi === "string") {
|
|
13
13
|
const config = await _openapicore.loadConfig.call(void 0, );
|
|
14
14
|
const bundleResults = await _openapicore.bundle.call(void 0, { ref: pathOrApi, config, base: pathOrApi });
|
|
@@ -19,14 +19,14 @@ async function parse(pathOrApi, options = {}, oasClass = _chunkUIWP4KHBcjs.Oas)
|
|
|
19
19
|
colorizeErrors: true
|
|
20
20
|
});
|
|
21
21
|
const document = await oasNormalize.load();
|
|
22
|
-
if (
|
|
22
|
+
if (_chunkWZOC4WVKcjs.isOpenApiV2Document.call(void 0, document)) {
|
|
23
23
|
const { openapi } = await _swagger2openapi2.default.convertObj(document, {
|
|
24
24
|
anchors: true
|
|
25
25
|
});
|
|
26
|
-
const oas2 = await
|
|
26
|
+
const oas2 = await _chunkWZOC4WVKcjs.filterAndSort.call(void 0, openapi, options);
|
|
27
27
|
return new oasClass({ oas: oas2 });
|
|
28
28
|
}
|
|
29
|
-
const oas = await
|
|
29
|
+
const oas = await _chunkWZOC4WVKcjs.filterAndSort.call(void 0, document, options);
|
|
30
30
|
return new oasClass({ oas });
|
|
31
31
|
}
|
|
32
32
|
|
package/dist/parser.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/oas",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.8",
|
|
4
4
|
"description": "Oas helpers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"!/**/__tests__/**"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@redocly/openapi-core": "^1.21.
|
|
51
|
+
"@redocly/openapi-core": "^1.21.1",
|
|
52
52
|
"hotscript": "^1.0.13",
|
|
53
53
|
"json-schema-to-ts": "^3.1.0",
|
|
54
54
|
"oas": "^24.6.0",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"expect-type": "^0.19.0",
|
|
66
66
|
"tsup": "^8.2.4",
|
|
67
67
|
"typescript": "^5.5.4",
|
|
68
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
69
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
70
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
68
|
+
"@kubb/config-biome": "3.0.0-alpha.8",
|
|
69
|
+
"@kubb/config-ts": "3.0.0-alpha.8",
|
|
70
|
+
"@kubb/config-tsup": "3.0.0-alpha.8"
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|
|
73
73
|
"node": ">=20"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/oas/dist/chunk-UIWP4KHB.cjs","../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings":"AAAA,qxBAAI,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG;AAC3B,EAAE,MAAM,SAAS,CAAC,GAAG,CAAC;AACtB,CAAC;AACD,IAAI,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,UAAU,EAAE,GAAG,CAAC;AACzF,IAAI,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChJ,IAAI,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,mDAAmD,EAAE,EAAE,OAAO,WAAW,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,GAAG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,IAAA,CAAK,EAAE,CAAA,EAAG;AACrD,QAAA,qBAAA,EAAuB,EAAA;AAAA,MACzB;AAAA,IACF,CAAC,CAAA;AAED,IAAA,GAAA,CAAI,CAAC,oBAAA,EAAsB;AACzB,MAAA,YAAA,CAAa,OAAA,CAAQ,CAAC,EAAA,EAAA,GAAe;AACnC,QAAA,GAAA,CAAI,CAAC,oBAAA,EAAsB;AACzB,UAAA,qBAAA,EAAuB,EAAA;AAAA,QACzB;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAEA,IAAA,GAAA,CAAI,oBAAA,EAAsB;AACxB,MAAA,OAAO,CAAC,oBAAA,EAAsB,YAAA,CAAa,OAAA,CAAQ,oBAAoB,CAAA,EAAI,GAAI,YAAA,CAAa,YAAA,EAAc,CAAC,YAAA,CAAa,WAAW,EAAA,EAAI,CAAC,CAAE,CAAA;AAAA,IAC5I;AAEA,IAAA,OAAO,KAAA;AAAA,EACT,CAAA;AACF,CAAA;AFuIF;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uTAAC","file":"/home/runner/work/kubb/kubb/packages/oas/dist/chunk-UIWP4KHB.cjs","sourcesContent":[null,"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 parser: {\n validate: {\n colorizeErrors: true,\n schema: false,\n spec: false,\n },\n },\n })\n }\n}\n"]}
|