forked from loafle/openapi-generator-original
Added generic enum
This commit is contained in:
parent
06d9556f13
commit
05f64c6732
@ -10,9 +10,17 @@ export enum HttpMethod {
|
|||||||
PATCH = "PATCH"
|
PATCH = "PATCH"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FormEntry {
|
||||||
|
contentType: string;
|
||||||
|
value: string | Blob;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FormData = { [key: string]: FormEntry };
|
||||||
|
|
||||||
|
|
||||||
export class Request {
|
export class Request {
|
||||||
public headers: { [key: string]: string } = {};
|
public headers: { [key: string]: string } = {};
|
||||||
public body: string = "";
|
public body: string | FormData = "";
|
||||||
|
|
||||||
public constructor(public url: string, public httpMethod: HttpMethod) {
|
public constructor(public url: string, public httpMethod: HttpMethod) {
|
||||||
|
|
||||||
|
@ -7,9 +7,19 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
|
|||||||
|
|
||||||
public send(request: Request): Promise<Response> {
|
public send(request: Request): Promise<Response> {
|
||||||
let method = request.httpMethod.toString();
|
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, {
|
return fetch(request.url, {
|
||||||
method: method,
|
method: method,
|
||||||
body: request.body,
|
body: body,
|
||||||
headers: request.headers,
|
headers: request.headers,
|
||||||
credentials: "same-origin"
|
credentials: "same-origin"
|
||||||
}).then((resp) => {
|
}).then((resp) => {
|
||||||
@ -23,5 +33,6 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
|
|||||||
return new Response(resp.status, headers, body)
|
return new Response(resp.status, headers, body)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
modules/openapi-generator/src/main/resources/typescript/models/modelEnum.mustache
vendored
Normal file
12
modules/openapi-generator/src/main/resources/typescript/models/modelEnum.mustache
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* {{{description}}}
|
||||||
|
* @export
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
export enum {{classname}} {
|
||||||
|
{{#allowableValues}}
|
||||||
|
{{#enumVars}}
|
||||||
|
{{{name}}} = <any> {{{value}}}{{^-last}},{{/-last}}
|
||||||
|
{{/enumVars}}
|
||||||
|
{{/allowableValues}}
|
||||||
|
}
|
41
modules/openapi-generator/src/main/resources/typescript/models/modelGeneric.mustache
vendored
Normal file
41
modules/openapi-generator/src/main/resources/typescript/models/modelGeneric.mustache
vendored
Normal file
@ -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}}} = <any> {{{value}}}{{^-last}},{{/-last}}
|
||||||
|
{{/enumVars}}
|
||||||
|
{{/allowableValues}}
|
||||||
|
}
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/vars}}
|
||||||
|
}{{/hasEnums}}
|
Loading…
x
Reference in New Issue
Block a user