@kubb/adapter-oas 5.1.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.d.ts +3 -3
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
package/dist/index.cjs
CHANGED
|
@@ -617,6 +617,19 @@ function isBinary(schema) {
|
|
|
617
617
|
return schema.type === "string" && schema.contentMediaType === "application/octet-stream";
|
|
618
618
|
}
|
|
619
619
|
/**
|
|
620
|
+
* Returns the binary schema for an `application/octet-stream` entry the OAS 3.1 upgrade emptied
|
|
621
|
+
* out, or `undefined` when the entry carries a schema of its own. Without the fallback such a
|
|
622
|
+
* body resolves to the empty schema type instead of a blob.
|
|
623
|
+
*/
|
|
624
|
+
function getBinaryFallbackSchema(mediaType, schema) {
|
|
625
|
+
if (mediaType !== "application/octet-stream") return void 0;
|
|
626
|
+
if (schema && Object.keys(schema).length > 0) return void 0;
|
|
627
|
+
return {
|
|
628
|
+
type: "string",
|
|
629
|
+
contentMediaType: "application/octet-stream"
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
620
633
|
* MIME type fragments that mark a media type as JSON-like.
|
|
621
634
|
*
|
|
622
635
|
* A content type is JSON when it contains any of these substrings. The `+json` entry catches
|
|
@@ -2085,9 +2098,8 @@ function getResponseBody(responseBody, contentType) {
|
|
|
2085
2098
|
if (isReference(responseBody)) return false;
|
|
2086
2099
|
const body = responseBody;
|
|
2087
2100
|
if (!body.content) return false;
|
|
2088
|
-
if (contentType) return contentType in body.content ? body.content[contentType] : false;
|
|
2089
|
-
|
|
2090
|
-
return picked ? picked[1] : false;
|
|
2101
|
+
if (contentType) return contentType in body.content ? [contentType, body.content[contentType]] : false;
|
|
2102
|
+
return pickContentEntry(body.content);
|
|
2091
2103
|
}
|
|
2092
2104
|
/**
|
|
2093
2105
|
* Returns the response schema for a given operation and HTTP status code.
|
|
@@ -2107,7 +2119,10 @@ function getResponseSchema({ document, operation, refs, statusCode, options = {}
|
|
|
2107
2119
|
statusCode
|
|
2108
2120
|
}), options.contentType);
|
|
2109
2121
|
if (responseBody === false) return {};
|
|
2110
|
-
const
|
|
2122
|
+
const [mediaType, entry] = responseBody;
|
|
2123
|
+
const schema = entry.schema;
|
|
2124
|
+
const binary = getBinaryFallbackSchema(mediaType, schema);
|
|
2125
|
+
if (binary) return binary;
|
|
2111
2126
|
if (!schema) return {};
|
|
2112
2127
|
return dereferenceWithRef(document, schema);
|
|
2113
2128
|
}
|
|
@@ -2128,10 +2143,8 @@ function getRequestSchema({ document, operation, refs, options = {} }) {
|
|
|
2128
2143
|
if (requestBody === false) return null;
|
|
2129
2144
|
const mediaType = Array.isArray(requestBody) ? requestBody[0] : options.contentType;
|
|
2130
2145
|
const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema;
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
contentMediaType: "application/octet-stream"
|
|
2134
|
-
};
|
|
2146
|
+
const binary = getBinaryFallbackSchema(mediaType, schema);
|
|
2147
|
+
if (binary) return binary;
|
|
2135
2148
|
if (!schema) return null;
|
|
2136
2149
|
return dereferenceWithRef(document, schema);
|
|
2137
2150
|
}
|