lua-radix-router
lua-radix-router copied to clipboard
How to dynamically match route against Open API Specification file?
I am trying to match the incoming request path against the swagger definition.
openapi: 3.0.0
paths:
"/users/{id}":
{operations}
"/users/{id}/profile":
{operations}
You can iterate the paths, and make a route for each path. The pseudocode would be like
local router, err = Router.new({
{
paths = { "/users/{id}" },
handler = $operations
},
{
paths = { "/users/{id}/profile" },
handler = $operations
},
})
if not router then
error("failed to create router: " .. err)
end
local operations = router:match(request_path)
if operations then
-- request_path can be matched
-- execute method evaluation if necessary
end