Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Oct 28, 2024
2 parents d0fb2c7 + 5c35c7b commit 42614be
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 deletions.
10 changes: 5 additions & 5 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Nullable>enable</Nullable>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.4.11</Version>
<Version>1.4.13</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand All @@ -31,15 +31,15 @@
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="8.0.2" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.3" />
<PackageReference Include="Microsoft.OData.Edm" Version="8.1.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.6" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<!--STJ
Expand Down
11 changes: 11 additions & 0 deletions src/Microsoft.OpenApi.Workbench/MainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Validations;

Expand Down Expand Up @@ -158,6 +159,7 @@ public OpenApiSpecVersion Version
_version = value;
OnPropertyChanged(nameof(IsV2_0));
OnPropertyChanged(nameof(IsV3_0));
OnPropertyChanged(nameof(IsV3_1));
}
}

Expand Down Expand Up @@ -185,6 +187,12 @@ public bool IsV3_0
set => Version = OpenApiSpecVersion.OpenApi3_0;
}

public bool IsV3_1
{
get => Version == OpenApiSpecVersion.OpenApi3_1;
set => Version = OpenApiSpecVersion.OpenApi3_1;
}

/// <summary>
/// Handling method when the property with given name has changed.
/// </summary>
Expand All @@ -203,6 +211,9 @@ protected void OnPropertyChanged(string propertyName)
/// </summary>
internal async Task ParseDocumentAsync()
{
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yml, new OpenApiYamlReader());

Stream stream = null;
try
{
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.OpenApi.Workbench/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Label>Version:</Label>
<RadioButton GroupName="Format" Content="V3.1.0" Padding="5" Height="24" VerticalAlignment="Top" IsChecked="{Binding IsV3_1}" />
<RadioButton GroupName="Format" Content="V3.0.1" Padding="5" Height="24" VerticalAlignment="Top" IsChecked="{Binding IsV3_0}" />
<RadioButton GroupName="Format" Content="V2.0" Padding="5" Height="24" VerticalAlignment="Top" IsChecked="{Binding IsV2_0}" />
</StackPanel>
Expand Down
15 changes: 8 additions & 7 deletions src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down Expand Up @@ -139,9 +139,10 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
var type = (ToIdentifier(schema.Type), schema.Format?.ToLowerInvariant(), schema.Nullable) switch
{
("boolean", null, false) => typeof(bool),
("integer", "int32", false) => typeof(int),
("integer", "int64", false) => typeof(long),
("integer", null, false) => typeof(int),
// integer is technically not valid with format, but we must provide some compatibility
("integer" or "number", "int32", false) => typeof(int),
("integer" or "number", "int64", false) => typeof(long),
("integer", null, false) => typeof(long),
("number", "float", false) => typeof(float),
("number", "double", false) => typeof(double),
("number", "decimal", false) => typeof(decimal),
Expand All @@ -154,9 +155,9 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
("string", null, false) => typeof(string),
("object", null, false) => typeof(object),
("string", "uri", false) => typeof(Uri),
("integer", "int32", true) => typeof(int?),
("integer", "int64", true) => typeof(long?),
("integer", null, true) => typeof(int?),
("integer" or "number", "int32", true) => typeof(int?),
("integer" or "number", "int64", true) => typeof(long?),
("integer", null, true) => typeof(long?),
("number", "float", true) => typeof(float?),
("number", "double", true) => typeof(double?),
("number", null, true) => typeof(double?),
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class Utils
/// <returns>The input value.</returns>
internal static T CheckArgumentNull<T>(
T value,
[CallerArgumentExpression("value")] string parameterName = "")
[CallerArgumentExpression(nameof(value))] string parameterName = "")
{
return value ?? throw new ArgumentNullException(parameterName, $"Value cannot be null: {parameterName}");
}
Expand Down
24 changes: 12 additions & 12 deletions src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && format == "int32")
if (type is "integer" or "number" && format is "int32")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -150,7 +150,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && format == "int64")
if (type is "integer" or "number" && format is "int64")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -162,7 +162,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && jsonElement.ValueKind is not JsonValueKind.Number)
if (type is "integer")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -174,7 +174,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "number" && format == "float")
if (type is "number" && format is "float")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -186,7 +186,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "number" && format == "double")
if (type is "number" && format is "double")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -198,7 +198,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "number")
if (type is "number")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -210,7 +210,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string" && format == "byte")
if (type is "string" && format is "byte")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -222,7 +222,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string" && format == "date")
if (type is "string" && format is "date")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -234,7 +234,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string" && format == "date-time")
if (type is "string" && format is "date-time")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -246,7 +246,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string" && format == "password")
if (type is "string" && format is "password")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -258,7 +258,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string")
if (type is "string")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -270,7 +270,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "boolean")
if (type is "boolean")
{
if (jsonElement.ValueKind is not JsonValueKind.True && jsonElement.ValueKind is not JsonValueKind.False)
{
Expand Down
25 changes: 16 additions & 9 deletions test/Microsoft.OpenApi.Tests/Extensions/OpenApiTypeMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ public class OpenApiTypeMapperTests
{
public static IEnumerable<object[]> PrimitiveTypeData => new List<object[]>
{
new object[] { typeof(int), new OpenApiSchema { Type = JsonSchemaType.Integer, Format = "int32" } },
new object[] { typeof(int), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int32" } },
new object[] { typeof(decimal), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "double" } },
new object[] { typeof(decimal?), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "double", Nullable = true } },
new object[] { typeof(bool?), new OpenApiSchema { Type = JsonSchemaType.Boolean, Nullable = true } },
new object[] { typeof(Guid), new OpenApiSchema { Type = JsonSchemaType.String, Format = "uuid" } },
new object[] { typeof(uint), new OpenApiSchema { Type = JsonSchemaType.Integer, Format = "int32" } },
new object[] { typeof(long), new OpenApiSchema { Type = JsonSchemaType.Integer, Format = "int64" } },
new object[] { typeof(ulong), new OpenApiSchema { Type = JsonSchemaType.Integer, Format = "int64" } },
new object[] { typeof(Guid?), new OpenApiSchema { Type = JsonSchemaType.String, Format = "uuid", Nullable = true } },
new object[] { typeof(uint), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int32" } },
new object[] { typeof(long), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int64" } },
new object[] { typeof(long?), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int64", Nullable = true } },
new object[] { typeof(ulong), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int64" } },
new object[] { typeof(string), new OpenApiSchema { Type = JsonSchemaType.String } },
new object[] { typeof(double), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "double" } },
new object[] { typeof(float?), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "float", Nullable = true } },
new object[] { typeof(byte?), new OpenApiSchema { Type = JsonSchemaType.String, Format = "byte", Nullable = true } },
new object[] { typeof(int?), new OpenApiSchema { Type = JsonSchemaType.Integer, Format = "int32", Nullable = true } },
new object[] { typeof(uint?), new OpenApiSchema { Type = JsonSchemaType.Integer, Format = "int32", Nullable = true } },
new object[] { typeof(int?), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int32", Nullable = true } },
new object[] { typeof(uint?), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int32", Nullable = true } },
new object[] { typeof(DateTimeOffset?), new OpenApiSchema { Type = JsonSchemaType.String, Format = "date-time", Nullable = true } },
new object[] { typeof(double?), new OpenApiSchema { Type = JsonSchemaType.Number, Format = "double", Nullable = true } },
new object[] { typeof(char?), new OpenApiSchema { Type = JsonSchemaType.String, Nullable = true } },
Expand All @@ -35,11 +38,15 @@ public class OpenApiTypeMapperTests

public static IEnumerable<object[]> OpenApiDataTypes => new List<object[]>
{
new object[] { new OpenApiSchema { Type = JsonSchemaType.Integer, Format = "int32"}, typeof(int) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int32", Nullable = false}, typeof(int) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int32", Nullable = true}, typeof(int?) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int64", Nullable = false}, typeof(long) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = "int64", Nullable = true}, typeof(long?) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = "decimal"}, typeof(decimal) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Integer, Format = null, Nullable = false}, typeof(long) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Integer, Format = null, Nullable = true}, typeof(long?) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = null, Nullable = false}, typeof(double) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Integer, Format = null, Nullable = false}, typeof(int) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Integer, Format = null, Nullable = true}, typeof(int?) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = null, Nullable = true}, typeof(double?) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = "decimal", Nullable = true}, typeof(decimal?) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.Number, Format = "double", Nullable = true}, typeof(double?) },
new object[] { new OpenApiSchema { Type = JsonSchemaType.String, Format = "date-time", Nullable = true}, typeof(DateTimeOffset?) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SharpYaml" Version="2.1.1" />
<PackageReference Include="Verify.Xunit" Version="26.6.0" />
<PackageReference Include="Verify.Xunit" Version="27.0.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand Down

0 comments on commit 42614be

Please sign in to comment.