Azure / autorest.typescript

Extension for AutoRest (https://github.com/Azure/autorest) that generates TypeScript code. The transpiled javascript code is isomorphic. It can be run in browser and in node.js environment.
MIT License
177 stars 75 forks source link

How to generate versions enum in modular? #2680

Open MaryGao opened 2 months ago

MaryGao commented 2 months ago

This is from the discussion. With the case we have client-level api version defined.

@versioned(Versions)
@armCommonTypesVersion(CommonTypes.Versions.v5)
namespace Microsoft.EdgeZones;

/** Api versions */
enum Versions {
  /** 2024-04-01-preview api version */
  @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
  `2024-04-01-preview`,
}

Then we would generate string as client options. And also generating a fixed & orphan Versions enum from getAllModels with Usage.Version.

export interface EdgeZonesClientOptionalParams extends ClientOptions {
  /** The API version to use for this operation. */
  apiVersion?: string;
}
/** Api versions */
export type Versions = "2024-04-01-preview";

This may not be proper because the api version is an extensible enum which allows customers to pass a list outside the enums.

To solve this we could either ignore this value or generate as extensible enum

export interface EdgeZonesClientOptionalParams extends ClientOptions { /** The API version to use for this operation.

Both are okay for me and personally i prefer generating as KnownVersions which could help suggest values in client side.

qiaozha commented 2 months ago

prefer to generate KnownVersions and update the document link in ClientOptions.

joheredi commented 2 months ago

Can we just emit a fixed union and have users cast to any if they need to provide an unknown api version?

export interface EdgeZonesClientOptionalParams extends ClientOptions {
  /** The API version to use for this operation. */
  apiVersion?: "2024-04-01-preview";
}
MaryGao commented 2 months ago

@joheredi Personally I prefer here to generate as string and with document enhancement for knownable values. Let me know how you think of this!

Firstly I'd like to clarify one thing here, there will be two concepts of api version,

Regarding the types these two versions are independent with each other but considering only one client-leve apiVesion case, we are talking about - if we could be smart to indicate the possible values for that parameter. I think a weak linkage between them would be better with following considerations:

MaryGao commented 1 month ago

Offline confired with Jose, we agreed to go with Option 2 - Generate as KnownVersions and link it to client option.