Comments (3)
Yeah, I've been putting some thought into that.
Locally right now, I'm hacking this with:
// Import absolute-path directly to get around
// https://github.com/swagger-api/swagger-ui/issues/4502
import pathToSwaggerUi from 'swagger-ui-dist/absolute-path';
...
const router = new express.Router();
router.get('/openapi.json', (req, res) =>
loadOpenapiDoc()
.then(doc => res.json(doc))
.catch(err => res.status(500).end(err.message))
);
router.get('/openapi.yaml', (req, res) =>
loadOpenapiDoc()
.then(doc => res.end(yaml.safeDump(doc)))
.catch(err => res.status(500).end(err.message))
);
router.use('/', express.static(pathToSwaggerUi()));
router.use(await exegesisExpress.middleware(...));
which exposes the UI at "/" (router
here ends up getting mounted in Express at /api/v2, so at the end of the day /api/v2/openapi.yaml gets you the doc, and /api/v2/ gets you docs). This means I need to import the OpenAPI doc myself, though. Also, plugins are allowed to modify the OpenAPI doc, so it would be nice if those modifications were served up via the UI; then I could make exegesis-plugin-roles automatically add a bit to each operation's description listing which roles are required to call the operation, for example, and this would show up in the UI.
So my plan was to make an exegesis-swagger-ui
plugin, which would cache a copy of the openapi doc in the preCompile()
step, and then serve it and swagger-ui postRouting()
. Or something along those lines. :)
from exegesis.
Wish I seen this comment a bit earlier before hacking a solution.
I spent some time going through Swagger-UI and different repos/solutions.
I put together a very quick solution that doesn't even use the router.
One route is used to parse the swagger yams file and returns a JSON version of it.
The second route (the one called), gets the JSON data from this first URL and displays.
app.route('/uidoc')
.get((req: Request, res: Response) => {
res.setHeader('content-type', 'application/json');
res.send(fs.readFileSync(path.resolve(__dirname, './openapi.yaml'),));
})
/**
* Route responsible for the generation of UI docs
*
* Gets the OpenAPI spec from /uidoc route as a JSON object
* Takes this JSON object and generates docs using the swagger-ui.ts file.
*/
app.route('/ui')
.get((req: Request, res: Response) => {
//Send the Swagger-UI docs with our OpenAPI spec applied.
res.send(swaggerUI.swaggerUI("/ui"));
})
In the code above swaggerUI is a typescript file with a single function returning a HTML string of the swagger docs.
If you decide to move forward with a exegesis-swagger-ui
, I can help anytime
from exegesis.
The following github repo may help:
https://github.com/phil-mitchell/exegesis-plugin-swagger-ui-express
Update: The plugin worked a treat once I figured out the URL had to end with a / in the browser.
from exegesis.
Related Issues (20)
- Can I have initialised/stateful controllers? HOT 2
- Can not demand an array to be one or more items long HOT 2
- Crash with recursive definition in referenced OpenAPI file HOT 5
- Incorrectly failing validation under a weird condition HOT 4
- Validation error of request body when oneOf is used HOT 5
- Crash with recursive definition in referenced OpenAPI file is back again
- Does not work well with newest json-ptr (1.3.1) HOT 2
- Your .dependabot/config.yml contained invalid details HOT 1
- Export class from controller HOT 2
- Could not find controller if controller is a .ts file HOT 2
- Can we access "ExegesisContext" at express middleware(app.use) not controllers/*.ts HOT 1
- How to filter the request body by only passing the defined requestBody schema? HOT 2
- Security vulnerability in `json-ptr` HOT 4
- Exegesis 3.0.0 using updated ajv outputs issues with OpenAPI spec, but 2.0.0 did not HOT 5
- res.redirect not supported HOT 3
- Is OpenAPI 3.1 supported?
- Bump json-ptr to fix security vulnerability HOT 1
- Support for additional string formats HOT 2
- json-schema-ref-parser dependency breaks node engine < 17 HOT 3
- How to use exegesis with multipart/form-data?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exegesis.