swaggerexpert / openapi-path-templating

OpenAPI Path Templating parser, validator and resolver.
Apache License 2.0
2 stars 0 forks source link

Feature Request: inverse function for resolve #98

Open christian-bromann opened 1 week ago

christian-bromann commented 1 week ago

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 commented 1 week ago

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:

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.