Azure / Azure/azure-functions-openapi-extension

Enums values are modified inconsistently, when enum is used as a type constraint for a parameter in path

Open
#448 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
388
Forks
202
PR merge metrics
No merged PRs in 30d

Description

**Describe the issue**
Enums values are modified inconsistently, when enum is used as a type constraint for a parameter in path.

**To Reproduce**
Steps to reproduce the behavior:
1. Set up an enum with JsonConverterAttribute and decorate members with EnumMemberAttribute as shown in the screen shot 1.
2. Set up an endpoint, where the enum we set up before is used as OpenApiParameter in ParameterLocation.Path. See screen shot 2.
3. Generate the openapi document. The tooling as attempted and failed to convert the enum values to camelCase.

**Expected behavior**
Enum shows up in the document as defined in code. The tooling does not enforce the produces document to be valid in other places either (for example, you can have Required = false for ParameterLocation.Path and invalid document is generated),

**Screenshots**
1: Setting the troublesome enum up for testing:
![image](https://user-images.githubusercontent.com/14314747/173038214-90d1cd36-3619-4cc1-8ab3-ec493a48ac7d.png)

2: Setting up the endpoint:
![image](https://user-images.githubusercontent.com/14314747/173043417-b7a36146-9410-49d7-af8b-43e561b5af64.png)

3: The casing of enum values are altered in an arbitrary manner:
![image](https://user-images.githubusercontent.com/14314747/173040374-20dee9d4-1429-4981-a43d-67b6a0772a18.png)

**Environment (please complete the following information, if applicable):**
- Openapi verison 3.0.1
- Microsoft.Azure.WebJobs.Extensions.OpenApi.Core 1.3.0
- Microsoft.Azure.WebJobs.Extensions.OpenApi 1.3.0
- Microsoft.OpenApi 1.3.1
- Local windows 11 dev environment, func --version: 4.0.4544

**Additional context**
When the troublesome enum is used as a property in a request body, the enum values are displayed on the document as expected:

![image](https://user-images.githubusercontent.com/14314747/173042333-858bc7b1-88ea-4921-80a5-1c1e3f346882.png)

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with an enum using JsonConverterAttribute and EnumMemberAttribute as an OpenApiParameter at ParameterLocation.Path, then generate the OpenAPI document. Compare the path-parameter enum values with the same enum used in a request-body property; done means the path values remain exactly as defined in code.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, openapi
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.