项目作者: badsyntax

项目描述 :
HTTP client SDK's for the Mail-in-a-Box API.
高级语言: HTML
项目地址: git://github.com/badsyntax/mailinabox-api.git
创建时间: 2020-06-26T11:14:22Z
项目社区:https://github.com/badsyntax/mailinabox-api

开源协议:MIT License

下载


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.

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

## Support posting text/(plain|html) bodies

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

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

php

python

License

See LICENSE.md.