Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b7d1006
Updated version to 1.2.0
darrelmiller May 24, 2020
1b904ab
Removed comparer functionality for this release as it is not ready
darrelmiller May 25, 2020
316d703
Added missing comment
darrelmiller May 25, 2020
c309dd9
Fixed build.cmd file
darrelmiller Jun 13, 2020
7b0332a
Fixed comment
darrelmiller Jun 13, 2020
a45aaa0
Merge pull request #482 from microsoft/release/1.2.0
darrelmiller Jun 14, 2020
424257b
Prevent breaking change on optional parameter #487
CumpsD Jun 22, 2020
6645fa7
Merge pull request #489 from CumpsD/patch-1
darrelmiller Jun 24, 2020
84dfd34
Update version to 1.2.1
darrelmiller Jun 24, 2020
e59b568
Merge pull request #490 from microsoft/dm/updateversion1.2.1
darrelmiller Jun 24, 2020
48685d3
make default parameter overloads binary compatible
CumpsD Jun 24, 2020
84af7ad
Merge branch 'master' into master
CumpsD Jun 24, 2020
37054bf
fix OpenApiWriterBase default param addition
CumpsD Jun 24, 2020
ad32cc4
remove the default param that causes 2 identical ctors
CumpsD Jun 24, 2020
bb8b087
Merge pull request #492 from CumpsD/master
darrelmiller Jun 24, 2020
2ab1eff
Updated to 1.2.2
darrelmiller Jun 24, 2020
be6a700
Merge pull request #493 from microsoft/dm/release1.2.2
darrelmiller Jun 24, 2020
544d0ba
Fixed multi-part file upload in V2
darrelmiller Aug 16, 2020
e5babbd
Added support retaining body parameter name
darrelmiller Aug 16, 2020
b851e24
Fixed bug #495
darrelmiller Aug 17, 2020
50b9a27
Resolve header references on read
brantburnett Aug 28, 2020
a8d3a3a
Merge pull request #516 from CenterEdge/issue515-header-references
darrelmiller Aug 29, 2020
0d1924a
Changed visitor to target map of headers
darrelmiller Aug 29, 2020
66e4d87
Updated version to 1.2.3
darrelmiller Aug 29, 2020
553061a
Merge pull request #511 from microsoft/hotfix/1.2.3
darrelmiller Aug 29, 2020
8b51738
Updated vNext branch will all chances in 1.2.3
darrelmiller Aug 29, 2020
fb89abc
Fix public API test
darrelmiller Aug 29, 2020
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 @@ -10,7 +10,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi.Readers</Title>
<PackageId>Microsoft.OpenApi.Readers</PackageId>
<Version>1.2.1</Version>
<Version>1.2.3</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public OpenApiDocument Read(TextReader input, out OpenApiDiagnostic diagnostic)
catch (YamlException ex)
{
diagnostic = new OpenApiDiagnostic();
diagnostic.Errors.Add(new OpenApiError($"#char={ex.Start.Line}", ex.Message));
diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message));
return new OpenApiDocument();
}

Expand Down
10 changes: 10 additions & 0 deletions src/Microsoft.OpenApi.Readers/Services/OpenApiReferenceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public override void Visit(OpenApiComponents components)
ResolveMap(components.Examples);
ResolveMap(components.Schemas);
ResolveMap(components.SecuritySchemes);
ResolveMap(components.Headers);
}

public override void Visit(IDictionary<string, OpenApiCallback> callbacks)
Expand Down Expand Up @@ -99,6 +100,15 @@ public override void Visit(OpenApiResponses responses)
ResolveMap(responses);
}

/// <summary>
/// Resolve all references to headers
/// </summary>
/// <param name="headers"></param>
public override void Visit(IDictionary<string, OpenApiHeader> headers)
{
ResolveMap(headers);
}

/// <summary>
/// Resolve all references to SecuritySchemes
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.ParseNodes;
Expand Down Expand Up @@ -164,6 +165,7 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List<Op
{
var schema = v.Schema;
schema.Description = v.Description;
schema.Extensions = v.Extensions;
return schema;
}),
Required = new HashSet<string>(formParameters.Where(p => p.Required).Select(p => p.Name))
Expand Down Expand Up @@ -201,9 +203,11 @@ internal static OpenApiRequestBody CreateRequestBody(
v => new OpenApiMediaType
{
Schema = bodyParameter.Schema
})
}),
Extensions = bodyParameter.Extensions
};

requestBody.Extensions[OpenApiConstants.BodyName] = new OpenApiString(bodyParameter.Name);
return requestBody;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi</Title>
<PackageId>Microsoft.OpenApi</PackageId>
<Version>1.2.1</Version>
<Version>1.2.3</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
5 changes: 5 additions & 0 deletions src/Microsoft.OpenApi/Models/OpenApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ public static class OpenApiConstants
/// </summary>
public const string DefaultDescription = "Default Description";

/// <summary>
/// Field: BodyName extensions
/// </summary>
public const string BodyName = "x-bodyName";

/// <summary>
/// Field: version3_0_0
/// </summary>
Expand Down
18 changes: 16 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,30 +228,44 @@ public void SerializeAsV2(IOpenApiWriter writer)
{
foreach (var property in RequestBody.Content.First().Value.Schema.Properties)
{
var paramName = property.Key;
var paramSchema = property.Value;
if (paramSchema.Type == "string" && paramSchema.Format == "binary") {
paramSchema.Type = "file";
paramSchema.Format = null;
}
parameters.Add(
new OpenApiFormDataParameter
{
Description = property.Value.Description,
Name = property.Key,
Schema = property.Value,
Required = RequestBody.Content.First().Value.Schema.Required.Contains(property.Key)

});
}
}
else
{
var content = RequestBody.Content.Values.FirstOrDefault();

var bodyParameter = new OpenApiBodyParameter
{
Description = RequestBody.Description,
// V2 spec actually allows the body to have custom name.
// Our library does not support this at the moment.
// To allow round-tripping we use an extension to hold the name
Name = "body",
Schema = content?.Schema ?? new OpenApiSchema(),
Required = RequestBody.Required,
Extensions = RequestBody.Extensions
Extensions = RequestBody.Extensions.ToDictionary(k => k.Key, v => v.Value) // Clone extensions so we can remove the x-bodyName extensions from the output V2 model.
};

if (bodyParameter.Extensions.ContainsKey(OpenApiConstants.BodyName))
{
bodyParameter.Name = (RequestBody.Extensions[OpenApiConstants.BodyName] as OpenApiString)?.Value ?? "body";
bodyParameter.Extensions.Remove(OpenApiConstants.BodyName);
}

parameters.Add(bodyParameter);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V3Tests\Samples\OpenApiExample\explicitString.yaml" />
<EmbeddedResource Include="V3Tests\Samples\OpenApiResponse\responseWithHeaderReference.yaml" />
<EmbeddedResource Include="V3Tests\Samples\OpenApiInfo\basicInfo.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.ParseNodes;
using Microsoft.OpenApi.Readers.V2;
Expand Down Expand Up @@ -180,6 +181,9 @@ public class OpenApiOperationTests
Type = "object"
}
}
},
Extensions = {
[OpenApiConstants.BodyName] = new OpenApiString("petObject")
}
},
Responses = new OpenApiResponses
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.IO;
using System.Linq;
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.ParseNodes;
using Microsoft.OpenApi.Readers.V3;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.V3Tests
{
[Collection("DefaultSettings")]
public class OpenApiResponseTests
{
private const string SampleFolderPath = "V3Tests/Samples/OpenApiResponse/";

[Fact]
public void ResponseWithReferencedHeaderShouldReferenceComponent()
{
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "responseWithHeaderReference.yaml")))
{
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);

var response = openApiDoc.Components.Responses["Test"];

Assert.Same(response.Headers.First().Value, openApiDoc.Components.Headers.First().Value);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: 3.0.0
info:
title: Example of response referencing a header
version: 1.0.0
components:
headers:
X-Test:
description: Test
schema:
type: string
responses:
Test:
description: Test Repsonse
headers:
X-Test:
$ref: '#/components/headers/X-Test'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute(@"Microsoft.OpenApi.Readers.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute(@"Microsoft.OpenApi.Readers.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute(@"Microsoft.OpenApi.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")]
[assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.6", FrameworkDisplayName=".NET Framework 4.6")]
namespace Microsoft.OpenApi.Any
Expand Down Expand Up @@ -352,6 +352,7 @@ namespace Microsoft.OpenApi.Models
public const string BasePath = "basePath";
public const string Basic = "basic";
public const string BearerFormat = "bearerFormat";
public const string BodyName = "x-bodyName";
public const string Callbacks = "callbacks";
public const string ClientCredentials = "clientCredentials";
public const string Components = "components";
Expand Down