azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

OpenApiRequestBody An item with the same key has already been added

Open dannythomas13 opened this issue 2 years ago • 15 comments

I have created a new Azure Function in VS2022 targetting .net 6 isolated and am now getting the following error: An item with the same key has already been added. Key: 'name of my parameter class'

The same code worked for a .net 6 Azure Function that was not running as an isolated process

dannythomas13 avatar May 10 '22 10:05 dannythomas13

I have the same problem. It works find if you use a primitive type ie string. However if you use your own custom object it returns the error:

An item with the same key has already been added. Key: 'name of my parameter class'.

For example this works fine: [OpenApiRequestBody(contentType: "application/json", bodyType: typeof(string), Description = "Parameters", Required = true)]

And this returns an error: [OpenApiRequestBody(contentType: "application/json", bodyType: typeof(TestModel), Description = "Parameters", Required = true)]

The same issue exists for the OpenApiResponseWithBody. Please let us know what we can do to fix this.

beukerz avatar May 13 '22 12:05 beukerz

Same happens with the response attribute. I downgraded to Microsoft.Azure.Functions.Worker.Extensions.OpenApi 1.2.0 and the issue is gone.

An item with the same key has already been added. Key: mockSearchRequestDTO

http://localhost:7071/api/swagger.json at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](List1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector) at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.DocumentHelper.GetOpenApiSchemas(List1 elements, NamingStrategy namingStrategy, VisitorCollection collection) at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Document.Build(Assembly assembly, OpenApiVersionType version) at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Functions.OpenApiTriggerFunction.RenderSwaggerDocument(HttpRequestData req, String extension, FunctionContext ctx)

taipignas avatar May 19 '22 09:05 taipignas

I'm having this issue using the response attribute together with a generic response type. As soon as I have two attributes with a different generic type I get this error:

An item with the same key has already been added. Key: apiResponse_iEnumerable1

A downgrade to 1.2.0 did not resolve my issue.

klemmchr avatar May 20 '22 12:05 klemmchr

I have this same issue, downgrading to 1.2.0 (or building the latest source and using that) works for me

CedNZ avatar May 23 '22 04:05 CedNZ

Having the same issue after upgrading to version 1.3.0, downgrading to 1.2.0 works also for me.

CyberMutter avatar May 25 '22 12:05 CyberMutter

I hope it's not too much of a distraction from this conversation/issue but has anyone else noticed that the example (when we do get it to work using 1.2.0) wraps itself in quotes so that it is a string rather than json? The impact of this for me is that when using the test function of Azure APIM the payload is not valid and I have to manually remove the surrounding quotes and remove escape characters

https://github.com/Azure/azure-functions-openapi-extension/issues/444

dannythomas13 avatar May 25 '22 13:05 dannythomas13

Same issue here. Downgrade to 1.2.0 did not resolve too.

diogokunde avatar Jun 08 '22 16:06 diogokunde

I'm also having this issue. Downgrading to 1.2.0 did fix the issue for me as well.

msundquist-onebridge avatar Jun 10 '22 20:06 msundquist-onebridge

@justinyoo

There are a lot of duplicates regarding this issue now. I see that one duplicate has been closed with two linked PRs suggesting a fix has been made. (https://github.com/Azure/azure-functions-openapi-extension/issues/407)

Due to this other bug (https://github.com/Azure/azure-functions-openapi-extension/issues/387) I am unable to downgrade while we wait for the fix to be released.

This is becoming pretty urgent for us. Is it possible to get a patch with the fix?

brennfoster avatar Jun 14 '22 19:06 brennfoster

Same issue here. Can't downgrade to 1.2.0 due to (https://github.com/Azure/azure-functions-openapi-extension/issues/387)

BronwenZ avatar Jun 23 '22 05:06 BronwenZ

@justinyoo

There are a lot of duplicates regarding this issue now. I see that one duplicate has been closed with two linked PRs suggesting a fix has been made. (#407)

Due to this other bug (#387) I am unable to downgrade while we wait for the fix to be released.

This is becoming pretty urgent for us. Is it possible to get a patch with the fix?

Same issues here - basically prevent us from automatically generating OpenAPI specs, which we use for autogenerating frontend TypeScript data contracts.

Is anyone aware of any alternative solutions, that work with Azure Functions v4, dotnet-isolated process and .NET 6.

Any ETA on when this will be fixed!!

jeckyl2010 avatar Jun 29 '22 05:06 jeckyl2010

I have the same issue in 1.3.0. (1.2.0 works fine.)

maurert avatar Jul 01 '22 08:07 maurert

I'm wondering if the package development is stalled and if someone else have some better alternative packages to generate OpenAPI documentation for .NET 6 Azure Function projects using dot-isolated coding scheme.

jeckyl2010 avatar Jul 05 '22 05:07 jeckyl2010

I just discovered that if I move the custom object into a separate project then the open api extension renders the swagger document successfully.

Sharing for anyone still struggling with this and needing a work around.

brennfoster avatar Jul 22 '22 20:07 brennfoster

Hey @brennfoster, I really regret I found your thread so lately. I had to spend a whole day to find work around. I confirmed it works! Really appreciate it. 👍🏻

hopefully it can be fixed in next release.

Dongbumlee avatar Aug 05 '22 18:08 Dongbumlee