azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
System.ArgumentException: An item with the same key has already been added. Key: xyz
I've created this sample repo to demonstrate the exception outlined in the subject line. The details of the issue have been described in the README.md file of that repo.
Would you please share a solution because renaming public MyRequest Request { get; set; }
in both MySubmittedData
and YourSubmittedData
classes is not feasible? Doing so will lead to other complexities and break the code's architecture (outside of this repo).
@arashcomsense Thanks for the issue!
It's because both MySubmittedData.MyResponse
and YourSubmittedData.MyResponse
are considered as the same one.
I'll have a look, but no ETA at this time. If you are in time challenge, change the naming on your end can sort out the issue, if you can.
@justinyoo Unfortunately we cannot change the naming due to the reasons I already shared. We prefer a fix for this issue and for that reason we are excluding those definitions from our Open Api definitions. Please keep me posted once a fix is in place.
Related to: https://github.com/aliencube/AzureFunctions.Extensions/issues/133
@justinyoo Probably it makes sense to accelerate addressing this issue.
@justinyoo any updates on this issue?
Seems like what is needed is a configuration setting and functionality similar to CustomSchemaIds as implemented here: https://github.com/domaindrivendev/Swashbuckle.AspNetCore#customize-schema-ids.
Same behaviour with nested generic types. Here a test case
`
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Threading.Tasks;
namespace FunctionApp1
{
public class Model1
{
[Required]
public string RequiredProperty { get; set; }
[JsonRequired]
public string JsonRequiredProperty { get; set; }
[JsonProperty(Required = Required.Always)]
public string JsonPropertyRequiredAlwaysProperty { get; set; }
}
public class Model2
{
public string Property { get; set; }
}
public class Page<T>
{
public int TotalRecords { get; set; }
public IEnumerable<T> Records { get; set; }
}
public class OkResponse<T>
{
public T Result { get; set; }
}
public static class Function2
{
[FunctionName(nameof(Function2.Run))]
[OpenApiOperation(nameof(Function2.Run))]
[OpenApiResponseWithBody(HttpStatusCode.OK, "application/json", bodyType: typeof(OkResponse<Page<Model1>>))]
public static Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
ILogger log)
=> throw new NotImplementedException();
[FunctionName(nameof(Function2.Run2))]
[OpenApiOperation(nameof(Function2.Run2))]
[OpenApiResponseWithBody(HttpStatusCode.OK, "application/json", bodyType: typeof(OkResponse<Page<Model2>>))]
public static Task<IActionResult> Run2(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
ILogger log)
=> throw new NotImplementedException();
}
}
`
This may be related #356
This issue with nested generic types is blocking us from adopting the library in place of Swashbuckle, please can you provide an update on a fix for this?
We are seeing this same issue when we updated our package from 1.0.0 to 1.3.0, What is the release date for the fix?
We're seeing this issue using 1.3.0 as well, but in the OpenApiRequestBody,
Just adding [OpenApiRequestBody(contentType: MediaTypeNames.Application.Json, bodyType: typeof(EtlRequest))]
causes this error to be displayed when attempting to view the Swagger UI.
I have done a Find All in our entire solution and we only have 1 type with that name, and double checked that I didn't duplicate the attribute, which I have not.
For now have rolled back to 1.1.0 and it's working.
I have the same issue with nested generic types. Downgrading to 1.0.0 doesn't fix it for me either.
Having these combined fails for me with the error message: An item with the same key has already been added. Key: Response_list
-
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: MediaTypeNames.Application.Json, bodyType: typeof(Response<List<Version>>))]
-
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: MediaTypeNames.Application.Json, bodyType: typeof(Response<List<Endpoint>>))]
I worked around the issue by changing the body types to Response<Version[]>
and Response<Endpoint[]>
#610 takes care of this issue. The fix will be released in the next v2-preview
release.