@kubb/adapter-oas 5.0.0-beta.63 → 5.0.0-beta.65
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 +86 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +87 -195
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
- package/src/adapter.bench.ts +0 -60
- package/src/adapter.ts +0 -207
- package/src/bundler.ts +0 -71
- package/src/constants.ts +0 -135
- package/src/dedupe.ts +0 -237
- package/src/dialect.ts +0 -42
- package/src/discriminator.ts +0 -132
- package/src/factory.ts +0 -180
- package/src/guards.ts +0 -68
- package/src/index.ts +0 -15
- package/src/mime.ts +0 -21
- package/src/operation.ts +0 -194
- package/src/parser.ts +0 -1129
- package/src/refs.ts +0 -86
- package/src/resolvers.ts +0 -590
- package/src/schemaDiagnostics.ts +0 -76
- package/src/stream.ts +0 -221
- package/src/types.ts +0 -235
- /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as __name } from "./
|
|
1
|
+
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { AdapterFactoryOptions, ast } from "@kubb/core";
|
|
3
3
|
|
|
4
4
|
//#region ../../node_modules/.pnpm/@types+json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts
|
|
@@ -1133,7 +1133,7 @@ type SchemaObject$1 = {
|
|
|
1133
1133
|
* Allowed values for this schema.
|
|
1134
1134
|
*/
|
|
1135
1135
|
enum?: Array<string | number | boolean | null>;
|
|
1136
|
-
} & (
|
|
1136
|
+
} & (OpenAPIV3_1.SchemaObject | JSONSchema4 | JSONSchema6 | JSONSchema7);
|
|
1137
1137
|
/**
|
|
1138
1138
|
* HTTP method in the lowercase form an OpenAPI path item uses for its keys.
|
|
1139
1139
|
*/
|
|
@@ -1141,27 +1141,27 @@ type HttpMethod = Lowercase<ast.HttpMethod>;
|
|
|
1141
1141
|
/**
|
|
1142
1142
|
* Normalized OpenAPI document after parsing.
|
|
1143
1143
|
*/
|
|
1144
|
-
type Document =
|
|
1144
|
+
type Document = OpenAPIV3_1.Document & Record<string, unknown>;
|
|
1145
1145
|
/**
|
|
1146
1146
|
* Single operation object (the `get`/`post`/… entry on a path item) plus any vendor extensions.
|
|
1147
1147
|
*/
|
|
1148
|
-
type OperationObject$1 =
|
|
1148
|
+
type OperationObject$1 = OpenAPIV3_1.OperationObject & Record<string, unknown>;
|
|
1149
1149
|
/**
|
|
1150
1150
|
* Discriminator object for `oneOf`/`anyOf` schemas in OpenAPI.
|
|
1151
1151
|
*/
|
|
1152
|
-
type DiscriminatorObject$1 =
|
|
1152
|
+
type DiscriminatorObject$1 = OpenAPIV3_1.DiscriminatorObject;
|
|
1153
1153
|
/**
|
|
1154
1154
|
* OpenAPI reference object pointing to a schema definition via `$ref`.
|
|
1155
1155
|
*/
|
|
1156
|
-
type ReferenceObject$1 =
|
|
1156
|
+
type ReferenceObject$1 = OpenAPIV3_1.ReferenceObject;
|
|
1157
1157
|
/**
|
|
1158
1158
|
* OpenAPI response object holding the content and headers for one status code.
|
|
1159
1159
|
*/
|
|
1160
|
-
type ResponseObject$1 =
|
|
1160
|
+
type ResponseObject$1 = OpenAPIV3_1.ResponseObject;
|
|
1161
1161
|
/**
|
|
1162
1162
|
* OpenAPI media type object that maps a content-type string to its schema.
|
|
1163
1163
|
*/
|
|
1164
|
-
type MediaTypeObject$1 =
|
|
1164
|
+
type MediaTypeObject$1 = OpenAPIV3_1.MediaTypeObject;
|
|
1165
1165
|
/**
|
|
1166
1166
|
* Configuration for the OpenAPI adapter: spec validation, content-type selection,
|
|
1167
1167
|
* server URL resolution, and how schema types are derived.
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import "./
|
|
1
|
+
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { Diagnostics, ast, createAdapter } from "@kubb/core";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { access, readFile } from "node:fs/promises";
|
|
5
5
|
import { compileErrors, validate } from "@readme/openapi-parser";
|
|
6
|
+
import { upgrade } from "@scalar/openapi-upgrader";
|
|
6
7
|
import { parse } from "yaml";
|
|
7
8
|
import { bundle } from "api-ref-bundler";
|
|
8
9
|
import { macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion } from "@kubb/ast/macros";
|
|
@@ -52,18 +53,6 @@ const SUPPORTED_METHODS = new Set([
|
|
|
52
53
|
"trace"
|
|
53
54
|
]);
|
|
54
55
|
/**
|
|
55
|
-
* OpenAPI version string written into the stub document created during multi-spec merges.
|
|
56
|
-
*/
|
|
57
|
-
const MERGE_OPENAPI_VERSION = "3.0.0";
|
|
58
|
-
/**
|
|
59
|
-
* Fallback `info.title` placed in the stub document when merging multiple API files.
|
|
60
|
-
*/
|
|
61
|
-
const MERGE_DEFAULT_TITLE = "Merged API";
|
|
62
|
-
/**
|
|
63
|
-
* Fallback `info.version` placed in the stub document when merging multiple API files.
|
|
64
|
-
*/
|
|
65
|
-
const MERGE_DEFAULT_VERSION = "1.0.0";
|
|
66
|
-
/**
|
|
67
56
|
* Set of JSON Schema keywords that prevent a schema fragment from being inlined during `allOf` flattening.
|
|
68
57
|
*
|
|
69
58
|
* A fragment that contains any of these keys carries structural meaning of its own and must stay as a separate
|
|
@@ -143,15 +132,6 @@ const formatMap = {
|
|
|
143
132
|
* ```
|
|
144
133
|
*/
|
|
145
134
|
const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
|
|
146
|
-
/**
|
|
147
|
-
* Maps the `unknownType`/`emptySchemaType` option string to its `ScalarSchemaType` constant.
|
|
148
|
-
* A `Map` (over a plain object) lets callers test key membership with `.has()`.
|
|
149
|
-
*/
|
|
150
|
-
const typeOptionMap = new Map([
|
|
151
|
-
["any", ast.schemaTypes.any],
|
|
152
|
-
["unknown", ast.schemaTypes.unknown],
|
|
153
|
-
["void", ast.schemaTypes.void]
|
|
154
|
-
]);
|
|
155
135
|
//#endregion
|
|
156
136
|
//#region ../../internals/utils/src/casing.ts
|
|
157
137
|
/**
|
|
@@ -292,40 +272,6 @@ async function read(path) {
|
|
|
292
272
|
return readFile(path, { encoding: "utf8" });
|
|
293
273
|
}
|
|
294
274
|
//#endregion
|
|
295
|
-
//#region ../../internals/utils/src/object.ts
|
|
296
|
-
/**
|
|
297
|
-
* Returns `true` when `value` is a plain (non-null, non-array) object.
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* ```ts
|
|
301
|
-
* isPlainObject({}) // true
|
|
302
|
-
* isPlainObject([]) // false
|
|
303
|
-
* isPlainObject(null) // false
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
function isPlainObject(value) {
|
|
307
|
-
return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Recursively merges `source` into `target`, combining nested plain objects.
|
|
311
|
-
* Arrays and non-object values from `source` override the corresponding values in `target`.
|
|
312
|
-
*
|
|
313
|
-
* @example
|
|
314
|
-
* ```ts
|
|
315
|
-
* mergeDeep({ a: { x: 1 } }, { a: { y: 2 } })
|
|
316
|
-
* // { a: { x: 1, y: 2 } }
|
|
317
|
-
* ```
|
|
318
|
-
*/
|
|
319
|
-
function mergeDeep(target, source) {
|
|
320
|
-
const result = { ...target };
|
|
321
|
-
for (const key of Object.keys(source)) {
|
|
322
|
-
const sv = source[key];
|
|
323
|
-
const tv = result[key];
|
|
324
|
-
result[key] = sv !== null && typeof sv === "object" && !Array.isArray(sv) && tv !== null && typeof tv === "object" && !Array.isArray(tv) ? mergeDeep(tv, sv) : sv;
|
|
325
|
-
}
|
|
326
|
-
return result;
|
|
327
|
-
}
|
|
328
|
-
//#endregion
|
|
329
275
|
//#region ../../internals/utils/src/reserved.ts
|
|
330
276
|
/**
|
|
331
277
|
* JavaScript and Java reserved words.
|
|
@@ -573,128 +519,29 @@ async function bundleDocument(pathOrUrl) {
|
|
|
573
519
|
return await bundle(pathOrUrl, resolver);
|
|
574
520
|
}
|
|
575
521
|
//#endregion
|
|
576
|
-
//#region src/guards.ts
|
|
577
|
-
/**
|
|
578
|
-
* Returns `true` when `doc` is a Swagger 2.0 document (no `openapi` key).
|
|
579
|
-
*
|
|
580
|
-
* @example
|
|
581
|
-
* ```ts
|
|
582
|
-
* if (isOpenApiV2Document(doc)) {
|
|
583
|
-
* // doc is OpenAPIV2.Document
|
|
584
|
-
* }
|
|
585
|
-
* ```
|
|
586
|
-
*/
|
|
587
|
-
function isOpenApiV2Document(doc) {
|
|
588
|
-
return !!doc && isPlainObject(doc) && !("openapi" in doc);
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* Returns `true` when a schema should be treated as nullable.
|
|
592
|
-
*
|
|
593
|
-
* Recognizes all nullable signals across OAS versions: `nullable: true` (OAS 3.0),
|
|
594
|
-
* `x-nullable: true` (vendor extension), `type: 'null'`, and `type: ['null', ...]` (OAS 3.1).
|
|
595
|
-
*
|
|
596
|
-
* @example
|
|
597
|
-
* ```ts
|
|
598
|
-
* isNullable({ type: 'string', nullable: true }) // true
|
|
599
|
-
* isNullable({ type: ['string', 'null'] }) // true
|
|
600
|
-
* isNullable({ type: 'string' }) // false
|
|
601
|
-
* ```
|
|
602
|
-
*/
|
|
603
|
-
function isNullable(schema) {
|
|
604
|
-
if ((schema?.nullable ?? schema?.["x-nullable"]) === true) return true;
|
|
605
|
-
const schemaType = schema?.type;
|
|
606
|
-
if (schemaType === "null") return true;
|
|
607
|
-
if (Array.isArray(schemaType)) return schemaType.includes("null");
|
|
608
|
-
return false;
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Returns `true` when `obj` is an OpenAPI `$ref` pointer object.
|
|
612
|
-
*
|
|
613
|
-
* @example
|
|
614
|
-
* ```ts
|
|
615
|
-
* isReference({ $ref: '#/components/schemas/Pet' }) // true
|
|
616
|
-
* isReference({ type: 'string' }) // false
|
|
617
|
-
* ```
|
|
618
|
-
*/
|
|
619
|
-
function isReference(obj) {
|
|
620
|
-
return !!obj && typeof obj === "object" && "$ref" in obj;
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Returns `true` when `obj` is a schema with a structured OAS 3.x `discriminator` object.
|
|
624
|
-
*
|
|
625
|
-
* @example
|
|
626
|
-
* ```ts
|
|
627
|
-
* isDiscriminator({ discriminator: { propertyName: 'type', mapping: {} } }) // true
|
|
628
|
-
* isDiscriminator({ discriminator: 'type' }) // false (Swagger 2 string form)
|
|
629
|
-
* ```
|
|
630
|
-
*/
|
|
631
|
-
function isDiscriminator(obj) {
|
|
632
|
-
const record = obj;
|
|
633
|
-
return !!obj && !!record["discriminator"] && typeof record["discriminator"] !== "string";
|
|
634
|
-
}
|
|
635
|
-
//#endregion
|
|
636
522
|
//#region src/factory.ts
|
|
637
523
|
/**
|
|
638
524
|
* Loads and bundles an OpenAPI document, returning the raw `Document`.
|
|
639
525
|
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
643
|
-
*
|
|
526
|
+
* A string is a file path or URL: it is bundled via `api-ref-bundler`, hoisting external file
|
|
527
|
+
* schemas into named `components.schemas` entries so generators can emit named types and imports.
|
|
528
|
+
* An object is treated as an already-parsed document. Swagger 2.0 and OpenAPI 3.0 documents are
|
|
529
|
+
* up-converted to OpenAPI 3.1 via `@scalar/openapi-upgrader`.
|
|
644
530
|
*
|
|
645
531
|
* @example
|
|
646
532
|
* ```ts
|
|
647
533
|
* const document = await parseDocument('./openapi.yaml')
|
|
648
|
-
* const document = await
|
|
649
|
-
* ```
|
|
650
|
-
*/
|
|
651
|
-
async function parseDocument(pathOrApi, { canBundle = true } = {}) {
|
|
652
|
-
if (typeof pathOrApi === "string" && canBundle) return parseDocument(await bundleDocument(pathOrApi), { canBundle: false });
|
|
653
|
-
const document = typeof pathOrApi === "string" ? parse(pathOrApi) : pathOrApi;
|
|
654
|
-
if (isOpenApiV2Document(document)) {
|
|
655
|
-
const { default: swagger2openapi } = await import("swagger2openapi");
|
|
656
|
-
const { openapi } = await swagger2openapi.convertObj(document, { anchors: true });
|
|
657
|
-
return openapi;
|
|
658
|
-
}
|
|
659
|
-
return document;
|
|
660
|
-
}
|
|
661
|
-
/**
|
|
662
|
-
* Deep-merges multiple OpenAPI documents into a single `Document`.
|
|
663
|
-
*
|
|
664
|
-
* Each document is parsed independently, then deep-merged into one in array order.
|
|
665
|
-
* Throws when the input array is empty.
|
|
666
|
-
*
|
|
667
|
-
* @example
|
|
668
|
-
* ```ts
|
|
669
|
-
* const document = await mergeDocuments(['./pets.yaml', './orders.yaml'])
|
|
534
|
+
* const document = await parseDocument(rawDocumentObject)
|
|
670
535
|
* ```
|
|
671
536
|
*/
|
|
672
|
-
async function
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
code: Diagnostics.code.inputRequired,
|
|
676
|
-
severity: "error",
|
|
677
|
-
message: "No OAS documents were provided for merging.",
|
|
678
|
-
help: "Pass at least one path or document to `input.path`.",
|
|
679
|
-
location: { kind: "config" }
|
|
680
|
-
});
|
|
681
|
-
const seed = {
|
|
682
|
-
openapi: MERGE_OPENAPI_VERSION,
|
|
683
|
-
info: {
|
|
684
|
-
title: MERGE_DEFAULT_TITLE,
|
|
685
|
-
version: MERGE_DEFAULT_VERSION
|
|
686
|
-
},
|
|
687
|
-
paths: {},
|
|
688
|
-
components: { schemas: {} }
|
|
689
|
-
};
|
|
690
|
-
return parseDocument(documents.reduce((acc, current) => mergeDeep(acc, current), seed));
|
|
537
|
+
async function parseDocument(pathOrApi) {
|
|
538
|
+
if (typeof pathOrApi === "string") return parseDocument(await bundleDocument(pathOrApi));
|
|
539
|
+
return upgrade(pathOrApi, "3.1");
|
|
691
540
|
}
|
|
692
541
|
/**
|
|
693
542
|
* Creates a `Document` from an `AdapterSource`.
|
|
694
543
|
*
|
|
695
|
-
* Handles all three source types:
|
|
696
544
|
* - `{ type: 'path' }` resolves and bundles a local file path or remote URL.
|
|
697
|
-
* - `{ type: 'paths' }` merges multiple file paths into a single document.
|
|
698
545
|
* - `{ type: 'data' }` parses an inline string (YAML/JSON) or raw object.
|
|
699
546
|
*
|
|
700
547
|
* @example
|
|
@@ -704,11 +551,7 @@ async function mergeDocuments(pathOrApi) {
|
|
|
704
551
|
* ```
|
|
705
552
|
*/
|
|
706
553
|
async function parseFromConfig(source) {
|
|
707
|
-
if (source.type === "data")
|
|
708
|
-
if (typeof source.data === "object") return parseDocument(structuredClone(source.data));
|
|
709
|
-
return parseDocument(source.data, { canBundle: false });
|
|
710
|
-
}
|
|
711
|
-
if (source.type === "paths") return mergeDocuments(source.paths);
|
|
554
|
+
if (source.type === "data") return parseDocument(typeof source.data === "string" ? parse(source.data) : structuredClone(source.data));
|
|
712
555
|
if (Url.canParse(source.path)) return parseDocument(source.path);
|
|
713
556
|
const resolved = path.resolve(path.dirname(source.path), source.path);
|
|
714
557
|
await assertInputExists(resolved);
|
|
@@ -767,7 +610,7 @@ function createRefNode(node, target) {
|
|
|
767
610
|
deprecated: node.deprecated,
|
|
768
611
|
description: node.description,
|
|
769
612
|
default: node.default,
|
|
770
|
-
|
|
613
|
+
examples: node.examples
|
|
771
614
|
});
|
|
772
615
|
}
|
|
773
616
|
/**
|
|
@@ -908,6 +751,53 @@ function plan(roots, context) {
|
|
|
908
751
|
};
|
|
909
752
|
}
|
|
910
753
|
//#endregion
|
|
754
|
+
//#region src/guards.ts
|
|
755
|
+
/**
|
|
756
|
+
* Returns `true` when a schema should be treated as nullable.
|
|
757
|
+
*
|
|
758
|
+
* Recognizes all nullable signals across OAS versions: `nullable: true` (OAS 3.0),
|
|
759
|
+
* `x-nullable: true` (vendor extension), `type: 'null'`, and `type: ['null', ...]` (OAS 3.1).
|
|
760
|
+
*
|
|
761
|
+
* @example
|
|
762
|
+
* ```ts
|
|
763
|
+
* isNullable({ type: 'string', nullable: true }) // true
|
|
764
|
+
* isNullable({ type: ['string', 'null'] }) // true
|
|
765
|
+
* isNullable({ type: 'string' }) // false
|
|
766
|
+
* ```
|
|
767
|
+
*/
|
|
768
|
+
function isNullable(schema) {
|
|
769
|
+
if ((schema?.nullable ?? schema?.["x-nullable"]) === true) return true;
|
|
770
|
+
const schemaType = schema?.type;
|
|
771
|
+
if (schemaType === "null") return true;
|
|
772
|
+
if (Array.isArray(schemaType)) return schemaType.includes("null");
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Returns `true` when `obj` is an OpenAPI `$ref` pointer object.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* ```ts
|
|
780
|
+
* isReference({ $ref: '#/components/schemas/Pet' }) // true
|
|
781
|
+
* isReference({ type: 'string' }) // false
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
784
|
+
function isReference(obj) {
|
|
785
|
+
return !!obj && typeof obj === "object" && "$ref" in obj;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Returns `true` when `obj` is a schema with a structured OAS 3.x `discriminator` object.
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* ```ts
|
|
792
|
+
* isDiscriminator({ discriminator: { propertyName: 'type', mapping: {} } }) // true
|
|
793
|
+
* isDiscriminator({ discriminator: 'type' }) // false (Swagger 2 string form)
|
|
794
|
+
* ```
|
|
795
|
+
*/
|
|
796
|
+
function isDiscriminator(obj) {
|
|
797
|
+
const record = obj;
|
|
798
|
+
return !!obj && !!record["discriminator"] && typeof record["discriminator"] !== "string";
|
|
799
|
+
}
|
|
800
|
+
//#endregion
|
|
911
801
|
//#region src/refs.ts
|
|
912
802
|
const _refCache = /* @__PURE__ */ new WeakMap();
|
|
913
803
|
/**
|
|
@@ -1389,14 +1279,16 @@ function getResponseBody(responseBody, contentType) {
|
|
|
1389
1279
|
* getResponseSchema(document, operation, '4XX') // {}
|
|
1390
1280
|
* ```
|
|
1391
1281
|
*/
|
|
1392
|
-
function
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
}
|
|
1282
|
+
function resolveResponseRefs(document, operation) {
|
|
1283
|
+
const responses = operation.schema.responses;
|
|
1284
|
+
if (!responses) return;
|
|
1285
|
+
for (const key in responses) {
|
|
1286
|
+
const schema = responses[key];
|
|
1287
|
+
if (schema && isReference(schema)) responses[key] = resolveRef(document, schema.$ref);
|
|
1399
1288
|
}
|
|
1289
|
+
}
|
|
1290
|
+
function getResponseSchema(document, operation, statusCode, options = {}) {
|
|
1291
|
+
resolveResponseRefs(document, operation);
|
|
1400
1292
|
const responseBody = getResponseBody(getResponseByStatusCode({
|
|
1401
1293
|
document,
|
|
1402
1294
|
operation,
|
|
@@ -1540,9 +1432,6 @@ const semanticSuffixes = {
|
|
|
1540
1432
|
responses: "Response",
|
|
1541
1433
|
requestBodies: "Request"
|
|
1542
1434
|
};
|
|
1543
|
-
function getSemanticSuffix(source) {
|
|
1544
|
-
return semanticSuffixes[source];
|
|
1545
|
-
}
|
|
1546
1435
|
function resolveSchemaRef(document, schema) {
|
|
1547
1436
|
if (!isReference(schema)) return schema;
|
|
1548
1437
|
const resolved = resolveRef(document, schema.$ref);
|
|
@@ -1597,7 +1486,7 @@ function getSchemas(document, { contentType }) {
|
|
|
1597
1486
|
}
|
|
1598
1487
|
}
|
|
1599
1488
|
items.forEach((item, index) => {
|
|
1600
|
-
const suffix = isSingle ? "" : hasMultipleSources ?
|
|
1489
|
+
const suffix = isSingle ? "" : hasMultipleSources ? semanticSuffixes[item.source] : index === 0 ? "" : String(index + 1);
|
|
1601
1490
|
const uniqueName = item.originalName + suffix;
|
|
1602
1491
|
schemas[uniqueName] = item.schema;
|
|
1603
1492
|
nameMapping.set(`#/components/${item.source}/${item.originalName}`, uniqueName);
|
|
@@ -1644,6 +1533,15 @@ function getDateType(options, format) {
|
|
|
1644
1533
|
/**
|
|
1645
1534
|
* Collects the shared metadata fields passed to every `createSchema` call.
|
|
1646
1535
|
*/
|
|
1536
|
+
/**
|
|
1537
|
+
* Reads schema examples as an array. OAS 3.1 uses an `examples` array, but specs (including ones
|
|
1538
|
+
* labeled 3.1) still use the singular OAS 3.0 `example`, which the upgrader only converts on the
|
|
1539
|
+
* 3.0 -> 3.1 hop. Normalize both into one array so the AST node exposes only `examples`.
|
|
1540
|
+
*/
|
|
1541
|
+
function extractExamples(schema) {
|
|
1542
|
+
if (Array.isArray(schema.examples)) return schema.examples;
|
|
1543
|
+
return schema.example !== void 0 ? [schema.example] : void 0;
|
|
1544
|
+
}
|
|
1647
1545
|
function buildSchemaNode(schema, name, nullable, defaultValue) {
|
|
1648
1546
|
return {
|
|
1649
1547
|
name,
|
|
@@ -1654,7 +1552,7 @@ function buildSchemaNode(schema, name, nullable, defaultValue) {
|
|
|
1654
1552
|
readOnly: schema.readOnly,
|
|
1655
1553
|
writeOnly: schema.writeOnly,
|
|
1656
1554
|
default: defaultValue,
|
|
1657
|
-
|
|
1555
|
+
examples: extractExamples(schema),
|
|
1658
1556
|
format: schema.format
|
|
1659
1557
|
};
|
|
1660
1558
|
}
|
|
@@ -1690,13 +1588,7 @@ function getRequestBodyContentTypes(document, operation) {
|
|
|
1690
1588
|
* ```
|
|
1691
1589
|
*/
|
|
1692
1590
|
function getResponseBodyContentTypes(document, operation, statusCode) {
|
|
1693
|
-
|
|
1694
|
-
const responses = operation.schema.responses;
|
|
1695
|
-
for (const key in responses) {
|
|
1696
|
-
const schema = responses[key];
|
|
1697
|
-
if (schema && isReference(schema)) responses[key] = resolveRef(document, schema.$ref);
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1591
|
+
resolveResponseRefs(document, operation);
|
|
1700
1592
|
const responseObj = getResponseByStatusCode({
|
|
1701
1593
|
document,
|
|
1702
1594
|
operation,
|
|
@@ -1840,7 +1732,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1840
1732
|
readOnly: schema.readOnly ?? memberNode.readOnly,
|
|
1841
1733
|
writeOnly: schema.writeOnly ?? memberNode.writeOnly,
|
|
1842
1734
|
default: mergedDefault,
|
|
1843
|
-
|
|
1735
|
+
examples: extractExamples(schema) ?? memberNode.examples,
|
|
1844
1736
|
pattern: schema.pattern ?? ("pattern" in memberNode ? memberNode.pattern : void 0),
|
|
1845
1737
|
format: schema.format ?? memberNode.format
|
|
1846
1738
|
});
|
|
@@ -2084,7 +1976,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
2084
1976
|
readOnly: schema.readOnly,
|
|
2085
1977
|
writeOnly: schema.writeOnly,
|
|
2086
1978
|
default: enumDefault,
|
|
2087
|
-
|
|
1979
|
+
examples: extractExamples(schema),
|
|
2088
1980
|
format: schema.format
|
|
2089
1981
|
};
|
|
2090
1982
|
const extensionKey = enumExtensionKeys.find((key) => key in schema);
|
|
@@ -2142,10 +2034,10 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
2142
2034
|
if (additionalProperties === true) return true;
|
|
2143
2035
|
if (additionalProperties === false) return false;
|
|
2144
2036
|
if (additionalProperties && Object.keys(additionalProperties).length > 0) return parseSchema({ schema: additionalProperties }, rawOptions);
|
|
2145
|
-
if (additionalProperties) return ast.factory.createSchema({ type:
|
|
2037
|
+
if (additionalProperties) return ast.factory.createSchema({ type: options.unknownType });
|
|
2146
2038
|
})();
|
|
2147
2039
|
const rawPatternProperties = "patternProperties" in schema ? schema.patternProperties : void 0;
|
|
2148
|
-
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ? ast.factory.createSchema({ type:
|
|
2040
|
+
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, patternSchema === true || typeof patternSchema === "object" && Object.keys(patternSchema).length === 0 ? ast.factory.createSchema({ type: options.unknownType }) : parseSchema({ schema: patternSchema }, rawOptions)])) : void 0;
|
|
2149
2041
|
const objectNode = ast.factory.createSchema({
|
|
2150
2042
|
type: "object",
|
|
2151
2043
|
primitive: "object",
|
|
@@ -2421,7 +2313,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
2421
2313
|
const node = rule.convert(schemaCtx);
|
|
2422
2314
|
if (node) return node;
|
|
2423
2315
|
}
|
|
2424
|
-
const emptyType =
|
|
2316
|
+
const emptyType = options.emptySchemaType;
|
|
2425
2317
|
return ast.factory.createSchema({
|
|
2426
2318
|
type: emptyType,
|
|
2427
2319
|
name,
|
|
@@ -2440,7 +2332,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
2440
2332
|
const schema = param["schema"] ? parseSchema({
|
|
2441
2333
|
schema: param["schema"],
|
|
2442
2334
|
name: schemaName
|
|
2443
|
-
}, options) : ast.factory.createSchema({ type:
|
|
2335
|
+
}, options) : ast.factory.createSchema({ type: options.unknownType });
|
|
2444
2336
|
return ast.factory.createParameter({
|
|
2445
2337
|
name: paramName,
|
|
2446
2338
|
in: param["in"],
|
|
@@ -2528,7 +2420,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
2528
2420
|
schema: raw && Object.keys(raw).length > 0 ? parseSchema({
|
|
2529
2421
|
schema: raw,
|
|
2530
2422
|
name: responseName
|
|
2531
|
-
}, options) : ast.factory.createSchema({ type:
|
|
2423
|
+
}, options) : ast.factory.createSchema({ type: options.emptySchemaType }),
|
|
2532
2424
|
keysToOmit: collectPropertyKeysByFlag(raw, "writeOnly")
|
|
2533
2425
|
};
|
|
2534
2426
|
};
|