@kubb/adapter-oas 5.0.0-alpha.53 → 5.0.0-alpha.55
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 +34 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/parser.ts +28 -17
- package/src/resolvers.ts +25 -0
package/dist/index.js
CHANGED
|
@@ -1044,6 +1044,26 @@ function buildSchemaNode(schema, name, nullable, defaultValue) {
|
|
|
1044
1044
|
example: schema.example
|
|
1045
1045
|
};
|
|
1046
1046
|
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Returns all request body content type keys for an operation.
|
|
1049
|
+
*
|
|
1050
|
+
* The requestBody is dereferenced **in-place** when it is a `$ref` — the same mutation
|
|
1051
|
+
* that `getRequestSchema` already performs — so that the returned list accurately reflects
|
|
1052
|
+
* the available content types even for referenced bodies.
|
|
1053
|
+
*
|
|
1054
|
+
* @example
|
|
1055
|
+
* ```ts
|
|
1056
|
+
* getRequestBodyContentTypes(document, operation)
|
|
1057
|
+
* // ['application/json', 'multipart/form-data']
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
function getRequestBodyContentTypes(document, operation) {
|
|
1061
|
+
if (operation.schema.requestBody) operation.schema.requestBody = dereferenceWithRef(document, operation.schema.requestBody);
|
|
1062
|
+
const body = operation.schema.requestBody;
|
|
1063
|
+
if (!body || isReference(body)) return [];
|
|
1064
|
+
const inline = body;
|
|
1065
|
+
return inline.content ? Object.keys(inline.content) : [];
|
|
1066
|
+
}
|
|
1047
1067
|
//#endregion
|
|
1048
1068
|
//#region src/parser.ts
|
|
1049
1069
|
/**
|
|
@@ -1631,7 +1651,7 @@ function createSchemaParser(ctx) {
|
|
|
1631
1651
|
});
|
|
1632
1652
|
}
|
|
1633
1653
|
/**
|
|
1634
|
-
* Reads the inline `requestBody` metadata (description / required
|
|
1654
|
+
* Reads the inline `requestBody` metadata (description / required) that OAS exposes
|
|
1635
1655
|
* outside the schema itself. Returns an empty object when the request body is missing or a `$ref`.
|
|
1636
1656
|
*/
|
|
1637
1657
|
function getRequestBodyMeta(operation) {
|
|
@@ -1640,8 +1660,7 @@ function createSchemaParser(ctx) {
|
|
|
1640
1660
|
const inline = body;
|
|
1641
1661
|
return {
|
|
1642
1662
|
description: inline.description,
|
|
1643
|
-
required: inline.required === true
|
|
1644
|
-
contentType: inline.content ? Object.keys(inline.content)[0] : void 0
|
|
1663
|
+
required: inline.required === true
|
|
1645
1664
|
};
|
|
1646
1665
|
}
|
|
1647
1666
|
/**
|
|
@@ -1673,15 +1692,21 @@ function createSchemaParser(ctx) {
|
|
|
1673
1692
|
*/
|
|
1674
1693
|
function parseOperation(options, operation) {
|
|
1675
1694
|
const parameters = getParameters(document, operation).map((param) => parseParameter(options, param));
|
|
1676
|
-
const
|
|
1677
|
-
const requestBodySchemaNode = requestBodySchema ? parseSchema({ schema: requestBodySchema }, options) : void 0;
|
|
1695
|
+
const allContentTypes = ctx.contentType ? [ctx.contentType] : getRequestBodyContentTypes(document, operation);
|
|
1678
1696
|
const requestBodyMeta = getRequestBodyMeta(operation);
|
|
1679
|
-
const
|
|
1697
|
+
const content = allContentTypes.flatMap((ct) => {
|
|
1698
|
+
const schema = getRequestSchema(document, operation, { contentType: ct });
|
|
1699
|
+
if (!schema) return [];
|
|
1700
|
+
return [{
|
|
1701
|
+
contentType: ct,
|
|
1702
|
+
schema: ast.syncOptionality(parseSchema({ schema }, options), requestBodyMeta.required),
|
|
1703
|
+
keysToOmit: collectPropertyKeysByFlag(schema, "readOnly")
|
|
1704
|
+
}];
|
|
1705
|
+
});
|
|
1706
|
+
const requestBody = content.length > 0 || requestBodyMeta.description ? {
|
|
1680
1707
|
description: requestBodyMeta.description,
|
|
1681
|
-
schema: ast.syncOptionality(requestBodySchemaNode, requestBodyMeta.required),
|
|
1682
|
-
keysToOmit: collectPropertyKeysByFlag(requestBodySchema, "readOnly"),
|
|
1683
1708
|
required: requestBodyMeta.required || void 0,
|
|
1684
|
-
|
|
1709
|
+
content: content.length > 0 ? content : void 0
|
|
1685
1710
|
} : void 0;
|
|
1686
1711
|
const responses = operation.getResponseStatusCodes().map((statusCode) => {
|
|
1687
1712
|
const responseObj = operation.getResponseByStatusCode(statusCode);
|