Swagger-codegen: [Typescript][Fetch] configurable BASE_PATH

Created on 27 Apr 2017  路  5Comments  路  Source: swagger-api/swagger-codegen

Hi,

I wonder if there is an easy way of having a configurable BASE_PATH as I need to switch between different hosts depending on the current environment (production and dev). This should be a common scenario in my opinion.

I realize that there are (at least) 2 solutions:

  1. Adjusting the host and/or basePath fields in the definition file
  2. Passing the desired base url to constructor function of each concrete API.

But I believe both options are far from ideal.

  1. This means that one needs multiple definition files (i.e. one for production, one for dev) and these need be kept in sync... Also one needs to switch between the production- and the dev-version of the generated clients depending on the environment.
  2. Is OK but tedious nonetheless (especially for large APIs) as one has to repeat the base url whenever one instantiates a concrete API.

Configuring the base url only once in centralized fashion would be less error-prone and much more convenient.

Thanks for any suggestions!

TypeScript Question

Most helpful comment

but can i would need to pass this for each API i create in the constructor if i understand that correct?

It would work if the template provides a function to override the base path. I tried it local and it would work, but i don't know if that's the best solution.

Could make a PR if you also think that it would be a good idea to provide a function.

All 5 comments

I think the following PR is related to your suggestion:

https://github.com/swagger-api/swagger-codegen/pull/3403

Oh... thx! Will definitely have a look at it!

@wing328 this is still a issue in the typescript-fetch templates.

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache#L9

I found no way to override the base-path for all APIs, instead you currently need to configure each API in each usage on their own.

Is there any plan to change this?

@zwenza the configuration object also contains the basePath parameter: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-fetch/configuration.mustache#L46

Is that what you're looking for?

but can i would need to pass this for each API i create in the constructor if i understand that correct?

It would work if the template provides a function to override the base path. I tried it local and it would work, but i don't know if that's the best solution.

Could make a PR if you also think that it would be a good idea to provide a function.

Was this page helpful?
0 / 5 - 0 ratings