[Feature request]x-ms-enum doesn't support combination of enum values.
Here is the situation, we want set a parameter with None or any combination of Logging | Metrics | Other. But following extension only support to set single enum value. I think it is a common case trying to set a combination of enum types.
Are we supporting this feature now? If not, are we planning to support this?
Sample
"type": "string",
"enum": [
"None",
"Logging",
"Metrics",
"Other"
],
"x-ms-enum": {
"name": "Bypass",
"modelAsString": false
},
"default": "Other",
Agreed; This would be a useful feature. In another issue we've discussed adding the concept of an ExtensibleEnum to AutoRest: https://github.com/Azure/autorest/issues/1591
Here's an example of how we've used ExtensibleEnum in the Azure Search .NET client library to implement enum "flags": https://github.com/Azure/azure-sdk-for-net/blob/AutoRest/src/Search/Microsoft.Azure.Search/Customizations/Indexes/Models/RegexFlags.cs
This approach should also be generalizable.
You can just model this as a collection of enums if you want (rendered into C# as List<Bypass> in this case).
JSON doesn't have a built in way to render a Logging | Metrics without putting them into a collection anyway.
A flag to allow AutoRest to render a collection of enums as a Flags enum for langauges that support it probably makes sense, but as far as the REST format is concerned I would think that what you're asking for is exactly a collection of enums.
@matthchr In our case, we literally wanted a string like "OPTION_A | OPTION_B" in the JSON. I'm guessing that's what @JasonYang-MSFT wanted too.
I'm hesitant to do something like that as it opposes (my understanding of) the Swagger spec. enum is supposed to literally enumerate all possible values that could go over the wire, so sending "... | ..." would sort of actively violate the contract.
enum is supposed to literally enumerate all possible values that could go over the wire
That interpretation is already violated by modelAsString: true.
fair point! Although in practice I've mainly seen it as breaking change prevention, so the contract will be violated merely when it becomes deprecated. We'll definitely think about this when building code generators 2.0 (OpenAPI 3.0 sort of requires some significant rethinking), at that point I'd also be more than happy to make your approach in #1591 one of the enum-implementations!
Needless to say, if this feature request gets significant traction, we'll consider adding [Flags] to the current generator.
@olydis That would be great, thanks!
moved to https://github.com/Azure/autorest/issues/2448