Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

basePath is undefined in multipleFileMode #137

Closed asineath-dbhglobal closed 3 years ago

asineath-dbhglobal commented 3 years ago

When services are generated with multipleFileMode=true, the 'basePath' variable in each individual service file is undefined. In index.defs.ts, the 'basePath' const is not exported. A solution would be to export 'basePath' in index.defs.ts and include it in the import statement at the top of each individual service file.

Manweill commented 3 years ago

you can set basePath with axios config?

asineath-dbhglobal commented 3 years ago

You're referring to the baseURL property in the axios config, which really refers to the host. 'basePath' is a part of the root structure of swagger spec, which indicates if all endpoint paths start with something like '/api'. (https://swagger.io/docs/specification/2-0/api-host-and-base-path/)

Our API doesn't have a universal basePath, so when I run swagger-axios-codegen with multipleFileMode=false, it sets " const basePath = ''; " in the produced index.ts, and all the methods below have access to that const when building the url, such as " let url = basePath + '/api/AddressCity/GetList'; " So everything works fine in that mode.

But when I run swagger-axios-codegen with multipleFileMode=true, which I would prefer to do in my project, the "basePath" variable is undefined in all service files because it is never declared/imported in the individual service files (see screenshot). The basePath const is declared in index.defs.ts, but it needs to be exported from that file and imported into all the generated service files.

image