Skip to content

HTTP client SDK's for the Mail-in-a-Box API.

License

Notifications You must be signed in to change notification settings

badsyntax/mailinabox-api

Repository files navigation

Mail-in-a-Box API

Build & Publish

Client SDK's for the Mail-in-a-Box API.

Code is generated using the openapi-generator and the HTTP spec.

HTTP specification

Initially this project contained the API spec but I submitted those changes upstream.

Clients

typescript-fetch

Template changes

Supporting oneOf response types

The Response Body spec says:

The schema keyword is used to describe the response body. A schema can define:

  • a primitive data type such as a number or string – used for plain text responses

For endpoints that return a single primitive data type, the default generator will build the client so that it returns a string type even if response type is set to application/json. This seems to conform to the spec.

The mailinabox API returns primitive data types (eg 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.

--- 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}}

Support posting text/(plain|html) bodies

Prevent quotes added to text/plain POST body. This seems like a bug in the generator, see OpenAPITools/openapi-generator#7083.

--- 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);

php

python

License

See LICENSE.md.