diff --git a/.azure-pipelines/ci-build.yml b/.azure-pipelines/ci-build.yml index 616776585..345d50af9 100644 --- a/.azure-pipelines/ci-build.yml +++ b/.azure-pipelines/ci-build.yml @@ -287,7 +287,7 @@ stages: nuGetFeedType: external publishFeedCredentials: 'OpenAPI Nuget Connection' - task: GitHubRelease@1 - displayName: 'GitHub release (create)' + displayName: 'GitHub release (edit)' inputs: gitHubConnection: 'Github-MaggieKimani1' tagSource: userSpecifiedTag diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 000000000..7cb46ae19 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @irvinesunday @darrelmiller @peombwa @zengin @baywet @millicentachieng @MaggieKimani1 diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index f885e8d6f..cee484046 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -15,16 +15,12 @@ Microsoft.OpenApi.Hidi hidi ./../../artifacts - 1.0.0-preview6 + 1.0.0-preview7 OpenAPI.NET CLI tool for slicing OpenAPI documents © Microsoft Corporation. All rights reserved. OpenAPI .NET https://github.com/Microsoft/OpenAPI.NET - -- Bumps up the Microsoft.OpenAPI library to v1.3.2 -- Bumps up the Microsoft.OData library to v7.12.0 -- Bumps up the Microsoft.OpenApi.OData library to v1.0.11-preview3 - + https://github.com/microsoft/OpenAPI.NET/releases Microsoft.OpenApi.Hidi Microsoft.OpenApi.Hidi true @@ -47,7 +43,7 @@ - + diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index 8835b373c..e9d3ba283 100644 --- a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj +++ b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj @@ -15,9 +15,7 @@ © Microsoft Corporation. All rights reserved. OpenAPI .NET https://github.com/Microsoft/OpenAPI.NET - -- Fixed a bug where contact information would not read properly. #892 - + https://github.com/microsoft/OpenAPI.NET/releases Microsoft.OpenApi.Readers Microsoft.OpenApi.Readers true diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs index 6302eaf84..02e868412 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs @@ -36,11 +36,22 @@ internal static partial class OpenApiV2Deserializer }, { "consumes", - (o, n) => n.Context.SetTempStorage(TempStorageKeys.GlobalConsumes, n.CreateSimpleList(s => s.GetScalarValue())) + (o, n) => { + var consumes = n.CreateSimpleList(s => s.GetScalarValue()); + if (consumes.Count > 0) + { + n.Context.SetTempStorage(TempStorageKeys.GlobalConsumes, consumes); + } + } }, { - "produces", - (o, n) => n.Context.SetTempStorage(TempStorageKeys.GlobalProduces, n.CreateSimpleList(s => s.GetScalarValue())) + "produces", (o, n) => { + var produces = n.CreateSimpleList(s => s.GetScalarValue()); + if (produces.Count > 0) + { + n.Context.SetTempStorage(TempStorageKeys.GlobalProduces, produces); + } + } }, {"paths", (o, n) => o.Paths = LoadPaths(n)}, { diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs index 45d076370..a3bda05e1 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs @@ -57,14 +57,20 @@ internal static partial class OpenApiV2Deserializer } }, { - "consumes", (o, n) => n.Context.SetTempStorage( - TempStorageKeys.OperationConsumes, - n.CreateSimpleList(s => s.GetScalarValue())) + "consumes", (o, n) => { + var consumes = n.CreateSimpleList(s => s.GetScalarValue()); + if (consumes.Count > 0) { + n.Context.SetTempStorage(TempStorageKeys.OperationConsumes,consumes); + } + } }, { - "produces", (o, n) => n.Context.SetTempStorage( - TempStorageKeys.OperationProduces, - n.CreateSimpleList(s => s.GetScalarValue())) + "produces", (o, n) => { + var produces = n.CreateSimpleList(s => s.GetScalarValue()); + if (produces.Count > 0) { + n.Context.SetTempStorage(TempStorageKeys.OperationProduces, produces); + } + } }, { "responses", (o, n) => diff --git a/src/Microsoft.OpenApi.Readers/V2/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi.Readers/V2/OpenApiPathItemDeserializer.cs index ba5707480..d905ea42e 100644 --- a/src/Microsoft.OpenApi.Readers/V2/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi.Readers/V2/OpenApiPathItemDeserializer.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. +using System.Collections.Generic; +using System.Linq; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers.ParseNodes; @@ -32,7 +34,7 @@ internal static partial class OpenApiV2Deserializer { "parameters", (o, n) => { - o.Parameters = n.CreateList(LoadParameter); + LoadPathParameters(o,n); } }, }; @@ -53,5 +55,51 @@ public static OpenApiPathItem LoadPathItem(ParseNode node) return pathItem; } + + private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node) + { + node.Context.SetTempStorage(TempStorageKeys.BodyParameter, null); + node.Context.SetTempStorage(TempStorageKeys.FormParameters, null); + + pathItem.Parameters = node.CreateList(LoadParameter); + + // Build request body based on information determined while parsing OpenApiOperation + var bodyParameter = node.Context.GetFromTempStorage(TempStorageKeys.BodyParameter); + if (bodyParameter != null) + { + var requestBody = CreateRequestBody(node.Context, bodyParameter); + foreach(var opPair in pathItem.Operations.Where(x => x.Value.RequestBody is null)) + { + switch (opPair.Key) + { + case OperationType.Post: + case OperationType.Put: + case OperationType.Patch: + opPair.Value.RequestBody = requestBody; + break; + } + } + } + else + { + var formParameters = node.Context.GetFromTempStorage>(TempStorageKeys.FormParameters); + if (formParameters != null) + { + var requestBody = CreateFormBody(node.Context, formParameters); + foreach (var opPair in pathItem.Operations.Where(x => x.Value.RequestBody is null)) + { + switch (opPair.Key) + { + case OperationType.Post: + case OperationType.Put: + case OperationType.Patch: + opPair.Value.RequestBody = requestBody; + break; + } + } + } + } + + } } } diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 980265e98..933b2bdb2 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -16,9 +16,7 @@ © Microsoft Corporation. All rights reserved. OpenAPI .NET https://github.com/Microsoft/OpenAPI.NET - -- Adds support for c-style hex notation strings. #908 - + https://github.com/microsoft/OpenAPI.NET/releases Microsoft.OpenApi Microsoft.OpenApi true diff --git a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj index e1ec38f8f..c04eb7fd2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj +++ b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj @@ -14,6 +14,8 @@ + + @@ -85,6 +87,12 @@ Never + + Never + + + Never + Never diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs index 5d3331207..a11497cdf 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using FluentAssertions; using Microsoft.OpenApi.Extensions; @@ -253,10 +254,50 @@ public void ParseBasicPathItemWithFormDataShouldSucceed() } // Act - var operation = OpenApiV2Deserializer.LoadPathItem(node); + var pathItem = OpenApiV2Deserializer.LoadPathItem(node); // Assert - operation.Should().BeEquivalentTo(_basicPathItemWithFormData); + pathItem.Should().BeEquivalentTo(_basicPathItemWithFormData); } + + [Fact] + public void ParsePathItemWithFormDataPathParameterShouldSucceed() + { + // Arrange + MapNode node; + using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "pathItemWithFormDataPathParameter.yaml"))) + { + node = TestHelper.CreateYamlMapNode(stream); + } + + // Act + var pathItem = OpenApiV2Deserializer.LoadPathItem(node); + + // Assert + // FormData parameters at in the path level are pushed into Operation request bodies. + Assert.True(pathItem.Operations[OperationType.Put].RequestBody != null); + Assert.True(pathItem.Operations[OperationType.Post].RequestBody != null); + Assert.Equal(2, pathItem.Operations.Count(o => o.Value.RequestBody != null)); + } + [Fact] + public void ParsePathItemBodyDataPathParameterShouldSucceed() + { + // Arrange + MapNode node; + using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "pathItemWithBodyPathParameter.yaml"))) + { + node = TestHelper.CreateYamlMapNode(stream); + } + + // Act + var pathItem = OpenApiV2Deserializer.LoadPathItem(node); + + // Assert + // FormData parameters at in the path level are pushed into Operation request bodies. + Assert.True(pathItem.Operations[OperationType.Put].RequestBody != null); + Assert.True(pathItem.Operations[OperationType.Post].RequestBody != null); + Assert.Equal(2, pathItem.Operations.Count(o => o.Value.RequestBody != null)); + } + } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiPathItem/pathItemWithBodyPathParameter.yaml b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiPathItem/pathItemWithBodyPathParameter.yaml new file mode 100644 index 000000000..c17f4c54e --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiPathItem/pathItemWithBodyPathParameter.yaml @@ -0,0 +1,31 @@ +put: + summary: Puts a pet in the store with form data + description: "" + responses: + '200': + description: Pet updated. + '405': + description: Invalid input +post: + summary: Posts a pet in the store with form data + description: "" + responses: + '200': + description: Pet updated. +parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: string + - name: name + in: body + description: Updated pet body + required: true + type: object + properties: + name: + type: string + status: + type: string \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiPathItem/pathItemWithFormDataPathParameter.yaml b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiPathItem/pathItemWithFormDataPathParameter.yaml new file mode 100644 index 000000000..57178b4ba --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiPathItem/pathItemWithFormDataPathParameter.yaml @@ -0,0 +1,41 @@ +put: + summary: Puts a pet in the store with form data + description: "" + responses: + '200': + description: Pet updated. + '405': + description: Invalid input + x-http-tests: + - parameterValues: + petId: 10 + name: Milo + status: Happy + expectedRequest: + href: /pathitem-form-parameter/10 + headers: + Content-Type: multipart/form-data + content: name=Milo&status=Happy +post: + summary: Posts a pet in the store with form data + description: "" + responses: + '200': + description: Pet updated. +parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: string + - name: name + in: formData + description: Updated name of the pet + required: true + type: string + - name: status + in: formData + description: Updated status of the pet + required: false + type: string diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 60bf287cc..9e1cb4f75 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -20,8 +20,7 @@ - - + all