Skip to content

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
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Copy link
Contributor

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 is RequestOpts. 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.

Copy link
Author

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.


/**
* {{&notes}}
{{#summary}}
Expand Down Expand Up @@ -95,17 +109,12 @@ export class {{classname}} extends runtime.BaseAPI {

{{#operation}}
/**
{{#notes}}
* {{&notes}}
{{/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) {
Expand Down Expand Up @@ -302,7 +311,7 @@ export class {{classname}} extends runtime.BaseAPI {
{{/isDateTimeType}}
{{/pathParams}}

const response = await this.request({
const requestOpts: runtime.RequestOpts = {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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,
Expand Down Expand Up @@ -335,7 +344,24 @@ export class {{classname}} extends runtime.BaseAPI {
{{#hasFormParams}}
body: formParams,
{{/hasFormParams}}
}, initOverrides);
};
return requestOpts;
}

/**
{{#notes}}
* {{&notes}}
{{/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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export interface ListRequest {
export class DefaultApi extends runtime.BaseAPI {

/**
* Creates request configuration for list without sending the request
*/
async listRaw(requestParameters: ListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Club>> {
async listRequestConfig(requestParameters: ListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.RequestOpts> {
if (requestParameters['personId'] == null) {
throw new runtime.RequiredError(
'personId',
Expand All @@ -49,12 +50,20 @@ export class DefaultApi extends runtime.BaseAPI {
let urlPath = `/person/display/{personId}`;
urlPath = urlPath.replace(`{${"personId"}}`, encodeURIComponent(String(requestParameters['personId'])));

const response = await this.request({
const requestOpts: runtime.RequestOpts = {
path: urlPath,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);
};
return requestOpts;
}

/**
*/
async listRaw(requestParameters: ListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Club>> {
const requestConfig = await this.listRequestConfig(requestParameters, initOverrides);
const response = await this.request(requestConfig, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => ClubFromJSON(jsonValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export interface ListRequest {
export class DefaultApi extends runtime.BaseAPI {

/**
* Creates request configuration for list without sending the request
*/
async listRaw(requestParameters: ListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Club>> {
async listRequestConfig(requestParameters: ListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.RequestOpts> {
if (requestParameters['personId'] == null) {
throw new runtime.RequiredError(
'personId',
Expand All @@ -49,12 +50,20 @@ export class DefaultApi extends runtime.BaseAPI {
let urlPath = `/person/display/{personId}`;
urlPath = urlPath.replace(`{${"personId"}}`, encodeURIComponent(String(requestParameters['personId'])));

const response = await this.request({
const requestOpts: runtime.RequestOpts = {
path: urlPath,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);
};
return requestOpts;
}

/**
*/
async listRaw(requestParameters: ListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Club>> {
const requestConfig = await this.listRequestConfig(requestParameters, initOverrides);
const response = await this.request(requestConfig, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => ClubFromJSON(jsonValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ export interface 123testSpecialTagsRequest {
export class AnotherFakeApi extends runtime.BaseAPI {

/**
* To test special tags and operation ID starting with number
* To test special tags
* Creates request configuration for _123testSpecialTags without sending the request
*/
async _123testSpecialTagsRaw(requestParameters: 123testSpecialTagsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Client>> {
async _123testSpecialTagsRequestConfig(requestParameters: 123testSpecialTagsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.RequestOpts> {
if (requestParameters['client'] == null) {
throw new runtime.RequiredError(
'client',
Expand All @@ -52,13 +51,23 @@ export class AnotherFakeApi extends runtime.BaseAPI {

let urlPath = `/another-fake/dummy`;

const response = await this.request({
const requestOpts: runtime.RequestOpts = {
path: urlPath,
method: 'PATCH',
headers: headerParameters,
query: queryParameters,
body: ClientToJSON(requestParameters['client']),
}, initOverrides);
};
return requestOpts;
}

/**
* To test special tags and operation ID starting with number
* To test special tags
*/
async _123testSpecialTagsRaw(requestParameters: 123testSpecialTagsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Client>> {
const requestConfig = await this._123testSpecialTagsRequestConfig(requestParameters, initOverrides);
const response = await this.request(requestConfig, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => ClientFromJSON(jsonValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,30 @@ import {
export class DefaultApi extends runtime.BaseAPI {

/**
* Creates request configuration for fooGet without sending the request
*/
async fooGetRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<FooGetDefaultResponse>> {
async fooGetRequestConfig(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.RequestOpts> {
const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};


let urlPath = `/foo`;

const response = await this.request({
const requestOpts: runtime.RequestOpts = {
path: urlPath,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);
};
return requestOpts;
}

/**
*/
async fooGetRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<FooGetDefaultResponse>> {
const requestConfig = await this.fooGetRequestConfig(initOverrides);
const response = await this.request(requestConfig, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => FooGetDefaultResponseFromJSON(jsonValue));
}
Expand Down
Loading