@kubb/oas 3.0.0-alpha.2 → 3.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/chunk-2ZT6EJGT.cjs +234 -0
- package/dist/chunk-2ZT6EJGT.cjs.map +1 -0
- package/dist/{chunk-7D7ASOLY.js → chunk-TVOJ46T6.js} +61 -84
- package/dist/chunk-TVOJ46T6.js.map +1 -0
- package/dist/index.cjs +37 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -379
- package/dist/index.d.ts +6 -379
- package/dist/index.js +4 -21
- package/dist/index.js.map +1 -1
- package/dist/infer.cjs +4 -0
- package/dist/infer.cjs.map +1 -0
- package/dist/infer.d.cts +380 -0
- package/dist/infer.d.ts +380 -0
- package/dist/infer.js +3 -0
- package/dist/infer.js.map +1 -0
- package/dist/parser.cjs +17 -15
- package/dist/parser.cjs.map +1 -1
- package/dist/parser.js +7 -12
- package/dist/parser.js.map +1 -1
- package/package.json +19 -12
- package/src/Oas.ts +1 -2
- package/src/parser/index.ts +1 -1
- package/dist/chunk-7D7ASOLY.js.map +0 -1
- package/dist/chunk-UIWP4KHB.cjs +0 -242
- package/dist/chunk-UIWP4KHB.cjs.map +0 -1
|
@@ -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,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,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"]}
|
package/dist/chunk-UIWP4KHB.cjs
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __typeError = (msg) => {
|
|
2
|
-
throw TypeError(msg);
|
|
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
|
|
11
|
-
var _types = require('oas/types');
|
|
12
|
-
var _openapiformat = require('openapi-format'); var _openapiformat2 = _interopRequireDefault(_openapiformat);
|
|
13
|
-
var _remeda = require('remeda');
|
|
14
|
-
function isOpenApiV2Document(doc) {
|
|
15
|
-
return doc && _remeda.isPlainObject.call(void 0, doc) && !("openapi" in doc);
|
|
16
|
-
}
|
|
17
|
-
function isOpenApiV3_1Document(doc) {
|
|
18
|
-
return doc && _remeda.isPlainObject.call(void 0, doc) && "openapi" in doc && doc.openapi.startsWith("3.1");
|
|
19
|
-
}
|
|
20
|
-
function isParameterObject(obj) {
|
|
21
|
-
return obj && "in" in obj;
|
|
22
|
-
}
|
|
23
|
-
function isReference(obj) {
|
|
24
|
-
return !!obj && _types.isRef.call(void 0, obj);
|
|
25
|
-
}
|
|
26
|
-
function isRequired(schema) {
|
|
27
|
-
if (!schema) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
return Array.isArray(schema.required) ? !!_optionalChain([schema, 'access', _ => _.required, 'optionalAccess', _2 => _2.length]) : !!schema.required;
|
|
31
|
-
}
|
|
32
|
-
function isOptional(schema) {
|
|
33
|
-
return !isRequired(schema);
|
|
34
|
-
}
|
|
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
|
-
|
|
77
|
-
// src/Oas.ts
|
|
78
|
-
var _oas = require('oas'); var _oas2 = _interopRequireDefault(_oas);
|
|
79
|
-
var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
|
|
80
|
-
var _utils = require('oas/utils');
|
|
81
|
-
var _options, _Oas_instances, getResponseBodyFactory_fn;
|
|
82
|
-
var Oas = class extends _oas2.default {
|
|
83
|
-
constructor({ oas, user }, options = {}) {
|
|
84
|
-
if (typeof oas === "string") {
|
|
85
|
-
oas = JSON.parse(oas);
|
|
86
|
-
}
|
|
87
|
-
super(oas, user);
|
|
88
|
-
__privateAdd(this, _Oas_instances);
|
|
89
|
-
__privateAdd(this, _options, {});
|
|
90
|
-
this.document = void 0;
|
|
91
|
-
this.document = oas;
|
|
92
|
-
__privateSet(this, _options, options);
|
|
93
|
-
}
|
|
94
|
-
dereferenceWithRef(schema) {
|
|
95
|
-
if (isReference(schema)) {
|
|
96
|
-
return {
|
|
97
|
-
..._utils.findSchemaDefinition.call(void 0, schema.$ref, this.api),
|
|
98
|
-
$ref: schema.$ref
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return schema;
|
|
102
|
-
}
|
|
103
|
-
getResponseSchema(operation, statusCode) {
|
|
104
|
-
if (operation.schema.responses) {
|
|
105
|
-
Object.keys(operation.schema.responses).forEach((key) => {
|
|
106
|
-
const schema2 = operation.schema.responses[key];
|
|
107
|
-
const $ref = isReference(schema2) ? schema2.$ref : void 0;
|
|
108
|
-
if (schema2 && $ref) {
|
|
109
|
-
operation.schema.responses[key] = _utils.findSchemaDefinition.call(void 0, $ref, this.api);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
const getResponseBody = __privateMethod(this, _Oas_instances, getResponseBodyFactory_fn).call(this, operation.getResponseByStatusCode(statusCode));
|
|
114
|
-
const { contentType } = __privateGet(this, _options);
|
|
115
|
-
const responseBody = getResponseBody(contentType);
|
|
116
|
-
if (responseBody === false) {
|
|
117
|
-
return {};
|
|
118
|
-
}
|
|
119
|
-
const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema;
|
|
120
|
-
if (!schema) {
|
|
121
|
-
return {};
|
|
122
|
-
}
|
|
123
|
-
return this.dereferenceWithRef(schema);
|
|
124
|
-
}
|
|
125
|
-
getRequestSchema(operation) {
|
|
126
|
-
const { contentType } = __privateGet(this, _options);
|
|
127
|
-
if (operation.schema.requestBody) {
|
|
128
|
-
operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody);
|
|
129
|
-
}
|
|
130
|
-
const requestBody = operation.getRequestBody(contentType);
|
|
131
|
-
if (requestBody === false) {
|
|
132
|
-
return void 0;
|
|
133
|
-
}
|
|
134
|
-
const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema;
|
|
135
|
-
if (!schema) {
|
|
136
|
-
return void 0;
|
|
137
|
-
}
|
|
138
|
-
return this.dereferenceWithRef(schema);
|
|
139
|
-
}
|
|
140
|
-
getParametersSchema(operation, inKey) {
|
|
141
|
-
const { contentType = operation.getContentType() } = __privateGet(this, _options);
|
|
142
|
-
const params = operation.getParameters().map((schema) => {
|
|
143
|
-
return this.dereferenceWithRef(schema);
|
|
144
|
-
}).filter((v) => v.in === inKey);
|
|
145
|
-
if (!params.length) {
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
return params.reduce(
|
|
149
|
-
(schema, pathParameters) => {
|
|
150
|
-
const property = _nullishCoalesce(_optionalChain([pathParameters, 'access', _3 => _3.content, 'optionalAccess', _4 => _4[contentType], 'optionalAccess', _5 => _5.schema]), () => ( pathParameters.schema));
|
|
151
|
-
const required = [...schema.required || [], pathParameters.required ? pathParameters.name : void 0].filter(Boolean);
|
|
152
|
-
return {
|
|
153
|
-
...schema,
|
|
154
|
-
description: schema.description,
|
|
155
|
-
deprecated: schema.deprecated,
|
|
156
|
-
example: schema.example,
|
|
157
|
-
required,
|
|
158
|
-
properties: {
|
|
159
|
-
...schema.properties,
|
|
160
|
-
[pathParameters.name]: {
|
|
161
|
-
description: pathParameters.description,
|
|
162
|
-
...property
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
{ type: "object", required: [], properties: {} }
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
async valdiate() {
|
|
171
|
-
const oasNormalize = new (0, _oasnormalize2.default)(this.api, {
|
|
172
|
-
enablePaths: true,
|
|
173
|
-
colorizeErrors: true
|
|
174
|
-
});
|
|
175
|
-
await oasNormalize.validate({
|
|
176
|
-
parser: {
|
|
177
|
-
validate: {
|
|
178
|
-
colorizeErrors: true,
|
|
179
|
-
schema: false,
|
|
180
|
-
spec: false
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
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
|
-
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
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-UIWP4KHB.cjs.map
|
|
@@ -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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C/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;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"]}
|