Search code examples
node.jstypescriptswagger-2.0

(Typescript/Node/Swagger) Create a version 2 of an api with little changes. How can I redirect v2 calls to v1 calls?


Using Typescript, Node.js, Swagger.

I want to change one GET call when upgrading to v2. I don't want to copy the whole entire code but make v2 calls redirect to v1 calls. How can I achieve that?

Format I'm using is router.get(blah blah, blah) ... { }


Solution

  • I ended up hooking the v1 TS files in my index.ts. That way I will not be writing duplicate code, instead I will be using my v1 code. Also, I will have my v2 API structure in place.

    If you think in Spring REST API, you will not be calling the controller methods from another controller. The goal here was to reuse as much code from v1 as possible without making v2 look unstructured. If Controller A and B (different endpoints) did almost the same thing, thinking in Spring REST API standards, Controller A would not call methods in Controller B. instead, it Controller A's methods would call the same ones as Controller B's call.