lua-radix-router icon indicating copy to clipboard operation
lua-radix-router copied to clipboard

How to dynamically match route against Open API Specification file?

Open darshak-patel opened this issue 1 year ago • 1 comments

I am trying to match the incoming request path against the swagger definition.

darshak-patel avatar Apr 12 '24 05:04 darshak-patel

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

vm-001 avatar Apr 13 '24 07:04 vm-001