@kubb/adapter-oas 5.0.0-beta.25 → 5.0.0-beta.27
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 +43 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -16
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter.ts +2 -2
- package/src/discriminator.ts +1 -1
- package/src/parser.ts +29 -16
- package/src/resolvers.ts +8 -8
- package/src/stream.ts +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1210,7 +1210,7 @@ function createSchemaParser(ctx) {
|
|
|
1210
1210
|
const [memberSchema] = schema.allOf;
|
|
1211
1211
|
const memberNode = parseSchema({
|
|
1212
1212
|
schema: memberSchema,
|
|
1213
|
-
name
|
|
1213
|
+
name
|
|
1214
1214
|
}, rawOptions);
|
|
1215
1215
|
const { kind: _kind, ...memberNodeProps } = memberNode;
|
|
1216
1216
|
const mergedNullable = nullable || memberNode.nullable || void 0;
|
|
@@ -1249,7 +1249,10 @@ function createSchemaParser(ctx) {
|
|
|
1249
1249
|
return false;
|
|
1250
1250
|
}
|
|
1251
1251
|
return true;
|
|
1252
|
-
}).map((s) => parseSchema({
|
|
1252
|
+
}).map((s) => parseSchema({
|
|
1253
|
+
schema: s,
|
|
1254
|
+
name
|
|
1255
|
+
}, rawOptions));
|
|
1253
1256
|
const syntheticStart = allOfMembers.length;
|
|
1254
1257
|
if (Array.isArray(schema.required) && schema.required.length) {
|
|
1255
1258
|
const outerKeys = schema.properties ? new Set(Object.keys(schema.properties)) : /* @__PURE__ */ new Set();
|
|
@@ -1261,10 +1264,13 @@ function createSchemaParser(ctx) {
|
|
|
1261
1264
|
return deref && !isReference(deref) ? [deref] : [];
|
|
1262
1265
|
});
|
|
1263
1266
|
for (const key of missingRequired) for (const resolved of resolvedMembers) if (resolved.properties?.[key]) {
|
|
1264
|
-
allOfMembers.push(parseSchema({
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1267
|
+
allOfMembers.push(parseSchema({
|
|
1268
|
+
schema: {
|
|
1269
|
+
properties: { [key]: resolved.properties[key] },
|
|
1270
|
+
required: [key]
|
|
1271
|
+
},
|
|
1272
|
+
name
|
|
1273
|
+
}, rawOptions));
|
|
1268
1274
|
break;
|
|
1269
1275
|
}
|
|
1270
1276
|
}
|
|
@@ -1315,7 +1321,10 @@ function createSchemaParser(ctx) {
|
|
|
1315
1321
|
const members = unionMembers.map((s) => {
|
|
1316
1322
|
const ref = isReference(s) ? s.$ref : void 0;
|
|
1317
1323
|
const discriminatorValue = _kubb_core.ast.findDiscriminator(discriminator?.mapping, ref);
|
|
1318
|
-
const memberNode = parseSchema({
|
|
1324
|
+
const memberNode = parseSchema({
|
|
1325
|
+
schema: s,
|
|
1326
|
+
name
|
|
1327
|
+
}, rawOptions);
|
|
1319
1328
|
if (!discriminatorValue || !discriminator) return memberNode;
|
|
1320
1329
|
const narrowedDiscriminatorNode = sharedPropertiesNode ? pickDiscriminatorPropertyNode(_kubb_core.ast.setDiscriminatorEnum({
|
|
1321
1330
|
node: sharedPropertiesNode,
|
|
@@ -1345,7 +1354,10 @@ function createSchemaParser(ctx) {
|
|
|
1345
1354
|
return _kubb_core.ast.createSchema({
|
|
1346
1355
|
type: "union",
|
|
1347
1356
|
...unionBase,
|
|
1348
|
-
members: _kubb_core.ast.simplifyUnion(unionMembers.map((s) => parseSchema({
|
|
1357
|
+
members: _kubb_core.ast.simplifyUnion(unionMembers.map((s) => parseSchema({
|
|
1358
|
+
schema: s,
|
|
1359
|
+
name
|
|
1360
|
+
}, rawOptions)))
|
|
1349
1361
|
});
|
|
1350
1362
|
}
|
|
1351
1363
|
/**
|
|
@@ -1578,7 +1590,7 @@ function createSchemaParser(ctx) {
|
|
|
1578
1590
|
*/
|
|
1579
1591
|
function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }) {
|
|
1580
1592
|
const rawItems = schema.items;
|
|
1581
|
-
const itemName = rawItems?.enum?.length && name ? _kubb_core.ast.enumPropName(null, name, options.enumSuffix) :
|
|
1593
|
+
const itemName = rawItems?.enum?.length && name ? _kubb_core.ast.enumPropName(null, name, options.enumSuffix) : name;
|
|
1582
1594
|
const items = rawItems ? [parseSchema({
|
|
1583
1595
|
schema: rawItems,
|
|
1584
1596
|
name: itemName
|
|
@@ -1728,11 +1740,16 @@ function createSchemaParser(ctx) {
|
|
|
1728
1740
|
/**
|
|
1729
1741
|
* Converts a dereferenced OAS parameter object into a `ParameterNode`.
|
|
1730
1742
|
*/
|
|
1731
|
-
function parseParameter(options, param) {
|
|
1743
|
+
function parseParameter(options, param, parentName) {
|
|
1732
1744
|
const required = param["required"] ?? false;
|
|
1733
|
-
const
|
|
1745
|
+
const paramName = param["name"];
|
|
1746
|
+
const schemaName = parentName && paramName ? pascalCase(`${parentName} ${paramName}`) : void 0;
|
|
1747
|
+
const schema = param["schema"] ? parseSchema({
|
|
1748
|
+
schema: param["schema"],
|
|
1749
|
+
name: schemaName
|
|
1750
|
+
}, options) : _kubb_core.ast.createSchema({ type: typeOptionMap.get(options.unknownType) });
|
|
1734
1751
|
return _kubb_core.ast.createParameter({
|
|
1735
|
-
name:
|
|
1752
|
+
name: paramName,
|
|
1736
1753
|
in: param["in"],
|
|
1737
1754
|
schema: {
|
|
1738
1755
|
...schema,
|
|
@@ -1781,15 +1798,21 @@ function createSchemaParser(ctx) {
|
|
|
1781
1798
|
* Converts an OAS `Operation` into an `OperationNode`.
|
|
1782
1799
|
*/
|
|
1783
1800
|
function parseOperation(options, operation) {
|
|
1784
|
-
const
|
|
1801
|
+
const operationId = operation.getOperationId();
|
|
1802
|
+
const operationName = operationId ? pascalCase(operationId) : void 0;
|
|
1803
|
+
const parameters = getParameters(document, operation).map((param) => parseParameter(options, param, operationName));
|
|
1785
1804
|
const allContentTypes = ctx.contentType ? [ctx.contentType] : getRequestBodyContentTypes(document, operation);
|
|
1786
1805
|
const requestBodyMeta = getRequestBodyMeta(operation);
|
|
1806
|
+
const requestBodyName = operationName ? `${operationName}Request` : void 0;
|
|
1787
1807
|
const content = allContentTypes.flatMap((ct) => {
|
|
1788
1808
|
const schema = getRequestSchema(document, operation, { contentType: ct });
|
|
1789
1809
|
if (!schema) return [];
|
|
1790
1810
|
return [{
|
|
1791
1811
|
contentType: ct,
|
|
1792
|
-
schema: _kubb_core.ast.syncOptionality(parseSchema({
|
|
1812
|
+
schema: _kubb_core.ast.syncOptionality(parseSchema({
|
|
1813
|
+
schema,
|
|
1814
|
+
name: requestBodyName
|
|
1815
|
+
}, options), requestBodyMeta.required),
|
|
1793
1816
|
keysToOmit: collectPropertyKeysByFlag(schema, "readOnly")
|
|
1794
1817
|
}];
|
|
1795
1818
|
});
|
|
@@ -1801,7 +1824,11 @@ function createSchemaParser(ctx) {
|
|
|
1801
1824
|
const responses = operation.getResponseStatusCodes().map((statusCode) => {
|
|
1802
1825
|
const responseObj = operation.getResponseByStatusCode(statusCode);
|
|
1803
1826
|
const responseSchema = getResponseSchema(document, operation, statusCode, { contentType: ctx.contentType });
|
|
1804
|
-
const
|
|
1827
|
+
const responseName = operationName ? `${operationName}Status${statusCode}` : void 0;
|
|
1828
|
+
const schema = responseSchema && Object.keys(responseSchema).length > 0 ? parseSchema({
|
|
1829
|
+
schema: responseSchema,
|
|
1830
|
+
name: responseName
|
|
1831
|
+
}, options) : _kubb_core.ast.createSchema({ type: typeOptionMap.get(options.emptySchemaType) });
|
|
1805
1832
|
const { description, content } = getResponseMeta(responseObj);
|
|
1806
1833
|
const mediaType = content ? getMediaType(Object.keys(content)[0] ?? "") : getMediaType(operation.contentType ?? "");
|
|
1807
1834
|
return _kubb_core.ast.createResponse({
|
|
@@ -1814,7 +1841,7 @@ function createSchemaParser(ctx) {
|
|
|
1814
1841
|
});
|
|
1815
1842
|
const urlPath = new URLPath(operation.path);
|
|
1816
1843
|
return _kubb_core.ast.createOperation({
|
|
1817
|
-
operationId
|
|
1844
|
+
operationId,
|
|
1818
1845
|
method: operation.method.toUpperCase(),
|
|
1819
1846
|
path: urlPath.path,
|
|
1820
1847
|
tags: operation.getTags().map((tag) => tag.name),
|