diff --git a/src/templates/angularClient.hbs b/src/templates/angularClient.hbs index ba45ab7..ff7090b 100644 --- a/src/templates/angularClient.hbs +++ b/src/templates/angularClient.hbs @@ -9,15 +9,18 @@ import { {{@key}} } from '../interfaces/{{@key}}.ts'; /** {{description}} */ -{{/if}} +{{/if}} @Injectable({ providedIn: 'root' }) export class {{tagname}}Service { - {{#servers}} - private server: string = '{{{url}}}'; - {{/servers}} + private servers: string[] = [ +{{#servers}} + '{{{url}}}', +{{/servers}} + ] + private readonly headers: HttpHeaders = new HttpHeaders(); constructor(private http: HttpClient) { @@ -26,10 +29,10 @@ export class {{tagname}}Service { {{#paths}} {{#methods}} - public {{operationId}}({{#parameters}}{{name}}: {{type}}, {{/parameters}}{{#with requestBody.content.[application/json]}}body: {{{getType this.type}}}{{/with}}){{#responses}}{{#with content.[application/json]}}: Observable<{{getType type}}>{{/with}}{{/responses}} { + public {{#if operationId}}{{{operationId}}}{{else}}{{methodName}}{{capitalize (removeSymbol ../route)}}{{/if}}({{#parameters}}{{name}}: {{type}}, {{/parameters}}{{#with requestBody.content.[application/json]}}body: {{{getType this.type}}}{{/with}}){{#responses}}{{#with content.[application/json]}}: Observable<{{getType type}}>{{/with}}{{/responses}} { return this.http.{{methodName}}{{#responses}}{{#with content.[application/json]}}<{{getType type}}>{{/with}}{{/responses}}(`{{{../route}}}`{{#requestBody}}, body{{/requestBody}}{{#unless requestBody}}, null{{/unless}}, { headers: this.headers }); } - + {{/methods}} {{/paths}} -} \ No newline at end of file +} diff --git a/src/templates/client.hbs b/src/templates/client.hbs index ab40f40..1da7432 100644 --- a/src/templates/client.hbs +++ b/src/templates/client.hbs @@ -7,17 +7,19 @@ import {{@key}} from '../interfaces/{{@key}}.ts'; /** {{description}} */ -{{/if}} +{{/if}} +const SERVERS = [ {{#servers}} -const SERVER = '{{{url}}}' + '{{{url}}}', {{/servers}} +] {{#paths}} {{#methods}} -export const {{{operationId}}} = async ({{#parameters}}{{name}}: {{getType type}}, {{/parameters}}{{#with requestBody.content.[application/json]}}body: {{{getType this.type}}}{{/with}}){{#responses}}{{#with content.[application/json]}}: {{getType type}}{{/with}}{{/responses}} => { - return await axios.{{methodName}}(`${SERVER}{{{../route}}}`{{#requestBody}}, body{{/requestBody}}) +export const {{#if operationId}}{{{operationId}}}{{else}}{{methodName}}{{capitalize (removeSymbol ../route)}}{{/if}} = async ({{#parameters}}{{name}}: {{getType type}}, {{/parameters}}{{#with requestBody.content.[application/json]}}body: {{{getType this.type}}}{{/with}}) {{#responses}}{{#with content.[application/json]}}: Promise<{{getType type}}>{{/with}}{{/responses}} => { + return axios.{{methodName}}(`${SERVERS[0]}{{{../route}}}`{{#requestBody}}, body{{/requestBody}}) } {{/methods}} -{{/paths}} \ No newline at end of file +{{/paths}} diff --git a/src/templates/javascriptClient.hbs b/src/templates/javascriptClient.hbs index 2a12568..eb48be1 100644 --- a/src/templates/javascriptClient.hbs +++ b/src/templates/javascriptClient.hbs @@ -4,17 +4,19 @@ import axios from 'axios' /** {{description}} */ -{{/if}} +{{/if}} +const SERVERS = [ {{#servers}} -const SERVER = '{{{url}}}'; + '{{{url}}}', {{/servers}} +] {{#paths}} {{#methods}} -export const {{{operationId}}} = async ({{#parameters}}{{name}},{{/parameters}}{{#with requestBody.content.[application/json]}}body{{/with}}) => { - return await axios.{{methodName}}(`${SERVER}{{{../route}}}`{{#requestBody}}, body{{/requestBody}}) +export const {{#if operationId}}{{{operationId}}}{{else}}{{methodName}}{{capitalize (removeSymbol ../route)}}{{/if}} = async ({{#parameters}}{{name}},{{/parameters}}{{#with requestBody.content.[application/json]}}body{{/with}}) => { + return axios.{{methodName}}(`${SERVERS[0]}{{{../route}}}`{{#requestBody}}, body{{/requestBody}}) } {{/methods}} -{{/paths}} \ No newline at end of file +{{/paths}} diff --git a/src/templates/javascriptServer.hbs b/src/templates/javascriptServer.hbs index dfd5ba2..d751e13 100644 --- a/src/templates/javascriptServer.hbs +++ b/src/templates/javascriptServer.hbs @@ -4,8 +4,8 @@ const express = require('express') /** {{description}} */ -{{/if}} +{{/if}} const app = express(); {{#paths}} diff --git a/src/templates/server.hbs b/src/templates/server.hbs index c980803..9b6d566 100644 --- a/src/templates/server.hbs +++ b/src/templates/server.hbs @@ -7,8 +7,8 @@ import {{@key}} from '../interfaces/{{@key}}.ts'; /** {{description}} */ -{{/if}} +{{/if}} const app = express(); {{#paths}}