Skip to content

Commit

Permalink
feat(typescript-axios): injectable FormData (#7455)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Somogyvari <peter.metz@unarin.com>
  • Loading branch information
petermetz authored Sep 21, 2020
1 parent 7fa02ee commit 2768021
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: '{{httpMethod}}', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;{{#vendorExtensions}}{{#hasFormParams}}
const localVarFormParams = new {{^multipartFormData}}URLSearchParams(){{/multipartFormData}}{{#multipartFormData}}FormData(){{/multipartFormData}};{{/hasFormParams}}{{/vendorExtensions}}
const localVarFormParams = new {{^multipartFormData}}URLSearchParams(){{/multipartFormData}}{{#multipartFormData}}(configuration?.formDataCtor || FormData)(){{/multipartFormData}};{{/hasFormParams}}{{/vendorExtensions}}
{{#authMethods}}
// authentication {{name}} required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ConfigurationParameters {
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
basePath?: string;
baseOptions?: any;
formDataCtor?: new () => any;
}

export class Configuration {
Expand Down Expand Up @@ -53,6 +54,14 @@ export class Configuration {
* @memberof Configuration
*/
baseOptions?: any;
/**
* The FormData constructor that will be used to create multipart form data
* requests. You can inject this here so that execution environments that
* do not support the FormData class can still run the generated client.
*
* @type {new () => FormData}
*/
formDataCtor?: new () => any;

constructor(param: ConfigurationParameters = {}) {
this.apiKey = param.apiKey;
Expand All @@ -61,5 +70,6 @@ export class Configuration {
this.accessToken = param.accessToken;
this.basePath = param.basePath;
this.baseOptions = param.baseOptions;
this.formDataCtor = param.formDataCtor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -241,6 +242,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'PATCH', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -281,6 +283,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'PATCH', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ConfigurationParameters {
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
basePath?: string;
baseOptions?: any;
formDataCtor?: new () => any;
}

export class Configuration {
Expand Down Expand Up @@ -64,6 +65,14 @@ export class Configuration {
* @memberof Configuration
*/
baseOptions?: any;
/**
* The FormData constructor that will be used to create multipart form data
* requests. You can inject this here so that execution environments that
* do not support the FormData class can still run the generated client.
*
* @type {new () => FormData}
*/
formDataCtor?: new () => any;

constructor(param: ConfigurationParameters = {}) {
this.apiKey = param.apiKey;
Expand All @@ -72,5 +81,6 @@ export class Configuration {
this.accessToken = param.accessToken;
this.basePath = param.basePath;
this.baseOptions = param.baseOptions;
this.formDataCtor = param.formDataCtor;
}
}
22 changes: 21 additions & 1 deletion samples/client/petstore/typescript-axios/builds/default/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -327,6 +328,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'DELETE', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -381,6 +383,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -435,6 +438,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -490,6 +494,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -539,6 +544,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -596,6 +602,7 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -661,10 +668,11 @@ export const PetApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
const localVarFormParams = new FormData();
const localVarFormParams = new (configuration?.formDataCtor || FormData)();

// authentication petstore_auth required
// oauth required
Expand Down Expand Up @@ -1063,6 +1071,7 @@ export const StoreApiAxiosParamCreator = function (configuration?: Configuration
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'DELETE', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1099,6 +1108,7 @@ export const StoreApiAxiosParamCreator = function (configuration?: Configuration
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1149,6 +1159,7 @@ export const StoreApiAxiosParamCreator = function (configuration?: Configuration
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1190,6 +1201,7 @@ export const StoreApiAxiosParamCreator = function (configuration?: Configuration
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1412,6 +1424,7 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1457,6 +1470,7 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1502,6 +1516,7 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1548,6 +1563,7 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'DELETE', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1590,6 +1606,7 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1636,6 +1653,7 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1680,6 +1698,7 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down Expand Up @@ -1727,6 +1746,7 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ConfigurationParameters {
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
basePath?: string;
baseOptions?: any;
formDataCtor?: new () => any;
}

export class Configuration {
Expand Down Expand Up @@ -64,6 +65,14 @@ export class Configuration {
* @memberof Configuration
*/
baseOptions?: any;
/**
* The FormData constructor that will be used to create multipart form data
* requests. You can inject this here so that execution environments that
* do not support the FormData class can still run the generated client.
*
* @type {new () => FormData}
*/
formDataCtor?: new () => any;

constructor(param: ConfigurationParameters = {}) {
this.apiKey = param.apiKey;
Expand All @@ -72,5 +81,6 @@ export class Configuration {
this.accessToken = param.accessToken;
this.basePath = param.basePath;
this.baseOptions = param.baseOptions;
this.formDataCtor = param.formDataCtor;
}
}
Loading

0 comments on commit 2768021

Please sign in to comment.