@kubb/oas 3.0.0-alpha.1 → 3.0.0-alpha.11
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-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.js +4 -21
- package/dist/index.js.map +1 -1
- 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 +7 -7
- 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
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var types = require('oas/types');
|
|
4
|
+
var openapiFormat = require('openapi-format');
|
|
5
|
+
var remeda = require('remeda');
|
|
6
|
+
var BaseOas = require('oas');
|
|
7
|
+
var OASNormalize = require('oas-normalize');
|
|
8
|
+
var utils = require('oas/utils');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var openapiFormat__default = /*#__PURE__*/_interopDefault(openapiFormat);
|
|
13
|
+
var BaseOas__default = /*#__PURE__*/_interopDefault(BaseOas);
|
|
14
|
+
var OASNormalize__default = /*#__PURE__*/_interopDefault(OASNormalize);
|
|
15
|
+
|
|
16
|
+
// src/utils.ts
|
|
17
|
+
function isOpenApiV2Document(doc) {
|
|
18
|
+
return doc && remeda.isPlainObject(doc) && !("openapi" in doc);
|
|
19
|
+
}
|
|
20
|
+
function isOpenApiV3_1Document(doc) {
|
|
21
|
+
return doc && remeda.isPlainObject(doc) && "openapi" in doc && doc.openapi.startsWith("3.1");
|
|
22
|
+
}
|
|
23
|
+
function isParameterObject(obj) {
|
|
24
|
+
return obj && "in" in obj;
|
|
25
|
+
}
|
|
26
|
+
function isReference(obj) {
|
|
27
|
+
return !!obj && types.isRef(obj);
|
|
28
|
+
}
|
|
29
|
+
function isRequired(schema) {
|
|
30
|
+
if (!schema) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required;
|
|
34
|
+
}
|
|
35
|
+
function isOptional(schema) {
|
|
36
|
+
return !isRequired(schema);
|
|
37
|
+
}
|
|
38
|
+
async function filterAndSort(data, options = {}) {
|
|
39
|
+
const mergedOptions = {
|
|
40
|
+
sort: options.sort ?? true,
|
|
41
|
+
["no-sort"]: options["no-sort"] ?? false,
|
|
42
|
+
sortSet: {
|
|
43
|
+
root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
|
|
44
|
+
get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
45
|
+
post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
46
|
+
put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
47
|
+
patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
48
|
+
delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
|
|
49
|
+
parameters: ["name", "in", "description", "required", "schema"],
|
|
50
|
+
requestBody: ["description", "required", "content"],
|
|
51
|
+
responses: ["description", "headers", "content", "links"],
|
|
52
|
+
content: [],
|
|
53
|
+
components: ["parameters", "schemas"],
|
|
54
|
+
schema: ["description", "type", "items", "properties", "format", "example", "default"],
|
|
55
|
+
schemas: ["description", "type", "items", "properties", "format", "example", "default"],
|
|
56
|
+
properties: ["description", "type", "items", "format", "example", "default", "enum"],
|
|
57
|
+
...options.sortSet
|
|
58
|
+
},
|
|
59
|
+
sortComponentsSet: {
|
|
60
|
+
...options.sortComponentsSet
|
|
61
|
+
},
|
|
62
|
+
filterSet: {
|
|
63
|
+
inverseMethods: ["get", "put", "post", "delete", "patch", "head", "options", "trace", "parameters"],
|
|
64
|
+
unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : [],
|
|
65
|
+
...options.filterSet
|
|
66
|
+
},
|
|
67
|
+
casingSet: {
|
|
68
|
+
...options.casingSet
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const restFilter = await openapiFormat__default.default.openapiFilter(data, mergedOptions);
|
|
72
|
+
data = restFilter.data;
|
|
73
|
+
const resFormat = await openapiFormat__default.default.openapiSort(data, mergedOptions);
|
|
74
|
+
data = resFormat.data;
|
|
75
|
+
const resChangeCase = await openapiFormat__default.default.openapiChangeCase(data, mergedOptions);
|
|
76
|
+
data = resChangeCase.data;
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
var Oas = class extends BaseOas__default.default {
|
|
80
|
+
#options = {};
|
|
81
|
+
document = void 0;
|
|
82
|
+
constructor({ oas, user }, options = {}) {
|
|
83
|
+
if (typeof oas === "string") {
|
|
84
|
+
oas = JSON.parse(oas);
|
|
85
|
+
}
|
|
86
|
+
super(oas, user);
|
|
87
|
+
this.document = oas;
|
|
88
|
+
this.#options = options;
|
|
89
|
+
}
|
|
90
|
+
dereferenceWithRef(schema) {
|
|
91
|
+
if (isReference(schema)) {
|
|
92
|
+
return {
|
|
93
|
+
...utils.findSchemaDefinition(schema.$ref, this.api),
|
|
94
|
+
$ref: schema.$ref
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return schema;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Oas does not have a getResponseBody(contentType)
|
|
101
|
+
*/
|
|
102
|
+
#getResponseBodyFactory(responseBody) {
|
|
103
|
+
function hasResponseBody(res = responseBody) {
|
|
104
|
+
return !!res;
|
|
105
|
+
}
|
|
106
|
+
return (contentType) => {
|
|
107
|
+
if (!hasResponseBody(responseBody)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (isReference(responseBody)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (!responseBody.content) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (contentType) {
|
|
117
|
+
if (!(contentType in responseBody.content)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return responseBody.content[contentType];
|
|
121
|
+
}
|
|
122
|
+
let availablecontentType = void 0;
|
|
123
|
+
const contentTypes = Object.keys(responseBody.content);
|
|
124
|
+
contentTypes.forEach((mt) => {
|
|
125
|
+
if (!availablecontentType && utils.matchesMimeType.json(mt)) {
|
|
126
|
+
availablecontentType = mt;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
if (!availablecontentType) {
|
|
130
|
+
contentTypes.forEach((mt) => {
|
|
131
|
+
if (!availablecontentType) {
|
|
132
|
+
availablecontentType = mt;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (availablecontentType) {
|
|
137
|
+
return [availablecontentType, responseBody.content[availablecontentType], ...responseBody.description ? [responseBody.description] : []];
|
|
138
|
+
}
|
|
139
|
+
return false;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
getResponseSchema(operation, statusCode) {
|
|
143
|
+
if (operation.schema.responses) {
|
|
144
|
+
Object.keys(operation.schema.responses).forEach((key) => {
|
|
145
|
+
const schema2 = operation.schema.responses[key];
|
|
146
|
+
const $ref = isReference(schema2) ? schema2.$ref : void 0;
|
|
147
|
+
if (schema2 && $ref) {
|
|
148
|
+
operation.schema.responses[key] = utils.findSchemaDefinition($ref, this.api);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode));
|
|
153
|
+
const { contentType } = this.#options;
|
|
154
|
+
const responseBody = getResponseBody(contentType);
|
|
155
|
+
if (responseBody === false) {
|
|
156
|
+
return {};
|
|
157
|
+
}
|
|
158
|
+
const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema;
|
|
159
|
+
if (!schema) {
|
|
160
|
+
return {};
|
|
161
|
+
}
|
|
162
|
+
return this.dereferenceWithRef(schema);
|
|
163
|
+
}
|
|
164
|
+
getRequestSchema(operation) {
|
|
165
|
+
const { contentType } = this.#options;
|
|
166
|
+
if (operation.schema.requestBody) {
|
|
167
|
+
operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody);
|
|
168
|
+
}
|
|
169
|
+
const requestBody = operation.getRequestBody(contentType);
|
|
170
|
+
if (requestBody === false) {
|
|
171
|
+
return void 0;
|
|
172
|
+
}
|
|
173
|
+
const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema;
|
|
174
|
+
if (!schema) {
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
177
|
+
return this.dereferenceWithRef(schema);
|
|
178
|
+
}
|
|
179
|
+
getParametersSchema(operation, inKey) {
|
|
180
|
+
const { contentType = operation.getContentType() } = this.#options;
|
|
181
|
+
const params = operation.getParameters().map((schema) => {
|
|
182
|
+
return this.dereferenceWithRef(schema);
|
|
183
|
+
}).filter((v) => v.in === inKey);
|
|
184
|
+
if (!params.length) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
return params.reduce(
|
|
188
|
+
(schema, pathParameters) => {
|
|
189
|
+
const property = pathParameters.content?.[contentType]?.schema ?? pathParameters.schema;
|
|
190
|
+
const required = [...schema.required || [], pathParameters.required ? pathParameters.name : void 0].filter(Boolean);
|
|
191
|
+
return {
|
|
192
|
+
...schema,
|
|
193
|
+
description: schema.description,
|
|
194
|
+
deprecated: schema.deprecated,
|
|
195
|
+
example: schema.example,
|
|
196
|
+
required,
|
|
197
|
+
properties: {
|
|
198
|
+
...schema.properties,
|
|
199
|
+
[pathParameters.name]: {
|
|
200
|
+
description: pathParameters.description,
|
|
201
|
+
...property
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
{ type: "object", required: [], properties: {} }
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
async valdiate() {
|
|
210
|
+
const oasNormalize = new OASNormalize__default.default(this.api, {
|
|
211
|
+
enablePaths: true,
|
|
212
|
+
colorizeErrors: true
|
|
213
|
+
});
|
|
214
|
+
await oasNormalize.validate({
|
|
215
|
+
convertToLatest: true,
|
|
216
|
+
parser: {
|
|
217
|
+
validate: {
|
|
218
|
+
colorizeErrors: true
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
exports.Oas = Oas;
|
|
226
|
+
exports.filterAndSort = filterAndSort;
|
|
227
|
+
exports.isOpenApiV2Document = isOpenApiV2Document;
|
|
228
|
+
exports.isOpenApiV3_1Document = isOpenApiV3_1Document;
|
|
229
|
+
exports.isOptional = isOptional;
|
|
230
|
+
exports.isParameterObject = isParameterObject;
|
|
231
|
+
exports.isReference = isReference;
|
|
232
|
+
exports.isRequired = isRequired;
|
|
233
|
+
//# sourceMappingURL=chunk-2ZT6EJGT.cjs.map
|
|
234
|
+
//# sourceMappingURL=chunk-2ZT6EJGT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["isPlainObject","isRef","openapiFormat","BaseOas","findSchemaDefinition","matchesMimeType","schema","OASNormalize"],"mappings":";;;;;;;;;;;;;;;;AAQO,SAAS,oBAAoB,GAAqC,EAAA;AACvE,EAAA,OAAO,GAAO,IAAAA,oBAAA,CAAc,GAAG,CAAA,IAAK,EAAE,SAAa,IAAA,GAAA,CAAA,CAAA;AACrD,CAAA;AAKO,SAAS,sBAAsB,GAAuC,EAAA;AAC3E,EAAO,OAAA,GAAA,IAAOA,qBAAoC,GAAG,CA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,KACjB,CAAA,CAAA;AAED,IAAA,MAAM,aAAa,QAAS,CAAA;AAAA,MAC1B,eAAiB,EAAA,IAAA;AAAA,MACjB,MAAQ,EAAA;AAAA,QACN,QAAU,EAAA;AAAA,UACR,cAAgB,EAAA,IAAA;AAAA,SAClB;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF","file":"chunk-2ZT6EJGT.cjs","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 convertToLatest: true,\n parser: {\n validate: {\n colorizeErrors: true,\n },\n },\n })\n }\n}\n"]}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
|
1
|
+
import { isRef } from 'oas/types';
|
|
2
|
+
import openapiFormat from 'openapi-format';
|
|
3
|
+
import { isPlainObject } from 'remeda';
|
|
4
|
+
import BaseOas from 'oas';
|
|
5
|
+
import OASNormalize from 'oas-normalize';
|
|
6
|
+
import { findSchemaDefinition, matchesMimeType } from 'oas/utils';
|
|
9
7
|
|
|
10
8
|
// src/utils.ts
|
|
11
|
-
import { isRef, isSchema } from "oas/types";
|
|
12
|
-
import openapiFormat from "openapi-format";
|
|
13
|
-
import { isPlainObject } from "remeda";
|
|
14
9
|
function isOpenApiV2Document(doc) {
|
|
15
10
|
return doc && isPlainObject(doc) && !("openapi" in doc);
|
|
16
11
|
}
|
|
@@ -73,23 +68,16 @@ async function filterAndSort(data, options = {}) {
|
|
|
73
68
|
data = resChangeCase.data;
|
|
74
69
|
return data;
|
|
75
70
|
}
|
|
76
|
-
|
|
77
|
-
// src/Oas.ts
|
|
78
|
-
import BaseOas from "oas";
|
|
79
|
-
import OASNormalize from "oas-normalize";
|
|
80
|
-
import { findSchemaDefinition, matchesMimeType } from "oas/utils";
|
|
81
|
-
var _options, _Oas_instances, getResponseBodyFactory_fn;
|
|
82
71
|
var Oas = class extends BaseOas {
|
|
72
|
+
#options = {};
|
|
73
|
+
document = void 0;
|
|
83
74
|
constructor({ oas, user }, options = {}) {
|
|
84
75
|
if (typeof oas === "string") {
|
|
85
76
|
oas = JSON.parse(oas);
|
|
86
77
|
}
|
|
87
78
|
super(oas, user);
|
|
88
|
-
__privateAdd(this, _Oas_instances);
|
|
89
|
-
__privateAdd(this, _options, {});
|
|
90
|
-
this.document = void 0;
|
|
91
79
|
this.document = oas;
|
|
92
|
-
|
|
80
|
+
this.#options = options;
|
|
93
81
|
}
|
|
94
82
|
dereferenceWithRef(schema) {
|
|
95
83
|
if (isReference(schema)) {
|
|
@@ -100,6 +88,49 @@ var Oas = class extends BaseOas {
|
|
|
100
88
|
}
|
|
101
89
|
return schema;
|
|
102
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Oas does not have a getResponseBody(contentType)
|
|
93
|
+
*/
|
|
94
|
+
#getResponseBodyFactory(responseBody) {
|
|
95
|
+
function hasResponseBody(res = responseBody) {
|
|
96
|
+
return !!res;
|
|
97
|
+
}
|
|
98
|
+
return (contentType) => {
|
|
99
|
+
if (!hasResponseBody(responseBody)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (isReference(responseBody)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (!responseBody.content) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (contentType) {
|
|
109
|
+
if (!(contentType in responseBody.content)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return responseBody.content[contentType];
|
|
113
|
+
}
|
|
114
|
+
let availablecontentType = void 0;
|
|
115
|
+
const contentTypes = Object.keys(responseBody.content);
|
|
116
|
+
contentTypes.forEach((mt) => {
|
|
117
|
+
if (!availablecontentType && matchesMimeType.json(mt)) {
|
|
118
|
+
availablecontentType = mt;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (!availablecontentType) {
|
|
122
|
+
contentTypes.forEach((mt) => {
|
|
123
|
+
if (!availablecontentType) {
|
|
124
|
+
availablecontentType = mt;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (availablecontentType) {
|
|
129
|
+
return [availablecontentType, responseBody.content[availablecontentType], ...responseBody.description ? [responseBody.description] : []];
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
103
134
|
getResponseSchema(operation, statusCode) {
|
|
104
135
|
if (operation.schema.responses) {
|
|
105
136
|
Object.keys(operation.schema.responses).forEach((key) => {
|
|
@@ -110,8 +141,8 @@ var Oas = class extends BaseOas {
|
|
|
110
141
|
}
|
|
111
142
|
});
|
|
112
143
|
}
|
|
113
|
-
const getResponseBody =
|
|
114
|
-
const { contentType } =
|
|
144
|
+
const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode));
|
|
145
|
+
const { contentType } = this.#options;
|
|
115
146
|
const responseBody = getResponseBody(contentType);
|
|
116
147
|
if (responseBody === false) {
|
|
117
148
|
return {};
|
|
@@ -123,7 +154,7 @@ var Oas = class extends BaseOas {
|
|
|
123
154
|
return this.dereferenceWithRef(schema);
|
|
124
155
|
}
|
|
125
156
|
getRequestSchema(operation) {
|
|
126
|
-
const { contentType } =
|
|
157
|
+
const { contentType } = this.#options;
|
|
127
158
|
if (operation.schema.requestBody) {
|
|
128
159
|
operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody);
|
|
129
160
|
}
|
|
@@ -138,7 +169,7 @@ var Oas = class extends BaseOas {
|
|
|
138
169
|
return this.dereferenceWithRef(schema);
|
|
139
170
|
}
|
|
140
171
|
getParametersSchema(operation, inKey) {
|
|
141
|
-
const { contentType = operation.getContentType() } =
|
|
172
|
+
const { contentType = operation.getContentType() } = this.#options;
|
|
142
173
|
const params = operation.getParameters().map((schema) => {
|
|
143
174
|
return this.dereferenceWithRef(schema);
|
|
144
175
|
}).filter((v) => v.in === inKey);
|
|
@@ -173,70 +204,16 @@ var Oas = class extends BaseOas {
|
|
|
173
204
|
colorizeErrors: true
|
|
174
205
|
});
|
|
175
206
|
await oasNormalize.validate({
|
|
207
|
+
convertToLatest: true,
|
|
176
208
|
parser: {
|
|
177
209
|
validate: {
|
|
178
|
-
colorizeErrors: true
|
|
179
|
-
schema: false,
|
|
180
|
-
spec: false
|
|
210
|
+
colorizeErrors: true
|
|
181
211
|
}
|
|
182
212
|
}
|
|
183
213
|
});
|
|
184
214
|
}
|
|
185
215
|
};
|
|
186
|
-
_options = new WeakMap();
|
|
187
|
-
_Oas_instances = new WeakSet();
|
|
188
|
-
/**
|
|
189
|
-
* Oas does not have a getResponseBody(contentType)
|
|
190
|
-
*/
|
|
191
|
-
getResponseBodyFactory_fn = function(responseBody) {
|
|
192
|
-
function hasResponseBody(res = responseBody) {
|
|
193
|
-
return !!res;
|
|
194
|
-
}
|
|
195
|
-
return (contentType) => {
|
|
196
|
-
if (!hasResponseBody(responseBody)) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
if (isReference(responseBody)) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
if (!responseBody.content) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
if (contentType) {
|
|
206
|
-
if (!(contentType in responseBody.content)) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
return responseBody.content[contentType];
|
|
210
|
-
}
|
|
211
|
-
let availablecontentType = void 0;
|
|
212
|
-
const contentTypes = Object.keys(responseBody.content);
|
|
213
|
-
contentTypes.forEach((mt) => {
|
|
214
|
-
if (!availablecontentType && matchesMimeType.json(mt)) {
|
|
215
|
-
availablecontentType = mt;
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
if (!availablecontentType) {
|
|
219
|
-
contentTypes.forEach((mt) => {
|
|
220
|
-
if (!availablecontentType) {
|
|
221
|
-
availablecontentType = mt;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
if (availablecontentType) {
|
|
226
|
-
return [availablecontentType, responseBody.content[availablecontentType], ...responseBody.description ? [responseBody.description] : []];
|
|
227
|
-
}
|
|
228
|
-
return false;
|
|
229
|
-
};
|
|
230
|
-
};
|
|
231
216
|
|
|
232
|
-
export {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
isParameterObject,
|
|
236
|
-
isReference,
|
|
237
|
-
isRequired,
|
|
238
|
-
isOptional,
|
|
239
|
-
filterAndSort,
|
|
240
|
-
Oas
|
|
241
|
-
};
|
|
242
|
-
//# sourceMappingURL=chunk-7D7ASOLY.js.map
|
|
217
|
+
export { Oas, filterAndSort, isOpenApiV2Document, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired };
|
|
218
|
+
//# sourceMappingURL=chunk-TVOJ46T6.js.map
|
|
219
|
+
//# sourceMappingURL=chunk-TVOJ46T6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings":";;;;;;;;AAQO,SAAS,oBAAoB,GAAqC,EAAA;AACvE,EAAA,OAAO,GAAO,IAAA,aAAA,CAAc,GAAG,CAAA,IAAK,EAAE,SAAa,IAAA,GAAA,CAAA,CAAA;AACrD,CAAA;AAKO,SAAS,sBAAsB,GAAuC,EAAA;AAC3E,EAAO,OAAA,GAAA,IAAO,cAAoC,GAAG,CAAA,IAAK,aAAa,GAAO,IAAA,GAAA,CAAI,OAAQ,CAAA,UAAA,CAAW,KAAK,CAAA,CAAA;AAC5G,CAAA;AAMO,SAAS,kBAAkB,GAA6D,EAAA;AAC7F,EAAA,OAAO,OAAO,IAAQ,IAAA,GAAA,CAAA;AACxB,CAAA;AAEO,SAAS,YAAY,GAA+E,EAAA;AACzG,EAAA,OAAO,CAAC,CAAC,GAAO,IAAA,KAAA,CAAM,GAAG,CAAA,CAAA;AAC3B,CAAA;AAEO,SAAS,WAAW,MAAgC,EAAA;AACzD,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,OAAO,KAAM,CAAA,OAAA,CAAQ,MAAO,CAAA,QAAQ,CAAI,GAAA,CAAC,CAAC,MAAA,CAAO,QAAU,EAAA,MAAA,GAAS,CAAC,CAAC,MAAO,CAAA,QAAA,CAAA;AAC/E,CAAA;AAEO,SAAS,WAAW,MAAgC,EAAA;AACzD,EAAO,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A;AAAA,UACpB,YAAY,MAAO,CAAA,UAAA;AAAA,UACnB,SAAS,MAAO,CAAA,OAAA;AAAA,UAChB,QAAA;AAAA,UACA,UAAY,EAAA;AAAA,YACV,GAAG,MAAO,CAAA,UAAA;AAAA,YACV,CAAC,cAAe,CAAA,IAAI,GAAG;AAAA,cACrB,aAAa,cAAe,CAAA,WAAA;AAAA,cAC5B,GAAG,QAAA;AAAA,aACL;AAAA,WACF;AAAA,SACF,CAAA;AAAA,OACF;AAAA,MACA,EAAE,MAAM,QAAU,EAAA,QAAA,EAAU,EAAI,EAAA,UAAA,EAAY,EAAG,EAAA;AAAA,KACjD,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,QAAW,GAAA;AACf,IAAA,MAAM,YAAe,GAAA,IAAI,YAAa,CAAA,IAAA,CAAK,GAAK,EAAA;AAAA,MAC9C,WAAa,EAAA,IAAA;AAAA,MACb,cAAgB,EAAA,IAAA;AAAA,KACjB,CAAA,CAAA;AAED,IAAA,MAAM,aAAa,QAAS,CAAA;AAAA,MAC1B,eAAiB,EAAA,IAAA;AAAA,MACjB,MAAQ,EAAA;AAAA,QACN,QAAU,EAAA;AAAA,UACR,cAAgB,EAAA,IAAA;AAAA,SAClB;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF","file":"chunk-TVOJ46T6.js","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 convertToLatest: true,\n parser: {\n validate: {\n colorizeErrors: true,\n },\n },\n })\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunkUIWP4KHBcjs = require('./chunk-UIWP4KHB.cjs');
|
|
3
|
+
var chunk2ZT6EJGT_cjs = require('./chunk-2ZT6EJGT.cjs');
|
|
4
|
+
var utils = require('oas/utils');
|
|
9
5
|
|
|
10
6
|
// src/types.ts
|
|
11
7
|
var HttpMethods = {
|
|
@@ -19,17 +15,38 @@ var HttpMethods = {
|
|
|
19
15
|
TRACE: "trace"
|
|
20
16
|
};
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
Object.defineProperty(exports, "Oas", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return chunk2ZT6EJGT_cjs.Oas; }
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "isOpenApiV3_1Document", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return chunk2ZT6EJGT_cjs.isOpenApiV3_1Document; }
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "isOptional", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return chunk2ZT6EJGT_cjs.isOptional; }
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "isParameterObject", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return chunk2ZT6EJGT_cjs.isParameterObject; }
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "isReference", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () { return chunk2ZT6EJGT_cjs.isReference; }
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(exports, "isRequired", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () { return chunk2ZT6EJGT_cjs.isRequired; }
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "findSchemaDefinition", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () { return utils.findSchemaDefinition; }
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "matchesMimeType", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () { return utils.matchesMimeType; }
|
|
49
|
+
});
|
|
50
|
+
exports.HttpMethods = HttpMethods;
|
|
51
|
+
//# sourceMappingURL=index.cjs.map
|
|
35
52
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":[],"mappings":";;;;;;AAeO,IAAM,WAAc,GAAA;AAAA,EACzB,GAAK,EAAA,KAAA;AAAA,EACL,IAAM,EAAA,MAAA;AAAA,EACN,GAAK,EAAA,KAAA;AAAA,EACL,KAAO,EAAA,OAAA;AAAA,EACP,MAAQ,EAAA,QAAA;AAAA,EACR,IAAM,EAAA,MAAA;AAAA,EACN,OAAS,EAAA,SAAA;AAAA,EACT,KAAO,EAAA,OAAA;AACT","file":"index.cjs","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"]}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
isOpenApiV3_1Document,
|
|
4
|
-
isOptional,
|
|
5
|
-
isParameterObject,
|
|
6
|
-
isReference,
|
|
7
|
-
isRequired
|
|
8
|
-
} from "./chunk-7D7ASOLY.js";
|
|
1
|
+
export { Oas, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired } from './chunk-TVOJ46T6.js';
|
|
2
|
+
export { findSchemaDefinition, matchesMimeType } from 'oas/utils';
|
|
9
3
|
|
|
10
4
|
// src/types.ts
|
|
11
5
|
var HttpMethods = {
|
|
@@ -19,17 +13,6 @@ var HttpMethods = {
|
|
|
19
13
|
TRACE: "trace"
|
|
20
14
|
};
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
HttpMethods,
|
|
26
|
-
Oas,
|
|
27
|
-
findSchemaDefinition,
|
|
28
|
-
isOpenApiV3_1Document,
|
|
29
|
-
isOptional,
|
|
30
|
-
isParameterObject,
|
|
31
|
-
isReference,
|
|
32
|
-
isRequired,
|
|
33
|
-
matchesMimeType
|
|
34
|
-
};
|
|
16
|
+
export { HttpMethods };
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
35
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":[],"mappings":";;;;AAeO,IAAM,WAAc,GAAA;AAAA,EACzB,GAAK,EAAA,KAAA;AAAA,EACL,IAAM,EAAA,MAAA;AAAA,EACN,GAAK,EAAA,KAAA;AAAA,EACL,KAAO,EAAA,OAAA;AAAA,EACP,MAAQ,EAAA,QAAA;AAAA,EACR,IAAM,EAAA,MAAA;AAAA,EACN,OAAS,EAAA,SAAA;AAAA,EACT,KAAO,EAAA,OAAA;AACT","file":"index.js","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"]}
|
package/dist/parser.cjs
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk2ZT6EJGT_cjs = require('./chunk-2ZT6EJGT.cjs');
|
|
4
|
+
var openapiCore = require('@redocly/openapi-core');
|
|
5
|
+
var OASNormalize = require('oas-normalize');
|
|
6
|
+
var swagger2openapi = require('swagger2openapi');
|
|
3
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
4
9
|
|
|
5
|
-
var
|
|
10
|
+
var OASNormalize__default = /*#__PURE__*/_interopDefault(OASNormalize);
|
|
11
|
+
var swagger2openapi__default = /*#__PURE__*/_interopDefault(swagger2openapi);
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
|
|
9
|
-
var _swagger2openapi = require('swagger2openapi'); var _swagger2openapi2 = _interopRequireDefault(_swagger2openapi);
|
|
10
|
-
var _openapicore = require('@redocly/openapi-core');
|
|
11
|
-
async function parse(pathOrApi, options = {}, oasClass = _chunkUIWP4KHBcjs.Oas) {
|
|
13
|
+
async function parse(pathOrApi, options = {}, oasClass = chunk2ZT6EJGT_cjs.Oas) {
|
|
12
14
|
if (typeof pathOrApi === "string") {
|
|
13
|
-
const config = await
|
|
14
|
-
const bundleResults = await
|
|
15
|
+
const config = await openapiCore.loadConfig();
|
|
16
|
+
const bundleResults = await openapiCore.bundle({ ref: pathOrApi, config, base: pathOrApi });
|
|
15
17
|
return parse(bundleResults.bundle.parsed, options);
|
|
16
18
|
}
|
|
17
|
-
const oasNormalize = new
|
|
19
|
+
const oasNormalize = new OASNormalize__default.default(pathOrApi, {
|
|
18
20
|
enablePaths: true,
|
|
19
21
|
colorizeErrors: true
|
|
20
22
|
});
|
|
21
23
|
const document = await oasNormalize.load();
|
|
22
|
-
if (
|
|
23
|
-
const { openapi } = await
|
|
24
|
+
if (chunk2ZT6EJGT_cjs.isOpenApiV2Document(document)) {
|
|
25
|
+
const { openapi } = await swagger2openapi__default.default.convertObj(document, {
|
|
24
26
|
anchors: true
|
|
25
27
|
});
|
|
26
|
-
const oas2 = await
|
|
28
|
+
const oas2 = await chunk2ZT6EJGT_cjs.filterAndSort(openapi, options);
|
|
27
29
|
return new oasClass({ oas: oas2 });
|
|
28
30
|
}
|
|
29
|
-
const oas = await
|
|
31
|
+
const oas = await chunk2ZT6EJGT_cjs.filterAndSort(document, options);
|
|
30
32
|
return new oasClass({ oas });
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
|
|
34
35
|
exports.parse = parse;
|
|
36
|
+
//# sourceMappingURL=parser.cjs.map
|
|
35
37
|
//# sourceMappingURL=parser.cjs.map
|
package/dist/parser.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../src/parser/index.ts"],"names":["Oas","loadConfig","bundle","OASNormalize","isOpenApiV2Document","swagger2openapi","oas","filterAndSort"],"mappings":";;;;;;;;;;;;AAoDA,eAAsB,MAAM,SAAiC,EAAA,OAAA,GAAyB,EAAC,EAAG,WAAuBA,qBAAmB,EAAA;AAClI,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAMC,sBAAW,EAAA,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAMC,kBAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA,CAAA;AAE9E,IAAA,OAAO,KAAM,CAAA,aAAA,CAAc,MAAO,CAAA,MAAA,EAAQ,OAAO,CAAA,CAAA;AAAA,GACnD;AAEA,EAAM,MAAA,YAAA,GAAe,IAAIC,6BAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,GACjB,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA,CAAA;AAE1C,EAAI,IAAAC,qCAAA,CAAoB,QAAQ,CAAG,EAAA;AACjC,IAAA,MAAM,EAAE,OAAQ,EAAA,GAAI,MAAMC,gCAAA,CAAgB,WAAW,QAAU,EAAA;AAAA,MAC7D,OAAS,EAAA,IAAA;AAAA,KACV,CAAA,CAAA;AAED,IAAA,MAAMC,IAAM,GAAA,MAAMC,+BAAc,CAAA,OAAA,EAAwB,OAAO,CAAA,CAAA;AAE/D,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAKD,MAAoB,CAAA,CAAA;AAAA,GACjD;AAEA,EAAA,MAAM,GAAM,GAAA,MAAMC,+BAAc,CAAA,QAAA,EAAyB,OAAO,CAAA,CAAA;AAEhE,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,CAAA,CAAA;AAC7B","file":"parser.cjs","sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { filterAndSort, isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport type FormatOptions = {\n verbose?: boolean\n 'no-sort'?: boolean\n sort?: boolean\n output?: string\n sortSet?: {\n root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>\n get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>\n requestBody?: Array<'description' | 'required' | 'content'>\n responses?: Array<'description' | 'headers' | 'content' | 'links'>\n content?: Array<string>\n components?: Array<'parameters' | 'schemas'>\n schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>\n }\n filterSet?: {\n methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>\n inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>\n tags?: Array<string>\n inverseTags?: Array<string>\n operationIds?: Array<string>\n inverseOperationIds?: Array<string>\n operations?: Array<string>\n flags?: Array<string>\n inverseFlags?: Array<string>\n flagValues?: Array<string>\n inverseFlagValues?: Array<string>\n stripFlags?: Array<string>\n responseContent?: Array<string>\n inverseResponseContent?: Array<string>\n unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>\n }\n sortComponentsSet?: {}\n casingSet?: {}\n}\n\nexport async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}, 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, options)\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 const oas = await filterAndSort(openapi as OASDocument, options)\n\n return new oasClass({ oas: oas as OASDocument })\n }\n\n const oas = await filterAndSort(document as OASDocument, options)\n\n return new oasClass({ oas })\n}\n"]}
|
package/dist/parser.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./chunk-7D7ASOLY.js";
|
|
1
|
+
import { isOpenApiV2Document, filterAndSort, Oas } from './chunk-TVOJ46T6.js';
|
|
2
|
+
import { loadConfig, bundle } from '@redocly/openapi-core';
|
|
3
|
+
import OASNormalize from 'oas-normalize';
|
|
4
|
+
import swagger2openapi from 'swagger2openapi';
|
|
6
5
|
|
|
7
|
-
// src/parser/index.ts
|
|
8
|
-
import OASNormalize from "oas-normalize";
|
|
9
|
-
import swagger2openapi from "swagger2openapi";
|
|
10
|
-
import { bundle, loadConfig } from "@redocly/openapi-core";
|
|
11
6
|
async function parse(pathOrApi, options = {}, oasClass = Oas) {
|
|
12
7
|
if (typeof pathOrApi === "string") {
|
|
13
8
|
const config = await loadConfig();
|
|
@@ -29,7 +24,7 @@ async function parse(pathOrApi, options = {}, oasClass = Oas) {
|
|
|
29
24
|
const oas = await filterAndSort(document, options);
|
|
30
25
|
return new oasClass({ oas });
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
|
|
28
|
+
export { parse };
|
|
29
|
+
//# sourceMappingURL=parser.js.map
|
|
35
30
|
//# sourceMappingURL=parser.js.map
|
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"],"names":["oas"],"mappings":";;;;;AAoDA,eAAsB,MAAM,SAAiC,EAAA,OAAA,GAAyB,EAAC,EAAG,WAAuB,GAAmB,EAAA;AAClI,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAM,UAAW,EAAA,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAM,MAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA,CAAA;AAE9E,IAAA,OAAO,KAAM,CAAA,aAAA,CAAc,MAAO,CAAA,MAAA,EAAQ,OAAO,CAAA,CAAA;AAAA,GACnD;AAEA,EAAM,MAAA,YAAA,GAAe,IAAI,YAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,GACjB,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA,CAAA;AAE1C,EAAI,IAAA,mBAAA,CAAoB,QAAQ,CAAG,EAAA;AACjC,IAAA,MAAM,EAAE,OAAQ,EAAA,GAAI,MAAM,eAAA,CAAgB,WAAW,QAAU,EAAA;AAAA,MAC7D,OAAS,EAAA,IAAA;AAAA,KACV,CAAA,CAAA;AAED,IAAA,MAAMA,IAAM,GAAA,MAAM,aAAc,CAAA,OAAA,EAAwB,OAAO,CAAA,CAAA;AAE/D,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAKA,MAAoB,CAAA,CAAA;AAAA,GACjD;AAEA,EAAA,MAAM,GAAM,GAAA,MAAM,aAAc,CAAA,QAAA,EAAyB,OAAO,CAAA,CAAA;AAEhE,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,CAAA,CAAA;AAC7B","file":"parser.js","sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { filterAndSort, isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport type FormatOptions = {\n verbose?: boolean\n 'no-sort'?: boolean\n sort?: boolean\n output?: string\n sortSet?: {\n root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>\n get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>\n requestBody?: Array<'description' | 'required' | 'content'>\n responses?: Array<'description' | 'headers' | 'content' | 'links'>\n content?: Array<string>\n components?: Array<'parameters' | 'schemas'>\n schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>\n }\n filterSet?: {\n methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>\n inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>\n tags?: Array<string>\n inverseTags?: Array<string>\n operationIds?: Array<string>\n inverseOperationIds?: Array<string>\n operations?: Array<string>\n flags?: Array<string>\n inverseFlags?: Array<string>\n flagValues?: Array<string>\n inverseFlagValues?: Array<string>\n stripFlags?: Array<string>\n responseContent?: Array<string>\n inverseResponseContent?: Array<string>\n unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>\n }\n sortComponentsSet?: {}\n casingSet?: {}\n}\n\nexport async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}, 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, options)\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 const oas = await filterAndSort(openapi as OASDocument, options)\n\n return new oasClass({ oas: oas as OASDocument })\n }\n\n const oas = await filterAndSort(document as OASDocument, options)\n\n return new oasClass({ oas })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/oas",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.11",
|
|
4
4
|
"description": "Oas helpers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"!/**/__tests__/**"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@redocly/openapi-core": "^1.
|
|
51
|
+
"@redocly/openapi-core": "^1.22.1",
|
|
52
52
|
"hotscript": "^1.0.13",
|
|
53
|
-
"json-schema-to-ts": "^3.1.
|
|
54
|
-
"oas": "^24.
|
|
53
|
+
"json-schema-to-ts": "^3.1.1",
|
|
54
|
+
"oas": "^24.7.0",
|
|
55
55
|
"oas-normalize": "^11.1.1",
|
|
56
56
|
"openapi-format": "^1.22.3",
|
|
57
57
|
"openapi-types": "^12.1.3",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
"expect-type": "^0.19.0",
|
|
66
66
|
"tsup": "^8.2.4",
|
|
67
67
|
"typescript": "^5.5.4",
|
|
68
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
69
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
70
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
68
|
+
"@kubb/config-biome": "3.0.0-alpha.11",
|
|
69
|
+
"@kubb/config-ts": "3.0.0-alpha.11",
|
|
70
|
+
"@kubb/config-tsup": "3.0.0-alpha.11"
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|
|
73
73
|
"node": ">=20"
|
package/src/Oas.ts
CHANGED
|
@@ -194,11 +194,10 @@ export class Oas<const TOAS = unknown> extends BaseOas {
|
|
|
194
194
|
})
|
|
195
195
|
|
|
196
196
|
await oasNormalize.validate({
|
|
197
|
+
convertToLatest: true,
|
|
197
198
|
parser: {
|
|
198
199
|
validate: {
|
|
199
200
|
colorizeErrors: true,
|
|
200
|
-
schema: false,
|
|
201
|
-
spec: false,
|
|
202
201
|
},
|
|
203
202
|
},
|
|
204
203
|
})
|
package/src/parser/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
6
|
import { filterAndSort, isOpenApiV2Document } from '../utils.ts'
|
|
@@ -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,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AAQ,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,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,mDAAmD,EAAE,EAAE,OAAO,WAAW,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;AACpM,IAAI,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EA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AA,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"]}
|