Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add response type text #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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/
18 changes: 17 additions & 1 deletion lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,23 @@ export class Codegen {
return Case.pascal(value);
});

this.engine.registerHelper('concat', (...values: string[]) => {
this.engine.registerHelper('if_eq', function(a, b, opts) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for? Use {#if (eq? a b)}

if (a == b) {
return opts.fn(this);
} else {
return opts.inverse(this);
}
});

this.engine.registerHelper('assign', function (varName, varValue, options) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure should be immutable. No assign allowed

if (!options.data.root) {
options.data.root = {};
}
options.data.root[varName] = varValue;
});

// tslint:disable-next-line
this.engine.registerHelper('concat', (...values) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why typescript without types?

const options = values.pop();

return values.join('');
Expand Down
28 changes: 27 additions & 1 deletion templates/typescript/angular/client.ts.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,38 @@ export class {{className info.title}} {
}
{{/first}}{{/each}}

{{#each responses}}
{{#if @first}}
{{#with (deref this)}}{{#first content}}{{#switch @key}}
{{#case "application/json"}}
{{assign 'responseType' 'json'}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to have assign here. Just put two conditional blocks below:
one for including <any> and one for defining responseType

{{/case}}
{{#case "text/csv"}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too strict should me some match against MIME top class

{{assign 'responseType' 'text'}}
{{/case}}
{{#default}}
{{assign 'responseType' 'json'}}
{{/default}}
{{/switch}}{{/first}}{{/with}}
{{/if}}
{{/each}}

{{#if_eq @root.responseType '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,
{{! withCredentials: this.configuration.withCredentials, }}
});
{{/if_eq}}
{{#if_eq @root.responseType '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_eq}}
}

{{/inline}}
Expand Down