Azure / Azure/typespec-azure

How to customize ResourceKindProperty

Open
#1,650 1 comment 0 reactions 0 assignees View on GitHub
design:needed lib:azure-resource-manager
Dominant language
TypeScript
Stars
27
Forks
90
Avg merge
1d 22h
Merged PRs (30d)
156

Description

Currently `ResourceKindProperty` is defined as:

https://github.com/Azure/typespec-azure/blob/433735c7fbb35a719ebde7e8d1cfa96303d36c58/packages/typespec-azure-resource-manager/lib/models.tsp#L282-L288

When it's mixed-in into a resource model:

```typespec
model Account is TrackedResource {
...ResourceKindProperty,
}
```
results in the following spec model:

```json
"kind": {
"type": "string",
"description": "Metadata used by portal/tooling/etc to render different UX experiences for resources of the same type; e.g. ApiApps are a kind of Microsoft.Web/sites type. If supported, the resource provider must validate and persist this value.",
"pattern": "^[-\\w\\._,\\(\\\\\\)]+$",
"x-ms-mutability": [
"read",
"create"
]
}
```

But I'd like to limit the value to an enum (list of well-known values), e.g. `direct` and `indirect`. Like what App Services have.

I could do it by defining my own model:

```typespec
union AccountKind {
Direct : "direct",
IndirectFoo : "indirect,foo",
IndirectBar: "indirect,bar",
string,
}
```

but it generates a warning:

>warning @azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property: Property "kind" is not valid in the resource envelope. Please remove this property, or add it to the resource-specific property bag.

Contributor guide

Open the contributing guide

Research direction

Start with ResourceKindProperty in packages/typespec-azure-resource-manager/lib/models.tsp at lines 282-288, then trace the ARM envelope validation that emits arm-resource-invalid-envelope-property. Define how a resource-specific kind union can replace or customize the standard property without triggering that warning, and verify that the generated schema preserves the allowed values.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.