@kubb/adapter-oas 5.0.0-beta.60 → 5.0.0-beta.61
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 +33 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -25
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/parser.ts +28 -25
package/dist/index.js
CHANGED
|
@@ -5,7 +5,8 @@ import { access, readFile } from "node:fs/promises";
|
|
|
5
5
|
import { compileErrors, validate } from "@readme/openapi-parser";
|
|
6
6
|
import { parse } from "yaml";
|
|
7
7
|
import { bundle } from "api-ref-bundler";
|
|
8
|
-
import {
|
|
8
|
+
import { macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion } from "@kubb/ast/macros";
|
|
9
|
+
import { childName, containsCircularRef, enumPropName, extractRefName, findCircularSchemas, mergeAdjacentObjectsLazy } from "@kubb/ast/utils";
|
|
9
10
|
import { collect, narrowSchema } from "@kubb/ast";
|
|
10
11
|
//#region src/constants.ts
|
|
11
12
|
/**
|
|
@@ -1560,6 +1561,23 @@ function normalizeArrayEnum(schema) {
|
|
|
1560
1561
|
};
|
|
1561
1562
|
}
|
|
1562
1563
|
/**
|
|
1564
|
+
* Names the inline enums on a property's schema, and on each item when the property is a tuple, from
|
|
1565
|
+
* the parent and property name. Wraps `macroEnumName` at the property construction site.
|
|
1566
|
+
*/
|
|
1567
|
+
function nameEnums(node, options) {
|
|
1568
|
+
const macro = macroEnumName(options);
|
|
1569
|
+
const named = ast.applyMacros(node, [macro], { depth: "shallow" });
|
|
1570
|
+
const tupleNode = ast.narrowSchema(named, "tuple");
|
|
1571
|
+
if (tupleNode?.items) {
|
|
1572
|
+
const namedItems = tupleNode.items.map((item) => ast.applyMacros(item, [macro], { depth: "shallow" }));
|
|
1573
|
+
if (namedItems.some((item, i) => item !== tupleNode.items[i])) return {
|
|
1574
|
+
...tupleNode,
|
|
1575
|
+
items: namedItems
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
return named;
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1563
1581
|
* Factory function that creates schema and operation converters for a given OpenAPI context.
|
|
1564
1582
|
*
|
|
1565
1583
|
* Returns closures that share mutable state (`resolvingRefs` set for cycle detection).
|
|
@@ -1700,7 +1718,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1700
1718
|
}));
|
|
1701
1719
|
return ast.factory.createSchema({
|
|
1702
1720
|
type: "intersection",
|
|
1703
|
-
members: [...
|
|
1721
|
+
members: [...mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ...mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))],
|
|
1704
1722
|
...buildSchemaNode(schema, name, nullable, defaultValue)
|
|
1705
1723
|
});
|
|
1706
1724
|
}
|
|
@@ -1741,11 +1759,10 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1741
1759
|
name
|
|
1742
1760
|
}, rawOptions);
|
|
1743
1761
|
if (!discriminatorValue || !discriminator) return memberNode;
|
|
1744
|
-
const narrowedDiscriminatorNode = sharedPropertiesNode ? pickDiscriminatorPropertyNode(ast.
|
|
1745
|
-
node: sharedPropertiesNode,
|
|
1762
|
+
const narrowedDiscriminatorNode = sharedPropertiesNode ? pickDiscriminatorPropertyNode(ast.applyMacros(sharedPropertiesNode, [macroDiscriminatorEnum({
|
|
1746
1763
|
propertyName: discriminator.propertyName,
|
|
1747
1764
|
values: [discriminatorValue]
|
|
1748
|
-
}), discriminator.propertyName) : void 0;
|
|
1765
|
+
})], { depth: "shallow" }), discriminator.propertyName) : void 0;
|
|
1749
1766
|
return ast.factory.createSchema({
|
|
1750
1767
|
type: "intersection",
|
|
1751
1768
|
members: [memberNode, narrowedDiscriminatorNode ?? createDiscriminantNode({
|
|
@@ -1766,14 +1783,15 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1766
1783
|
members: [unionNode, sharedPropertiesNode]
|
|
1767
1784
|
});
|
|
1768
1785
|
}
|
|
1769
|
-
|
|
1786
|
+
const unionNode = ast.factory.createSchema({
|
|
1770
1787
|
type: "union",
|
|
1771
1788
|
...unionBase,
|
|
1772
|
-
members:
|
|
1789
|
+
members: unionMembers.map((s) => parseSchema({
|
|
1773
1790
|
schema: s,
|
|
1774
1791
|
name
|
|
1775
|
-
}, rawOptions))
|
|
1792
|
+
}, rawOptions))
|
|
1776
1793
|
});
|
|
1794
|
+
return ast.applyMacros(unionNode, [macroSimplifyUnion], { depth: "shallow" });
|
|
1777
1795
|
}
|
|
1778
1796
|
/**
|
|
1779
1797
|
* Converts an OAS 3.1 `const` schema into a null scalar or a single-value `EnumSchemaNode`.
|
|
@@ -1936,22 +1954,14 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1936
1954
|
const required = Array.isArray(schema.required) ? schema.required.includes(propName) : !!schema.required;
|
|
1937
1955
|
const resolvedPropSchema = propSchema;
|
|
1938
1956
|
const propNullable = dialect.isNullable(resolvedPropSchema);
|
|
1939
|
-
const
|
|
1957
|
+
const schemaNode = nameEnums(parseSchema({
|
|
1940
1958
|
schema: resolvedPropSchema,
|
|
1941
1959
|
name: childName(name, propName)
|
|
1942
|
-
}, rawOptions)
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
const namedItems = tupleNode.items.map((item) => ast.setEnumName(item, name, propName, options.enumSuffix));
|
|
1948
|
-
if (namedItems.some((item, i) => item !== tupleNode.items[i])) return {
|
|
1949
|
-
...tupleNode,
|
|
1950
|
-
items: namedItems
|
|
1951
|
-
};
|
|
1952
|
-
}
|
|
1953
|
-
return node;
|
|
1954
|
-
})();
|
|
1960
|
+
}, rawOptions), {
|
|
1961
|
+
parentName: name,
|
|
1962
|
+
propName,
|
|
1963
|
+
enumSuffix: options.enumSuffix
|
|
1964
|
+
});
|
|
1955
1965
|
return ast.factory.createProperty({
|
|
1956
1966
|
name: propName,
|
|
1957
1967
|
schema: {
|
|
@@ -1984,12 +1994,11 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1984
1994
|
const discPropName = schema.discriminator.propertyName;
|
|
1985
1995
|
const values = Object.keys(schema.discriminator.mapping);
|
|
1986
1996
|
const enumName = name ? enumPropName(name, discPropName, options.enumSuffix) : void 0;
|
|
1987
|
-
return ast.
|
|
1988
|
-
node: objectNode,
|
|
1997
|
+
return ast.applyMacros(objectNode, [macroDiscriminatorEnum({
|
|
1989
1998
|
propertyName: discPropName,
|
|
1990
1999
|
values,
|
|
1991
2000
|
enumName
|
|
1992
|
-
});
|
|
2001
|
+
})], { depth: "shallow" });
|
|
1993
2002
|
}
|
|
1994
2003
|
return objectNode;
|
|
1995
2004
|
}
|