@kubb/adapter-oas 4.33.4 → 4.35.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/index.cjs +8 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -29
- package/dist/index.js +9 -45
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter.ts +2 -11
- package/src/index.ts +0 -1
- package/src/parser.ts +5 -5
- package/src/types.ts +0 -11
- package/src/devtools.ts +0 -60
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,6 @@ let node_path = require("node:path");
|
|
|
25
25
|
node_path = __toESM(node_path);
|
|
26
26
|
let _kubb_ast = require("@kubb/ast");
|
|
27
27
|
let _kubb_core = require("@kubb/core");
|
|
28
|
-
let fflate = require("fflate");
|
|
29
28
|
let _redocly_openapi_core = require("@redocly/openapi-core");
|
|
30
29
|
let _stoplight_yaml = require("@stoplight/yaml");
|
|
31
30
|
_stoplight_yaml = __toESM(_stoplight_yaml);
|
|
@@ -40,38 +39,6 @@ jsonpointer = __toESM(jsonpointer);
|
|
|
40
39
|
let oas = require("oas");
|
|
41
40
|
oas = __toESM(oas);
|
|
42
41
|
let oas_utils = require("oas/utils");
|
|
43
|
-
/**
|
|
44
|
-
* Encodes a `RootNode` as a compressed, URL-safe string.
|
|
45
|
-
*
|
|
46
|
-
* The JSON representation is deflate-compressed with {@link deflateSync} before
|
|
47
|
-
* base64url encoding, which typically reduces payload size by 70–80 % and
|
|
48
|
-
* keeps URLs well within browser and server path-length limits.
|
|
49
|
-
*
|
|
50
|
-
* Use {@link decodeAst} to reverse.
|
|
51
|
-
*/
|
|
52
|
-
function encodeAst(root) {
|
|
53
|
-
const compressed = (0, fflate.deflateSync)(new TextEncoder().encode(JSON.stringify(root)));
|
|
54
|
-
return Buffer.from(compressed).toString("base64url");
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Constructs the Kubb Studio URL for visual AST inspection.
|
|
58
|
-
* The `root` is encoded and attached as the `?root=` query parameter so Studio
|
|
59
|
-
* can decode and render it without a round-trip to any server.
|
|
60
|
-
*/
|
|
61
|
-
function getAstUrl(root, options = {}) {
|
|
62
|
-
return `${(options.studioUrl ?? "https://studio.kubb.dev").replace(/\/$/, "")}/ast?root=${encodeAst(root)}`;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Prints the Kubb Studio URL for the given `RootNode` — inspired by
|
|
66
|
-
* [testing-playground](https://testing-playground.com/).
|
|
67
|
-
*
|
|
68
|
-
* Drop this call next to an assertion during development or in a failing test
|
|
69
|
-
* to get an instantly-clickable link for visual debugging.
|
|
70
|
-
*/
|
|
71
|
-
function logAst(root, options = {}) {
|
|
72
|
-
console.log(`\n ${getAstUrl(root, options)}\n`);
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
42
|
//#region src/oas/resolveServerUrl.ts
|
|
76
43
|
/**
|
|
77
44
|
* Resolves an OpenAPI server URL by substituting `{variable}` placeholders.
|
|
@@ -1029,7 +996,7 @@ function applyDiscriminatorEnum(schema) {
|
|
|
1029
996
|
* Creates an OAS parser that converts an OpenAPI/Swagger spec into
|
|
1030
997
|
* the `@kubb/ast` tree.
|
|
1031
998
|
*
|
|
1032
|
-
* Options are passed per-call to `
|
|
999
|
+
* Options are passed per-call to `parse` or `convertSchema` rather than
|
|
1033
1000
|
* at construction time, keeping the factory lightweight.
|
|
1034
1001
|
*
|
|
1035
1002
|
* This is the **kubb-parser** stage of the compilation lifecycle:
|
|
@@ -1041,7 +1008,7 @@ function applyDiscriminatorEnum(schema) {
|
|
|
1041
1008
|
* @example
|
|
1042
1009
|
* ```ts
|
|
1043
1010
|
* const parser = createOasParser(oas)
|
|
1044
|
-
* const root = parser.
|
|
1011
|
+
* const root = parser.parse({ emptySchemaType: 'unknown' })
|
|
1045
1012
|
* ```
|
|
1046
1013
|
*/
|
|
1047
1014
|
function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
@@ -1669,7 +1636,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1669
1636
|
* Converts an OpenAPI/Swagger spec (wrapped in a Kubb `Oas` instance) into
|
|
1670
1637
|
* a `RootNode` — the top-level node of the `@kubb/ast` tree.
|
|
1671
1638
|
*/
|
|
1672
|
-
function
|
|
1639
|
+
function parse(options) {
|
|
1673
1640
|
const mergedOptions = {
|
|
1674
1641
|
...DEFAULT_OPTIONS,
|
|
1675
1642
|
...options
|
|
@@ -1733,7 +1700,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1733
1700
|
} });
|
|
1734
1701
|
}
|
|
1735
1702
|
return {
|
|
1736
|
-
|
|
1703
|
+
parse,
|
|
1737
1704
|
convertSchema,
|
|
1738
1705
|
resolveRefs,
|
|
1739
1706
|
getImports
|
|
@@ -1761,7 +1728,7 @@ const adapterOasName = "oas";
|
|
|
1761
1728
|
* ```
|
|
1762
1729
|
*/
|
|
1763
1730
|
const adapterOas = (0, _kubb_core.defineAdapter)((options) => {
|
|
1764
|
-
const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", collisionDetection = false, dateType = "string", integerType = "number", unknownType = "any", emptySchemaType = unknownType
|
|
1731
|
+
const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", collisionDetection = false, dateType = "string", integerType = "number", unknownType = "any", emptySchemaType = unknownType } = options;
|
|
1765
1732
|
return {
|
|
1766
1733
|
name: "oas",
|
|
1767
1734
|
options: {
|
|
@@ -1775,8 +1742,7 @@ const adapterOas = (0, _kubb_core.defineAdapter)((options) => {
|
|
|
1775
1742
|
dateType,
|
|
1776
1743
|
integerType,
|
|
1777
1744
|
unknownType,
|
|
1778
|
-
emptySchemaType
|
|
1779
|
-
devtools
|
|
1745
|
+
emptySchemaType
|
|
1780
1746
|
},
|
|
1781
1747
|
async parse(source) {
|
|
1782
1748
|
const oas = await parseFromConfig(sourceToFakeConfig(source), oasClass);
|
|
@@ -1790,11 +1756,11 @@ const adapterOas = (0, _kubb_core.defineAdapter)((options) => {
|
|
|
1790
1756
|
} catch (_err) {}
|
|
1791
1757
|
const server = serverIndex !== void 0 ? oas.api.servers?.at(serverIndex) : void 0;
|
|
1792
1758
|
const baseURL = server?.url ? resolveServerUrl(server, serverVariables) : void 0;
|
|
1793
|
-
|
|
1759
|
+
return (0, _kubb_ast.createRoot)({
|
|
1794
1760
|
...createOasParser(oas, {
|
|
1795
1761
|
contentType,
|
|
1796
1762
|
collisionDetection
|
|
1797
|
-
}).
|
|
1763
|
+
}).parse({
|
|
1798
1764
|
dateType,
|
|
1799
1765
|
integerType,
|
|
1800
1766
|
unknownType,
|
|
@@ -1806,8 +1772,6 @@ const adapterOas = (0, _kubb_core.defineAdapter)((options) => {
|
|
|
1806
1772
|
baseURL
|
|
1807
1773
|
}
|
|
1808
1774
|
});
|
|
1809
|
-
if (devtools) logAst(rootNode, devtools === true ? {} : devtools);
|
|
1810
|
-
return rootNode;
|
|
1811
1775
|
}
|
|
1812
1776
|
};
|
|
1813
1777
|
});
|
|
@@ -1830,6 +1794,5 @@ function sourceToFakeConfig(source) {
|
|
|
1830
1794
|
//#endregion
|
|
1831
1795
|
exports.adapterOas = adapterOas;
|
|
1832
1796
|
exports.adapterOasName = adapterOasName;
|
|
1833
|
-
exports.logAst = logAst;
|
|
1834
1797
|
|
|
1835
1798
|
//# sourceMappingURL=index.cjs.map
|