@kubb/oas 2.26.2 → 2.26.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-7D7ASOLY.js → chunk-E3CJ2UJM.js} +1 -44
- package/dist/chunk-E3CJ2UJM.js.map +1 -0
- package/dist/{chunk-UIWP4KHB.cjs → chunk-UHBNBTKP.cjs} +2 -45
- package/dist/chunk-UHBNBTKP.cjs.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -52
- package/dist/index.d.ts +0 -52
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/parser.cjs +7 -10
- package/dist/parser.cjs.map +1 -1
- package/dist/parser.d.cts +2 -43
- package/dist/parser.d.ts +2 -43
- package/dist/parser.js +6 -9
- package/dist/parser.js.map +1 -1
- package/package.json +11 -12
- package/src/index.ts +0 -2
- package/src/parser/index.ts +6 -52
- package/src/utils.ts +1 -49
- package/dist/chunk-7D7ASOLY.js.map +0 -1
- package/dist/chunk-UIWP4KHB.cjs.map +0 -1
- package/src/typings.d.ts +0 -51
|
@@ -9,7 +9,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
9
9
|
|
|
10
10
|
// src/utils.ts
|
|
11
11
|
import { isRef, isSchema } from "oas/types";
|
|
12
|
-
import openapiFormat from "openapi-format";
|
|
13
12
|
import { isPlainObject } from "remeda";
|
|
14
13
|
function isOpenApiV2Document(doc) {
|
|
15
14
|
return doc && isPlainObject(doc) && !("openapi" in doc);
|
|
@@ -32,47 +31,6 @@ function isRequired(schema) {
|
|
|
32
31
|
function isOptional(schema) {
|
|
33
32
|
return !isRequired(schema);
|
|
34
33
|
}
|
|
35
|
-
async function filterAndSort(data, options = {}) {
|
|
36
|
-
const mergedOptions = {
|
|
37
|
-
sort: options.sort ?? true,
|
|
38
|
-
["no-sort"]: options["no-sort"] ?? false,
|
|
39
|
-
sortSet: {
|
|
40
|
-
root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
|
|
41
|
-
get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
42
|
-
post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
43
|
-
put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
44
|
-
patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
45
|
-
delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
46
|
-
parameters: ["name", "in", "description", "required", "schema"],
|
|
47
|
-
requestBody: ["description", "required", "content"],
|
|
48
|
-
responses: ["description", "headers", "content", "links"],
|
|
49
|
-
content: [],
|
|
50
|
-
components: ["parameters", "schemas"],
|
|
51
|
-
schema: ["description", "type", "items", "properties", "format", "example", "default"],
|
|
52
|
-
schemas: ["description", "type", "items", "properties", "format", "example", "default"],
|
|
53
|
-
properties: ["description", "type", "items", "format", "example", "default", "enum"],
|
|
54
|
-
...options.sortSet
|
|
55
|
-
},
|
|
56
|
-
sortComponentsSet: {
|
|
57
|
-
...options.sortComponentsSet
|
|
58
|
-
},
|
|
59
|
-
filterSet: {
|
|
60
|
-
inverseMethods: ["get", "put", "post", "delete", "patch", "head", "options", "trace", "parameters"],
|
|
61
|
-
unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : [],
|
|
62
|
-
...options.filterSet
|
|
63
|
-
},
|
|
64
|
-
casingSet: {
|
|
65
|
-
...options.casingSet
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const restFilter = await openapiFormat.openapiFilter(data, mergedOptions);
|
|
69
|
-
data = restFilter.data;
|
|
70
|
-
const resFormat = await openapiFormat.openapiSort(data, mergedOptions);
|
|
71
|
-
data = resFormat.data;
|
|
72
|
-
const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions);
|
|
73
|
-
data = resChangeCase.data;
|
|
74
|
-
return data;
|
|
75
|
-
}
|
|
76
34
|
|
|
77
35
|
// src/Oas.ts
|
|
78
36
|
import BaseOas from "oas";
|
|
@@ -236,7 +194,6 @@ export {
|
|
|
236
194
|
isReference,
|
|
237
195
|
isRequired,
|
|
238
196
|
isOptional,
|
|
239
|
-
filterAndSort,
|
|
240
197
|
Oas
|
|
241
198
|
};
|
|
242
|
-
//# sourceMappingURL=chunk-
|
|
199
|
+
//# sourceMappingURL=chunk-E3CJ2UJM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { 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 && 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","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,SAAS,qBAAqB;AAKvB,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,cAAc,GAAG,KAAK,EAAE,aAAa;AACrD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,cAAoC,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AAC5G;AAMO,SAAS,kBAAkB,KAA6D;AAC7F,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,YAAY,KAA+E;AACzG,SAAO,CAAC,CAAC,OAAO,MAAM,GAAG;AAC3B;AAEO,SAAS,WAAW,QAAgC;AACzD,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,QAAQ,OAAO,QAAQ,IAAI,CAAC,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,OAAO;AAC/E;AAEO,SAAS,WAAW,QAAgC;AACzD,SAAO,CAAC,WAAW,MAAM;AAC3B;;;ACvCA,OAAO,aAAa;AACpB,OAAO,kBAAkB;AACzB,SAAS,sBAAsB,uBAAuB;AAFtD;AAcO,IAAM,MAAN,cAAwC,QAAQ;AAAA,EAIrD,YAAY,EAAE,KAAK,KAAK,GAAsD,UAAmB,CAAC,GAAG;AACnG,QAAI,OAAO,QAAQ,UAAU;AAC3B,YAAM,KAAK,MAAM,GAAG;AAAA,IACtB;AAEA,UAAM,KAAoB,IAAI;AAT3B;AACL,iCAAoB,CAAC;AACrB,oBAAiB;AASf,SAAK,WAAW;AAChB,uBAAK,UAAW;AAAA,EAClB;AAAA,EAEA,mBAAmB,QAAkB;AACnC,QAAI,YAAY,MAAM,GAAG;A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uB,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"]}
|
|
@@ -9,7 +9,6 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
|
|
|
9
9
|
|
|
10
10
|
// src/utils.ts
|
|
11
11
|
var _types = require('oas/types');
|
|
12
|
-
var _openapiformat = require('openapi-format'); var _openapiformat2 = _interopRequireDefault(_openapiformat);
|
|
13
12
|
var _remeda = require('remeda');
|
|
14
13
|
function isOpenApiV2Document(doc) {
|
|
15
14
|
return doc && _remeda.isPlainObject.call(void 0, doc) && !("openapi" in doc);
|
|
@@ -32,47 +31,6 @@ function isRequired(schema) {
|
|
|
32
31
|
function isOptional(schema) {
|
|
33
32
|
return !isRequired(schema);
|
|
34
33
|
}
|
|
35
|
-
async function filterAndSort(data, options = {}) {
|
|
36
|
-
const mergedOptions = {
|
|
37
|
-
sort: _nullishCoalesce(options.sort, () => ( true)),
|
|
38
|
-
["no-sort"]: _nullishCoalesce(options["no-sort"], () => ( false)),
|
|
39
|
-
sortSet: {
|
|
40
|
-
root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
|
|
41
|
-
get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
42
|
-
post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
43
|
-
put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
44
|
-
patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
45
|
-
delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
46
|
-
parameters: ["name", "in", "description", "required", "schema"],
|
|
47
|
-
requestBody: ["description", "required", "content"],
|
|
48
|
-
responses: ["description", "headers", "content", "links"],
|
|
49
|
-
content: [],
|
|
50
|
-
components: ["parameters", "schemas"],
|
|
51
|
-
schema: ["description", "type", "items", "properties", "format", "example", "default"],
|
|
52
|
-
schemas: ["description", "type", "items", "properties", "format", "example", "default"],
|
|
53
|
-
properties: ["description", "type", "items", "format", "example", "default", "enum"],
|
|
54
|
-
...options.sortSet
|
|
55
|
-
},
|
|
56
|
-
sortComponentsSet: {
|
|
57
|
-
...options.sortComponentsSet
|
|
58
|
-
},
|
|
59
|
-
filterSet: {
|
|
60
|
-
inverseMethods: ["get", "put", "post", "delete", "patch", "head", "options", "trace", "parameters"],
|
|
61
|
-
unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : [],
|
|
62
|
-
...options.filterSet
|
|
63
|
-
},
|
|
64
|
-
casingSet: {
|
|
65
|
-
...options.casingSet
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const restFilter = await _openapiformat2.default.openapiFilter(data, mergedOptions);
|
|
69
|
-
data = restFilter.data;
|
|
70
|
-
const resFormat = await _openapiformat2.default.openapiSort(data, mergedOptions);
|
|
71
|
-
data = resFormat.data;
|
|
72
|
-
const resChangeCase = await _openapiformat2.default.openapiChangeCase(data, mergedOptions);
|
|
73
|
-
data = resChangeCase.data;
|
|
74
|
-
return data;
|
|
75
|
-
}
|
|
76
34
|
|
|
77
35
|
// src/Oas.ts
|
|
78
36
|
var _oas = require('oas'); var _oas2 = _interopRequireDefault(_oas);
|
|
@@ -237,6 +195,5 @@ getResponseBodyFactory_fn = function(responseBody) {
|
|
|
237
195
|
|
|
238
196
|
|
|
239
197
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
//# sourceMappingURL=chunk-UIWP4KHB.cjs.map
|
|
198
|
+
exports.isOpenApiV2Document = isOpenApiV2Document; exports.isOpenApiV3_1Document = isOpenApiV3_1Document; exports.isParameterObject = isParameterObject; exports.isReference = isReference; exports.isRequired = isRequired; exports.isOptional = isOptional; exports.Oas = Oas;
|
|
199
|
+
//# sourceMappingURL=chunk-UHBNBTKP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/oas/dist/chunk-UHBNBTKP.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,M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,WAAW,CAAA;AAAA,IACzC;AAIA,IAAA,IAAI,qBAAA,EAA2C,KAAA,CAAA;AAC/C,IAAA,MAAM,aAAA,EAAe,MAAA,CAAO,IAAA,CAAK,YAAA,CAAa,OAAO,CAAA;AACrD,IAAA,YAAA,CAAa,OAAA,CAAQ,CAAC,EAAA,EAAA,GAAe;AACnC,MAAA,GAAA,CAAI,CAAC,qBAAA,GAAwB,sBAAA,CAAgB,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;AF6FF;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,gRAAC","file":"/home/runner/work/kubb/kubb/packages/oas/dist/chunk-UHBNBTKP.cjs","sourcesContent":[null,"import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { 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 && 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","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 _chunkUHBNBTKPcjs = require('./chunk-UHBNBTKP.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 = _chunkUHBNBTKPcjs.Oas; exports.findSchemaDefinition = _utils.findSchemaDefinition; exports.isOpenApiV3_1Document = _chunkUHBNBTKPcjs.isOpenApiV3_1Document; exports.isOptional = _chunkUHBNBTKPcjs.isOptional; exports.isParameterObject = _chunkUHBNBTKPcjs.isParameterObject; exports.isReference = _chunkUHBNBTKPcjs.isReference; exports.isRequired = _chunkUHBNBTKPcjs.isRequired; exports.matchesMimeType = _utils.matchesMimeType;
|
|
35
35
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/oas/dist/index.cjs","../src/types.ts","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACMO,IAAM,YAAA,EAAc;AAAA,EACzB,GAAA,EAAK,KAAA;AAAA,EACL,IAAA,EAAM,MAAA;AAAA,EACN,GAAA,EAAK,KAAA;AAAA,EACL,KAAA,EAAO,OAAA;AAAA,EACP,MAAA,EAAQ,QAAA;AAAA,EACR,IAAA,EAAM,MAAA;AAAA,EACN,OAAA,EAAS,SAAA;AAAA,EACT,KAAA,EAAO;AACT,CAAA;ADJA;AACA;
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/oas/dist/index.cjs","../src/types.ts","../src/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACMO,IAAM,YAAA,EAAc;AAAA,EACzB,GAAA,EAAK,KAAA;AAAA,EACL,IAAA,EAAM,MAAA;AAAA,EACN,GAAA,EAAK,KAAA;AAAA,EACL,KAAA,EAAO,OAAA;AAAA,EACP,MAAA,EAAQ,QAAA;AAAA,EACR,IAAA,EAAM,MAAA;AAAA,EACN,OAAA,EAAS,SAAA;AAAA,EACT,KAAA,EAAO;AACT,CAAA;ADJA;AACA;AEpBA,kCAAsD;AFsBtD;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,0dAAC","file":"/home/runner/work/kubb/kubb/packages/oas/dist/index.cjs","sourcesContent":[null,"import type * as OasTypes from 'oas/types'\n\n// external packages\nexport type { Operation } from 'oas/operation'\nexport type { HttpMethods as HttpMethod } from 'oas/types'\nexport type * as OasTypes from 'oas/types'\nexport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport type contentType = 'application/json' | (string & {})\n\nexport type SchemaObject = OasTypes.SchemaObject & {\n 'x-nullable'?: boolean\n $ref?: string\n}\n\nexport const HttpMethods = {\n GET: 'get',\n POST: 'post',\n PUT: 'put',\n PATCH: 'patch',\n DELETE: 'delete',\n HEAD: 'head',\n OPTIONS: 'options',\n TRACE: 'trace',\n} satisfies Record<Uppercase<OasTypes.HttpMethods>, OasTypes.HttpMethods>\n","export * from './types.ts'\nexport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\nexport { isRequired, isOptional, isReference, isParameterObject, isOpenApiV3_1Document } from './utils.ts'\nexport { Oas } from './Oas.ts'\nexport type { Infer, Model, RequestParams, Response } from './infer/index.ts'\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -12,58 +12,6 @@ import { JSONSchema, FromSchema } from 'json-schema-to-ts';
|
|
|
12
12
|
export { Operation } from 'oas/operation';
|
|
13
13
|
import 'oas';
|
|
14
14
|
|
|
15
|
-
declare module 'openapi-format' {
|
|
16
|
-
interface Options {
|
|
17
|
-
verbose?: boolean
|
|
18
|
-
'no-sort'?: boolean
|
|
19
|
-
sort?: boolean
|
|
20
|
-
output?: string
|
|
21
|
-
sortSet?: {
|
|
22
|
-
root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>
|
|
23
|
-
get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
24
|
-
post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
25
|
-
put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
26
|
-
patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
27
|
-
delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
28
|
-
parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>
|
|
29
|
-
requestBody?: Array<'description' | 'required' | 'content'>
|
|
30
|
-
responses?: Array<'description' | 'headers' | 'content' | 'links'>
|
|
31
|
-
content?: Array<string>
|
|
32
|
-
components?: Array<'parameters' | 'schemas'>
|
|
33
|
-
schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
|
|
34
|
-
schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
|
|
35
|
-
properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
|
|
36
|
-
}
|
|
37
|
-
filterSet?: {
|
|
38
|
-
methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
|
|
39
|
-
inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
|
|
40
|
-
tags?: Array<string>
|
|
41
|
-
inverseTags?: Array<string>
|
|
42
|
-
operationIds?: Array<string>
|
|
43
|
-
inverseOperationIds?: Array<string>
|
|
44
|
-
operations?: Array<string>
|
|
45
|
-
flags?: Array<string>
|
|
46
|
-
inverseFlags?: Array<string>
|
|
47
|
-
flagValues?: Array<string>
|
|
48
|
-
inverseFlagValues?: Array<string>
|
|
49
|
-
stripFlags?: Array<string>
|
|
50
|
-
responseContent?: Array<string>
|
|
51
|
-
inverseResponseContent?: Array<string>
|
|
52
|
-
unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>
|
|
53
|
-
}
|
|
54
|
-
sortComponentsSet?: {}
|
|
55
|
-
casingSet?: {}
|
|
56
|
-
}
|
|
57
|
-
function parseFile(path: string): Promise<unknown>
|
|
58
|
-
|
|
59
|
-
function openapiFilter<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
60
|
-
|
|
61
|
-
function openapiSort<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
62
|
-
function openapiChangeCase<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
63
|
-
|
|
64
|
-
function stringify<TOas>(document: TOas, options: Options): string
|
|
65
|
-
}
|
|
66
|
-
|
|
67
15
|
declare function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document;
|
|
68
16
|
declare function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject;
|
|
69
17
|
declare function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject;
|
package/dist/index.d.ts
CHANGED
|
@@ -12,58 +12,6 @@ import { JSONSchema, FromSchema } from 'json-schema-to-ts';
|
|
|
12
12
|
export { Operation } from 'oas/operation';
|
|
13
13
|
import 'oas';
|
|
14
14
|
|
|
15
|
-
declare module 'openapi-format' {
|
|
16
|
-
interface Options {
|
|
17
|
-
verbose?: boolean
|
|
18
|
-
'no-sort'?: boolean
|
|
19
|
-
sort?: boolean
|
|
20
|
-
output?: string
|
|
21
|
-
sortSet?: {
|
|
22
|
-
root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>
|
|
23
|
-
get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
24
|
-
post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
25
|
-
put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
26
|
-
patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
27
|
-
delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
28
|
-
parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>
|
|
29
|
-
requestBody?: Array<'description' | 'required' | 'content'>
|
|
30
|
-
responses?: Array<'description' | 'headers' | 'content' | 'links'>
|
|
31
|
-
content?: Array<string>
|
|
32
|
-
components?: Array<'parameters' | 'schemas'>
|
|
33
|
-
schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
|
|
34
|
-
schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
|
|
35
|
-
properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
|
|
36
|
-
}
|
|
37
|
-
filterSet?: {
|
|
38
|
-
methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
|
|
39
|
-
inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
|
|
40
|
-
tags?: Array<string>
|
|
41
|
-
inverseTags?: Array<string>
|
|
42
|
-
operationIds?: Array<string>
|
|
43
|
-
inverseOperationIds?: Array<string>
|
|
44
|
-
operations?: Array<string>
|
|
45
|
-
flags?: Array<string>
|
|
46
|
-
inverseFlags?: Array<string>
|
|
47
|
-
flagValues?: Array<string>
|
|
48
|
-
inverseFlagValues?: Array<string>
|
|
49
|
-
stripFlags?: Array<string>
|
|
50
|
-
responseContent?: Array<string>
|
|
51
|
-
inverseResponseContent?: Array<string>
|
|
52
|
-
unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>
|
|
53
|
-
}
|
|
54
|
-
sortComponentsSet?: {}
|
|
55
|
-
casingSet?: {}
|
|
56
|
-
}
|
|
57
|
-
function parseFile(path: string): Promise<unknown>
|
|
58
|
-
|
|
59
|
-
function openapiFilter<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
60
|
-
|
|
61
|
-
function openapiSort<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
62
|
-
function openapiChangeCase<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
63
|
-
|
|
64
|
-
function stringify<TOas>(document: TOas, options: Options): string
|
|
65
|
-
}
|
|
66
|
-
|
|
67
15
|
declare function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document;
|
|
68
16
|
declare function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject;
|
|
69
17
|
declare function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject;
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["import type * as OasTypes from 'oas/types'\n\n// external packages\nexport type { Operation } from 'oas/operation'\nexport type { HttpMethods as HttpMethod } from 'oas/types'\nexport type * as OasTypes from 'oas/types'\nexport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport type contentType = 'application/json' | (string & {})\n\nexport type SchemaObject = OasTypes.SchemaObject & {\n 'x-nullable'?: boolean\n $ref?: string\n}\n\nexport const HttpMethods = {\n GET: 'get',\n POST: 'post',\n PUT: 'put',\n PATCH: 'patch',\n DELETE: 'delete',\n HEAD: 'head',\n OPTIONS: 'options',\n TRACE: 'trace',\n} satisfies Record<Uppercase<OasTypes.HttpMethods>, OasTypes.HttpMethods>\n","
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["import type * as OasTypes from 'oas/types'\n\n// external packages\nexport type { Operation } from 'oas/operation'\nexport type { HttpMethods as HttpMethod } from 'oas/types'\nexport type * as OasTypes from 'oas/types'\nexport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport type contentType = 'application/json' | (string & {})\n\nexport type SchemaObject = OasTypes.SchemaObject & {\n 'x-nullable'?: boolean\n $ref?: string\n}\n\nexport const HttpMethods = {\n GET: 'get',\n POST: 'post',\n PUT: 'put',\n PATCH: 'patch',\n DELETE: 'delete',\n HEAD: 'head',\n OPTIONS: 'options',\n TRACE: 'trace',\n} satisfies Record<Uppercase<OasTypes.HttpMethods>, OasTypes.HttpMethods>\n","export * from './types.ts'\nexport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\nexport { isRequired, isOptional, isReference, isParameterObject, isOpenApiV3_1Document } from './utils.ts'\nexport { Oas } from './Oas.ts'\nexport type { Infer, Model, RequestParams, Response } from './infer/index.ts'\n"],"mappings":";;;;;;;;;;AAeO,IAAM,cAAc;AAAA,EACzB,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT;;;ACvBA,SAAS,sBAAsB,uBAAuB;","names":[]}
|
package/dist/parser.cjs
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
var _chunkUIWP4KHBcjs = require('./chunk-UIWP4KHB.cjs');
|
|
4
|
+
var _chunkUHBNBTKPcjs = require('./chunk-UHBNBTKP.cjs');
|
|
6
5
|
|
|
7
6
|
// src/parser/index.ts
|
|
7
|
+
var _openapicore = require('@redocly/openapi-core');
|
|
8
8
|
var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
|
|
9
9
|
var _swagger2openapi = require('swagger2openapi'); var _swagger2openapi2 = _interopRequireDefault(_swagger2openapi);
|
|
10
|
-
|
|
11
|
-
async function parse(pathOrApi, options = {}, oasClass = _chunkUIWP4KHBcjs.Oas) {
|
|
10
|
+
async function parse(pathOrApi, oasClass = _chunkUHBNBTKPcjs.Oas) {
|
|
12
11
|
if (typeof pathOrApi === "string") {
|
|
13
12
|
const config = await _openapicore.loadConfig.call(void 0, );
|
|
14
13
|
const bundleResults = await _openapicore.bundle.call(void 0, { ref: pathOrApi, config, base: pathOrApi });
|
|
15
|
-
return parse(bundleResults.bundle.parsed
|
|
14
|
+
return parse(bundleResults.bundle.parsed);
|
|
16
15
|
}
|
|
17
16
|
const oasNormalize = new (0, _oasnormalize2.default)(pathOrApi, {
|
|
18
17
|
enablePaths: true,
|
|
19
18
|
colorizeErrors: true
|
|
20
19
|
});
|
|
21
20
|
const document = await oasNormalize.load();
|
|
22
|
-
if (
|
|
21
|
+
if (_chunkUHBNBTKPcjs.isOpenApiV2Document.call(void 0, document)) {
|
|
23
22
|
const { openapi } = await _swagger2openapi2.default.convertObj(document, {
|
|
24
23
|
anchors: true
|
|
25
24
|
});
|
|
26
|
-
|
|
27
|
-
return new oasClass({ oas: oas2 });
|
|
25
|
+
return new oasClass({ oas: openapi });
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
return new oasClass({ oas });
|
|
27
|
+
return new oasClass({ oas: document });
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
|
package/dist/parser.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/oas/dist/parser.cjs","../src/parser/index.ts"],"names":[
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/oas/dist/parser.cjs","../src/parser/index.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,oDAAmC;AACnC,yGAAyB;AACzB,oHAA4B;AAQ5B,MAAA,SAAsB,KAAA,CAAM,SAAA,EAAiC,SAAA,EAAuB,qBAAA,EAAmB;AACrG,EAAA,GAAA,CAAI,OAAO,UAAA,IAAc,QAAA,EAAU;AAEjC,IAAA,MAAM,OAAA,EAAS,MAAM,qCAAA,CAAW;AAChC,IAAA,MAAM,cAAA,EAAgB,MAAM,iCAAA,EAAS,GAAA,EAAK,SAAA,EAAW,MAAA,EAAQ,IAAA,EAAM,UAAU,CAAC,CAAA;AAE9E,IAAA,OAAO,KAAA,CAAM,aAAA,CAAc,MAAA,CAAO,MAAM,CAAA;AAAA,EAC1C;AAEA,EAAA,MAAM,aAAA,EAAe,IAAI,2BAAA,CAAa,SAAA,EAAW;AAAA,IAC/C,WAAA,EAAa,IAAA;AAAA,IACb,cAAA,EAAgB;AAAA,EAClB,CAAC,CAAA;AACD,EAAA,MAAM,SAAA,EAAY,MAAM,YAAA,CAAa,IAAA,CAAK,CAAA;AAE1C,EAAA,GAAA,CAAI,mDAAA,QAA4B,CAAA,EAAG;AACjC,IAAA,MAAM,EAAE,QAAQ,EAAA,EAAI,MAAM,yBAAA,CAAgB,UAAA,CAAW,QAAA,EAAU;AAAA,MAC7D,OAAA,EAAS;AAAA,IACX,CAAC,CAAA;AAED,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,QAAuB,CAAC,CAAA;AAAA,EACrD;AAEA,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,SAAwB,CAAC,CAAA;AACtD;ADNA;AACE;AACF,sBAAC","file":"/home/runner/work/kubb/kubb/packages/oas/dist/parser.cjs","sourcesContent":[null,"import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n return new oasClass({ oas: openapi as OASDocument })\n }\n\n return new oasClass({ oas: document as OASDocument })\n}\n"]}
|
package/dist/parser.d.cts
CHANGED
|
@@ -3,47 +3,6 @@ import { OASDocument } from 'oas/types';
|
|
|
3
3
|
import 'oas';
|
|
4
4
|
import 'oas/operation';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
verbose?: boolean;
|
|
8
|
-
'no-sort'?: boolean;
|
|
9
|
-
sort?: boolean;
|
|
10
|
-
output?: string;
|
|
11
|
-
sortSet?: {
|
|
12
|
-
root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>;
|
|
13
|
-
get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
14
|
-
post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
15
|
-
put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
16
|
-
patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
17
|
-
delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
18
|
-
parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>;
|
|
19
|
-
requestBody?: Array<'description' | 'required' | 'content'>;
|
|
20
|
-
responses?: Array<'description' | 'headers' | 'content' | 'links'>;
|
|
21
|
-
content?: Array<string>;
|
|
22
|
-
components?: Array<'parameters' | 'schemas'>;
|
|
23
|
-
schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
|
|
24
|
-
schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
|
|
25
|
-
properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>;
|
|
26
|
-
};
|
|
27
|
-
filterSet?: {
|
|
28
|
-
methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
|
|
29
|
-
inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
|
|
30
|
-
tags?: Array<string>;
|
|
31
|
-
inverseTags?: Array<string>;
|
|
32
|
-
operationIds?: Array<string>;
|
|
33
|
-
inverseOperationIds?: Array<string>;
|
|
34
|
-
operations?: Array<string>;
|
|
35
|
-
flags?: Array<string>;
|
|
36
|
-
inverseFlags?: Array<string>;
|
|
37
|
-
flagValues?: Array<string>;
|
|
38
|
-
inverseFlagValues?: Array<string>;
|
|
39
|
-
stripFlags?: Array<string>;
|
|
40
|
-
responseContent?: Array<string>;
|
|
41
|
-
inverseResponseContent?: Array<string>;
|
|
42
|
-
unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>;
|
|
43
|
-
};
|
|
44
|
-
sortComponentsSet?: {};
|
|
45
|
-
casingSet?: {};
|
|
46
|
-
};
|
|
47
|
-
declare function parse(pathOrApi: string | OASDocument, options?: FormatOptions, oasClass?: typeof Oas): Promise<Oas>;
|
|
6
|
+
declare function parse(pathOrApi: string | OASDocument, oasClass?: typeof Oas): Promise<Oas>;
|
|
48
7
|
|
|
49
|
-
export {
|
|
8
|
+
export { parse };
|
package/dist/parser.d.ts
CHANGED
|
@@ -3,47 +3,6 @@ import { OASDocument } from 'oas/types';
|
|
|
3
3
|
import 'oas';
|
|
4
4
|
import 'oas/operation';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
verbose?: boolean;
|
|
8
|
-
'no-sort'?: boolean;
|
|
9
|
-
sort?: boolean;
|
|
10
|
-
output?: string;
|
|
11
|
-
sortSet?: {
|
|
12
|
-
root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>;
|
|
13
|
-
get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
14
|
-
post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
15
|
-
put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
16
|
-
patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
17
|
-
delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
|
|
18
|
-
parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>;
|
|
19
|
-
requestBody?: Array<'description' | 'required' | 'content'>;
|
|
20
|
-
responses?: Array<'description' | 'headers' | 'content' | 'links'>;
|
|
21
|
-
content?: Array<string>;
|
|
22
|
-
components?: Array<'parameters' | 'schemas'>;
|
|
23
|
-
schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
|
|
24
|
-
schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
|
|
25
|
-
properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>;
|
|
26
|
-
};
|
|
27
|
-
filterSet?: {
|
|
28
|
-
methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
|
|
29
|
-
inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
|
|
30
|
-
tags?: Array<string>;
|
|
31
|
-
inverseTags?: Array<string>;
|
|
32
|
-
operationIds?: Array<string>;
|
|
33
|
-
inverseOperationIds?: Array<string>;
|
|
34
|
-
operations?: Array<string>;
|
|
35
|
-
flags?: Array<string>;
|
|
36
|
-
inverseFlags?: Array<string>;
|
|
37
|
-
flagValues?: Array<string>;
|
|
38
|
-
inverseFlagValues?: Array<string>;
|
|
39
|
-
stripFlags?: Array<string>;
|
|
40
|
-
responseContent?: Array<string>;
|
|
41
|
-
inverseResponseContent?: Array<string>;
|
|
42
|
-
unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>;
|
|
43
|
-
};
|
|
44
|
-
sortComponentsSet?: {};
|
|
45
|
-
casingSet?: {};
|
|
46
|
-
};
|
|
47
|
-
declare function parse(pathOrApi: string | OASDocument, options?: FormatOptions, oasClass?: typeof Oas): Promise<Oas>;
|
|
6
|
+
declare function parse(pathOrApi: string | OASDocument, oasClass?: typeof Oas): Promise<Oas>;
|
|
48
7
|
|
|
49
|
-
export {
|
|
8
|
+
export { parse };
|
package/dist/parser.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Oas,
|
|
3
|
-
filterAndSort,
|
|
4
3
|
isOpenApiV2Document
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-E3CJ2UJM.js";
|
|
6
5
|
|
|
7
6
|
// src/parser/index.ts
|
|
7
|
+
import { bundle, loadConfig } from "@redocly/openapi-core";
|
|
8
8
|
import OASNormalize from "oas-normalize";
|
|
9
9
|
import swagger2openapi from "swagger2openapi";
|
|
10
|
-
|
|
11
|
-
async function parse(pathOrApi, options = {}, oasClass = Oas) {
|
|
10
|
+
async function parse(pathOrApi, oasClass = Oas) {
|
|
12
11
|
if (typeof pathOrApi === "string") {
|
|
13
12
|
const config = await loadConfig();
|
|
14
13
|
const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi });
|
|
15
|
-
return parse(bundleResults.bundle.parsed
|
|
14
|
+
return parse(bundleResults.bundle.parsed);
|
|
16
15
|
}
|
|
17
16
|
const oasNormalize = new OASNormalize(pathOrApi, {
|
|
18
17
|
enablePaths: true,
|
|
@@ -23,11 +22,9 @@ async function parse(pathOrApi, options = {}, oasClass = Oas) {
|
|
|
23
22
|
const { openapi } = await swagger2openapi.convertObj(document, {
|
|
24
23
|
anchors: true
|
|
25
24
|
});
|
|
26
|
-
|
|
27
|
-
return new oasClass({ oas: oas2 });
|
|
25
|
+
return new oasClass({ oas: openapi });
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
return new oasClass({ oas });
|
|
27
|
+
return new oasClass({ oas: document });
|
|
31
28
|
}
|
|
32
29
|
export {
|
|
33
30
|
parse
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parser/index.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/parser/index.ts"],"sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n return new oasClass({ oas: openapi as OASDocument })\n }\n\n return new oasClass({ oas: document as OASDocument })\n}\n"],"mappings":";;;;;;AAAA,SAAS,QAAQ,kBAAkB;AACnC,OAAO,kBAAkB;AACzB,OAAO,qBAAqB;AAQ5B,eAAsB,MAAM,WAAiC,WAAuB,KAAmB;AACrG,MAAI,OAAO,cAAc,UAAU;AAEjC,UAAM,SAAS,MAAM,WAAW;AAChC,UAAM,gBAAgB,MAAM,OAAO,EAAE,KAAK,WAAW,QAAQ,MAAM,UAAU,CAAC;AAE9E,WAAO,MAAM,cAAc,OAAO,MAAM;AAAA,EAC1C;AAEA,QAAM,eAAe,IAAI,aAAa,WAAW;AAAA,IAC/C,aAAa;AAAA,IACb,gBAAgB;AAAA,EAClB,CAAC;AACD,QAAM,WAAY,MAAM,aAAa,KAAK;AAE1C,MAAI,oBAAoB,QAAQ,GAAG;AACjC,UAAM,EAAE,QAAQ,IAAI,MAAM,gBAAgB,WAAW,UAAU;AAAA,MAC7D,SAAS;AAAA,IACX,CAAC;AAED,WAAO,IAAI,SAAS,EAAE,KAAK,QAAuB,CAAC;AAAA,EACrD;AAEA,SAAO,IAAI,SAAS,EAAE,KAAK,SAAwB,CAAC;AACtD;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/oas",
|
|
3
|
-
"version": "2.26.
|
|
3
|
+
"version": "2.26.4",
|
|
4
4
|
"description": "Oas helpers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -48,14 +48,13 @@
|
|
|
48
48
|
"!/**/__tests__/**"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@redocly/openapi-core": "^1.
|
|
51
|
+
"@redocly/openapi-core": "^1.25.3",
|
|
52
52
|
"hotscript": "^1.0.13",
|
|
53
|
-
"json-schema-to-ts": "^3.1.
|
|
54
|
-
"oas": "^24.
|
|
55
|
-
"oas-normalize": "^11.1.
|
|
56
|
-
"openapi-format": "^1.22.3",
|
|
53
|
+
"json-schema-to-ts": "^3.1.1",
|
|
54
|
+
"oas": "^24.9.0",
|
|
55
|
+
"oas-normalize": "^11.1.2",
|
|
57
56
|
"openapi-types": "^12.1.3",
|
|
58
|
-
"remeda": "^2.
|
|
57
|
+
"remeda": "^2.14.0",
|
|
59
58
|
"swagger2openapi": "^7.0.8",
|
|
60
59
|
"ts-toolbelt": "^9.6.0"
|
|
61
60
|
},
|
|
@@ -63,11 +62,11 @@
|
|
|
63
62
|
"@stoplight/yaml": "^4.3.0",
|
|
64
63
|
"@types/swagger2openapi": "^7.0.4",
|
|
65
64
|
"expect-type": "^0.19.0",
|
|
66
|
-
"tsup": "^8.
|
|
67
|
-
"typescript": "^5.
|
|
68
|
-
"@kubb/config-biome": "2.26.
|
|
69
|
-
"@kubb/config-ts": "2.26.
|
|
70
|
-
"@kubb/config-tsup": "2.26.
|
|
65
|
+
"tsup": "^8.3.0",
|
|
66
|
+
"typescript": "^5.6.2",
|
|
67
|
+
"@kubb/config-biome": "2.26.4",
|
|
68
|
+
"@kubb/config-ts": "2.26.4",
|
|
69
|
+
"@kubb/config-tsup": "2.26.4"
|
|
71
70
|
},
|
|
72
71
|
"engines": {
|
|
73
72
|
"node": ">=18"
|
package/src/index.ts
CHANGED
package/src/parser/index.ts
CHANGED
|
@@ -1,62 +1,20 @@
|
|
|
1
|
+
import { bundle, loadConfig } from '@redocly/openapi-core'
|
|
1
2
|
import OASNormalize from 'oas-normalize'
|
|
2
3
|
import swagger2openapi from 'swagger2openapi'
|
|
3
|
-
import { bundle, loadConfig } from '@redocly/openapi-core'
|
|
4
4
|
|
|
5
5
|
import { Oas } from '../Oas.ts'
|
|
6
|
-
import {
|
|
6
|
+
import { isOpenApiV2Document } from '../utils.ts'
|
|
7
7
|
|
|
8
8
|
import type { OASDocument } from 'oas/types'
|
|
9
9
|
import type { OpenAPI } from 'openapi-types'
|
|
10
10
|
|
|
11
|
-
export
|
|
12
|
-
verbose?: boolean
|
|
13
|
-
'no-sort'?: boolean
|
|
14
|
-
sort?: boolean
|
|
15
|
-
output?: string
|
|
16
|
-
sortSet?: {
|
|
17
|
-
root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>
|
|
18
|
-
get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
19
|
-
post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
20
|
-
put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
21
|
-
patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
22
|
-
delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
23
|
-
parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>
|
|
24
|
-
requestBody?: Array<'description' | 'required' | 'content'>
|
|
25
|
-
responses?: Array<'description' | 'headers' | 'content' | 'links'>
|
|
26
|
-
content?: Array<string>
|
|
27
|
-
components?: Array<'parameters' | 'schemas'>
|
|
28
|
-
schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
|
|
29
|
-
schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
|
|
30
|
-
properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
|
|
31
|
-
}
|
|
32
|
-
filterSet?: {
|
|
33
|
-
methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
|
|
34
|
-
inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
|
|
35
|
-
tags?: Array<string>
|
|
36
|
-
inverseTags?: Array<string>
|
|
37
|
-
operationIds?: Array<string>
|
|
38
|
-
inverseOperationIds?: Array<string>
|
|
39
|
-
operations?: Array<string>
|
|
40
|
-
flags?: Array<string>
|
|
41
|
-
inverseFlags?: Array<string>
|
|
42
|
-
flagValues?: Array<string>
|
|
43
|
-
inverseFlagValues?: Array<string>
|
|
44
|
-
stripFlags?: Array<string>
|
|
45
|
-
responseContent?: Array<string>
|
|
46
|
-
inverseResponseContent?: Array<string>
|
|
47
|
-
unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>
|
|
48
|
-
}
|
|
49
|
-
sortComponentsSet?: {}
|
|
50
|
-
casingSet?: {}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}, oasClass: typeof Oas = Oas): Promise<Oas> {
|
|
11
|
+
export async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {
|
|
54
12
|
if (typeof pathOrApi === 'string') {
|
|
55
13
|
// resolve external refs
|
|
56
14
|
const config = await loadConfig()
|
|
57
15
|
const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })
|
|
58
16
|
|
|
59
|
-
return parse(bundleResults.bundle.parsed
|
|
17
|
+
return parse(bundleResults.bundle.parsed)
|
|
60
18
|
}
|
|
61
19
|
|
|
62
20
|
const oasNormalize = new OASNormalize(pathOrApi, {
|
|
@@ -70,12 +28,8 @@ export async function parse(pathOrApi: string | OASDocument, options: FormatOpti
|
|
|
70
28
|
anchors: true,
|
|
71
29
|
})
|
|
72
30
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return new oasClass({ oas: oas as OASDocument })
|
|
31
|
+
return new oasClass({ oas: openapi as OASDocument })
|
|
76
32
|
}
|
|
77
33
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return new oasClass({ oas })
|
|
34
|
+
return new oasClass({ oas: document as OASDocument })
|
|
81
35
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { isRef, isSchema } from 'oas/types'
|
|
2
|
-
import openapiFormat from 'openapi-format'
|
|
3
2
|
import { isPlainObject } from 'remeda'
|
|
4
3
|
|
|
5
|
-
import type {
|
|
4
|
+
import type { ParameterObject, SchemaObject } from 'oas/types'
|
|
6
5
|
import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
|
|
7
|
-
import type { FormatOptions } from './parser/index.ts'
|
|
8
6
|
|
|
9
7
|
export function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {
|
|
10
8
|
return doc && isPlainObject(doc) && !('openapi' in doc)
|
|
@@ -40,49 +38,3 @@ export function isRequired(schema?: SchemaObject): boolean {
|
|
|
40
38
|
export function isOptional(schema?: SchemaObject): boolean {
|
|
41
39
|
return !isRequired(schema)
|
|
42
40
|
}
|
|
43
|
-
|
|
44
|
-
export async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {
|
|
45
|
-
const mergedOptions: FormatOptions = {
|
|
46
|
-
sort: options.sort ?? true,
|
|
47
|
-
['no-sort']: options['no-sort'] ?? false,
|
|
48
|
-
sortSet: {
|
|
49
|
-
root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],
|
|
50
|
-
get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
|
|
51
|
-
post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
|
|
52
|
-
put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
|
|
53
|
-
patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
|
|
54
|
-
delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
|
|
55
|
-
parameters: ['name', 'in', 'description', 'required', 'schema'],
|
|
56
|
-
requestBody: ['description', 'required', 'content'],
|
|
57
|
-
responses: ['description', 'headers', 'content', 'links'],
|
|
58
|
-
content: [],
|
|
59
|
-
components: ['parameters', 'schemas'],
|
|
60
|
-
schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],
|
|
61
|
-
schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],
|
|
62
|
-
properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],
|
|
63
|
-
...options.sortSet,
|
|
64
|
-
},
|
|
65
|
-
sortComponentsSet: {
|
|
66
|
-
...options.sortComponentsSet,
|
|
67
|
-
},
|
|
68
|
-
filterSet: {
|
|
69
|
-
inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace', 'parameters'],
|
|
70
|
-
unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],
|
|
71
|
-
...options.filterSet,
|
|
72
|
-
},
|
|
73
|
-
casingSet: {
|
|
74
|
-
...options.casingSet,
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)
|
|
79
|
-
data = restFilter.data
|
|
80
|
-
|
|
81
|
-
const resFormat = await openapiFormat.openapiSort(data, mergedOptions)
|
|
82
|
-
data = resFormat.data
|
|
83
|
-
|
|
84
|
-
const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions)
|
|
85
|
-
data = resChangeCase.data
|
|
86
|
-
|
|
87
|
-
return data
|
|
88
|
-
}
|
|
@@ -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 { 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;AACX,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,QAAQ,OAAO,QAAQ,IAAI,CAAC,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,OAAO;AAC/E;AAEO,SAAS,WAAW,QAAgC;AACzD,SAAO,CAAC,WAAW,MAAM;AAC3B;AAEA,eAAsB,cAAc,MAAmB,UAAyB,CAAC,GAAyB;AACxG,QAAM,gBAA+B;AAAA,IACnC,MAAM,QAAQ,QAAQ;AAAA,IACtB,CAAC,SAAS,GAAG,QAAQ,SAAS,KAAK;AAAA,IACnC,SAAS;AAAA,MACP,MAAM,CAAC,WAAW,QAAQ,WAAW,SAAS,cAAc,QAAQ,eAAe,cAAc;AAAA,MACjG,KAAK,CAAC,eAAe,WAAW,eAAe,cAAc,eAAe,WAAW;AAAA,MACvF,MAAM,CAAC,eAAe,WAAW,eA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A,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"]}
|
package/src/typings.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
declare module 'openapi-format' {
|
|
2
|
-
interface Options {
|
|
3
|
-
verbose?: boolean
|
|
4
|
-
'no-sort'?: boolean
|
|
5
|
-
sort?: boolean
|
|
6
|
-
output?: string
|
|
7
|
-
sortSet?: {
|
|
8
|
-
root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>
|
|
9
|
-
get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
10
|
-
post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
11
|
-
put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
12
|
-
patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
13
|
-
delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
|
|
14
|
-
parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>
|
|
15
|
-
requestBody?: Array<'description' | 'required' | 'content'>
|
|
16
|
-
responses?: Array<'description' | 'headers' | 'content' | 'links'>
|
|
17
|
-
content?: Array<string>
|
|
18
|
-
components?: Array<'parameters' | 'schemas'>
|
|
19
|
-
schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
|
|
20
|
-
schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
|
|
21
|
-
properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
|
|
22
|
-
}
|
|
23
|
-
filterSet?: {
|
|
24
|
-
methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
|
|
25
|
-
inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
|
|
26
|
-
tags?: Array<string>
|
|
27
|
-
inverseTags?: Array<string>
|
|
28
|
-
operationIds?: Array<string>
|
|
29
|
-
inverseOperationIds?: Array<string>
|
|
30
|
-
operations?: Array<string>
|
|
31
|
-
flags?: Array<string>
|
|
32
|
-
inverseFlags?: Array<string>
|
|
33
|
-
flagValues?: Array<string>
|
|
34
|
-
inverseFlagValues?: Array<string>
|
|
35
|
-
stripFlags?: Array<string>
|
|
36
|
-
responseContent?: Array<string>
|
|
37
|
-
inverseResponseContent?: Array<string>
|
|
38
|
-
unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>
|
|
39
|
-
}
|
|
40
|
-
sortComponentsSet?: {}
|
|
41
|
-
casingSet?: {}
|
|
42
|
-
}
|
|
43
|
-
function parseFile(path: string): Promise<unknown>
|
|
44
|
-
|
|
45
|
-
function openapiFilter<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
46
|
-
|
|
47
|
-
function openapiSort<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
48
|
-
function openapiChangeCase<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
|
|
49
|
-
|
|
50
|
-
function stringify<TOas>(document: TOas, options: Options): string
|
|
51
|
-
}
|