lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.54k stars 499 forks source link

Endpoint to support multiple api versions #1488

Closed ben-leonard-tbol closed 11 months ago

ben-leonard-tbol commented 1 year ago

I currently have a single version of an api with the following resources which contains endpoints for creating a product, retrieving all etc. v1/products v1/orders.

In order to support this I have a controller attributes like @Route('v1/products'). I now need a new version of my api, products endpoints need a breaking change so I have a new controller for that and the appropriate functions with the @Route('v2/products') attribute.

The orders endpoint never changes except for the version. So I was hoping to add another attribute with the new version which would mean two route attributes are added but I get the following error Only one Route decorator allowed. I could duplicate the controller code and update the route but this added a lot of duplicate code.

Whats the best mechanism to support multiple versions for a controller?

Sorting

Expected Behavior

Ability to add another Route attribute to identify a given controller should work for multiple routes.

Current Behavior

Adding another Route attribute Only one Route decorator allowed

Possible Solution

Assuming support of multiple Route attribute / accept an array. There might be better solutions that currently exist.

github-actions[bot] commented 1 year ago

Hello there ben-leonard-tbol šŸ‘‹

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.šŸ‘€

github-actions[bot] commented 12 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

HarryVGI commented 7 months ago

Hey @ben-leonard-tbol!

Did you proceed by duplicating the controller code or did you find a more elegant solution?