swagger ui
i'm trying to solve this problem but somehow i still didn't manage to do it. /swagger endpoint seems to read only part of the swagger.json file. I configured everything and still not a single error popped up. It just says "No operations defined in spec" even tho i created one test model. Googling this was a disaster,so few articles and they are all different completely.
in app.js i added :
import swaggerUi from "swagger-ui-express";
import * as swaggerDoc from "./swagger.json";
app.use("/swagger", swaggerUi.serve, swaggerUi.setup(swaggerDoc));
in swagger.json :
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Stefan Back-end Swagger",
"description": "Test",
"license": {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
}
},
"Cat": {
"type": "object",
"properties": {
"genus": {
"type": "string"
}
}
}
}
You are using openapi-3, look at the components section ,
Your swagger.json
file should be like:
{
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Stefan Back-end Swagger",
"description": "Test",
"license": {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
}
},
"components": {
"schema": {
"Cat": {
"type": "object",
"properties": {
"genus": {
"type": "string"
}
}
}
}
}
}
Hope this help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.