@kubb/adapter-oas 5.0.0-beta.28 → 5.0.0-beta.29
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 +45 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -16
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/parser.ts +22 -13
- package/src/resolvers.ts +30 -0
package/dist/index.js
CHANGED
|
@@ -756,12 +756,6 @@ function getPrimitiveType(type) {
|
|
|
756
756
|
return "string";
|
|
757
757
|
}
|
|
758
758
|
/**
|
|
759
|
-
* Narrows a content-type string to the `MediaType` union Kubb recognizes, or returns `null`.
|
|
760
|
-
*/
|
|
761
|
-
function getMediaType(contentType) {
|
|
762
|
-
return Object.values(ast.mediaTypes).includes(contentType) ? contentType : null;
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
759
|
* Returns all parameters for an operation, merging path-level and operation-level entries.
|
|
766
760
|
* Operation-level parameters override path-level ones with the same `in:name` key.
|
|
767
761
|
* `$ref` parameters resolve via `dereferenceWithRef` for backward compatibility.
|
|
@@ -1093,6 +1087,31 @@ function getRequestBodyContentTypes(document, operation) {
|
|
|
1093
1087
|
if (!body) return [];
|
|
1094
1088
|
return body.content ? Object.keys(body.content) : [];
|
|
1095
1089
|
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Returns all response content type keys for an operation at a given status code.
|
|
1092
|
+
*
|
|
1093
|
+
* Response `$ref`s are resolved in-place first — the same mutation `getResponseSchema` performs —
|
|
1094
|
+
* so the returned list reflects the available content types even for referenced responses.
|
|
1095
|
+
*
|
|
1096
|
+
* @example
|
|
1097
|
+
* ```ts
|
|
1098
|
+
* getResponseBodyContentTypes(document, operation, 200)
|
|
1099
|
+
* // ['application/json', 'application/xml']
|
|
1100
|
+
* ```
|
|
1101
|
+
*/
|
|
1102
|
+
function getResponseBodyContentTypes(document, operation, statusCode) {
|
|
1103
|
+
if (operation.schema.responses) {
|
|
1104
|
+
const responses = operation.schema.responses;
|
|
1105
|
+
for (const key in responses) {
|
|
1106
|
+
const schema = responses[key];
|
|
1107
|
+
if (schema && isReference(schema)) responses[key] = resolveRef(document, schema.$ref);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
const responseObj = operation.getResponseByStatusCode(statusCode);
|
|
1111
|
+
if (!responseObj || typeof responseObj !== "object" || isReference(responseObj)) return [];
|
|
1112
|
+
const body = responseObj;
|
|
1113
|
+
return body.content ? Object.keys(body.content) : [];
|
|
1114
|
+
}
|
|
1096
1115
|
//#endregion
|
|
1097
1116
|
//#region src/parser.ts
|
|
1098
1117
|
/**
|
|
@@ -1797,20 +1816,30 @@ function createSchemaParser(ctx) {
|
|
|
1797
1816
|
} : void 0;
|
|
1798
1817
|
const responses = operation.getResponseStatusCodes().map((statusCode) => {
|
|
1799
1818
|
const responseObj = operation.getResponseByStatusCode(statusCode);
|
|
1800
|
-
const responseSchema = getResponseSchema(document, operation, statusCode, { contentType: ctx.contentType });
|
|
1801
1819
|
const responseName = operationName ? `${operationName}Status${statusCode}` : void 0;
|
|
1802
|
-
const
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1820
|
+
const { description } = getResponseMeta(responseObj);
|
|
1821
|
+
const parseEntrySchema = (contentType) => {
|
|
1822
|
+
const raw = getResponseSchema(document, operation, statusCode, { contentType });
|
|
1823
|
+
return {
|
|
1824
|
+
schema: raw && Object.keys(raw).length > 0 ? parseSchema({
|
|
1825
|
+
schema: raw,
|
|
1826
|
+
name: responseName
|
|
1827
|
+
}, options) : ast.createSchema({ type: typeOptionMap.get(options.emptySchemaType) }),
|
|
1828
|
+
keysToOmit: collectPropertyKeysByFlag(raw, "writeOnly")
|
|
1829
|
+
};
|
|
1830
|
+
};
|
|
1831
|
+
const content = (ctx.contentType ? [ctx.contentType] : getResponseBodyContentTypes(document, operation, statusCode)).map((contentType) => ({
|
|
1832
|
+
contentType,
|
|
1833
|
+
...parseEntrySchema(contentType)
|
|
1834
|
+
}));
|
|
1835
|
+
if (content.length === 0) content.push({
|
|
1836
|
+
contentType: operation.contentType || "application/json",
|
|
1837
|
+
...parseEntrySchema(ctx.contentType)
|
|
1838
|
+
});
|
|
1808
1839
|
return ast.createResponse({
|
|
1809
1840
|
statusCode,
|
|
1810
1841
|
description,
|
|
1811
|
-
|
|
1812
|
-
mediaType,
|
|
1813
|
-
keysToOmit: collectPropertyKeysByFlag(responseSchema, "writeOnly")
|
|
1842
|
+
content
|
|
1814
1843
|
});
|
|
1815
1844
|
});
|
|
1816
1845
|
const urlPath = new URLPath(operation.path);
|