Skip to content

Commit

Permalink
Merge pull request #1099 from microsoft/mk/fix-schema-copy-constructo…
Browse files Browse the repository at this point in the history
…r-stackoverflow

StackOverflow when using OpenApiSchema Copy Constructor
  • Loading branch information
MaggieKimani1 authored Dec 6, 2022
2 parents 5e3d9d3 + 1dae8dc commit 563b046
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public OpenApiSchema(OpenApiSchema schema)
MaxProperties = schema?.MaxProperties ?? MaxProperties;
MinProperties = schema?.MinProperties ?? MinProperties;
AdditionalPropertiesAllowed = schema?.AdditionalPropertiesAllowed ?? AdditionalPropertiesAllowed;
AdditionalProperties = new(schema?.AdditionalProperties);
AdditionalProperties = schema?.AdditionalProperties != null ? new(schema?.AdditionalProperties) : null;
Discriminator = schema?.Discriminator != null ? new(schema?.Discriminator) : null;
Example = OpenApiAnyCloneHelper.CloneFromCopyConstructor(schema?.Example);
Enum = schema?.Enum != null ? new List<IOpenApiAny>(schema.Enum) : null;
Expand Down
19 changes: 19 additions & 0 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,5 +463,24 @@ public void SerializeAsV2ShouldSetFormatPropertyInParentSchemaIfPresentInChildre
// Assert
Assert.Equal(expectedV2Schema, v2Schema);
}

[Fact]
public void OpenApiSchemaCopyConstructorSucceeds()
{
var baseSchema = new OpenApiSchema()
{
Type = "string",
Format = "date"
};

var actualSchema = new OpenApiSchema(baseSchema)
{
Nullable = true
};

Assert.Equal("string", actualSchema.Type);
Assert.Equal("date", actualSchema.Format);
Assert.True(actualSchema.Nullable);
}
}
}

0 comments on commit 563b046

Please sign in to comment.