Search code examples
swagger-uivert.x

Vert.x: can I mix a wildcard route with an explicit route?


I want to host Swagger UI as static content using Vert.x. The swagger-initializer.js needs the spec somewhere on the server and I want it to be in /api/swagger-ui as well, so I can define the spec in swagger-initializer.js as

window.onload = function() {
  window.ui = SwaggerUIBundle({
    url: "petstore.yaml",
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  });
};

It works perfectly like this

Router.router(vertx).route("/api/swagger-ui/petstore.json").handler(StaticHandler.create("path/to/petstore.json"));
Router.router(vertx).route("/api/swagger-ui/*").handler(StaticHandler.create("path/to/swagger-ui"));

serving Swagger UI together with the provided spec.

But I wonder if there are any side effects by mixing a wildcard with an explicit route?

Are there any resources if this is good practice and it doesn't just work by coincidence?


Solution

  • It's fine, because by default routes are matched in the order they are added to the router.

    When a request arrives, the router will step through each route and check if it matches, if it matches then the handler for that route will be called.