@kubb/adapter-oas 5.0.0-beta.75 → 5.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -0
- package/dist/index.cjs +14 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -49
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/extension.yaml +344 -0
- package/package.json +5 -4
- package/src/adapter.ts +5 -1
- package/src/constants.ts +1 -1
- package/src/factory.ts +1 -4
- package/src/index.ts +2 -2
- package/src/refs.ts +15 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import * as _$_kubb_core0 from "@kubb/core";
|
|
3
|
-
import { AdapterFactoryOptions,
|
|
3
|
+
import { AdapterFactoryOptions, ast } from "@kubb/core";
|
|
4
4
|
import { DiscriminatorObject as DiscriminatorObject$2, MediaTypeObject as MediaTypeObject$2, OASDocument, ResponseObject as ResponseObject$2, SchemaObject as SchemaObject$2 } from "oas/types";
|
|
5
5
|
import { Operation as Operation$1 } from "oas/operation";
|
|
6
6
|
|
|
@@ -525,30 +525,9 @@ declare const adapterOasName = "oas";
|
|
|
525
525
|
declare const adapterOas: (options?: AdapterOasOptions | undefined) => _$_kubb_core0.Adapter<AdapterOas>;
|
|
526
526
|
//#endregion
|
|
527
527
|
//#region src/factory.d.ts
|
|
528
|
-
type ParseOptions = {
|
|
529
|
-
canBundle?: boolean;
|
|
530
|
-
enablePaths?: boolean;
|
|
531
|
-
};
|
|
532
528
|
type ValidateDocumentOptions = {
|
|
533
529
|
throwOnError?: boolean;
|
|
534
530
|
};
|
|
535
|
-
/**
|
|
536
|
-
* Loads and dereferences an OpenAPI document, returning the raw `Document`.
|
|
537
|
-
*
|
|
538
|
-
* Accepts a file path string or an already-parsed document object. File paths are bundled via
|
|
539
|
-
* Redocly to resolve external `$ref`s. Swagger 2.0 documents are automatically up-converted
|
|
540
|
-
* to OpenAPI 3.0 via `swagger2openapi`.
|
|
541
|
-
*
|
|
542
|
-
* @example
|
|
543
|
-
* ```ts
|
|
544
|
-
* const document = await parseDocument('./openapi.yaml')
|
|
545
|
-
* const document = await parse(rawDocumentObject, { canBundle: false })
|
|
546
|
-
* ```
|
|
547
|
-
*/
|
|
548
|
-
declare function parseDocument(pathOrApi: string | Document, {
|
|
549
|
-
canBundle,
|
|
550
|
-
enablePaths
|
|
551
|
-
}?: ParseOptions): Promise<Document>;
|
|
552
531
|
/**
|
|
553
532
|
* Deep-merges multiple OpenAPI documents into a single `Document`.
|
|
554
533
|
*
|
|
@@ -561,32 +540,6 @@ declare function parseDocument(pathOrApi: string | Document, {
|
|
|
561
540
|
* ```
|
|
562
541
|
*/
|
|
563
542
|
declare function mergeDocuments(pathOrApi: Array<string | Document>): Promise<Document>;
|
|
564
|
-
/**
|
|
565
|
-
* Creates a `Document` from an `AdapterSource`.
|
|
566
|
-
*
|
|
567
|
-
* Handles all three source types:
|
|
568
|
-
* - `{ type: 'path' }` — resolves and bundles a local file path or remote URL.
|
|
569
|
-
* - `{ type: 'paths' }` — merges multiple file paths into a single document.
|
|
570
|
-
* - `{ type: 'data' }` — parses an inline string (YAML/JSON) or raw object.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```ts
|
|
574
|
-
* const document = await parseFromConfig({ type: 'path', path: './openapi.yaml' })
|
|
575
|
-
* const document = await parseFromConfig({ type: 'data', data: '{"openapi":"3.0.0",...}' })
|
|
576
|
-
* ```
|
|
577
|
-
*/
|
|
578
|
-
declare function parseFromConfig(source: AdapterSource): Promise<Document>;
|
|
579
|
-
/**
|
|
580
|
-
* Validates an OpenAPI document using `oas-normalize` with colorized error output.
|
|
581
|
-
*
|
|
582
|
-
* @example
|
|
583
|
-
* ```ts
|
|
584
|
-
* await validateDocument(document)
|
|
585
|
-
* ```
|
|
586
|
-
*/
|
|
587
|
-
declare function validateDocument(document: Document, {
|
|
588
|
-
throwOnError
|
|
589
|
-
}?: ValidateDocumentOptions): Promise<void>;
|
|
590
543
|
//#endregion
|
|
591
|
-
export { type AdapterOas, type AdapterOasOptions, type AdapterOasResolvedOptions, type ContentType, type DiscriminatorObject$1 as DiscriminatorObject, type Document, type HttpMethod, HttpMethods$1 as HttpMethods, type MediaTypeObject$1 as MediaTypeObject, type Operation, type
|
|
544
|
+
export { type AdapterOas, type AdapterOasOptions, type AdapterOasResolvedOptions, type ContentType, type DiscriminatorObject$1 as DiscriminatorObject, type Document, type HttpMethod, HttpMethods$1 as HttpMethods, type MediaTypeObject$1 as MediaTypeObject, type Operation, type ReferenceObject$1 as ReferenceObject, type ResponseObject$1 as ResponseObject, type SchemaObject$1 as SchemaObject, type ValidateDocumentOptions, adapterOas, adapterOasName, mergeDocuments };
|
|
592
545
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import { matchesMimeType } from "oas/utils";
|
|
|
21
21
|
*/
|
|
22
22
|
const DEFAULT_PARSER_OPTIONS = {
|
|
23
23
|
dateType: "string",
|
|
24
|
-
integerType: "
|
|
24
|
+
integerType: "bigint",
|
|
25
25
|
unknownType: "any",
|
|
26
26
|
emptySchemaType: "any",
|
|
27
27
|
enumSuffix: "enum"
|
|
@@ -660,11 +660,10 @@ async function parseDocument(pathOrApi, { canBundle = true, enablePaths = true }
|
|
|
660
660
|
* ```
|
|
661
661
|
*/
|
|
662
662
|
async function mergeDocuments(pathOrApi) {
|
|
663
|
-
const documents =
|
|
664
|
-
for (const p of pathOrApi) documents.push(await parseDocument(p, {
|
|
663
|
+
const documents = await Promise.all(pathOrApi.map((p) => parseDocument(p, {
|
|
665
664
|
enablePaths: false,
|
|
666
665
|
canBundle: false
|
|
667
|
-
}));
|
|
666
|
+
})));
|
|
668
667
|
if (documents.length === 0) throw new Error("No OAS documents provided for merging.");
|
|
669
668
|
const seed = {
|
|
670
669
|
openapi: MERGE_OPENAPI_VERSION,
|
|
@@ -720,6 +719,7 @@ async function validateDocument(document, { throwOnError = false } = {}) {
|
|
|
720
719
|
}
|
|
721
720
|
//#endregion
|
|
722
721
|
//#region src/refs.ts
|
|
722
|
+
const _refCache = /* @__PURE__ */ new WeakMap();
|
|
723
723
|
/**
|
|
724
724
|
* Resolves a local JSON pointer reference from a document.
|
|
725
725
|
*
|
|
@@ -737,8 +737,15 @@ function resolveRef(document, $ref) {
|
|
|
737
737
|
if ($ref === "") return null;
|
|
738
738
|
if ($ref.startsWith("#")) $ref = globalThis.decodeURIComponent($ref.substring(1));
|
|
739
739
|
else return null;
|
|
740
|
+
let docCache = _refCache.get(document);
|
|
741
|
+
if (!docCache) {
|
|
742
|
+
docCache = /* @__PURE__ */ new Map();
|
|
743
|
+
_refCache.set(document, docCache);
|
|
744
|
+
}
|
|
745
|
+
if (docCache.has($ref)) return docCache.get($ref);
|
|
740
746
|
const current = $ref.split("/").filter(Boolean).reduce((obj, key) => obj?.[key], document);
|
|
741
747
|
if (!current) throw new Error(`Could not find a definition for ${origRef}.`);
|
|
748
|
+
docCache.set($ref, current);
|
|
742
749
|
return current;
|
|
743
750
|
}
|
|
744
751
|
/**
|
|
@@ -1920,6 +1927,9 @@ const adapterOas = createAdapter((options) => {
|
|
|
1920
1927
|
get inputNode() {
|
|
1921
1928
|
return inputNode;
|
|
1922
1929
|
},
|
|
1930
|
+
async validate(input, options) {
|
|
1931
|
+
await validateDocument(await parseDocument(input), options);
|
|
1932
|
+
},
|
|
1923
1933
|
getImports(node, resolve) {
|
|
1924
1934
|
return ast.collectImports({
|
|
1925
1935
|
node,
|
|
@@ -1976,6 +1986,6 @@ const adapterOas = createAdapter((options) => {
|
|
|
1976
1986
|
*/
|
|
1977
1987
|
const HttpMethods = Object.fromEntries(Object.entries(ast.httpMethods).map(([lower, upper]) => [upper, lower]));
|
|
1978
1988
|
//#endregion
|
|
1979
|
-
export { HttpMethods, adapterOas, adapterOasName, mergeDocuments
|
|
1989
|
+
export { HttpMethods, adapterOas, adapterOasName, mergeDocuments };
|
|
1980
1990
|
|
|
1981
1991
|
//# sourceMappingURL=index.js.map
|