Azure / azure-functions-openapi-extension

This extension provides an Azure Functions app with Open API capability for better discoverability to consuming parties
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/
MIT License
375 stars 196 forks source link

TypeExtensions.GetOpenApiReferenceId does not support generics more than 1 level deep #666

Open Arclights opened 2 months ago

Arclights commented 2 months ago

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.

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<T> {
   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<List<Foo>>)
)]

and

[OpenApiResponseWithBody(
        statusCode: HttpStatusCode.OK,
        contentType: MediaTypeNames.Application.Json,
        bodyType: typeof(ResponseModel<List<Bar>>)
)]

This will result in ResponseModel<List<Foo>> (if processed first) being used for documenting the response body of both functions

Expected behavior ResponseModel<List<Foo>> for documenting the first function and ResponseModel<List<Bar>> for documenting the second one.