@kubb/adapter-oas 5.0.0-beta.26 → 5.0.0-beta.28
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 +2 -2
- package/src/parser.ts +26 -13
package/dist/index.js
CHANGED
|
@@ -1184,7 +1184,7 @@ function createSchemaParser(ctx) {
|
|
|
1184
1184
|
const [memberSchema] = schema.allOf;
|
|
1185
1185
|
const memberNode = parseSchema({
|
|
1186
1186
|
schema: memberSchema,
|
|
1187
|
-
name
|
|
1187
|
+
name
|
|
1188
1188
|
}, rawOptions);
|
|
1189
1189
|
const { kind: _kind, ...memberNodeProps } = memberNode;
|
|
1190
1190
|
const mergedNullable = nullable || memberNode.nullable || void 0;
|
|
@@ -1223,7 +1223,10 @@ function createSchemaParser(ctx) {
|
|
|
1223
1223
|
return false;
|
|
1224
1224
|
}
|
|
1225
1225
|
return true;
|
|
1226
|
-
}).map((s) => parseSchema({
|
|
1226
|
+
}).map((s) => parseSchema({
|
|
1227
|
+
schema: s,
|
|
1228
|
+
name
|
|
1229
|
+
}, rawOptions));
|
|
1227
1230
|
const syntheticStart = allOfMembers.length;
|
|
1228
1231
|
if (Array.isArray(schema.required) && schema.required.length) {
|
|
1229
1232
|
const outerKeys = schema.properties ? new Set(Object.keys(schema.properties)) : /* @__PURE__ */ new Set();
|
|
@@ -1235,10 +1238,13 @@ function createSchemaParser(ctx) {
|
|
|
1235
1238
|
return deref && !isReference(deref) ? [deref] : [];
|
|
1236
1239
|
});
|
|
1237
1240
|
for (const key of missingRequired) for (const resolved of resolvedMembers) if (resolved.properties?.[key]) {
|
|
1238
|
-
allOfMembers.push(parseSchema({
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1241
|
+
allOfMembers.push(parseSchema({
|
|
1242
|
+
schema: {
|
|
1243
|
+
properties: { [key]: resolved.properties[key] },
|
|
1244
|
+
required: [key]
|
|
1245
|
+
},
|
|
1246
|
+
name
|
|
1247
|
+
}, rawOptions));
|
|
1242
1248
|
break;
|
|
1243
1249
|
}
|
|
1244
1250
|
}
|
|
@@ -1289,7 +1295,10 @@ function createSchemaParser(ctx) {
|
|
|
1289
1295
|
const members = unionMembers.map((s) => {
|
|
1290
1296
|
const ref = isReference(s) ? s.$ref : void 0;
|
|
1291
1297
|
const discriminatorValue = ast.findDiscriminator(discriminator?.mapping, ref);
|
|
1292
|
-
const memberNode = parseSchema({
|
|
1298
|
+
const memberNode = parseSchema({
|
|
1299
|
+
schema: s,
|
|
1300
|
+
name
|
|
1301
|
+
}, rawOptions);
|
|
1293
1302
|
if (!discriminatorValue || !discriminator) return memberNode;
|
|
1294
1303
|
const narrowedDiscriminatorNode = sharedPropertiesNode ? pickDiscriminatorPropertyNode(ast.setDiscriminatorEnum({
|
|
1295
1304
|
node: sharedPropertiesNode,
|
|
@@ -1319,7 +1328,10 @@ function createSchemaParser(ctx) {
|
|
|
1319
1328
|
return ast.createSchema({
|
|
1320
1329
|
type: "union",
|
|
1321
1330
|
...unionBase,
|
|
1322
|
-
members: ast.simplifyUnion(unionMembers.map((s) => parseSchema({
|
|
1331
|
+
members: ast.simplifyUnion(unionMembers.map((s) => parseSchema({
|
|
1332
|
+
schema: s,
|
|
1333
|
+
name
|
|
1334
|
+
}, rawOptions)))
|
|
1323
1335
|
});
|
|
1324
1336
|
}
|
|
1325
1337
|
/**
|
|
@@ -1552,7 +1564,7 @@ function createSchemaParser(ctx) {
|
|
|
1552
1564
|
*/
|
|
1553
1565
|
function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }) {
|
|
1554
1566
|
const rawItems = schema.items;
|
|
1555
|
-
const itemName = rawItems?.enum?.length && name ? ast.enumPropName(null, name, options.enumSuffix) :
|
|
1567
|
+
const itemName = rawItems?.enum?.length && name ? ast.enumPropName(null, name, options.enumSuffix) : name;
|
|
1556
1568
|
const items = rawItems ? [parseSchema({
|
|
1557
1569
|
schema: rawItems,
|
|
1558
1570
|
name: itemName
|
|
@@ -1702,11 +1714,16 @@ function createSchemaParser(ctx) {
|
|
|
1702
1714
|
/**
|
|
1703
1715
|
* Converts a dereferenced OAS parameter object into a `ParameterNode`.
|
|
1704
1716
|
*/
|
|
1705
|
-
function parseParameter(options, param) {
|
|
1717
|
+
function parseParameter(options, param, parentName) {
|
|
1706
1718
|
const required = param["required"] ?? false;
|
|
1707
|
-
const
|
|
1719
|
+
const paramName = param["name"];
|
|
1720
|
+
const schemaName = parentName && paramName ? pascalCase(`${parentName} ${paramName}`) : void 0;
|
|
1721
|
+
const schema = param["schema"] ? parseSchema({
|
|
1722
|
+
schema: param["schema"],
|
|
1723
|
+
name: schemaName
|
|
1724
|
+
}, options) : ast.createSchema({ type: typeOptionMap.get(options.unknownType) });
|
|
1708
1725
|
return ast.createParameter({
|
|
1709
|
-
name:
|
|
1726
|
+
name: paramName,
|
|
1710
1727
|
in: param["in"],
|
|
1711
1728
|
schema: {
|
|
1712
1729
|
...schema,
|
|
@@ -1755,15 +1772,21 @@ function createSchemaParser(ctx) {
|
|
|
1755
1772
|
* Converts an OAS `Operation` into an `OperationNode`.
|
|
1756
1773
|
*/
|
|
1757
1774
|
function parseOperation(options, operation) {
|
|
1758
|
-
const
|
|
1775
|
+
const operationId = operation.getOperationId();
|
|
1776
|
+
const operationName = operationId ? pascalCase(operationId) : void 0;
|
|
1777
|
+
const parameters = getParameters(document, operation).map((param) => parseParameter(options, param, operationName));
|
|
1759
1778
|
const allContentTypes = ctx.contentType ? [ctx.contentType] : getRequestBodyContentTypes(document, operation);
|
|
1760
1779
|
const requestBodyMeta = getRequestBodyMeta(operation);
|
|
1780
|
+
const requestBodyName = operationName ? `${operationName}Request` : void 0;
|
|
1761
1781
|
const content = allContentTypes.flatMap((ct) => {
|
|
1762
1782
|
const schema = getRequestSchema(document, operation, { contentType: ct });
|
|
1763
1783
|
if (!schema) return [];
|
|
1764
1784
|
return [{
|
|
1765
1785
|
contentType: ct,
|
|
1766
|
-
schema: ast.syncOptionality(parseSchema({
|
|
1786
|
+
schema: ast.syncOptionality(parseSchema({
|
|
1787
|
+
schema,
|
|
1788
|
+
name: requestBodyName
|
|
1789
|
+
}, options), requestBodyMeta.required),
|
|
1767
1790
|
keysToOmit: collectPropertyKeysByFlag(schema, "readOnly")
|
|
1768
1791
|
}];
|
|
1769
1792
|
});
|
|
@@ -1775,7 +1798,11 @@ function createSchemaParser(ctx) {
|
|
|
1775
1798
|
const responses = operation.getResponseStatusCodes().map((statusCode) => {
|
|
1776
1799
|
const responseObj = operation.getResponseByStatusCode(statusCode);
|
|
1777
1800
|
const responseSchema = getResponseSchema(document, operation, statusCode, { contentType: ctx.contentType });
|
|
1778
|
-
const
|
|
1801
|
+
const responseName = operationName ? `${operationName}Status${statusCode}` : void 0;
|
|
1802
|
+
const schema = responseSchema && Object.keys(responseSchema).length > 0 ? parseSchema({
|
|
1803
|
+
schema: responseSchema,
|
|
1804
|
+
name: responseName
|
|
1805
|
+
}, options) : ast.createSchema({ type: typeOptionMap.get(options.emptySchemaType) });
|
|
1779
1806
|
const { description, content } = getResponseMeta(responseObj);
|
|
1780
1807
|
const mediaType = content ? getMediaType(Object.keys(content)[0] ?? "") : getMediaType(operation.contentType ?? "");
|
|
1781
1808
|
return ast.createResponse({
|
|
@@ -1788,7 +1815,7 @@ function createSchemaParser(ctx) {
|
|
|
1788
1815
|
});
|
|
1789
1816
|
const urlPath = new URLPath(operation.path);
|
|
1790
1817
|
return ast.createOperation({
|
|
1791
|
-
operationId
|
|
1818
|
+
operationId,
|
|
1792
1819
|
method: operation.method.toUpperCase(),
|
|
1793
1820
|
path: urlPath.path,
|
|
1794
1821
|
tags: operation.getTags().map((tag) => tag.name),
|