Azure / Azure/azure-functions-openapi-extension
An item with the same key has already been added when hiding inherited member
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the issue**
When a derived class hides an inherited member of its base, "An item with the same key has already been added" is encountered.
**To Reproduce**
Steps to reproduce the behavior:
1. Clone https://github.com/techfg/azure-functions-openapi-extension
2. Checkout brach `hide-inherited-repro`
3. Run sample project `Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.InProc`
4. Open `http://localhost:7071/api/swagger/ui` in browser
**Expected behavior**
Swagger should display with `MyDerivedClass.Data` of type `MyData` property visible on `MyDerivedClass`
**Environment (please complete the following information, if applicable):**
- OS: Windows
- Browser: Edge
- Version: 1.5.1
**Additional context**
The problem occurs in [ObjectTypeVisitor](https://github.com/Azure/azure-functions-openapi-extension/blob/v1.5.1/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/ObjectTypeVisitor.cs#L117) where it detects `Data` property on both derived and base class. Using `JsonIgnore` on base class resolves issue but that creates issues when using MyBase directly in other areas. Common use case for this scenario is deriving a base class into a generic replacing the [`Data` property](https://github.com/techfg/azure-functions-openapi-extension/blob/hide-inherited-repro/samples/Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Models/ReplacedProperty.cs#L21).
Contributor guide
Research direction
Start with src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/ObjectTypeVisitor.cs at line 117, then reproduce the issue using the hide-inherited-repro branch and the Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.InProc sample. Open the Swagger UI and verify that MyDerivedClass.Data is shown as a MyData property without the duplicate-key error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100