Comments (4)
I'm not sure if I understand what the problem is here. You are trying to declare a dynamic route like /{segment1}/{segment2}
and when calling GET /docs/swagger
(suppose this is the path where SwaggerUI middleware is registered) you get the response from the router instead of the SwaggerUI right?
Changing the order in the middleware would give priority to the SwaggerUI instead of the router, which may be not desired in some cases.
from oas-tools.
You are trying to declare a dynamic route like /{segment1}/{segment2} and when calling GET /docs/swagger (suppose this is the path where SwaggerUI middleware is registered) you get the response from the router instead of the SwaggerUI right?
Yes, that's right.
Currently, the only way to show SwaggerUI when dynamic routes are defined is to write a path that does not conflict with the number of the dynamic segment.
That means when /{dynamic1}/{dynamic2}
is defined in oasFile, the only way to enable swaggerUI is to allocate /
(with no subdirectory) or /static1/static2/static3/...
(with 3 or more subdirectories).
/static1
won't work either.
I just thought it's more intuitive to have the concrete definition (the config) take precedence over dynamic paths.
I have also confirmed that dynamic segments still work even when SwaggerUI is given priority in the middleware chain.
For example, when /{dynamic1}/{dynamic2}
is defined in oasFile and /docs/swagger
is allocated for SwaggerUI, GET /example1/example2
will still work.
from oas-tools.
The problem here is that currently you can't call next() on your controllers. The router should be executed before the swaggerUI because you may want to modify req.swaggerFile
to modify the the swaggerDoc dynamically. In case you had dynamic routes conflicting with the docs route you should manage it on your controllers, since they are responsible for managing requests, for example:
// SomeController.js
export function myController(req, res, next) {
if (/^\/docs(?:\/.*)?$/.test(req.path)) {
next(); // Calls next middleware (swaggerUI)
} else {
/* Manage other requests */
}
}
I think the problem is more related to the ability to solve these conflicts on controllers rather than to the priority of the middleware. I'll take this into account for future versions.
from oas-tools.
I see. Thanks a lot.
from oas-tools.
Related Issues (20)
- How to use http query params with oas tools? HOT 3
- @oas-tools/core typescript support HOT 9
- [BUG] Dynamic routes have higher priority over static routes HOT 6
- [BUG] oas tool 3.0 fail to treat optional field in schema as option. HOT 9
- [BUG] V3 Not Backwards Compatible with V2 JSON Specification File Code HOT 1
- [BUG] Cannot convert undefined or null to object oas param file has issue HOT 2
- [BUG] File spec loading error in legacy project HOT 2
- oas tools module import issue when doing tests with jest. HOT 9
- Align js-yaml version with @oas-tools/commons HOT 1
- [BUG] JSON double-encoding when using res.json() and validator.responseValidation HOT 3
- [BUG] oneof yaml specification is not valid json HOT 1
- [Question]: Controller & Service file naming convention HOT 2
- [SUGGESTION] Problem with default exports "Controller X does not have method Y" HOT 1
- [BUG] customHandler for errors is not working as expected HOT 2
- Basepath is removed when calling any endpoint on google cloud functions. HOT 1
- [SUGESTION] Add support for mutualTLS security handler HOT 1
- The Controller annotation requires empty line be placed after the annotation
- [BUG] Invalid JSON in params results in Internal Server Error instead of Bad Request
- [SUGESTION] Remove check of multiple http security schemes
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 oas-tools.