From ed68eebcd7bee3320983e97e0d90945bf88ad745 Mon Sep 17 00:00:00 2001 From: Adan Toscano Date: Thu, 14 Sep 2023 14:08:00 +0200 Subject: [PATCH 1/6] refactor: remove new line if no description --- src/templates/angularClient.hbs | 6 +++--- src/templates/client.hbs | 4 ++-- src/templates/javascriptClient.hbs | 4 ++-- src/templates/javascriptServer.hbs | 2 +- src/templates/server.hbs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/templates/angularClient.hbs b/src/templates/angularClient.hbs index ba45ab7..014a345 100644 --- a/src/templates/angularClient.hbs +++ b/src/templates/angularClient.hbs @@ -9,8 +9,8 @@ import { {{@key}} } from '../interfaces/{{@key}}.ts'; /** {{description}} */ -{{/if}} +{{/if}} @Injectable({ providedIn: 'root' }) @@ -29,7 +29,7 @@ export class {{tagname}}Service { 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}} { 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..ad5caa8 100644 --- a/src/templates/client.hbs +++ b/src/templates/client.hbs @@ -7,8 +7,8 @@ import {{@key}} from '../interfaces/{{@key}}.ts'; /** {{description}} */ -{{/if}} +{{/if}} {{#servers}} const SERVER = '{{{url}}}' {{/servers}} @@ -20,4 +20,4 @@ export const {{{operationId}}} = async ({{#parameters}}{{name}}: {{getType type} } {{/methods}} -{{/paths}} \ No newline at end of file +{{/paths}} diff --git a/src/templates/javascriptClient.hbs b/src/templates/javascriptClient.hbs index 2a12568..2643fe9 100644 --- a/src/templates/javascriptClient.hbs +++ b/src/templates/javascriptClient.hbs @@ -4,8 +4,8 @@ import axios from 'axios' /** {{description}} */ -{{/if}} +{{/if}} {{#servers}} const SERVER = '{{{url}}}'; {{/servers}} @@ -17,4 +17,4 @@ export const {{{operationId}}} = async ({{#parameters}}{{name}},{{/parameters}}{ } {{/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}} From 793ecce8388ddb340491551699901f83e279a53d Mon Sep 17 00:00:00 2001 From: Adan Toscano Date: Thu, 14 Sep 2023 17:21:46 +0200 Subject: [PATCH 2/6] feat: default names if no operationId --- src/templates/client.hbs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/templates/client.hbs b/src/templates/client.hbs index ad5caa8..bbc0036 100644 --- a/src/templates/client.hbs +++ b/src/templates/client.hbs @@ -9,14 +9,16 @@ import {{@key}} from '../interfaces/{{@key}}.ts'; */ {{/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}}operation{{@index}}{{/if}} = 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}}(`${SERVERS[0]}{{{../route}}}`{{#requestBody}}, body{{/requestBody}}) } {{/methods}} From bd98fa5363e098e58b5a85fd278fb37f199c91ce Mon Sep 17 00:00:00 2001 From: Adan Toscano Date: Thu, 14 Sep 2023 17:34:10 +0200 Subject: [PATCH 3/6] fix: missing promise and no needed await --- src/templates/client.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/templates/client.hbs b/src/templates/client.hbs index bbc0036..bb7f1b5 100644 --- a/src/templates/client.hbs +++ b/src/templates/client.hbs @@ -17,8 +17,8 @@ const SERVERS = [ {{#paths}} {{#methods}} -export const {{#if operationId}}{{{operationId}}}{{else}}operation{{@index}}{{/if}} = 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}}(`${SERVERS[0]}{{{../route}}}`{{#requestBody}}, body{{/requestBody}}) +export const {{#if operationId}}{{{operationId}}}{{else}}operation{{@index}}{{/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}} From df732a67c17dd560681e9a0c268e9eb3d7da1800 Mon Sep 17 00:00:00 2001 From: Adan Toscano Date: Fri, 15 Sep 2023 17:09:29 +0200 Subject: [PATCH 4/6] feat: create a default name based on path and method --- src/templates/client.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/client.hbs b/src/templates/client.hbs index bb7f1b5..1da7432 100644 --- a/src/templates/client.hbs +++ b/src/templates/client.hbs @@ -17,7 +17,7 @@ const SERVERS = [ {{#paths}} {{#methods}} -export const {{#if operationId}}{{{operationId}}}{{else}}operation{{@index}}{{/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}} => { +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}} From 7d32427a909d60d04d3fed8a0b311e064664cf86 Mon Sep 17 00:00:00 2001 From: Adan Toscano Date: Fri, 15 Sep 2023 17:21:42 +0200 Subject: [PATCH 5/6] fix: js and angular client template --- src/templates/angularClient.hbs | 9 +++++---- src/templates/javascriptClient.hbs | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/templates/angularClient.hbs b/src/templates/angularClient.hbs index 014a345..a2d5ce7 100644 --- a/src/templates/angularClient.hbs +++ b/src/templates/angularClient.hbs @@ -15,9 +15,10 @@ import { {{@key}} } from '../interfaces/{{@key}}.ts'; 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,7 +27,7 @@ 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 }); } diff --git a/src/templates/javascriptClient.hbs b/src/templates/javascriptClient.hbs index 2643fe9..d0ff8cc 100644 --- a/src/templates/javascriptClient.hbs +++ b/src/templates/javascriptClient.hbs @@ -6,14 +6,16 @@ import axios from 'axios' */ {{/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}} From 889f4099df6088f3426b3d992e6abc20835740bf Mon Sep 17 00:00:00 2001 From: Adan Toscano Date: Mon, 18 Sep 2023 10:17:04 +0200 Subject: [PATCH 6/6] fix: template styles --- src/templates/angularClient.hbs | 6 ++++-- src/templates/javascriptClient.hbs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/templates/angularClient.hbs b/src/templates/angularClient.hbs index a2d5ce7..ff7090b 100644 --- a/src/templates/angularClient.hbs +++ b/src/templates/angularClient.hbs @@ -16,8 +16,10 @@ import { {{@key}} } from '../interfaces/{{@key}}.ts'; }) export class {{tagname}}Service { private servers: string[] = [ - {{#servers}}'{{{url}}}', - {{/servers}}] +{{#servers}} + '{{{url}}}', +{{/servers}} + ] private readonly headers: HttpHeaders = new HttpHeaders(); diff --git a/src/templates/javascriptClient.hbs b/src/templates/javascriptClient.hbs index d0ff8cc..eb48be1 100644 --- a/src/templates/javascriptClient.hbs +++ b/src/templates/javascriptClient.hbs @@ -15,7 +15,7 @@ const SERVERS = [ {{#paths}} {{#methods}} 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}}) + return axios.{{methodName}}(`${SERVERS[0]}{{{../route}}}`{{#requestBody}}, body{{/requestBody}}) } {{/methods}}