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 headers support to Flow method #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 templates/flow-class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class {{&className}} {
method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH',
query: {[string]: mixed},
body?: {[string]: any} | string | Array<any>,
headers?: {[string]: any} | string | Array<any>,
) {
throw new Error("Must be implemented");
}
Expand Down
16 changes: 14 additions & 2 deletions templates/flow-method.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ static async {{&methodName}}(
{{/parameters}}
}
{{/hasParameters}}
): Promise<{{#methodResponse}}"{{&methodResponse}}"{{/methodResponse}}{{#methodFlowType}}{{> type}}{{/methodFlowType}}> {
): Promise<{{#methodResponse}}"{{&methodResponse}}"{{/methodResponse}}{{#methodFlowType}}{{> type}}{{/methodFlowType}}{{^methodResponse}}{{^methodFlowType}}any{{/methodFlowType}}{{/methodResponse}}> {
let path = '{{&path}}';
let body;
let query = {};
let headers = {};
{{#parameters}}
{{#required}}
if(parameters['{{&camelCaseName}}'] === undefined) {
Expand All @@ -21,6 +22,17 @@ static async {{&methodName}}(
path = path.replace('{{=<% %>=}}{<%&name%>}<%={{ }}=%>', `${parameters['{{&camelCaseName}}']}`);
{{/isPathParameter}}

{{#isHeaderParameter}}
{{#isSingleton}}
headers['{{&name}}'] = '{{&singleton}}';
{{/isSingleton}}
{{^isSingleton}}
if(parameters['{{&camelCaseName}}'] !== undefined) {
headers['{{&name}}'] = parameters['{{&camelCaseName}}'];
}
{{/isSingleton}}
{{/isHeaderParameter}}

{{#isBodyParameter}}
if(parameters['{{&camelCaseName}}'] !== undefined) {
body = parameters['{{&camelCaseName}}'];
Expand All @@ -35,5 +47,5 @@ static async {{&methodName}}(

{{/parameters}}

return await this.request(path, '{{method}}', query, body);
return await this.request(path, '{{method}}', query, body, headers);
}