Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dynamically match route against Open API Specification file? #41

Open
darshak-patel opened this issue Apr 12, 2024 · 1 comment
Labels
question Further information is requested

Comments

@darshak-patel
Copy link

darshak-patel commented Apr 12, 2024

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

@vm-001
Copy link
Owner

vm-001 commented Apr 13, 2024

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 vm-001 added the question Further information is requested label Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants