@kubb/oas 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +257 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -9
- package/dist/index.d.ts +46 -9
- package/dist/index.js +245 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -12
- package/src/index.ts +1 -1
- package/src/utils.ts +32 -1
- package/dist/Oas-Br0yKhGF.d.cts +0 -42
- package/dist/Oas-Br0yKhGF.d.ts +0 -42
- package/dist/chunk-4ZPTFFHL.cjs +0 -241
- package/dist/chunk-4ZPTFFHL.cjs.map +0 -1
- package/dist/chunk-X2CIM2ZZ.js +0 -227
- package/dist/chunk-X2CIM2ZZ.js.map +0 -1
- package/dist/parser.cjs +0 -35
- package/dist/parser.cjs.map +0 -1
- package/dist/parser.d.cts +0 -8
- package/dist/parser.d.ts +0 -8
- package/dist/parser.js +0 -28
- package/dist/parser.js.map +0 -1
- package/src/parser/index.ts +0 -35
package/dist/chunk-4ZPTFFHL.cjs
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var types = require('oas/types');
|
|
4
|
-
var remeda = require('remeda');
|
|
5
|
-
var BaseOas = require('oas');
|
|
6
|
-
var OASNormalize = require('oas-normalize');
|
|
7
|
-
var utils = require('oas/utils');
|
|
8
|
-
var jsonpointer = require('jsonpointer');
|
|
9
|
-
|
|
10
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
|
|
12
|
-
var BaseOas__default = /*#__PURE__*/_interopDefault(BaseOas);
|
|
13
|
-
var OASNormalize__default = /*#__PURE__*/_interopDefault(OASNormalize);
|
|
14
|
-
var jsonpointer__default = /*#__PURE__*/_interopDefault(jsonpointer);
|
|
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
|
-
var Oas = class extends BaseOas__default.default {
|
|
39
|
-
#options = {};
|
|
40
|
-
document = void 0;
|
|
41
|
-
constructor({ oas, user }, options = {}) {
|
|
42
|
-
if (typeof oas === "string") {
|
|
43
|
-
oas = JSON.parse(oas);
|
|
44
|
-
}
|
|
45
|
-
super(oas, user);
|
|
46
|
-
this.document = oas;
|
|
47
|
-
this.#options = options;
|
|
48
|
-
}
|
|
49
|
-
get($ref) {
|
|
50
|
-
const origRef = $ref;
|
|
51
|
-
$ref = $ref.trim();
|
|
52
|
-
if ($ref === "") {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
if ($ref.startsWith("#")) {
|
|
56
|
-
$ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
57
|
-
} else {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const current = jsonpointer__default.default.get(this.api, $ref);
|
|
61
|
-
if (!current) {
|
|
62
|
-
throw new Error(`Could not find a definition for ${origRef}.`);
|
|
63
|
-
}
|
|
64
|
-
return current;
|
|
65
|
-
}
|
|
66
|
-
set($ref, value) {
|
|
67
|
-
$ref = $ref.trim();
|
|
68
|
-
if ($ref === "") {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
if ($ref.startsWith("#")) {
|
|
72
|
-
$ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
73
|
-
jsonpointer__default.default.set(this.api, $ref, value);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
resolveDiscriminators() {
|
|
77
|
-
const schemas = this.api.components?.schemas || {};
|
|
78
|
-
Object.entries(schemas).forEach(([key, schemaObject]) => {
|
|
79
|
-
if ("discriminator" in schemaObject) {
|
|
80
|
-
const { mapping = {}, propertyName } = schemaObject.discriminator || {};
|
|
81
|
-
Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
|
|
82
|
-
if (mappingValue) {
|
|
83
|
-
const childSchema = this.get(mappingValue);
|
|
84
|
-
const property = childSchema.properties?.[propertyName];
|
|
85
|
-
if (property) {
|
|
86
|
-
childSchema.properties[propertyName] = {
|
|
87
|
-
...childSchema.properties[propertyName],
|
|
88
|
-
enum: [...property?.enum?.filter((value) => value !== mappingKey) ?? [], mappingKey]
|
|
89
|
-
};
|
|
90
|
-
childSchema.required = [...childSchema.required ?? [], propertyName];
|
|
91
|
-
this.set(mappingValue, childSchema);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
dereferenceWithRef(schema) {
|
|
99
|
-
if (isReference(schema)) {
|
|
100
|
-
return {
|
|
101
|
-
...this.get(schema.$ref),
|
|
102
|
-
$ref: schema.$ref
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return schema;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Oas does not have a getResponseBody(contentType)
|
|
109
|
-
*/
|
|
110
|
-
#getResponseBodyFactory(responseBody) {
|
|
111
|
-
function hasResponseBody(res = responseBody) {
|
|
112
|
-
return !!res;
|
|
113
|
-
}
|
|
114
|
-
return (contentType) => {
|
|
115
|
-
if (!hasResponseBody(responseBody)) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
if (isReference(responseBody)) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
if (!responseBody.content) {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
if (contentType) {
|
|
125
|
-
if (!(contentType in responseBody.content)) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
return responseBody.content[contentType];
|
|
129
|
-
}
|
|
130
|
-
let availablecontentType = void 0;
|
|
131
|
-
const contentTypes = Object.keys(responseBody.content);
|
|
132
|
-
contentTypes.forEach((mt) => {
|
|
133
|
-
if (!availablecontentType && utils.matchesMimeType.json(mt)) {
|
|
134
|
-
availablecontentType = mt;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
if (!availablecontentType) {
|
|
138
|
-
contentTypes.forEach((mt) => {
|
|
139
|
-
if (!availablecontentType) {
|
|
140
|
-
availablecontentType = mt;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
if (availablecontentType) {
|
|
145
|
-
return [availablecontentType, responseBody.content[availablecontentType], ...responseBody.description ? [responseBody.description] : []];
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
getResponseSchema(operation, statusCode) {
|
|
151
|
-
if (operation.schema.responses) {
|
|
152
|
-
Object.keys(operation.schema.responses).forEach((key) => {
|
|
153
|
-
const schema2 = operation.schema.responses[key];
|
|
154
|
-
const $ref = isReference(schema2) ? schema2.$ref : void 0;
|
|
155
|
-
if (schema2 && $ref) {
|
|
156
|
-
operation.schema.responses[key] = this.get($ref);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode));
|
|
161
|
-
const { contentType } = this.#options;
|
|
162
|
-
const responseBody = getResponseBody(contentType);
|
|
163
|
-
if (responseBody === false) {
|
|
164
|
-
return {};
|
|
165
|
-
}
|
|
166
|
-
const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema;
|
|
167
|
-
if (!schema) {
|
|
168
|
-
return {};
|
|
169
|
-
}
|
|
170
|
-
return this.dereferenceWithRef(schema);
|
|
171
|
-
}
|
|
172
|
-
getRequestSchema(operation) {
|
|
173
|
-
const { contentType } = this.#options;
|
|
174
|
-
if (operation.schema.requestBody) {
|
|
175
|
-
operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody);
|
|
176
|
-
}
|
|
177
|
-
const requestBody = operation.getRequestBody(contentType);
|
|
178
|
-
if (requestBody === false) {
|
|
179
|
-
return void 0;
|
|
180
|
-
}
|
|
181
|
-
const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema;
|
|
182
|
-
if (!schema) {
|
|
183
|
-
return void 0;
|
|
184
|
-
}
|
|
185
|
-
return this.dereferenceWithRef(schema);
|
|
186
|
-
}
|
|
187
|
-
getParametersSchema(operation, inKey) {
|
|
188
|
-
const { contentType = operation.getContentType() } = this.#options;
|
|
189
|
-
const params = operation.getParameters().map((schema) => {
|
|
190
|
-
return this.dereferenceWithRef(schema);
|
|
191
|
-
}).filter((v) => v.in === inKey);
|
|
192
|
-
if (!params.length) {
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
return params.reduce(
|
|
196
|
-
(schema, pathParameters) => {
|
|
197
|
-
const property = pathParameters.content?.[contentType]?.schema ?? pathParameters.schema;
|
|
198
|
-
const required = [...schema.required || [], pathParameters.required ? pathParameters.name : void 0].filter(Boolean);
|
|
199
|
-
return {
|
|
200
|
-
...schema,
|
|
201
|
-
description: schema.description,
|
|
202
|
-
deprecated: schema.deprecated,
|
|
203
|
-
example: schema.example,
|
|
204
|
-
required,
|
|
205
|
-
properties: {
|
|
206
|
-
...schema.properties,
|
|
207
|
-
[pathParameters.name]: {
|
|
208
|
-
description: pathParameters.description,
|
|
209
|
-
...property
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
},
|
|
214
|
-
{ type: "object", required: [], properties: {} }
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
async valdiate() {
|
|
218
|
-
const oasNormalize = new OASNormalize__default.default(this.api, {
|
|
219
|
-
enablePaths: true,
|
|
220
|
-
colorizeErrors: true
|
|
221
|
-
});
|
|
222
|
-
await oasNormalize.validate({
|
|
223
|
-
convertToLatest: true,
|
|
224
|
-
parser: {
|
|
225
|
-
validate: {
|
|
226
|
-
colorizeErrors: true
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
exports.Oas = Oas;
|
|
234
|
-
exports.isOpenApiV2Document = isOpenApiV2Document;
|
|
235
|
-
exports.isOpenApiV3_1Document = isOpenApiV3_1Document;
|
|
236
|
-
exports.isOptional = isOptional;
|
|
237
|
-
exports.isParameterObject = isParameterObject;
|
|
238
|
-
exports.isReference = isReference;
|
|
239
|
-
exports.isRequired = isRequired;
|
|
240
|
-
//# sourceMappingURL=chunk-4ZPTFFHL.cjs.map
|
|
241
|
-
//# sourceMappingURL=chunk-4ZPTFFHL.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["isPlainObject","isRef","BaseOas","jsonpointer","matchesMimeType","schema","OASNormalize"],"mappings":";;;;;;;;;;;;;;;;AAMO,SAAS,oBAAoB,GAAqC,EAAA;AACvE,EAAA,OAAO,GAAO,IAAAA,oBAAA,CAAc,GAAG,CAAA,IAAK,EAAE,SAAa,IAAA,GAAA,CAAA;AACrD;AAKO,SAAS,sBAAsB,GAAuC,EAAA;AAC3E,EAAO,OAAA,GAAA,IAAOA,qBAAoC,GAAG,CAAA,IAAK,aAAa,GAAO,IAAA,GAAA,CAAI,OAAQ,CAAA,UAAA,CAAW,KAAK,CAAA;AAC5G;AAMO,SAAS,kBAAkB,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A,cAC5B,GAAG;AAAA;AACL;AACF,SACF;AAAA,OACF;AAAA,MACA,EAAE,MAAM,QAAU,EAAA,QAAA,EAAU,EAAI,EAAA,UAAA,EAAY,EAAG;AAAA,KACjD;AAAA;AACF,EAEA,MAAM,QAAW,GAAA;AACf,IAAA,MAAM,YAAe,GAAA,IAAIC,6BAAa,CAAA,IAAA,CAAK,GAAK,EAAA;AAAA,MAC9C,WAAa,EAAA,IAAA;AAAA,MACb,cAAgB,EAAA;AAAA,KACjB,CAAA;AAED,IAAA,MAAM,aAAa,QAAS,CAAA;AAAA,MAC1B,eAAiB,EAAA,IAAA;AAAA,MACjB,MAAQ,EAAA;AAAA,QACN,QAAU,EAAA;AAAA,UACR,cAAgB,EAAA;AAAA;AAClB;AACF,KACD,CAAA;AAAA;AAEL","file":"chunk-4ZPTFFHL.cjs","sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { matchesMimeType } from 'oas/utils'\n\nimport jsonpointer from 'jsonpointer'\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 { OasTypes, OpenAPIV3 } from './index.ts'\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 get($ref: string) {\n const origRef = $ref\n $ref = $ref.trim()\n if ($ref === '') {\n return false\n }\n if ($ref.startsWith('#')) {\n $ref = globalThis.decodeURIComponent($ref.substring(1))\n } else {\n return null\n }\n const current = jsonpointer.get(this.api, $ref)\n\n if (!current) {\n throw new Error(`Could not find a definition for ${origRef}.`)\n }\n return current\n }\n\n set($ref: string, value: unknown) {\n $ref = $ref.trim()\n if ($ref === '') {\n return false\n }\n if ($ref.startsWith('#')) {\n $ref = globalThis.decodeURIComponent($ref.substring(1))\n\n jsonpointer.set(this.api, $ref, value)\n }\n }\n\n resolveDiscriminators(): void {\n const schemas = (this.api.components?.schemas || {}) as Record<string, OasTypes.SchemaObject>\n\n Object.entries(schemas).forEach(([key, schemaObject]) => {\n if ('discriminator' in schemaObject) {\n const { mapping = {}, propertyName } = (schemaObject.discriminator || {}) as OpenAPIV3.DiscriminatorObject\n\n Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {\n if (mappingValue) {\n const childSchema = this.get(mappingValue)\n const property = childSchema.properties?.[propertyName] as SchemaObject\n\n if (property) {\n childSchema.properties[propertyName] = {\n ...childSchema.properties[propertyName],\n enum: [...(property?.enum?.filter((value) => value !== mappingKey) ?? []), mappingKey],\n }\n\n childSchema.required = [...(childSchema.required ?? []), propertyName]\n\n this.set(mappingValue, childSchema)\n }\n }\n })\n }\n })\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...this.get(schema.$ref),\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] = this.get($ref)\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/chunk-X2CIM2ZZ.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { isRef } from 'oas/types';
|
|
2
|
-
import { isPlainObject } from 'remeda';
|
|
3
|
-
import BaseOas from 'oas';
|
|
4
|
-
import OASNormalize from 'oas-normalize';
|
|
5
|
-
import { matchesMimeType } from 'oas/utils';
|
|
6
|
-
import jsonpointer from 'jsonpointer';
|
|
7
|
-
|
|
8
|
-
// src/utils.ts
|
|
9
|
-
function isOpenApiV2Document(doc) {
|
|
10
|
-
return doc && isPlainObject(doc) && !("openapi" in doc);
|
|
11
|
-
}
|
|
12
|
-
function isOpenApiV3_1Document(doc) {
|
|
13
|
-
return doc && isPlainObject(doc) && "openapi" in doc && doc.openapi.startsWith("3.1");
|
|
14
|
-
}
|
|
15
|
-
function isParameterObject(obj) {
|
|
16
|
-
return obj && "in" in obj;
|
|
17
|
-
}
|
|
18
|
-
function isReference(obj) {
|
|
19
|
-
return !!obj && isRef(obj);
|
|
20
|
-
}
|
|
21
|
-
function isRequired(schema) {
|
|
22
|
-
if (!schema) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required;
|
|
26
|
-
}
|
|
27
|
-
function isOptional(schema) {
|
|
28
|
-
return !isRequired(schema);
|
|
29
|
-
}
|
|
30
|
-
var Oas = class extends BaseOas {
|
|
31
|
-
#options = {};
|
|
32
|
-
document = void 0;
|
|
33
|
-
constructor({ oas, user }, options = {}) {
|
|
34
|
-
if (typeof oas === "string") {
|
|
35
|
-
oas = JSON.parse(oas);
|
|
36
|
-
}
|
|
37
|
-
super(oas, user);
|
|
38
|
-
this.document = oas;
|
|
39
|
-
this.#options = options;
|
|
40
|
-
}
|
|
41
|
-
get($ref) {
|
|
42
|
-
const origRef = $ref;
|
|
43
|
-
$ref = $ref.trim();
|
|
44
|
-
if ($ref === "") {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
if ($ref.startsWith("#")) {
|
|
48
|
-
$ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
49
|
-
} else {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
const current = jsonpointer.get(this.api, $ref);
|
|
53
|
-
if (!current) {
|
|
54
|
-
throw new Error(`Could not find a definition for ${origRef}.`);
|
|
55
|
-
}
|
|
56
|
-
return current;
|
|
57
|
-
}
|
|
58
|
-
set($ref, value) {
|
|
59
|
-
$ref = $ref.trim();
|
|
60
|
-
if ($ref === "") {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
if ($ref.startsWith("#")) {
|
|
64
|
-
$ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
65
|
-
jsonpointer.set(this.api, $ref, value);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
resolveDiscriminators() {
|
|
69
|
-
const schemas = this.api.components?.schemas || {};
|
|
70
|
-
Object.entries(schemas).forEach(([key, schemaObject]) => {
|
|
71
|
-
if ("discriminator" in schemaObject) {
|
|
72
|
-
const { mapping = {}, propertyName } = schemaObject.discriminator || {};
|
|
73
|
-
Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
|
|
74
|
-
if (mappingValue) {
|
|
75
|
-
const childSchema = this.get(mappingValue);
|
|
76
|
-
const property = childSchema.properties?.[propertyName];
|
|
77
|
-
if (property) {
|
|
78
|
-
childSchema.properties[propertyName] = {
|
|
79
|
-
...childSchema.properties[propertyName],
|
|
80
|
-
enum: [...property?.enum?.filter((value) => value !== mappingKey) ?? [], mappingKey]
|
|
81
|
-
};
|
|
82
|
-
childSchema.required = [...childSchema.required ?? [], propertyName];
|
|
83
|
-
this.set(mappingValue, childSchema);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
dereferenceWithRef(schema) {
|
|
91
|
-
if (isReference(schema)) {
|
|
92
|
-
return {
|
|
93
|
-
...this.get(schema.$ref),
|
|
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 && 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] = this.get($ref);
|
|
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(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
|
-
export { Oas, isOpenApiV2Document, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired };
|
|
226
|
-
//# sourceMappingURL=chunk-X2CIM2ZZ.js.map
|
|
227
|
-
//# sourceMappingURL=chunk-X2CIM2ZZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings":";;;;;;;;AAMO,SAAS,oBAAoB,GAAqC,EAAA;AACvE,EAAA,OAAO,GAAO,IAAA,aAAA,CAAc,GAAG,CAAA,IAAK,EAAE,SAAa,IAAA,GAAA,CAAA;AACrD;AAKO,SAAS,sBAAsB,GAAuC,EAAA;AAC3E,EAAO,OAAA,GAAA,IAAO,cAAoC,GAAG,CAAA,IAAK,aAAa,GAAO,IAAA,GAAA,CAAI,O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,IAAI,GAAG;AAAA,cACrB,aAAa,cAAe,CAAA,WAAA;AAAA,cAC5B,GAAG;AAAA;AACL;AACF,SACF;AAAA,OACF;AAAA,MACA,EAAE,MAAM,QAAU,EAAA,QAAA,EAAU,EAAI,EAAA,UAAA,EAAY,EAAG;AAAA,KACjD;AAAA;AACF,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;AAAA,KACjB,CAAA;AAED,IAAA,MAAM,aAAa,QAAS,CAAA;AAAA,MAC1B,eAAiB,EAAA,IAAA;AAAA,MACjB,MAAQ,EAAA;AAAA,QACN,QAAU,EAAA;AAAA,UACR,cAAgB,EAAA;AAAA;AAClB;AACF,KACD,CAAA;AAAA;AAEL","file":"chunk-X2CIM2ZZ.js","sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { matchesMimeType } from 'oas/utils'\n\nimport jsonpointer from 'jsonpointer'\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 { OasTypes, OpenAPIV3 } from './index.ts'\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 get($ref: string) {\n const origRef = $ref\n $ref = $ref.trim()\n if ($ref === '') {\n return false\n }\n if ($ref.startsWith('#')) {\n $ref = globalThis.decodeURIComponent($ref.substring(1))\n } else {\n return null\n }\n const current = jsonpointer.get(this.api, $ref)\n\n if (!current) {\n throw new Error(`Could not find a definition for ${origRef}.`)\n }\n return current\n }\n\n set($ref: string, value: unknown) {\n $ref = $ref.trim()\n if ($ref === '') {\n return false\n }\n if ($ref.startsWith('#')) {\n $ref = globalThis.decodeURIComponent($ref.substring(1))\n\n jsonpointer.set(this.api, $ref, value)\n }\n }\n\n resolveDiscriminators(): void {\n const schemas = (this.api.components?.schemas || {}) as Record<string, OasTypes.SchemaObject>\n\n Object.entries(schemas).forEach(([key, schemaObject]) => {\n if ('discriminator' in schemaObject) {\n const { mapping = {}, propertyName } = (schemaObject.discriminator || {}) as OpenAPIV3.DiscriminatorObject\n\n Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {\n if (mappingValue) {\n const childSchema = this.get(mappingValue)\n const property = childSchema.properties?.[propertyName] as SchemaObject\n\n if (property) {\n childSchema.properties[propertyName] = {\n ...childSchema.properties[propertyName],\n enum: [...(property?.enum?.filter((value) => value !== mappingKey) ?? []), mappingKey],\n }\n\n childSchema.required = [...(childSchema.required ?? []), propertyName]\n\n this.set(mappingValue, childSchema)\n }\n }\n })\n }\n })\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...this.get(schema.$ref),\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] = this.get($ref)\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/parser.cjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunk4ZPTFFHL_cjs = require('./chunk-4ZPTFFHL.cjs');
|
|
4
|
-
var openapiCore = require('@redocly/openapi-core');
|
|
5
|
-
var OASNormalize = require('oas-normalize');
|
|
6
|
-
var swagger2openapi = require('swagger2openapi');
|
|
7
|
-
|
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
|
|
10
|
-
var OASNormalize__default = /*#__PURE__*/_interopDefault(OASNormalize);
|
|
11
|
-
var swagger2openapi__default = /*#__PURE__*/_interopDefault(swagger2openapi);
|
|
12
|
-
|
|
13
|
-
async function parse(pathOrApi, oasClass = chunk4ZPTFFHL_cjs.Oas) {
|
|
14
|
-
if (typeof pathOrApi === "string") {
|
|
15
|
-
const config = await openapiCore.loadConfig();
|
|
16
|
-
const bundleResults = await openapiCore.bundle({ ref: pathOrApi, config, base: pathOrApi });
|
|
17
|
-
return parse(bundleResults.bundle.parsed);
|
|
18
|
-
}
|
|
19
|
-
const oasNormalize = new OASNormalize__default.default(pathOrApi, {
|
|
20
|
-
enablePaths: true,
|
|
21
|
-
colorizeErrors: true
|
|
22
|
-
});
|
|
23
|
-
const document = await oasNormalize.load();
|
|
24
|
-
if (chunk4ZPTFFHL_cjs.isOpenApiV2Document(document)) {
|
|
25
|
-
const { openapi } = await swagger2openapi__default.default.convertObj(document, {
|
|
26
|
-
anchors: true
|
|
27
|
-
});
|
|
28
|
-
return new oasClass({ oas: openapi });
|
|
29
|
-
}
|
|
30
|
-
return new oasClass({ oas: document });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
exports.parse = parse;
|
|
34
|
-
//# sourceMappingURL=parser.cjs.map
|
|
35
|
-
//# sourceMappingURL=parser.cjs.map
|
package/dist/parser.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parser/index.ts"],"names":["Oas","loadConfig","bundle","OASNormalize","isOpenApiV2Document","swagger2openapi"],"mappings":";;;;;;;;;;;;AAUA,eAAsB,KAAA,CAAM,SAAiC,EAAA,QAAA,GAAuBA,qBAAmB,EAAA;AACrG,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAMC,sBAAW,EAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAMC,kBAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA;AAE9E,IAAO,OAAA,KAAA,CAAM,aAAc,CAAA,MAAA,CAAO,MAAM,CAAA;AAAA;AAG1C,EAAM,MAAA,YAAA,GAAe,IAAIC,6BAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA;AAAA,GACjB,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA;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;AAAA,KACV,CAAA;AAED,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,SAAwB,CAAA;AAAA;AAGrD,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,UAAU,CAAA;AACvC","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 { isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n return new oasClass({ oas: openapi as OASDocument })\n }\n\n return new oasClass({ oas: document })\n}\n"]}
|
package/dist/parser.d.cts
DELETED
package/dist/parser.d.ts
DELETED
package/dist/parser.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { isOpenApiV2Document, Oas } from './chunk-X2CIM2ZZ.js';
|
|
2
|
-
import { loadConfig, bundle } from '@redocly/openapi-core';
|
|
3
|
-
import OASNormalize from 'oas-normalize';
|
|
4
|
-
import swagger2openapi from 'swagger2openapi';
|
|
5
|
-
|
|
6
|
-
async function parse(pathOrApi, oasClass = Oas) {
|
|
7
|
-
if (typeof pathOrApi === "string") {
|
|
8
|
-
const config = await loadConfig();
|
|
9
|
-
const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi });
|
|
10
|
-
return parse(bundleResults.bundle.parsed);
|
|
11
|
-
}
|
|
12
|
-
const oasNormalize = new OASNormalize(pathOrApi, {
|
|
13
|
-
enablePaths: true,
|
|
14
|
-
colorizeErrors: true
|
|
15
|
-
});
|
|
16
|
-
const document = await oasNormalize.load();
|
|
17
|
-
if (isOpenApiV2Document(document)) {
|
|
18
|
-
const { openapi } = await swagger2openapi.convertObj(document, {
|
|
19
|
-
anchors: true
|
|
20
|
-
});
|
|
21
|
-
return new oasClass({ oas: openapi });
|
|
22
|
-
}
|
|
23
|
-
return new oasClass({ oas: document });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { parse };
|
|
27
|
-
//# sourceMappingURL=parser.js.map
|
|
28
|
-
//# sourceMappingURL=parser.js.map
|
package/dist/parser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parser/index.ts"],"names":[],"mappings":";;;;;AAUA,eAAsB,KAAA,CAAM,SAAiC,EAAA,QAAA,GAAuB,GAAmB,EAAA;AACrG,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAM,UAAW,EAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAM,MAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA;AAE9E,IAAO,OAAA,KAAA,CAAM,aAAc,CAAA,MAAA,CAAO,MAAM,CAAA;AAAA;AAG1C,EAAM,MAAA,YAAA,GAAe,IAAI,YAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA;AAAA,GACjB,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA;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;AAAA,KACV,CAAA;AAED,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,SAAwB,CAAA;AAAA;AAGrD,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,UAAU,CAAA;AACvC","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 { isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n return new oasClass({ oas: openapi as OASDocument })\n }\n\n return new oasClass({ oas: document })\n}\n"]}
|