Skip to content

[Typescript][Fetch] added option to override default basePath #7609

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 3 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.*;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;

public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen {
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import * as url from "url";
import * as portableFetch from "portable-fetch";
import { Configuration } from "./configuration";

const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");

/**
*
* @export
Expand Down Expand Up @@ -46,10 +44,10 @@ export interface FetchArgs {
export class BaseAPI {
protected configuration: Configuration;

constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected fetch: FetchAPI = portableFetch) {
constructor(configuration: Configuration = Configuration.DEFAULT_INSTANCE, protected basePath: string = Configuration.DEFAULT_INSTANCE.basePath, protected fetch: FetchAPI = portableFetch) {
if (configuration) {
this.configuration = configuration;
this.basePath = configuration.basePath || this.basePath;
this.basePath = configuration.basePath || this.basePath || '';
}
}
};
Expand Down Expand Up @@ -262,7 +260,7 @@ export const {{classname}}Fp = function(configuration?: Configuration) {
*/
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Response{{/returnType}}> {
const localVarFetchArgs = {{classname}}FetchParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
return (fetch: FetchAPI = portableFetch, basePath: string = BASE_PATH) => {
return (fetch: FetchAPI = portableFetch, basePath: string = Configuration.DEFAULT_INSTANCE.basePath) => {
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response{{#returnType}}.json(){{/returnType}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface ConfigurationParameters {
}

export class Configuration {
/**
* object for default configurations
*/
static DEFAULT_INSTANCE = new Configuration({basePath: "{{{basePath}}}".replace(/\/+$/, "")});
/**
* parameter for apiKey security
* @param name security name
Expand Down
46 changes: 22 additions & 24 deletions samples/client/petstore/typescript-fetch/builds/default/api.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface ConfigurationParameters {
}

export class Configuration {
/**
* object for default configurations
*/
static DEFAULT_INSTANCE = new Configuration({basePath: "http://petstore.swagger.io/v2".replace(/\/+$/, "")});
/**
* parameter for apiKey security
* @param name security name
Expand Down
46 changes: 22 additions & 24 deletions samples/client/petstore/typescript-fetch/builds/es6-target/api.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface ConfigurationParameters {
}

export class Configuration {
/**
* object for default configurations
*/
static DEFAULT_INSTANCE = new Configuration({basePath: "http://petstore.swagger.io/v2".replace(/\/+$/, "")});
/**
* parameter for apiKey security
* @param name security name
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface ConfigurationParameters {
}

export class Configuration {
/**
* object for default configurations
*/
static DEFAULT_INSTANCE = new Configuration({basePath: "http://petstore.swagger.io/v2".replace(/\/+$/, "")});
/**
* parameter for apiKey security
* @param name security name
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface ConfigurationParameters {
}

export class Configuration {
/**
* object for default configurations
*/
static DEFAULT_INSTANCE = new Configuration({basePath: "http://petstore.swagger.io/v2".replace(/\/+$/, "")});
/**
* parameter for apiKey security
* @param name security name
Expand Down