-
Notifications
You must be signed in to change notification settings - Fork 226
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
Cannot load two different API specs #353
Comments
Have you tried this https://github.com/scottie1984/swagger-ui-express#two-swagger-documents |
With the way I have things set up currently with my Node.js application, I can't switch over to JSON for loading the swagger documents. Are you interested in having this bug fixed? I may be able to put some time in to investigate the issue @scottie1984 |
@ronaldlong46 yeah - if you can that would be great. |
I have the same issue and I am unable to load two separate API specs. @ronaldlong46, @scottie1984 any update on the issue? |
I was able to have separate endpoints for separate specs. const path = require("path");
const swaggerDocs = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");
const SPEC_1 = {
definition: {
openapi: "3.0.1",
info: {
version: "1.0.0",
title: "API",
description: "Dscription",
},
servers: [
{
url: "http://localhost:3000",
description: "Development server",
},
],
paths: {
"/auth/login": {
post: {
tags: ["auth"],
summary: "User Login",
description: "User Login",
operationId: "Login",
requestBody: {
description: "User Login",
content: {
"application/json": {
schema: {
type: "object",
properties: {
email: {
type: "string",
},
password: {
type: "string",
},
},
},
},
},
},
responses: {
200: {
description: "Success",
content: {},
},
400: {
description: "Error",
content: {},
},
},
},
},
},
},
apis: [path.join(__dirname, "index.yaml")],
};
const SPEC_2 = {
definition: {
openapi: "3.0.1",
info: {
version: "1.0.0",
title: "API 2",
description: "Dscription 2",
},
servers: [
{
url: "http://localhost:3000",
description: "Development server",
},
],
paths: {
"/auth/login": {
post: {
tags: ["auth"],
summary: "User Login",
description: "User Login",
operationId: "Login",
requestBody: {
description: "User Login",
content: {
"application/json": {
schema: {
type: "object",
properties: {
email: {
type: "string",
},
password: {
type: "string",
},
},
},
},
},
},
responses: {
200: {
description: "Success",
content: {},
},
400: {
description: "Error",
content: {},
},
},
},
},
},
},
apis: [path.join(__dirname, "index.yaml")],
};
const SCHEMA_1 = swaggerDocs(SPEC_1);
const SCHEMA_2 = swaggerDocs(SPEC_2);
app.use("/docs/1",swaggerUi.serveFiles(SCHEMA_1, {}),swaggerUi.setup(SCHEMA_1));
app.use("/docs/2",swaggerUi.serveFiles(SCHEMA_2, {}),swaggerUi.setup(SCHEMA_2),); Codesandbox: https://codesandbox.io/p/sandbox/swagger-js-docs-c7f6w2?file=%2Findex.js%3A1%2C1-137%2C1 |
@talha-ah You saved my day! Thank you!! |
However, is there a way to do this with 2 different URLs (without the explorer dropdown?)
Originally posted by @ronaldlong46 in #305 (comment)
Loading two separate API specs at two separate URLs like this:
It will only show whichever API specs is last for both routes.
The text was updated successfully, but these errors were encountered: