diff --git a/modules/openapi-generator/src/main/resources/typescript/http/http.mustache b/modules/openapi-generator/src/main/resources/typescript/http/http.mustache index f5bbf2df97d..f41e109fef6 100644 --- a/modules/openapi-generator/src/main/resources/typescript/http/http.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/http/http.mustache @@ -10,9 +10,17 @@ export enum HttpMethod { PATCH = "PATCH" } +export interface FormEntry { + contentType: string; + value: string | Blob; +} + +export type FormData = { [key: string]: FormEntry }; + + export class Request { public headers: { [key: string]: string } = {}; - public body: string = ""; + public body: string | FormData = ""; public constructor(public url: string, public httpMethod: HttpMethod) { diff --git a/modules/openapi-generator/src/main/resources/typescript/http/isomorphic-fetch.mustache b/modules/openapi-generator/src/main/resources/typescript/http/isomorphic-fetch.mustache index 69aaffd071e..25bef19fa9e 100644 --- a/modules/openapi-generator/src/main/resources/typescript/http/isomorphic-fetch.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/http/isomorphic-fetch.mustache @@ -7,9 +7,19 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary { public send(request: Request): Promise { let method = request.httpMethod.toString(); + let body: string | FormData = ""; + if (typeof request.body === "string") { + body = request.body; + } else { + body = new FormData(); + for (const key in request.body) { + body.append(key, request.body[key].value); + } + } + return fetch(request.url, { method: method, - body: request.body, + body: body, headers: request.headers, credentials: "same-origin" }).then((resp) => { @@ -23,5 +33,6 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary { return new Response(resp.status, headers, body) }); }); + } } diff --git a/modules/openapi-generator/src/main/resources/typescript/models/modelEnum.mustache b/modules/openapi-generator/src/main/resources/typescript/models/modelEnum.mustache new file mode 100644 index 00000000000..5fa32c28b88 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/typescript/models/modelEnum.mustache @@ -0,0 +1,12 @@ +/** + * {{{description}}} + * @export + * @enum {string} + */ +export enum {{classname}} { +{{#allowableValues}} +{{#enumVars}} + {{{name}}} = {{{value}}}{{^-last}},{{/-last}} +{{/enumVars}} +{{/allowableValues}} +} diff --git a/modules/openapi-generator/src/main/resources/typescript/models/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/typescript/models/modelGeneric.mustache new file mode 100644 index 00000000000..d4ba9f7b862 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/typescript/models/modelGeneric.mustache @@ -0,0 +1,41 @@ +/** + * {{{description}}} + * @export + * @interface {{classname}} + */ +export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ +{{#additionalPropertiesType}} + [key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}}; + +{{/additionalPropertiesType}} +{{#vars}} + /** + * {{{description}}} + * @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%> + * @memberof {{classname}} + */ + {{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}; +{{/vars}} +}{{#hasEnums}} + +/** + * @export + * @namespace {{classname}} + */ +export namespace {{classname}} { +{{#vars}} + {{#isEnum}} + /** + * @export + * @enum {string} + */ + export enum {{enumName}} { + {{#allowableValues}} + {{#enumVars}} + {{{name}}} = {{{value}}}{{^-last}},{{/-last}} + {{/enumVars}} + {{/allowableValues}} + } + {{/isEnum}} +{{/vars}} +}{{/hasEnums}}