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

Feature Request: inverse function for resolve #98

Open
christian-bromann opened this issue Jun 27, 2024 · 1 comment
Open

Feature Request: inverse function for resolve #98

christian-bromann opened this issue Jun 27, 2024 · 1 comment

Comments

@christian-bromann
Copy link

Hey there 👋

first off, thanks for all the work you've done on this package, it's awesome!

I would like to request a feature: allow to verify if a given path, e.g. /api/foobar/123 matches a pathname from the OpenAPI specification, e.g. /api/foobar/{id}. It would be the inverse to resolve.

Does this make sense?

@char0n
Copy link
Member

char0n commented Jun 28, 2024

Hi @christian-bromann,

first off, thanks for all the work you've done on this package, it's awesome!

Thanks a lot mate!

I would like to request a feature: allow to verify if a given path, e.g. /api/foobar/123 matches a pathname from the OpenAPI specification, e.g. /api/foobar/{id}. It would be the inverse to resolve.

I think this has broader context and might be related to overall concrete URI Reference / URL matching against the path templates. We need to design an API that would satisfy your simple usecase but would allow to do the more complex matching and handle ambiguities:

OpenAPI 3.1.0 spec reference:
image

From that we can inferere following predicates:

  • isIdentical(pathTemplate1: string, pathTemplate2: string): boolean
  • isAmbiguous(pathTemplate1: string, pathTemplate2: string): boolean

Now these predicates still don't solve your request, we need additional match function for that:

match('/pets/mine', [
 '/pets/{petId}',
 '/pets/mine'
]); => '/pets/mine'

Your case can be specialized into:

match('/pets/mine', [
 '/pets/{petId}',
]); => '/pets/{petId}'

NOTE: the function will return null if no matches are found

I have to think about this a bit more, but feel about right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants