Skip to content

[Codegen/TypeSpec] Handle apiVersion as Path Parameter #2148

@masons-msft

Description

@masons-msft

Microsoft Fabric's API guidelines require the API version to be a path parameter rather than a query parameter. We would like to use this tool for generating our TypeScript SDK from our TypeSpec definition but incorporating the API version as a path parameter cannot be accomplished as cleanly as we would like, at least from what we know of the tool. There are two things we would like to be able to do.

First, we would like to set the API version as part of the client creation or route definition rather than having to specify the API version as a parameter in every request. It seems like this is already a feature in the autorest.python project.

Second, we would like api-version to not be automatically added as a query parameter to all requests. I believe there is already an issue that has been created related to this along with a pull request to resolve it.

Are there already features to support this use case that we are simply not aware of? If not, would it be possible to add this as a feature?

Here is a quick example of what our TypeSpec looks like.

model ApiVersionPathParameter {
  apiVersion: string;
}

@resource("exampleResources")
model ExampleResource {
  @Key
  id: string;
}

@tag("ExampleResources")
interface ExampleResourceInterface {
  @autoRoute
  @readsResource(ExampleResource)
  get(
    ...ApiVersionPathParameter
    ...Resource.ResourceParameters<ExampleResource>
  ): ExampleResource;
}

The generated clientDefinition.ts file would then have a Routes interface like the following.

export interface Routes {
  (
    path: "/{apiVersion}/exampleResources/{id}",
    apiVersion: string,
    id: string
): ExampleResourcesGet;

Is there a way to either set the path to "/v1/exampleResource/{id}" with no apiVersion parameter or set the client's baseUrl to include the api version at the end and then have all paths look like "/exampleResource/{id}"?

Metadata

Metadata

Assignees

Labels

customer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions