Azure / Azure/azure-rest-api-specs

Can't specify default value in enums for SDK

Open
#11,054 1 comment 0 reactions 0 assignees View on GitHub
Cognitive Services question Service Attention
Dominant language
TypeSpec
Stars
3.1k
Forks
5.9k
Avg merge
3d 2h
Merged PRs (30d)
424

Description

I had an enum with only one value, so it was treated as a constant. That meant customers didn't have to provide it and it was always set.
After adding new values to the enum I was hoping there was a way to add a default value to continue the same behavior (If not set, then it would take the first one).
I tried with "Default" and "x-ms-client-default" but didn't work.

I was hoping this:
public FactoryIdentity(string type = default(string)){ ... }

to be this:
public FactoryIdentity(string type = "DefaultValue"){ ... }

Contributor guide

Open the contributing guide

Research direction

No source file, generator entry point, or test is named. Start by tracing how enum definitions and the Default or x-ms-client-default extensions are consumed during C# SDK generation; done means an omitted enum argument produces the requested default value and is covered by a relevant generation test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.