Azure / Azure/azure-functions-openapi-extension
TypeExtensions.GetOpenApiReferenceId does not support generics more than 1 level deep
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the issue**
When declaring objects using generics that go more than one levels deep, the `GetOpenApiReferenceId` method will generate the same id, no matter what the inner classes are, due to the logic [here](https://github.com/Azure/azure-functions-openapi-extension/blob/877a1db3294995fba1a7b233e6e5d14b87b6570a/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/TypeExtensions.cs#L416).
This will result in that all the instances where the outer classes are the same, only one schema will be used in the resulting documentation.
**To Reproduce**
Assume that we have a common response model
```
class ResponseModel {
public T data {get; set;}
}
```
And two classes we want to respond with
```
class Foo {}
class Bar {}
```
And two functions with the following attributes
```
[OpenApiResponseWithBody(
statusCode: HttpStatusCode.OK,
contentType: MediaTypeNames.Application.Json,
bodyType: typeof(ResponseModel>)
)]
```
and
```
[OpenApiResponseWithBody(
statusCode: HttpStatusCode.OK,
contentType: MediaTypeNames.Application.Json,
bodyType: typeof(ResponseModel>)
)]
```
This will result in `ResponseModel>` (if processed first) being used for documenting the response body of both functions
**Expected behavior**
`ResponseModel>` for documenting the first function and `ResponseModel>` for documenting the second one.
Contributor guide
Research direction
Start in src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/TypeExtensions.cs at GetOpenApiReferenceId and inspect the linked generic-type logic. Reproduce the ResponseModel> and ResponseModel> example, then verify that each nested generic type produces its own schema reference and the corresponding function documentation uses the correct model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, openapi
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100