HTTP client SDK's for the Mail-in-a-Box API.
Client SDK’s for the Mail-in-a-Box API.
Code is generated using the openapi-generator and the HTTP spec.
Initially this project contained the API spec but I submitted those changes upstream.
string
type even if response type is set to application/json
. This seems to conform to the spec.boolean
) for application/json
responses, and we want that type represented in TypeScript. The follow changes were made to support both application/json
and text/html
endpoints that return a primitive data type.diff
--- a/templates/typescript-fetch/apis.mustache
+++ b/templates/typescript-fetch/apis.mustache
@@ -287,7 +287,9 @@ export class {{classname}} extends runtime.BaseAPI {
return new runtime.JSONApiResponse<any>(response);
{{/isListContainer}}
{{#returnSimpleType}}
- return new runtime.TextApiResponse(response) as any;
+ const contentType = response.headers.get('content-type');
+ const isJson = contentType && contentType.includes('application/json');
+ return new runtime[isJson ? 'JSONApiResponse' : 'TextApiResponse'](response) as any;
{{/returnSimpleType}}
{{/returnTypeIsPrimitive}}
{{^returnTypeIsPrimitive}}
diff
--- a/templates/typescript-fetch/runtime.mustache
+++ b/templates/typescript-fetch/runtime.mustache
@@ -50,7 +50,7 @@ export class BaseAPI {
// do not handle correctly sometimes.
url += '?' + this.configuration.queryParamsStringify(context.query);
}
- const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body))
+ const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) || context.headers['Content-Type'] !== 'application/json'
? context.body
: JSON.stringify(context.body);
See LICENSE.md.