lonestone / nest-sdk-generator

A REST SDK generator for NestJS. Strictly type your frontend's API calls :rocket:
MIT License
92 stars 10 forks source link

Failed to generate SDK controller when configured path comes from variable #4

Open samchon opened 2 years ago

samchon commented 2 years ago

image

If a parameter path of Controler decorator comes from a variable, nest-sdk-generator failed to build the SDK controller class.

clement-estone commented 2 years ago

This is unfortunately a very hard problem to solve, because handling dynamic variables that are known only at runtime isn't possible as the URI could technically change every time the application is started.

We could specifically handle const variables, but this is a complex niche case that would require to solve scoped variables to find its declaration, extract the constant string from it, resolving imports if the variable is imported from another file, etc.

This would be quite tricky to implement for a problem to solve a case very few users have. If the string is fixed and will never change, it should be provided as a literal to the @Controller decorator.

samchon commented 2 years ago

You're saying that using variable path is an extremely rare case, but I've seen that many people are defining long path using the Array.join() function like below. They're saying that using Array.join() is convenient, easy to manage and much safer than the long constant string value.

Therefore, I recommend you to specialize the variable defined path through the asynchronous import function.

@Controller([
    "shoppings",
    "customers",
    "orders",
    ":orderId",
    "revert",
    "denial"
].join("/"))
export class ShoppingCustomerOrderRevertDenialsController {
}
clement-estone commented 2 years ago

This could indeed prove to be a problem, in that case I think we can at least handle inline expressions like the one you just shown, for variables it could be a bit trickier but I'll look into that.