samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.85k stars 95 forks source link

Ability to pass version through the connection object. #830

Closed ArjunAtlast closed 8 months ago

ArjunAtlast commented 8 months ago

Feature Request

I can understand that it's hard to extract versions from the Controller and automatically use this in SDK. But right now the only way to pass a version is to hardcode it in the base URL. It would be helpful if the connection object accepted a version option with the schema:

interface IConnectionVersion {
   versionNumber: string;
   versionType: VersionType;
 }
samchon commented 8 months ago

Well, in the NestJS, the version number can be specified below three ways:

// 1st way -> overloaded functions
export function someFunction(version: "1", input: AI): Promise<AO>;
export function someFunction(version: "2", input: BI): Promise<BO>;

// 2nd way -> individual functions
export function someAFunction(input: AI): Promise<AO>;
export function someBFunction(input: BI): Promise<BO>;

By the way, to specify the target controller method of each version, have to define the version number as discriminator. To accomplish the discriminator, there're two ways. The 1st is writing overloaded pair of route functions which has the version number as discriminator paramter. The 2nd way is just writing each API endpoint functions for each version number.

Current @nestia/sdk is adapting the second way.

It is the reason why @nestia/sdk is supporting only path level versioning strategy. The others, query and header paramters, there's not way to accomplish the discriminator. In the same reason, if you put the version property into the connection instance, it would not possible to accomplish the discriminator either.