Skip to main content
Version: Latest (Core: 0.60.x, Azure: 0.46.x)

Versioning

This doc details what emitters will generate for versioned specs

Single api Version​

If there is just one api version in the spec, we will generate the api surface area for that one version.

import "@typespec/versioning";
import "@typespec/http";

using TypeSpec.Versioning;
using TypeSpec.Http;

@versioned(My.Service.Versions)
@service
namespace My.Service;

enum Versions {
v2023_11_01: "2023-11-01",
}

model StableModel {
stableFeature: string;
}

op stableFunctionality(@body stableModel: StableModel): void;

Multiple api versions​

The configuration flag api-version allows you to toggle the behavior that our emitters will generate.

We will get the versioning information from the Versions enum that you pass to the @versioned decorator from the @typespec/versioning library.

NOTE: The ordering of the values in the Versions enum is very important. We use this information to determine the order of versions. Our default value will be the last entry in the Versions list

Default​

By default our emitters will only generate the surface used by the latest api version if there are multiple defined. This includes generating only the models used in the surface area of the latest api version.

Documentation and enums showing the available api versions will still include all of the known api versions, meaning there will be documentation for both the preview and stable releases.

For the below example, all languages will generate the api surface of default version v2023_11_01. There will be no generation of the operation previewFunctionality, and we will also not generate the PreviewModel because it's only used in previewFunctionality, and therefore is not used in the api surface of v2023_11_01.

import "@typespec/versioning";
import "@typespec/http";

using TypeSpec.Versioning;
using TypeSpec.Http;

@versioned(My.Service.Versions)
@service
namespace My.Service;

enum Versions {
v2023_11_01_preview: "2023-11-01-preview",
v2023_11_01: "2023-11-01",
}

model PreviewModel {
betaFeature: string;
}

model StableModel {
stableFeature: string;
}

@added(Versions.v2023_11_01_preview)
@removed(Versions.v2023_11_01)
op previewFunctionality(@body previewModel: PreviewModel): void;

op stableFunctionality(@body stableModel: StableModel): void;

Override to a specific version​

You can override the signature to return the api surface area for a specific api version.

In this example, we are going to override to return the preview api surface area for our spec. The preview api surface area contains all of the functionality.

import "@typespec/versioning";
import "@typespec/http";

using TypeSpec.Versioning;
using TypeSpec.Http;

@versioned(My.Service.Versions)
@service
namespace My.Service;

enum Versions {
v2023_11_01_preview: "2023-11-01-preview",
v2023_11_01: "2023-11-01",
}

model PreviewModel {
betaFeature: string;
}

model StableModel {
stableFeature: string;
}

@added(Versions.v2023_11_01_preview)
@removed(Versions.v2023_11_01)
op previewFunctionality(@body previewModel: PreviewModel): void;

op stableFunctionality(@body stableModel: StableModel): void;

Override to return all​

You can also override the signature to return the combined api surface area of all of the separate api versions. Different languages have different support for versioning validation

import "@typespec/versioning";
import "@typespec/http";

using TypeSpec.Versioning;
using TypeSpec.Http;

@versioned(My.Service.Versions)
@service
namespace My.Service;

enum Versions {
v2023_11_01_preview: "2023-11-01-preview",
v2023_11_01: "2023-11-01",
}

model PreviewModel {
betaFeature: string;
}

model StableModel {
stableFeature: string;
}

@added(Versions.v2023_11_01_preview)
@removed(Versions.v2023_11_01)
op previewFunctionality(@body previewModel: PreviewModel): void;

op stableFunctionality(@body stableModel: StableModel): void;