swagger-ui: When deploying swagger on vercel on nodejs it does not show UI
This is How it does look like this and I do not know how to fix this issue.
Q&A (please complete the following information)
- OS: M1 Pro
- Browser" Chrome, Safari
- Version: 22
- Method of installation: npm
- Swagger-UI version: 3
- Swagger/OpenAPI version: 2
Content & configuration
Swagger/OpenAPI definition:
# your YAML here
Swagger-UI configuration options:
SwaggerUI({
// your config options here
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Library API",
version: "1.0.0",
description: "A simple Express Library API",
termsOfService: "http://example.com/terms/",
contact: {
name: "API Support",
url: "http://www.exmaple.com/support",
email: "support@example.com",
},
},
servers: [
{
url: "https://localhost:2001",
description: "My API Documentation",
},
],
},
// This is to call all the files
apis: ["src/**/*.js"],
};
})
?yourQueryStringConfig
Screenshots
How can we help?
I have built a backend on node.js and after deploying swagger on vercel it does not show UI for api-docs rest of the things are working as they should. Also, I have added custom HTML as well which is also working you can check the SS.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 2
- Comments: 46
Commits related to this issue
- maybe downgrade would help https://github.com/swagger-api/swagger-ui/issues/8461#issuecomment-1680582184 — committed to Itttikorn/HotelReservationAPI by Taihenc 3 years ago
- read css directly from its path in node_modules https://github.com/swagger-api/swagger-ui/issues/8461#issuecomment-2002404091 — committed to Itttikorn/HotelReservationAPI by Taihenc 3 years ago
- vercel fix? https://github.com/swagger-api/swagger-ui/issues/8461#issuecomment-2661747952 — committed to azimut/course-node by azimut a year ago
@jcs-2020 sure! It is not a sufficient way to do it but there are no other options!
you can directly use CDN // CDN CSS const CSS_URL = “https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.0/swagger-ui.min.css”;
and pass it down to your app.use where you have swagger api-docs
swaggerUI.setup(specs, { customCssUrl: CSS_URL })
and boom it should work 😃
you also can check out my repo as well 😃 https://github.com/Milan-960/Nodejs-swagger-api/blob/master/index.js
Thanks for your solution, @Milan-960 but it didn’t fully solve my issue, all of the request summaries were messed up as you can see here:
My solution was similar, but I added custom css to display summaries properly.
I don’t think this is the best solution but at least it works… If anyone has a better solution, feel free to share it!
Full code can be found here: https://github.com/DaviidMM/api-auvasa
I met the same problem with you. Thank you for your method. I’m going to downgrade my package version now. 😊
Thanks, man it works now, my version was 5.0.0 downgraded it to 4.3.0, and it shows now.
Bless up.💪🏾
On Tue, Aug 15, 2023 at 1:05 PM VenkateshMogili @.***> wrote:
This time I deployed a nest app and now nothing loads on both android and desktop! I also used customCssUrl… “@nestjs/swagger”: “^7.1.17”,
UPDATE: solved it using : customJs: [ ‘https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-bundle.min.js’, ‘https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-standalone-preset.min.js’, ], customCssUrl: [ ‘https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui.min.css’, ‘https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-standalone-preset.min.css’, ‘https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui.css’, ],
but still it does not load schemas 😃))))))))))
UPDATE: using @ApiProperty() solved the issue
Hey my problem is that my swaggerUI doesn’t show at all. any help?
I deployed using vercel and when I click my link that should take me to my link it doesn’t show anything.
I didn’t have any issues when I was using heroku though, didn’t have to use path.resolve for my swagger.yaml document, or it not displaying at all.
Thanks, it worked!
Temporary workaround, but it does not address the root cause. It works with the following versions: • express: ^4.18.2 • swagger-ui-express: ^4.6.3”
Thank you, it worked for me🎉🎉🎉🥳
In my project, swagger-ui-express version is 4.3.0, the same version I replaced, then it worked properly.
https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.3.0/swagger-ui.min.css
NestJS was helped by the following solution: I created a public folder at the root of the project, then inside the public folder, I created css and js folders. I copied the file from the Swagger modules to the css folder (swagger-ui.css), and moved the files swagger-ui-bundle.js and swagger-ui-standalone-preset.js to the js folder.
Next, I installed the @nestjs/serve-static library and added the following configuration to the AppModule: ServeStaticModule.forRoot({ rootPath: join(__dirname, ‘…’, ‘public’), serveRoot: ‘/public’, }),
In the Swagger configuration, I added custom paths: SwaggerModule.setup(‘api’, app, document, { customCssUrl: ‘/public/css/swagger-ui.css’, customJs: [ ‘/public/js/swagger-ui-bundle.js’, ‘/public/js/swagger-ui-standalone-preset.js’, ], });
Everything works in all browsers! The styles are applied correctly, and the schemas are displayed.