-
Notifications
You must be signed in to change notification settings - Fork 507
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
Support for multiple servers information #720
Comments
There is an abandoned PR here. |
Thanks for reply @WoH, I'm keen to move the PR # #633 forward if it is the case. My solution also support host configuration as a string but if it is an array will treat as multiples host configuration. I do have the changes on my machine not sure if I should open another PR, it is lacking corner cases coverage at this moment. export interface Spec2 extends Spec {
swagger: '2.0';
host?: string | Array<Host>;
... export interface Host {
host: string;
description?: string;
} |
What would you do in case |
its any workaround in mid time? |
Workaround: Below I used the spec.spec override to get my servers in there.
Resulting in the final
|
also let's open option to specify http/https |
Hmm... |
Also curious about this as I'm currently evaluating tsoa as an option for a project that uses custom headers for versioning. It seems like templates might be a solution, but I'm just starting to dig into that. |
I am also curious how others do api versioning. Currently we have something like this: import { v1 } from "./v1.js";
@Tags("V2")
@Route("/api/v2/something")
@Response<string>("500", "Internal server error")
export class v2 extends v1 {
/**
* something
*/
// @Example<...
@Post("/create")
public async create(
@Res() serverErrorResponse: TsoaResponse<500, ErrorApiResponse>,
): Promise<SuccessfulApiResponse<null>> {
logger.debug("v2::create");
return await super.create( Hoped that tsoa would pick up the routes it inherits from v1 but unfortunately its not the case right now. So a lot annotation is duplicated and the super.method is called. But back on topic: But as was pointed out earlier, I also have the problem of specifying localhost, int and prod:
Maybe it could be fixed by something like this: diff --git a/packages/cli/src/swagger/specGenerator3.ts b/packages/cli/src/swagger/specGenerator3.ts
index 1510cc76..239e32d9 100644
--- a/packages/cli/src/swagger/specGenerator3.ts
+++ b/packages/cli/src/swagger/specGenerator3.ts
@@ -144,7 +144,7 @@ export class SpecGenerator3 extends SpecGenerator {
const basePath = normalisePath(this.config.basePath as string, '/', undefined, false);
const scheme = this.config.schemes ? this.config.schemes[0] : 'https';
const hosts = this.config.servers ? this.config.servers : this.config.host ? [this.config.host!] : undefined;
- const convertHost = (host: string) => ({ url: `${scheme}://${host}${basePath}` });
+ const convertHost = (host: string) => host.includes("://") ? { url: host + basePath } : ({ url: `${scheme}://${host}${basePath}` });
return (hosts?.map(convertHost) || [{ url: basePath }]) as Swagger.Server[];
}
|
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
Current Behavior
Possible Solution
Context (Environment)
Version of the library: 3.0.8
Version of NodeJS: v12.16.3
Detailed Description
OpenApi3 supports multiples servers information and that can be useful to be used swagger pointing to multiple environments.
Breaking change?
The solution is a workaround to a breaking change.
The text was updated successfully, but these errors were encountered: