OpenAPI.NET.OData icon indicating copy to clipboard operation
OpenAPI.NET.OData copied to clipboard

Support for enum flags

Open andrueastman opened this issue 1 year ago • 2 comments

Taking a look at the metadata for the SourceType enum in the graph metadata, there exists the IsFlags property which is set to true.

      <EnumType Name="sourceType" IsFlags="true">
        <Member Name="mailbox" Value="1" />
        <Member Name="site" Value="2" />
      </EnumType>

The flags attribute is not propagated to the converted openApi description in any way at the moment and also information on the values is also lost in the conversion process.

    microsoft.graph.security.sourceType:
      title: sourceType
      enum:
        - mailbox
        - site
        - unknownFutureValue
      type: string

This poses a challenge to Kiota at the moment as there is no signal for the generator to generate an appropriate Flag property.

Notes

  • According to https://github.com/OAI/OpenAPI-Specification/issues/348#issuecomment-336194030 enums could be better described to cater for values by conforming to the json schema
  • Some extensions like x-enumFlags to denote flagged enums
  • AutoRest uses [x-ms-enum](https://github.com/Azure/autorest/tree/main/docs/extensions#x-ms-enum) to denote values and fields.

Related to https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet/issues/496

cc @baywet @darrelmiller

andrueastman avatar Jul 21 '22 08:07 andrueastman

We're using the x-ms-enum extension when Aliasing the code symbol and the serialized value. It'd be great if we could pr their specification to add the information there instead of coming up with our own. Also we should check whether oai 3.1 or Json schema has something to support that notion which arguably is very dotnetty.

baywet avatar Jul 22 '22 07:07 baywet

I think doing a PR to the x-ms-enum would be the right thing. If we add "isFlagEnum" and set the modelAsString to true then that would cover all cases.

@andrueastman Could you create a PR for this change? You could reach out to Mike Kistler to help you get eyes on the issue.

darrelmiller avatar Aug 18 '22 14:08 darrelmiller

Is there any Update to this issue. Adding x-ms-enum extension is enough as described in AutoRest. I set the property AddEnumDescriptionExtension=true in the setting , but it has no effect.

moh-hassan avatar Aug 21 '23 00:08 moh-hassan