@kubb/adapter-oas 5.2.0 → 5.2.1
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 +21 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
package/dist/index.js
CHANGED
|
@@ -594,6 +594,19 @@ function isBinary(schema) {
|
|
|
594
594
|
return schema.type === "string" && schema.contentMediaType === "application/octet-stream";
|
|
595
595
|
}
|
|
596
596
|
/**
|
|
597
|
+
* Returns the binary schema for an `application/octet-stream` entry the OAS 3.1 upgrade emptied
|
|
598
|
+
* out, or `undefined` when the entry carries a schema of its own. Without the fallback such a
|
|
599
|
+
* body resolves to the empty schema type instead of a blob.
|
|
600
|
+
*/
|
|
601
|
+
function getBinaryFallbackSchema(mediaType, schema) {
|
|
602
|
+
if (mediaType !== "application/octet-stream") return void 0;
|
|
603
|
+
if (schema && Object.keys(schema).length > 0) return void 0;
|
|
604
|
+
return {
|
|
605
|
+
type: "string",
|
|
606
|
+
contentMediaType: "application/octet-stream"
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
597
610
|
* MIME type fragments that mark a media type as JSON-like.
|
|
598
611
|
*
|
|
599
612
|
* A content type is JSON when it contains any of these substrings. The `+json` entry catches
|
|
@@ -2062,9 +2075,8 @@ function getResponseBody(responseBody, contentType) {
|
|
|
2062
2075
|
if (isReference(responseBody)) return false;
|
|
2063
2076
|
const body = responseBody;
|
|
2064
2077
|
if (!body.content) return false;
|
|
2065
|
-
if (contentType) return contentType in body.content ? body.content[contentType] : false;
|
|
2066
|
-
|
|
2067
|
-
return picked ? picked[1] : false;
|
|
2078
|
+
if (contentType) return contentType in body.content ? [contentType, body.content[contentType]] : false;
|
|
2079
|
+
return pickContentEntry(body.content);
|
|
2068
2080
|
}
|
|
2069
2081
|
/**
|
|
2070
2082
|
* Returns the response schema for a given operation and HTTP status code.
|
|
@@ -2084,7 +2096,10 @@ function getResponseSchema({ document, operation, refs, statusCode, options = {}
|
|
|
2084
2096
|
statusCode
|
|
2085
2097
|
}), options.contentType);
|
|
2086
2098
|
if (responseBody === false) return {};
|
|
2087
|
-
const
|
|
2099
|
+
const [mediaType, entry] = responseBody;
|
|
2100
|
+
const schema = entry.schema;
|
|
2101
|
+
const binary = getBinaryFallbackSchema(mediaType, schema);
|
|
2102
|
+
if (binary) return binary;
|
|
2088
2103
|
if (!schema) return {};
|
|
2089
2104
|
return dereferenceWithRef(document, schema);
|
|
2090
2105
|
}
|
|
@@ -2105,10 +2120,8 @@ function getRequestSchema({ document, operation, refs, options = {} }) {
|
|
|
2105
2120
|
if (requestBody === false) return null;
|
|
2106
2121
|
const mediaType = Array.isArray(requestBody) ? requestBody[0] : options.contentType;
|
|
2107
2122
|
const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema;
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
contentMediaType: "application/octet-stream"
|
|
2111
|
-
};
|
|
2123
|
+
const binary = getBinaryFallbackSchema(mediaType, schema);
|
|
2124
|
+
if (binary) return binary;
|
|
2112
2125
|
if (!schema) return null;
|
|
2113
2126
|
return dereferenceWithRef(document, schema);
|
|
2114
2127
|
}
|