OpenAPI.NET icon indicating copy to clipboard operation
OpenAPI.NET copied to clipboard

Copy constructor doesn't create new `OpenApiPathItem` objects when creating new instance of `OpenApiPaths`

Open irvinesunday opened this issue 2 years ago • 3 comments

Describe the bug Copy constructors doesn't create a new instance of OpenApiPathItem and its constituent properties on new OpenApiDocument(document).

To Reproduce I have created a breaking test to demonstrate this: https://github.com/microsoft/OpenAPI.NET/blob/d5a5f8a8890825824f31187355850945416aa7ea/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs#L1341-L1358 This is in the branch: is/copy-ctrs

Expected behavior In the test, I change the operationId of the cloned OpenAPI document. I don't expect the operationId of the original OpenAPI document to also be updated.

irvinesunday avatar Mar 28 '23 10:03 irvinesunday

When cloning OpenApiPaths we are using the standard Dictionary constructor which does not do a clone of the values of the key value pairs. https://github.com/microsoft/OpenAPI.NET/blob/vnext/src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs#L31

darrelmiller avatar Apr 02 '23 15:04 darrelmiller

Reopening this issue as its not fixed.

MaggieKimani1 avatar Apr 24 '23 11:04 MaggieKimani1

Having this issue with cloning OpenApiPathItem as well. As a workaround I serialize to json via the built-in functionality and use ReadFragment to deserialize it again.

kevinharing avatar Dec 01 '23 14:12 kevinharing