Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
2 changes: 1 addition & 1 deletion 2 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 18 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 37 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.