You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| 2022-Sep-07 | Updated URL guidelines for DNS Done Right ||
19
+
| 2023-Apr-07 | Update/clarify guidelines on polymorphism |
20
+
| 2022-Sep-07 | Updated URL guidelines for DNS Done Right |
17
21
| 2022-Jul-15 | Update guidance on long-running operations |
18
22
| 2022-May-11 | Drop guidance on version discovery |
19
23
| 2022-Mar-29 | Add guidelines about using durations |
@@ -24,6 +28,8 @@ Please ensure that you add an anchor tag to any new guidelines that you add and
24
28
| 2020-Jul-31 | Added service advice for initial versions |
25
29
| 2020-Mar-31 | 1st public release of the Azure REST API Guidelines |
26
30
31
+
</details>
32
+
27
33
## Introduction
28
34
29
35
These guidelines apply to Azure service teams implementing _data plane_ APIs. They offer prescriptive guidance that Azure service teams MUST follow ensuring that customers have a great experience by designing APIs meeting these goals:
@@ -492,6 +498,12 @@ This indicates to client libraries and customers that values of the enumeration
492
498
<aname="json-document-extensible-enums"></a>
493
499
:white_check_mark:**DO** document to customers that new values may appear in the future so that customers write their code today expecting these new values tomorrow.
494
500
501
+
<aname="json-return-extensible-enum-value"></a>
502
+
:heavy_check_mark:**YOU MAY** return a value for an extensible enum that is not one of the values defined for the api-version specified in the request.
503
+
504
+
<aname="json-accept-extensible-enum-value"></a>
505
+
:warning:**YOU SHOULD NOT** accept a value for an extensible enum that is not one of the values defined for the api-version specified in the request.
:white_check_mark:**DO** define a `kind` field indicating the kind of the resource and include any kind-specific fields in the body.
518
+
:white_check_mark:**DO** define a discriminator field indicating the kind of the resource and include any kind-specific fields in the body.
507
519
508
-
Below is an example of JSON for a Rectangle and Circle:
520
+
Below is an example of JSON for a Rectangle and Circle with a discriminator field named `kind`:
509
521
**Rectangle**
510
522
```json
511
523
{
@@ -540,6 +552,22 @@ Below is an example of JSON for a Rectangle and Circle:
540
552
```
541
553
Both Rectangle and Circle have common fields: `kind`, `fillColor`, `lineColor`, and `subscription`. A Rectangle also has `x`, `y`, `width`, and `length` while a Circle has `x`, `y`, and `radius`. The `subscription` is a nested polymorphic type. A `free` subscription has no additional fields and a `paid` subscription has `expiration` and `invoice` fields.
542
554
555
+
The [Azure Naming Guidelines](./ConsiderationsForServiceDesign.md#common-names) recommend that the discriminator field be named `kind`.
556
+
557
+
<aname="json-polymorphism-kind-extensible"></a>
558
+
:ballot_box_with_check:**YOU SHOULD** define the discriminator field of a polymorphic type to be an extensible enum.
559
+
560
+
<aname="json-polymorphism-kind-immutable"></a>
561
+
:warning:**YOU SHOULD NOT** allow an update (patch) to change the discriminator field of a polymorphic type.
562
+
563
+
<aname="json-polymorphism-versioning"></a>
564
+
:warning:**YOU SHOULD NOT** return properties of a polymorphic type that are not defined for the api-version specified in the request.
565
+
566
+
<aname="json-polymorphism-arrays"></a>
567
+
:warning:**YOU SHOULD NOT** have a property of an updatable resource whose value is an array of polymorphic objects.
568
+
569
+
Updating an array property with JSON merge-patch is not version-resilient if the array contains polymorphic types.
0 commit comments