Skip to content

Commit 2e05824

Browse files
Copilotmarkcowl
andauthored
Reorganize versioning docs: move ARM docs to Versioning root, merge introductions, update links
Agent-Logs-Url: https://github.com/Azure/typespec-azure/sessions/e3f6341b-5c80-4f75-8fe5-e8b9a30074e8 Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
1 parent 0630d78 commit 2e05824

10 files changed

Lines changed: 196 additions & 198 deletions

File tree

website/src/content/docs/docs/getstarted/versioning.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Versioning
33
---
44

5-
Versioning lets you evolve your API without breaking existing clients. This guide covers the basics of declaring versions and adding new resources, operations, and properties in a clear, easy-to-follow way. For more advanced scenarios, see the [full versioning documentation](../howtos/ARM/versioning.md).
5+
Versioning lets you evolve your API without breaking existing clients. This guide covers the basics of declaring versions and adding new resources, operations, and properties in a clear, easy-to-follow way. For more advanced scenarios, see the [full versioning documentation](../howtos/Versioning/01-about-versioning.md).
66

77
## Declaring Versions
88

@@ -96,4 +96,4 @@ interface Employees {
9696

9797
---
9898

99-
For more details and advanced scenarios, see the [full versioning documentation](../howtos/ARM/versioning.md).
99+
For more details and advanced scenarios, see the [full versioning documentation](../howtos/Versioning/01-about-versioning.md).
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
---
2+
title: Introduction
3+
llmstxt: true
4+
---
5+
6+
See [`@typespec/versioning` documentation](https://typespec.io/docs/libraries/versioning/guide) for the general versioning concept. This guide expands on how Azure Services should define and manage API versions.
7+
8+
See [Common Versioning Scenarios](../ARM/versioning.md) for how to make specific kinds of common API changes in your specs.
9+
10+
## How Versioning Works in TypeSpec
11+
12+
TypeSpec uses a versioning library that models the changes in each new version of the API, rather than having a separate API description for each api-version. This works well when APIs evolve according to versioning guidelines, without breaking changes. For the most part, this means that this system is very good at modeling differences between stable api-versions for Azure APIs, but can be cumbersome when describing differences between preview APIs.
13+
14+
Additionally, in Azure, preview APIs have a limited lifespan and limited support in SDKs and other tooling. For this reason and others, specs should only have a _single active preview_ in TypeSpec at any point during the spec development process.
15+
16+
## Preview Versioning Rules for All Azure APIs
17+
18+
- Always make the last enum value the preview and apply `@previewVersion` to it.
19+
- Only one version may be marked with the `@previewVersion` decorator.
20+
- Mark all changes from the latest stable with appropriate versioning decorators, using `Versions.<PreviewVersion>` as the version argument (where `<PreviewVersion>` is the name of the last enum value)
21+
22+
## Preview Versioning Rules for Data Plane APIs
23+
24+
- For a new GA, add a new version enum **BEFORE** the preview enum value. Manually change all **preview** items that are GA'ing so that the `@added` version value matches the new GA enum value
25+
- For any items remaining in **preview**, rename the **old preview** enum value to the **new preview** enum value.
26+
27+
## Common Version Transition Scenarios
28+
29+
This section describes how to evolve APIs according to these guidelines, and how to meet both the single active preview guideline and the need to maintain some preview versions in certain situations:
30+
31+
- [How to add a new preview version when the last version was preview](./02-preview-after-preview.md)
32+
- [How to add a new stable version when the last version was preview](./03-stable-after-preview.md)
33+
- [How to add a new preview version when the last version was stable](./04-preview-after-stable.md)
34+
- [How to add a new stable version when the last version was stable](./05-stable-after-stable.md)
35+
36+
This section also describes how to convert an existing multi-API TypeSpec spec with multiple previews into a spec with a single active preview. Note that this is not required, but it may significantly simplify the versioning decoration in your spec:
37+
38+
- [How to convert a spec with multiple preview versions into a spec with a single active preview](./uncommon-scenarios/01-converting-specs.md)
39+
40+
Additionally, there are some services that may always have features that remain in preview after a stable version is released. This can happen, for example, if there are multiple independent teams that own different resources in a service and operate on their own schedule. The recommended way to handle this scenario is to model your ResourceProvider as multiple services, so each version and the corresponding SDKs can version independently. For some older services, this is not an option, so there is specialized guidance on how to maintain preview features over stable API releases (described below). If you are thinking about splitting your service, or about creating a new preview version with every stable version, be sure to have a discussion with the [Azure API Stewardship Board](https://aka.ms/azapi/officehours) and the [Azure SDK team](https://eng.ms/docs/products/azure-developer-experience/onboard) first.
41+
42+
- [How to manage a single active preview if your service always has some features in preview (ARM only)](./uncommon-scenarios/02-perpetual-preview.md)
43+
44+
## Should I Retain the OpenAPI for an Old Preview API (ARM Only)
45+
46+
:::note
47+
This section applies specifically to **Azure Resource Manager (ARM) APIs**. ARM teams may need to maintain OpenAPI files for preview versions until they are retired for reasons including:
48+
49+
- RPaaS live validation support
50+
- ARM registration support
51+
:::
52+
53+
It is safe to remove the swagger for an old API version if any of the following is true:
54+
55+
- The api-version is retired
56+
- The OpenAPI document in the azure-rest-api-specs repo is not needed for RPaaS live validation
57+
- The OpenAPI document in the azure-rest-api-specs repo is not needed for ARM registration
58+
59+
It is recommended that preview api-versions are set for retirement within 90 days when a preview or stable API is introduced. See the [Azure Retirement Policy](https://aka.ms/AzureRetirementPolicy) and [Azure Retirement Process](https://aka.ms/cpexretirementsprocess) for details.
60+
61+
### Usage Examples
62+
63+
#### New preview version
64+
65+
In the following example we introduce a new preview version called `v3Preview` which includes everything from `v2` plus adds a new property to the `Widget` resource.
66+
67+
```diff lang=tsp
68+
import "@typespec/http";
69+
import "@typespec/rest";
70+
import "@typespec/versioning";
71+
import "@azure-tools/typespec-azure-core";
72+
73+
using Http;
74+
using Rest;
75+
using Versioning;
76+
using Azure.Core;
77+
78+
79+
@versioned(Versions)
80+
@service(#{ title: "Widget Service" })
81+
namespace DemoService;
82+
83+
enum Versions {
84+
v1,
85+
v2,
86+
+ @previewVersion
87+
+ v3Preview
88+
}
89+
90+
/**
91+
* Model defining the Widget resource
92+
*/
93+
model Widget {
94+
/**
95+
* Identifier of the Widget Resource
96+
*/
97+
@visibility(Lifecycle.Read)
98+
@key id: string;
99+
/**
100+
* Weight of the widget
101+
*/
102+
weight: int32;
103+
/**
104+
* Color of the widget;
105+
*/
106+
color: "red" | "blue";
107+
/**
108+
* Nickname of the Widget resource
109+
*/
110+
+ @added(Versions.v3Preview) nickname: string;
111+
}
112+
```
113+
114+
#### Adding a new stable (GA) version
115+
116+
This example builds on the previous one, where `v3` is introduced which GA's the `nickname` property introduced in `v3Preview`
117+
118+
```diff lang=tsp
119+
import "@typespec/http";
120+
import "@typespec/rest";
121+
import "@typespec/versioning";
122+
import "@azure-tools/typespec-azure-core";
123+
124+
using Http;
125+
using Rest;
126+
using Versioning;
127+
using Azure.Core;
128+
129+
130+
@versioned(Versions)
131+
@service(#{ title: "Widget Service" })
132+
namespace DemoService;
133+
134+
enum Versions {
135+
v1,
136+
v2,
137+
- @previewVersion
138+
- v3Preview
139+
+ v3
140+
}
141+
142+
/**
143+
* Model defining the Widget resource
144+
*/
145+
model Widget {
146+
/**
147+
* Identifier of the Widget Resource
148+
*/
149+
@visibility(Lifecycle.Read)
150+
@key id: string;
151+
/**
152+
* Weight of the widget
153+
*/
154+
weight: int32;
155+
/**
156+
* Color of the widget;
157+
*/
158+
color: "red" | "blue";
159+
/**
160+
* Nickname of the Widget resource
161+
*/
162+
- @added(Versions.v3Preview) nickname: string;
163+
+ @added(Versions.v3) nickname: string;
164+
}
165+
```

website/src/content/docs/docs/howtos/Versioning/01-preview-version.md

Lines changed: 0 additions & 129 deletions
This file was deleted.

website/src/content/docs/docs/howtos/Versioning/ARM/02-preview-after-preview.md renamed to website/src/content/docs/docs/howtos/Versioning/02-preview-after-preview.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ When the last api-version in your TypeSpec spec is a preview, adding a new previ
77

88
## The Simplest Case: No Stable api-versions
99

10-
If your spec is in preview and has not ever had a stable api-version, then there is no need to have versioning decoration in your typespec at all:
10+
If your spec is in preview and has not ever had a stable api-version, then there is no need to have versioning decoration in your TypeSpec at all:
1111

1212
- Change the api-version to match the new api-version
1313
```diff lang=tsp
@@ -18,7 +18,7 @@ If your spec is in preview and has not ever had a stable api-version, then there
1818
}
1919
```
2020
- Remove any versioning decorators
21-
- Make any api changes for the new preview, there is no need to use versioning decoration for this.
21+
- Make any API changes for the new preview, there is no need to use versioning decoration for this.
2222
- Update the example folder name to match the new api-version
2323

2424
```bash
@@ -38,7 +38,7 @@ If your spec is in preview and has not ever had a stable api-version, then there
3838
}
3939
```
4040

41-
- If you **do not need** to retain the OpenAPI for older previews (see [Should I delete an old preview](./01-about-versioning.md#should-i-retain-the-openapi-for-an-old-preview-api) if you are not sure).
41+
- If you **do not need** to retain the OpenAPI for older previews (see [Should I Retain the OpenAPI for an Old Preview API](./01-about-versioning.md#should-i-retain-the-openapi-for-an-old-preview-api-arm-only) if you are not sure).
4242
- Remove the associated OpenAPI file and examples
4343

4444
```bash
@@ -58,7 +58,7 @@ This includes the following steps:
5858
### Making Changes to your TypeSpec spec
5959

6060
- Rename the latest preview version to match the new preview version, in all instances in the spec
61-
- In vscode, highlight the version name and select `rename symbol` from the context menu to rename the version throughout your spec
61+
- In VS Code, highlight the version name and select `rename symbol` from the context menu to rename the version throughout your spec
6262
- In any editor, search and replace the latest preview version in the spec with the new preview version
6363
- Update the version value of this version to match the new api-version string, for example:
6464
@@ -136,7 +136,7 @@ This includes the following steps:
136136
}
137137
```
138138
139-
- Add and modify examples to match the api changes
139+
- Add and modify examples to match the API changes
140140
141141
### Preparing a PR into the azure-rest-api-specs repo
142142
@@ -167,10 +167,10 @@ This includes the following steps:
167167
C:\repos\azure-rest-api-specs\specification\myRpShortname\resource-manager\Microsoft.MyRP\MyService > npx tsp compile .
168168
```
169169
170-
- If you _don't_ need the older preview version (see [Should I delete an old preview](./01-about-versioning.md#should-i-retain-the-openapi-for-an-old-preview-api) if you are not sure), remove the OpenAPI directory for that version and update the `README.md` file to use the new version instead.
170+
- If you _don't_ need the older preview version (see [Should I Retain the OpenAPI for an Old Preview API](./01-about-versioning.md#should-i-retain-the-openapi-for-an-old-preview-api-arm-only) if you are not sure), remove the OpenAPI directory for that version and update the `README.md` file to use the new version instead.
171171
172172
```bash
173173
C:\repos\azure-rest-api-specs\specification\myRpShortname\resource-manager\Microsoft.MyRP\ > rm -r 2025-12-01-preview
174174
```
175175
176-
- If you _do_ need the older preview version (see [Should I delete an old preview](./01-about-versioning.md#should-i-retain-the-openapi-for-an-old-preview-api) if you are not sure), update README.md to include a new entry for the new preview version.
176+
- If you _do_ need the older preview version (see [Should I Retain the OpenAPI for an Old Preview API](./01-about-versioning.md#should-i-retain-the-openapi-for-an-old-preview-api-arm-only) if you are not sure), update README.md to include a new entry for the new preview version.

0 commit comments

Comments
 (0)