Giter VIP home page Giter VIP logo

Comments (4)

alesancor1 avatar alesancor1 commented on June 2, 2024

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.

stevenfukase avatar stevenfukase commented on June 2, 2024

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.

alesancor1 avatar alesancor1 commented on June 2, 2024

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.

stevenfukase avatar stevenfukase commented on June 2, 2024

I see. Thanks a lot.

from oas-tools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.