Skip to content

Commit

Permalink
Merge pull request #1002 from microsoft/vnext
Browse files Browse the repository at this point in the history
Release `v1.4.1`
  • Loading branch information
baywet authored Sep 7, 2022
2 parents ddcdf25 + 6ff3176 commit 512c795
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi</Title>
<PackageId>Microsoft.OpenApi</PackageId>
<Version>1.4.0</Version>
<Version>1.4.1</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
18 changes: 14 additions & 4 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.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.Collections.Generic;
Expand Down Expand Up @@ -566,6 +566,13 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
writer.WriteProperty(OpenApiConstants.Type, Type);

// format
if (string.IsNullOrEmpty(Format))
{
Format = AllOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
AnyOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
OneOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format;
}

writer.WriteProperty(OpenApiConstants.Format, Format);

// items
Expand Down Expand Up @@ -630,9 +637,12 @@ internal void WriteAsSchemaProperties(
}

// format
Format ??= AllOf?.FirstOrDefault(static x => x.Format != null)?.Format ??
AnyOf?.FirstOrDefault(static x => x.Format != null)?.Format ??
OneOf?.FirstOrDefault(static x => x.Format != null)?.Format;
if (string.IsNullOrEmpty(Format))
{
Format = AllOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
AnyOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
OneOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format;
}

writer.WriteProperty(OpenApiConstants.Format, Format);

Expand Down
37 changes: 36 additions & 1 deletion test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public class OpenApiParameterTests
Schema = new OpenApiSchema
{
Title = "title2",
Description = "description2"
Description = "description2",
OneOf = new List<OpenApiSchema>
{
new OpenApiSchema { Type = "number", Format = "double" },
new OpenApiSchema { Type = "string" }
}
},
Examples = new Dictionary<string, OpenApiExample>
{
Expand Down Expand Up @@ -234,6 +239,15 @@ public void SerializeAdvancedParameterAsV3JsonWorks()
""explode"": true,
""schema"": {
""title"": ""title2"",
""oneOf"": [
{
""type"": ""number"",
""format"": ""double""
},
{
""type"": ""string""
}
],
""description"": ""description2""
},
""examples"": {
Expand All @@ -253,6 +267,27 @@ public void SerializeAdvancedParameterAsV3JsonWorks()
actual.Should().Be(expected);
}

[Fact]
public void SerializeAdvancedParameterAsV2JsonWorks()
{
// Arrange
var expected = @"{
""in"": ""path"",
""name"": ""name1"",
""description"": ""description1"",
""required"": true,
""format"": ""double""
}";

// Act
var actual = AdvancedPathParameterWithSchema.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0);

// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
expected = expected.MakeLineBreaksEnvironmentNeutral();
actual.Should().Be(expected);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down

0 comments on commit 512c795

Please sign in to comment.