Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List<Op
schema.Description = v.Description;
return schema;
}),
Required = formParameters.Where(p => p.Required).Select(p => p.Name).ToList()
Required = new HashSet<string>(formParameters.Where(p => p.Required).Select(p => p.Name))
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.ParseNodes;
using System.Collections.Generic;

namespace Microsoft.OpenApi.Readers.V2
{
Expand Down Expand Up @@ -103,7 +104,7 @@ internal static partial class OpenApiV2Deserializer
{
"required", (o, n) =>
{
o.Required = n.CreateSimpleList(n2 => n2.GetScalarValue()).ToArray();
o.Required = new HashSet<string>(n.CreateSimpleList(n2 => n2.GetScalarValue()));
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.ParseNodes;
using System.Collections.Generic;

namespace Microsoft.OpenApi.Readers.V3
{
Expand Down Expand Up @@ -103,7 +104,7 @@ internal static partial class OpenApiV3Deserializer
{
"required", (o, n) =>
{
o.Required = n.CreateSimpleList(n2 => n2.GetScalarValue()).ToArray();
o.Required = new HashSet<string>(n.CreateSimpleList(n2 => n2.GetScalarValue()));
}
},
{
Expand Down
14 changes: 7 additions & 7 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public class OpenApiSchema : IOpenApiSerializable, IOpenApiReferenceable, IOpenA
/// <summary>
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
/// </summary>
public IList<string> Required { get; set; } = new List<string>();
public ISet<string> Required { get; set; } = new HashSet<string>();

/// <summary>
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
Expand Down Expand Up @@ -393,7 +393,7 @@ public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
/// </summary>
public void SerializeAsV2(IOpenApiWriter writer)
{
SerializeAsV2(writer: writer, parentRequiredProperties: new List<string>(), propertyName: null);
SerializeAsV2(writer: writer, parentRequiredProperties: new HashSet<string>(), propertyName: null);
}

/// <summary>
Expand All @@ -403,7 +403,7 @@ public void SerializeAsV2WithoutReference(IOpenApiWriter writer)
{
SerializeAsV2WithoutReference(
writer: writer,
parentRequiredProperties: new List<string>(),
parentRequiredProperties: new HashSet<string>(),
propertyName: null);
}

Expand All @@ -416,7 +416,7 @@ public void SerializeAsV2WithoutReference(IOpenApiWriter writer)
/// <param name="propertyName">The property name that will be serialized.</param>
internal void SerializeAsV2(
IOpenApiWriter writer,
IList<string> parentRequiredProperties,
ISet<string> parentRequiredProperties,
string propertyName)
{
if (writer == null)
Expand All @@ -432,7 +432,7 @@ internal void SerializeAsV2(

if (parentRequiredProperties == null)
{
parentRequiredProperties = new List<string>();
parentRequiredProperties = new HashSet<string>();
}

SerializeAsV2WithoutReference(writer, parentRequiredProperties, propertyName);
Expand All @@ -447,7 +447,7 @@ internal void SerializeAsV2(
/// <param name="propertyName">The property name that will be serialized.</param>
internal void SerializeAsV2WithoutReference(
IOpenApiWriter writer,
IList<string> parentRequiredProperties,
ISet<string> parentRequiredProperties,
string propertyName)
{
writer.WriteStartObject();
Expand Down Expand Up @@ -521,7 +521,7 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)

internal void WriteAsSchemaProperties(
IOpenApiWriter writer,
IList<string> parentRequiredProperties,
ISet<string> parentRequiredProperties,
string propertyName)
{
if (writer == null)
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static void WriteRequiredObject<T>(
public static void WriteOptionalCollection(
this IOpenApiWriter writer,
string name,
IList<string> elements,
IEnumerable<string> elements,
Action<IOpenApiWriter, string> action)
{
if (elements != null && elements.Any())
Expand All @@ -191,7 +191,7 @@ public static void WriteOptionalCollection(
public static void WriteOptionalCollection<T>(
this IOpenApiWriter writer,
string name,
IList<T> elements,
IEnumerable<T> elements,
Action<IOpenApiWriter, T> action)
where T : IOpenApiElement
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void LoadResponseAndSchemaReference()
Schema = new OpenApiSchema
{
Description = "Sample description",
Required = new List<string> {"name" },
Required = new HashSet<string> {"name" },
Properties = {
["name"] = new OpenApiSchema()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class OpenApiOperationTests
Type = "string"
}
},
Required = new List<string>
Required = new HashSet<string>
{
"name"
}
Expand All @@ -115,7 +115,7 @@ public class OpenApiOperationTests
Type = "string"
}
},
Required = new List<string>
Required = new HashSet<string>
{
"name"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class OpenApiPathItemTests
Type = "string"
}
},
Required = new List<string>
Required = new HashSet<string>
{
"name"
}
Expand All @@ -104,7 +104,7 @@ public class OpenApiPathItemTests
Type = "string"
}
},
Required = new List<string>
Required = new HashSet<string>
{
"name"
}
Expand Down Expand Up @@ -190,7 +190,7 @@ public class OpenApiPathItemTests
Type = "string"
}
},
Required = new List<string>
Required = new HashSet<string>
{
"name"
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public class OpenApiPathItemTests
Type = "string"
}
},
Required = new List<string>
Required = new HashSet<string>
{
"name"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void ParseStandardPetStoreDocumentShouldSucceed()
["pet"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"id",
"name"
Expand Down Expand Up @@ -183,7 +183,7 @@ public void ParseStandardPetStoreDocumentShouldSucceed()
["newPet"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"name"
},
Expand Down Expand Up @@ -212,7 +212,7 @@ public void ParseStandardPetStoreDocumentShouldSucceed()
["errorModel"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"code",
"message"
Expand Down Expand Up @@ -580,7 +580,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["pet"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"id",
"name"
Expand Down Expand Up @@ -610,7 +610,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["newPet"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"name"
},
Expand Down Expand Up @@ -639,7 +639,7 @@ public void ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
["errorModel"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"code",
"message"
Expand Down
12 changes: 6 additions & 6 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public class OpenApiDocumentTests
["pet"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"id",
"name"
Expand Down Expand Up @@ -155,7 +155,7 @@ public class OpenApiDocumentTests
["newPet"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"name"
},
Expand Down Expand Up @@ -184,7 +184,7 @@ public class OpenApiDocumentTests
["errorModel"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"code",
"message"
Expand Down Expand Up @@ -516,7 +516,7 @@ public class OpenApiDocumentTests
["pet"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"id",
"name"
Expand All @@ -541,7 +541,7 @@ public class OpenApiDocumentTests
["newPet"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"name"
},
Expand All @@ -565,7 +565,7 @@ public class OpenApiDocumentTests
["errorModel"] = new OpenApiSchema
{
Type = "object",
Required = new List<string>
Required = new HashSet<string>
{
"code",
"message"
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ [new OpenApiSecurityScheme
Type = "string"
}
},
Required = new List<string>()
Required = new HashSet<string>()
{
"name"
}
Expand All @@ -274,7 +274,7 @@ [new OpenApiSecurityScheme
Type = "string"
}
},
Required = new List<string>()
Required = new HashSet<string>()
{
"name"
}
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ public class OpenApiSchemaTests
public static OpenApiSchema AdvancedSchemaWithRequiredPropertiesObject = new OpenApiSchema
{
Title = "title1",
Required = new List<string>(){ "property1" },
Required = new HashSet<string>(){ "property1" },
Properties = new Dictionary<string, OpenApiSchema>
{
["property1"] = new OpenApiSchema
{
Required = new List<string>() { "property3" },
Required = new HashSet<string>() { "property3" },
Properties = new Dictionary<string, OpenApiSchema>
{
["property2"] = new OpenApiSchema
Expand Down