Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
irvinesunday opened this issue Mar 28, 2023 · 3 comments · Fixed by #1203
Assignees
Labels
type:bug A broken experience

Comments

@irvinesunday
Copy link
Contributor

irvinesunday commented Mar 28, 2023

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:

[Fact]
public void CopyConstructorForAdvancedDocumentWorks()
{
// Arrange & Act
var doc = new OpenApiDocument(AdvancedDocument);
// Change value of operation id for a given url
var docOpId = doc.Paths["/pets"].Operations[OperationType.Get].OperationId = "findAllMyPets";
var advancedDocOpId = AdvancedDocument.Paths["/pets"].Operations[OperationType.Get].OperationId;
// Assert
Assert.NotNull(doc.Info);
Assert.NotNull(doc.Servers);
Assert.NotNull(doc.Paths);
Assert.Equal(2, doc.Paths.Count);
Assert.NotNull(doc.Components);
Assert.NotEqual(docOpId, advancedDocOpId);
}

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.

@darrelmiller
Copy link
Member

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

@MaggieKimani1
Copy link
Contributor

Reopening this issue as its not fixed.

@MaggieKimani1 MaggieKimani1 reopened this Apr 24, 2023
@kevinharing
Copy link

kevinharing commented Dec 1, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A broken experience
Projects
None yet
4 participants