connecting express middleware with own routes #539
-
I trying to connect swagger-ui-express in express it is connected with code import swaggerUi from 'swagger-ui-express';
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(scheme, options)); here I connect it using export const routing: Routing = {
v1: apiRouter,
internal: internalRouting,
};
const options = {
swaggerOptions: {
validatorUrl: null,
},
};
const schema = JSON.parse(new OpenAPI({
routing, // the same routing and config that you use to start the server
config: serverConfig,
version: '1.0.0',
title: 'Some title',
serverUrl: 'https://localhost:9999/image',
}).getSpecAsJson());
export const swagger = appFactory
.addExpressMiddleware(swaggerUi.serve[0] as any)
.addExpressMiddleware(swaggerUi.serve[1] as any)
.addExpressMiddleware(swaggerUi.setup(schema as any, options))
.build({
method: 'get',
input: z.object({}),
output: z.object({}),
async handler() {
return {};
},
});
routing.swagger = swagger; but seems like it permit to make request only to route that exist in routing, but don't for routes that will added by swaggerUI also try it with express router export const swagger = appFactory
.addExpressMiddleware(express.Router().use('/swagger', swaggerUi.serve, swaggerUi.setup(schema, options)))
.build({
method: 'get',
input: z.object({}),
output: z.object({}),
async handler() {
return {};
},
}); but it don't help Of course here can just create express app and attachRouting |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Wow. Thank you @HardCoreQual for showing this. Instead all of that, I recommend to separate the actual routes from this UI by using This way you wouldn't need to create fake endpoint. |
Beta Was this translation helpful? Give feedback.
Wow. Thank you @HardCoreQual for showing this.
Instead all of that, I recommend to separate the actual routes from this UI by using
attachRouting()
.This approach is described here:
https://github.com/RobinTail/express-zod-api#connect-to-your-own-express-app
This way you wouldn't need to create fake endpoint.