Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
out/
dist/
/node_modules/
6 changes: 5 additions & 1 deletion lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Codegen {
return Case.pascal(value);
});

this.engine.registerHelper('concat', (...values: string[]) => {
this.engine.registerHelper('concat', (...values) => {
const options = values.pop();

return values.join('');
Expand Down Expand Up @@ -65,6 +65,10 @@ export class Codegen {
return Array.isArray(value1) && value1.indexOf(value2) >= 0;
});

this.engine.registerHelper('contains?', (value1: string, value2: string, _options) => {
return value1.indexOf(value2) >= 0;
});

this.engine.registerHelper('successResponses', (value: OpenAPI3.Responses, _options): OpenAPI3.Responses => {
const out: OpenAPI3.Responses = {};
Object.keys(value).filter(_ => !_.match(/^([45][\dX]{2}|default)$/)).forEach(key => {
Expand Down
30 changes: 24 additions & 6 deletions templates/typescript/angular/client.ts.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,30 @@ export class {{className info.title}} {
}
{{/first}}{{/each}}

return this.httpClient.request<any>('{{method}}', `${this.basePath}${path}`, {
{{#with (deref requestBody @root)}}body: this._encodeHttpBody(body, {{#first content}}'{{@key}}'{{/first}}),{{/with}}
params,
headers,
{{! withCredentials: this.configuration.withCredentials, }}
});
{{#each responses}}
{{#if @first}}
{{#with (deref this)}}
{{#first content}}
{{#if (eq? @key "application/json")}}
return this.httpClient.request<any>('{{../../method}}', `${this.basePath}${path}`, {
{{#with (deref ../../requestBody @root)}}body: this._encodeHttpBody(body, {{#first content}}'{{@key}}'{{/first}}),{{/with}}
responseType: 'json',
params,
headers,
});
{{/if}}
{{#if (contains? @key "text")}}
return this.httpClient.request('{{../../method}}', `${this.basePath}${path}`, {
{{#with (deref ../../requestBody @root)}}body: this._encodeHttpBody(body, {{#first content}}'{{@key}}'{{/first}}),{{/with}}
responseType: 'text',
params,
headers,
});
{{/if}}
{{/first}}
{{/with}}
{{/if}}
{{/each}}
}

{{/inline}}
Expand Down