[OpenApiResponseWithBody(HttpStatusCode.OK, "application/json", typeof(SampleResponseDto))]
[OpenApiResponseWithBody(HttpStatusCode.InternalServerError, "application/json", typeof(SampleErrorResponseDto))]
[OpenApiResponseWithBody(HttpStatusCode.Unauthorized, "application/json", typeof(ErrorResponseDto))]
[OpenApiResponseWithBody(HttpStatusCode.Forbidden, "application/json", typeof(ErrorResponseDto))]
These are the ones we want to add in that particular attribute which is used by all the Functions in a Function App For eg:
public class OpenApiDefaultsAttribute : Attribute, IMetadatAttribute
{
public Attribute[] Process()
{
var attributes = new Attribute[] {
new OpenApiResponseWithBodyAttribute(HttpStatusCode.Unauthorized, "application/json", typeof(ErrorResponseDto)),
new OpenApiResponseWithBodyAttribute(HttpStatusCode.Forbidden, "application/json", typeof(ErrorResponseDto))
};
return attributes;
}
}
and use that instead of all that messy code.
I followed this particual approach and it didnt work for the mentioned use case
I have created Http trigger function with dotnet runtime stack in vs code.
I have created custom attributes and added in the function code by using below code:
The above function holds multiple attributes but when it ran given response like below: