-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add create requestOpts method to {{classname}}Interface #21708 #21709
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
Open
azertyalex
wants to merge
4
commits into
OpenAPITools:master
Choose a base branch
from
azertyalex:generate-request-config-typescript-fetch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
017440e
feat(types): Add request configuration method to {{classname}}Interface
azertyalex 57ca8c5
update docs and samples
azertyalex dfffb0f
refactor: change naming to better mirror openapi context
azertyalex 3e7b054
docs: update typescript-fetch
azertyalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,20 @@ export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterIn | |
*/ | ||
export interface {{classname}}Interface { | ||
{{#operation}} | ||
/** | ||
* Creates request configuration for {{nickname}} without sending the request | ||
{{#allParams}} | ||
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}} | ||
{{/allParams}} | ||
* @param {*} [options] Override http request option. | ||
{{#isDeprecated}} | ||
* @deprecated | ||
{{/isDeprecated}} | ||
* @throws {RequiredError} | ||
* @memberof {{classname}}Interface | ||
*/ | ||
{{nickname}}RequestConfig({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request, {{/allParams.0}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.RequestOpts>; | ||
|
||
/** | ||
* {{¬es}} | ||
{{#summary}} | ||
|
@@ -95,17 +109,12 @@ export class {{classname}} extends runtime.BaseAPI { | |
|
||
{{#operation}} | ||
/** | ||
{{#notes}} | ||
* {{¬es}} | ||
{{/notes}} | ||
{{#summary}} | ||
* {{&summary}} | ||
{{/summary}} | ||
* Creates request configuration for {{nickname}} without sending the request | ||
{{#isDeprecated}} | ||
* @deprecated | ||
{{/isDeprecated}} | ||
*/ | ||
async {{nickname}}Raw({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request, {{/allParams.0}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<{{{returnType}}}{{^returnType}}void{{/returnType}}>> { | ||
async {{nickname}}RequestConfig({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request, {{/allParams.0}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.RequestOpts> { | ||
{{#allParams}} | ||
{{#required}} | ||
if (requestParameters['{{paramName}}'] == null) { | ||
|
@@ -302,7 +311,7 @@ export class {{classname}} extends runtime.BaseAPI { | |
{{/isDateTimeType}} | ||
{{/pathParams}} | ||
|
||
const response = await this.request({ | ||
const requestOpts: runtime.RequestOpts = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to return the object directly without having a intermediate variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right. writing code in mustache is hard |
||
path: urlPath, | ||
method: '{{httpMethod}}', | ||
headers: headerParameters, | ||
|
@@ -335,7 +344,24 @@ export class {{classname}} extends runtime.BaseAPI { | |
{{#hasFormParams}} | ||
body: formParams, | ||
{{/hasFormParams}} | ||
}, initOverrides); | ||
}; | ||
return requestOpts; | ||
} | ||
|
||
/** | ||
{{#notes}} | ||
* {{¬es}} | ||
{{/notes}} | ||
{{#summary}} | ||
* {{&summary}} | ||
{{/summary}} | ||
{{#isDeprecated}} | ||
* @deprecated | ||
{{/isDeprecated}} | ||
*/ | ||
async {{nickname}}Raw({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request, {{/allParams.0}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<{{{returnType}}}{{^returnType}}void{{/returnType}}>> { | ||
const requestConfig = await this.{{nickname}}RequestConfig({{#allParams.0}}requestParameters, {{/allParams.0}}initOverrides); | ||
const response = await this.request(requestConfig, initOverrides); | ||
|
||
{{#returnType}} | ||
{{#isResponseFile}} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface in
Runtime.ts
isRequestOpts
. It might be better to refer to this as{{nickname}}RequestOpts
instead of{{nickname}}RequestConfig
&creates request options
as otherwise the name of the method may be misleading.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some libraries it's called request config, such as axios. But it indeed makes more sense to have opts/options here.