Skip to content
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

Multiple swaggers in one single app using swagger-express-ts #61

Open
Roldanhollow opened this issue Jul 18, 2020 · 2 comments
Open

Multiple swaggers in one single app using swagger-express-ts #61

Roldanhollow opened this issue Jul 18, 2020 · 2 comments

Comments

@Roldanhollow
Copy link

Roldanhollow commented Jul 18, 2020

Hi there!
Is there a way to generate or expose multiple swagger by using swagger-express-ts?

@Roldanhollow Roldanhollow changed the title Is it possible two ports with two swagger express? Multiple swaggers in one single app using swagger-express-ts Jul 22, 2020
@L-U-C-K-Y
Copy link

Would be also interested in this, @Roldanhollow did you try a possible config?

@Roldanhollow
Copy link
Author

Hey, Thx for answer. Yep, I did this:
`
import feathers from "@feathersjs/feathers";
import express, { Application } from "@feathersjs/express";
import * as swagger from "swagger-express-ts";
import bodyParser from "body-parser";
import app from "./app";
import { TestRoutes } from "./routes/test.route";
import { TestProtectedRoutes } from "./routes/test.protected.route";

//-----Normal part-----//
// Docs
app.use("/api-docs/swagger", express.static("swagger"));
app.use(
"/api-docs/swagger/assets",
express.static("node_modules/swagger-ui-dist")
);

app.use(
swagger.express({
definition: {
info: {
title: This is Protected,
description:
"Protected",
version: "1.0.0",
},
produces: ["application/json"],
externalDocs: {
url: "###",
},
// Models can be defined here
},
})
);

app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: false,
})
);
new TestRoutes().route(app); //Expose 2 endpoints

app.listen(8080, () => {
console.log("Running on 8080");
});

//-----Protected part-----//
const appProtected: Application = express(feathers());
// Docs
appProtected.use("/api-docs/swagger", express.static("swagger"));
appProtected.use(
"/api-docs/swagger/assets",
express.static("node_modules/swagger-ui-dist")
);

appProtected.use(
swagger.express({
definition: {
info: {
title: This is Protected,
description:
"Protected",
version: "1.0.0",
},
produces: ["application/json"],
externalDocs: {
url: "###",
},
// Models can be defined here
},
})
);

appProtected.use(bodyParser.json());
appProtected.use(
bodyParser.urlencoded({
extended: false,
})
);
new TestProtectedRoutes().route(appProtected); //Expose 1 endpoint

appProtected.listen(8081, () => {
console.log("Running on 8081");
});
`
If this previous code is used, swagger is going to mix the endpoints together in both swagger (localhost:8080/api-docs/swagger and localhost:8081/api-docs/swagger). So, is possible separate them by port?

  • localhost:8080/api-docs/swagger: TestRoutes >> endpoint_1, endpoint_2,
  • localhost:8081/api-docs/swagger: TestProtectedRoutes >> endpoint_3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants