@kubb/oas 2.26.7 → 2.27.0
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/{Oas-BEe7KZDj.d.cts → Oas-Br0yKhGF.d.cts} +3 -0
- package/dist/{Oas-BEe7KZDj.d.ts → Oas-Br0yKhGF.d.ts} +3 -0
- package/dist/{chunk-UHBNBTKP.cjs → chunk-ATRCKZ2K.cjs} +57 -4
- package/dist/chunk-ATRCKZ2K.cjs.map +1 -0
- package/dist/{chunk-E3CJ2UJM.js → chunk-HGPATTCE.js} +57 -4
- package/dist/chunk-HGPATTCE.js.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/parser.cjs +3 -3
- package/dist/parser.d.cts +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +1 -1
- package/package.json +5 -4
- package/src/Oas.ts +68 -3
- package/dist/chunk-E3CJ2UJM.js.map +0 -1
- package/dist/chunk-UHBNBTKP.cjs.map +0 -1
|
@@ -29,6 +29,9 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
|
|
|
29
29
|
oas: TOAS | OASDocument | string;
|
|
30
30
|
user?: User;
|
|
31
31
|
}, options?: Options);
|
|
32
|
+
get($ref: string): any;
|
|
33
|
+
set($ref: string, value: unknown): false | undefined;
|
|
34
|
+
resolveDiscriminators(): void;
|
|
32
35
|
dereferenceWithRef(schema?: unknown): any;
|
|
33
36
|
getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject$1;
|
|
34
37
|
getRequestSchema(operation: Operation): SchemaObject$1 | undefined;
|
|
@@ -29,6 +29,9 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
|
|
|
29
29
|
oas: TOAS | OASDocument | string;
|
|
30
30
|
user?: User;
|
|
31
31
|
}, options?: Options);
|
|
32
|
+
get($ref: string): any;
|
|
33
|
+
set($ref: string, value: unknown): false | undefined;
|
|
34
|
+
resolveDiscriminators(): void;
|
|
32
35
|
dereferenceWithRef(schema?: unknown): any;
|
|
33
36
|
getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject$1;
|
|
34
37
|
getRequestSchema(operation: Operation): SchemaObject$1 | undefined;
|
|
@@ -36,6 +36,7 @@ function isOptional(schema) {
|
|
|
36
36
|
var _oas = require('oas'); var _oas2 = _interopRequireDefault(_oas);
|
|
37
37
|
var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
|
|
38
38
|
var _utils = require('oas/utils');
|
|
39
|
+
var _jsonpointer = require('jsonpointer'); var _jsonpointer2 = _interopRequireDefault(_jsonpointer);
|
|
39
40
|
var _options, _Oas_instances, getResponseBodyFactory_fn;
|
|
40
41
|
var Oas = class extends _oas2.default {
|
|
41
42
|
constructor({ oas, user }, options = {}) {
|
|
@@ -49,10 +50,62 @@ var Oas = class extends _oas2.default {
|
|
|
49
50
|
this.document = oas;
|
|
50
51
|
__privateSet(this, _options, options);
|
|
51
52
|
}
|
|
53
|
+
get($ref) {
|
|
54
|
+
const origRef = $ref;
|
|
55
|
+
$ref = $ref.trim();
|
|
56
|
+
if ($ref === "") {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if ($ref.startsWith("#")) {
|
|
60
|
+
$ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
61
|
+
} else {
|
|
62
|
+
throw new Error(`Could not find a definition for ${origRef}.`);
|
|
63
|
+
}
|
|
64
|
+
const current = _jsonpointer2.default.get(this.api, $ref);
|
|
65
|
+
if (!current) {
|
|
66
|
+
throw new Error(`Could not find a definition for ${origRef}.`);
|
|
67
|
+
}
|
|
68
|
+
return current;
|
|
69
|
+
}
|
|
70
|
+
set($ref, value) {
|
|
71
|
+
const origRef = $ref;
|
|
72
|
+
$ref = $ref.trim();
|
|
73
|
+
if ($ref === "") {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if ($ref.startsWith("#")) {
|
|
77
|
+
$ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error(`Could not find a definition for ${origRef}.`);
|
|
80
|
+
}
|
|
81
|
+
_jsonpointer2.default.set(this.api, $ref, value);
|
|
82
|
+
}
|
|
83
|
+
resolveDiscriminators() {
|
|
84
|
+
const schemas = _optionalChain([this, 'access', _3 => _3.api, 'access', _4 => _4.components, 'optionalAccess', _5 => _5.schemas]) || {};
|
|
85
|
+
Object.entries(schemas).forEach(([key, schemaObject]) => {
|
|
86
|
+
if ("discriminator" in schemaObject) {
|
|
87
|
+
const { mapping = {}, propertyName } = schemaObject.discriminator || {};
|
|
88
|
+
Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
|
|
89
|
+
if (mappingValue) {
|
|
90
|
+
const childSchema = this.get(mappingValue);
|
|
91
|
+
const property = _optionalChain([childSchema, 'access', _6 => _6.properties, 'optionalAccess', _7 => _7[propertyName]]);
|
|
92
|
+
if (property) {
|
|
93
|
+
childSchema.properties[propertyName] = {
|
|
94
|
+
...childSchema.properties[propertyName],
|
|
95
|
+
enum: [..._nullishCoalesce(_optionalChain([property, 'optionalAccess', _8 => _8.enum, 'optionalAccess', _9 => _9.filter, 'call', _10 => _10((value) => value !== mappingKey)]), () => ( [])), mappingKey]
|
|
96
|
+
};
|
|
97
|
+
childSchema.required = [..._nullishCoalesce(childSchema.required, () => ( [])), propertyName];
|
|
98
|
+
this.set(mappingValue, childSchema);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
52
105
|
dereferenceWithRef(schema) {
|
|
53
106
|
if (isReference(schema)) {
|
|
54
107
|
return {
|
|
55
|
-
...
|
|
108
|
+
...this.get(schema.$ref),
|
|
56
109
|
$ref: schema.$ref
|
|
57
110
|
};
|
|
58
111
|
}
|
|
@@ -64,7 +117,7 @@ var Oas = class extends _oas2.default {
|
|
|
64
117
|
const schema2 = operation.schema.responses[key];
|
|
65
118
|
const $ref = isReference(schema2) ? schema2.$ref : void 0;
|
|
66
119
|
if (schema2 && $ref) {
|
|
67
|
-
operation.schema.responses[key] =
|
|
120
|
+
operation.schema.responses[key] = this.get($ref);
|
|
68
121
|
}
|
|
69
122
|
});
|
|
70
123
|
}
|
|
@@ -105,7 +158,7 @@ var Oas = class extends _oas2.default {
|
|
|
105
158
|
}
|
|
106
159
|
return params.reduce(
|
|
107
160
|
(schema, pathParameters) => {
|
|
108
|
-
const property = _nullishCoalesce(_optionalChain([pathParameters, 'access',
|
|
161
|
+
const property = _nullishCoalesce(_optionalChain([pathParameters, 'access', _11 => _11.content, 'optionalAccess', _12 => _12[contentType], 'optionalAccess', _13 => _13.schema]), () => ( pathParameters.schema));
|
|
109
162
|
const required = [...schema.required || [], pathParameters.required ? pathParameters.name : void 0].filter(Boolean);
|
|
110
163
|
return {
|
|
111
164
|
...schema,
|
|
@@ -196,4 +249,4 @@ getResponseBodyFactory_fn = function(responseBody) {
|
|
|
196
249
|
|
|
197
250
|
|
|
198
251
|
exports.isOpenApiV2Document = isOpenApiV2Document; exports.isOpenApiV3_1Document = isOpenApiV3_1Document; exports.isParameterObject = isParameterObject; exports.isReference = isReference; exports.isRequired = isRequired; exports.isOptional = isOptional; exports.Oas = Oas;
|
|
199
|
-
//# sourceMappingURL=chunk-
|
|
252
|
+
//# sourceMappingURL=chunk-ATRCKZ2K.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/oas/dist/chunk-ATRCKZ2K.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,C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;AACA;AACA;AACF,gRAAC","file":"/home/runner/work/kubb/kubb/packages/oas/dist/chunk-ATRCKZ2K.cjs","sourcesContent":[null,"import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { 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 throw new Error(`Could not find a definition for ${origRef}.`)\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 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 throw new Error(`Could not find a definition for ${origRef}.`)\n }\n\n jsonpointer.set(this.api, $ref, value)\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 parser: {\n validate: {\n colorizeErrors: true,\n schema: false,\n spec: false,\n },\n },\n })\n }\n}\n"]}
|
|
@@ -35,7 +35,8 @@ function isOptional(schema) {
|
|
|
35
35
|
// src/Oas.ts
|
|
36
36
|
import BaseOas from "oas";
|
|
37
37
|
import OASNormalize from "oas-normalize";
|
|
38
|
-
import {
|
|
38
|
+
import { matchesMimeType } from "oas/utils";
|
|
39
|
+
import jsonpointer from "jsonpointer";
|
|
39
40
|
var _options, _Oas_instances, getResponseBodyFactory_fn;
|
|
40
41
|
var Oas = class extends BaseOas {
|
|
41
42
|
constructor({ oas, user }, options = {}) {
|
|
@@ -49,10 +50,62 @@ var Oas = class extends BaseOas {
|
|
|
49
50
|
this.document = oas;
|
|
50
51
|
__privateSet(this, _options, options);
|
|
51
52
|
}
|
|
53
|
+
get($ref) {
|
|
54
|
+
const origRef = $ref;
|
|
55
|
+
$ref = $ref.trim();
|
|
56
|
+
if ($ref === "") {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if ($ref.startsWith("#")) {
|
|
60
|
+
$ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
61
|
+
} else {
|
|
62
|
+
throw new Error(`Could not find a definition for ${origRef}.`);
|
|
63
|
+
}
|
|
64
|
+
const current = jsonpointer.get(this.api, $ref);
|
|
65
|
+
if (!current) {
|
|
66
|
+
throw new Error(`Could not find a definition for ${origRef}.`);
|
|
67
|
+
}
|
|
68
|
+
return current;
|
|
69
|
+
}
|
|
70
|
+
set($ref, value) {
|
|
71
|
+
const origRef = $ref;
|
|
72
|
+
$ref = $ref.trim();
|
|
73
|
+
if ($ref === "") {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if ($ref.startsWith("#")) {
|
|
77
|
+
$ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error(`Could not find a definition for ${origRef}.`);
|
|
80
|
+
}
|
|
81
|
+
jsonpointer.set(this.api, $ref, value);
|
|
82
|
+
}
|
|
83
|
+
resolveDiscriminators() {
|
|
84
|
+
const schemas = this.api.components?.schemas || {};
|
|
85
|
+
Object.entries(schemas).forEach(([key, schemaObject]) => {
|
|
86
|
+
if ("discriminator" in schemaObject) {
|
|
87
|
+
const { mapping = {}, propertyName } = schemaObject.discriminator || {};
|
|
88
|
+
Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
|
|
89
|
+
if (mappingValue) {
|
|
90
|
+
const childSchema = this.get(mappingValue);
|
|
91
|
+
const property = childSchema.properties?.[propertyName];
|
|
92
|
+
if (property) {
|
|
93
|
+
childSchema.properties[propertyName] = {
|
|
94
|
+
...childSchema.properties[propertyName],
|
|
95
|
+
enum: [...property?.enum?.filter((value) => value !== mappingKey) ?? [], mappingKey]
|
|
96
|
+
};
|
|
97
|
+
childSchema.required = [...childSchema.required ?? [], propertyName];
|
|
98
|
+
this.set(mappingValue, childSchema);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
52
105
|
dereferenceWithRef(schema) {
|
|
53
106
|
if (isReference(schema)) {
|
|
54
107
|
return {
|
|
55
|
-
...
|
|
108
|
+
...this.get(schema.$ref),
|
|
56
109
|
$ref: schema.$ref
|
|
57
110
|
};
|
|
58
111
|
}
|
|
@@ -64,7 +117,7 @@ var Oas = class extends BaseOas {
|
|
|
64
117
|
const schema2 = operation.schema.responses[key];
|
|
65
118
|
const $ref = isReference(schema2) ? schema2.$ref : void 0;
|
|
66
119
|
if (schema2 && $ref) {
|
|
67
|
-
operation.schema.responses[key] =
|
|
120
|
+
operation.schema.responses[key] = this.get($ref);
|
|
68
121
|
}
|
|
69
122
|
});
|
|
70
123
|
}
|
|
@@ -196,4 +249,4 @@ export {
|
|
|
196
249
|
isOptional,
|
|
197
250
|
Oas
|
|
198
251
|
};
|
|
199
|
-
//# sourceMappingURL=chunk-
|
|
252
|
+
//# sourceMappingURL=chunk-HGPATTCE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { 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 throw new Error(`Could not find a definition for ${origRef}.`)\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 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 throw new Error(`Could not find a definition for ${origRef}.`)\n }\n\n jsonpointer.set(this.api, $ref, value)\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 parser: {\n validate: {\n colorizeErrors: true,\n schema: false,\n spec: false,\n },\n },\n })\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,SAAS,qBAAqB;AAKvB,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,cAAc,GAAG,KAAK,EAAE,aAAa;AACrD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,cAAoC,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AAC5G;AAMO,SAAS,kBAAkB,KAA6D;AAC7F,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,YAAY,KAA+E;AACzG,SAAO,CAAC,CAAC,OAAO,MAAM,GAAG;AAC3B;AAEO,SAAS,WAAW,QAAgC;AACzD,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,QAAQ,OAAO,QAAQ,IAAI,CAAC,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,OAAO;AAC/E;AAEO,SAAS,WAAW,QAAgC;AACzD,SAAO,CAAC,WAAW,MAAM;AAC3B;;;ACvCA,OAAO,aAAa;AACpB,OAAO,kBAAkB;AACzB,SAAS,uBAAuB;AAEhC,OAAO,iBAAiB;AAJxB;AAiBO,IAAM,MAAN,cAAwC,QAAQ;AAAA,EAIrD,YAAY,EAAE,KAAK,KAAK,GAAsD,UAAmB,CAAC,GAAG;AAC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ACF,CAAC;AAAA,IACH;AAEA,QAAI,sBAAsB;AACxB,aAAO,CAAC,sBAAsB,aAAa,QAAQ,oBAAoB,GAAI,GAAI,aAAa,cAAc,CAAC,aAAa,WAAW,IAAI,CAAC,CAAE;AAAA,IAC5I;AAEA,WAAO;AAAA,EACT;AACF;","names":["schema"]}
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkATRCKZ2Kcjs = require('./chunk-ATRCKZ2K.cjs');
|
|
9
9
|
|
|
10
10
|
// src/types.ts
|
|
11
11
|
var HttpMethods = {
|
|
@@ -31,5 +31,5 @@ var _utils = require('oas/utils');
|
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
exports.HttpMethods = HttpMethods; exports.Oas =
|
|
34
|
+
exports.HttpMethods = HttpMethods; exports.Oas = _chunkATRCKZ2Kcjs.Oas; exports.findSchemaDefinition = _utils.findSchemaDefinition; exports.isOpenApiV3_1Document = _chunkATRCKZ2Kcjs.isOpenApiV3_1Document; exports.isOptional = _chunkATRCKZ2Kcjs.isOptional; exports.isParameterObject = _chunkATRCKZ2Kcjs.isParameterObject; exports.isReference = _chunkATRCKZ2Kcjs.isReference; exports.isRequired = _chunkATRCKZ2Kcjs.isRequired; exports.matchesMimeType = _utils.matchesMimeType;
|
|
35
35
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { H as HttpMethods, O as Oas, S as SchemaObject, c as contentType } from './Oas-
|
|
1
|
+
export { H as HttpMethods, O as Oas, S as SchemaObject, c as contentType } from './Oas-Br0yKhGF.cjs';
|
|
2
2
|
export { findSchemaDefinition, matchesMimeType } from 'oas/utils';
|
|
3
3
|
import * as OasTypes from 'oas/types';
|
|
4
4
|
import { ParameterObject, SchemaObject } from 'oas/types';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { H as HttpMethods, O as Oas, S as SchemaObject, c as contentType } from './Oas-
|
|
1
|
+
export { H as HttpMethods, O as Oas, S as SchemaObject, c as contentType } from './Oas-Br0yKhGF.js';
|
|
2
2
|
export { findSchemaDefinition, matchesMimeType } from 'oas/utils';
|
|
3
3
|
import * as OasTypes from 'oas/types';
|
|
4
4
|
import { ParameterObject, SchemaObject } from 'oas/types';
|
package/dist/index.js
CHANGED
package/dist/parser.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkATRCKZ2Kcjs = require('./chunk-ATRCKZ2K.cjs');
|
|
5
5
|
|
|
6
6
|
// src/parser/index.ts
|
|
7
7
|
var _openapicore = require('@redocly/openapi-core');
|
|
8
8
|
var _oasnormalize = require('oas-normalize'); var _oasnormalize2 = _interopRequireDefault(_oasnormalize);
|
|
9
9
|
var _swagger2openapi = require('swagger2openapi'); var _swagger2openapi2 = _interopRequireDefault(_swagger2openapi);
|
|
10
|
-
async function parse(pathOrApi, oasClass =
|
|
10
|
+
async function parse(pathOrApi, oasClass = _chunkATRCKZ2Kcjs.Oas) {
|
|
11
11
|
if (typeof pathOrApi === "string") {
|
|
12
12
|
const config = await _openapicore.loadConfig.call(void 0, );
|
|
13
13
|
const bundleResults = await _openapicore.bundle.call(void 0, { ref: pathOrApi, config, base: pathOrApi });
|
|
@@ -18,7 +18,7 @@ async function parse(pathOrApi, oasClass = _chunkUHBNBTKPcjs.Oas) {
|
|
|
18
18
|
colorizeErrors: true
|
|
19
19
|
});
|
|
20
20
|
const document = await oasNormalize.load();
|
|
21
|
-
if (
|
|
21
|
+
if (_chunkATRCKZ2Kcjs.isOpenApiV2Document.call(void 0, document)) {
|
|
22
22
|
const { openapi } = await _swagger2openapi2.default.convertObj(document, {
|
|
23
23
|
anchors: true
|
|
24
24
|
});
|
package/dist/parser.d.cts
CHANGED
package/dist/parser.d.ts
CHANGED
package/dist/parser.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/oas",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.27.0",
|
|
4
4
|
"description": "Oas helpers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@redocly/openapi-core": "^1.25.3",
|
|
52
52
|
"hotscript": "^1.0.13",
|
|
53
53
|
"json-schema-to-ts": "^3.1.1",
|
|
54
|
+
"jsonpointer": "^5.0.1",
|
|
54
55
|
"oas": "^24.9.0",
|
|
55
56
|
"oas-normalize": "^11.1.2",
|
|
56
57
|
"openapi-types": "^12.1.3",
|
|
@@ -64,9 +65,9 @@
|
|
|
64
65
|
"expect-type": "^0.19.0",
|
|
65
66
|
"tsup": "^8.3.0",
|
|
66
67
|
"typescript": "^5.6.2",
|
|
67
|
-
"@kubb/config-biome": "2.
|
|
68
|
-
"@kubb/config-ts": "2.
|
|
69
|
-
"@kubb/config-tsup": "2.
|
|
68
|
+
"@kubb/config-biome": "2.27.0",
|
|
69
|
+
"@kubb/config-ts": "2.27.0",
|
|
70
|
+
"@kubb/config-tsup": "2.27.0"
|
|
70
71
|
},
|
|
71
72
|
"engines": {
|
|
72
73
|
"node": ">=18"
|
package/src/Oas.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import BaseOas from 'oas'
|
|
2
2
|
import OASNormalize from 'oas-normalize'
|
|
3
|
-
import {
|
|
3
|
+
import { matchesMimeType } from 'oas/utils'
|
|
4
|
+
|
|
5
|
+
import jsonpointer from 'jsonpointer'
|
|
4
6
|
|
|
5
7
|
import { isReference } from './utils.ts'
|
|
6
8
|
|
|
7
9
|
import type { Operation } from 'oas/operation'
|
|
8
10
|
import type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'
|
|
11
|
+
import type { OasTypes, OpenAPIV3 } from './index.ts'
|
|
9
12
|
import type { contentType } from './types.ts'
|
|
10
13
|
|
|
11
14
|
type Options = {
|
|
@@ -27,10 +30,72 @@ export class Oas<const TOAS = unknown> extends BaseOas {
|
|
|
27
30
|
this.#options = options
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
get($ref: string) {
|
|
34
|
+
const origRef = $ref
|
|
35
|
+
$ref = $ref.trim()
|
|
36
|
+
if ($ref === '') {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
if ($ref.startsWith('#')) {
|
|
40
|
+
$ref = globalThis.decodeURIComponent($ref.substring(1))
|
|
41
|
+
} else {
|
|
42
|
+
throw new Error(`Could not find a definition for ${origRef}.`)
|
|
43
|
+
}
|
|
44
|
+
const current = jsonpointer.get(this.api, $ref)
|
|
45
|
+
|
|
46
|
+
if (!current) {
|
|
47
|
+
throw new Error(`Could not find a definition for ${origRef}.`)
|
|
48
|
+
}
|
|
49
|
+
return current
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
set($ref: string, value: unknown) {
|
|
53
|
+
const origRef = $ref
|
|
54
|
+
$ref = $ref.trim()
|
|
55
|
+
if ($ref === '') {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
if ($ref.startsWith('#')) {
|
|
59
|
+
$ref = globalThis.decodeURIComponent($ref.substring(1))
|
|
60
|
+
} else {
|
|
61
|
+
throw new Error(`Could not find a definition for ${origRef}.`)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
jsonpointer.set(this.api, $ref, value)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
resolveDiscriminators(): void {
|
|
68
|
+
const schemas = (this.api.components?.schemas || {}) as Record<string, OasTypes.SchemaObject>
|
|
69
|
+
|
|
70
|
+
Object.entries(schemas).forEach(([key, schemaObject]) => {
|
|
71
|
+
if ('discriminator' in schemaObject) {
|
|
72
|
+
const { mapping = {}, propertyName } = (schemaObject.discriminator || {}) as OpenAPIV3.DiscriminatorObject
|
|
73
|
+
|
|
74
|
+
Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
|
|
75
|
+
if (mappingValue) {
|
|
76
|
+
const childSchema = this.get(mappingValue)
|
|
77
|
+
const property = childSchema.properties?.[propertyName] as SchemaObject
|
|
78
|
+
|
|
79
|
+
if (property) {
|
|
80
|
+
childSchema.properties[propertyName] = {
|
|
81
|
+
...childSchema.properties[propertyName],
|
|
82
|
+
enum: [...(property?.enum?.filter((value) => value !== mappingKey) ?? []), mappingKey],
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
childSchema.required = [...(childSchema.required ?? []), propertyName]
|
|
86
|
+
|
|
87
|
+
this.set(mappingValue, childSchema)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
30
95
|
dereferenceWithRef(schema?: unknown) {
|
|
31
96
|
if (isReference(schema)) {
|
|
32
97
|
return {
|
|
33
|
-
...
|
|
98
|
+
...this.get(schema.$ref),
|
|
34
99
|
$ref: schema.$ref,
|
|
35
100
|
}
|
|
36
101
|
}
|
|
@@ -102,7 +167,7 @@ export class Oas<const TOAS = unknown> extends BaseOas {
|
|
|
102
167
|
const $ref = isReference(schema) ? schema.$ref : undefined
|
|
103
168
|
|
|
104
169
|
if (schema && $ref) {
|
|
105
|
-
operation.schema.responses![key] =
|
|
170
|
+
operation.schema.responses![key] = this.get($ref)
|
|
106
171
|
}
|
|
107
172
|
})
|
|
108
173
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...findSchemaDefinition(schema.$ref, this.api),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = findSchemaDefinition($ref, this.api)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate({\n parser: {\n validate: {\n colorizeErrors: true,\n schema: false,\n spec: false,\n },\n },\n })\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,OAAO,gBAAgB;AAChC,SAAS,qBAAqB;AAKvB,SAAS,oBAAoB,KAAqC;AACvE,SAAO,OAAO,cAAc,GAAG,KAAK,EAAE,aAAa;AACrD;AAKO,SAAS,sBAAsB,KAAuC;AAC3E,SAAO,OAAO,cAAoC,GAAG,KAAK,aAAa,OAAO,IAAI,QAAQ,WAAW,KAAK;AAC5G;AAMO,SAAS,kBAAkB,KAA6D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AE,CAAA,EAAG;AACrD,QAAA,qBAAA,EAAuB,EAAA;AAAA,MACzB;AAAA,IACF,CAAC,CAAA;AAED,IAAA,GAAA,CAAI,CAAC,oBAAA,EAAsB;AACzB,MAAA,YAAA,CAAa,OAAA,CAAQ,CAAC,EAAA,EAAA,GAAe;AACnC,QAAA,GAAA,CAAI,CAAC,oBAAA,EAAsB;AACzB,UAAA,qBAAA,EAAuB,EAAA;AAAA,QACzB;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAEA,IAAA,GAAA,CAAI,oBAAA,EAAsB;AACxB,MAAA,OAAO,CAAC,oBAAA,EAAsB,YAAA,CAAa,OAAA,CAAQ,oBAAoB,CAAA,EAAI,GAAI,YAAA,CAAa,YAAA,EAAc,CAAC,YAAA,CAAa,WAAW,EAAA,EAAI,CAAC,CAAE,CAAA;AAAA,IAC5I;AAEA,IAAA,OAAO,KAAA;AAAA,EACT,CAAA;AACF,CAAA;AF6FF;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,gRAAC","file":"/home/runner/work/kubb/kubb/packages/oas/dist/chunk-UHBNBTKP.cjs","sourcesContent":[null,"import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...findSchemaDefinition(schema.$ref, this.api),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = findSchemaDefinition($ref, this.api)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate({\n parser: {\n validate: {\n colorizeErrors: true,\n schema: false,\n spec: false,\n },\n },\n })\n }\n}\n"]}
|