From b022828786c6b623754e8516b11c49eaf5f4fd0f Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 30 Mar 2023 23:14:00 +0300 Subject: [PATCH 1/3] Add entry for singularizing drives --- OpenAPIService/PowershellFormatter.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OpenAPIService/PowershellFormatter.cs b/OpenAPIService/PowershellFormatter.cs index 743d9bdbd..9f011868c 100644 --- a/OpenAPIService/PowershellFormatter.cs +++ b/OpenAPIService/PowershellFormatter.cs @@ -1,4 +1,4 @@ -// ------------------------------------------------------------------------------------------------------------------------------------------------------ +// ------------------------------------------------------------------------------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. // ------------------------------------------------------------------------------------------------------------------------------------------------------ @@ -216,6 +216,9 @@ private static string SingularizeAndDeduplicateOperationId(string operationId) if (string.IsNullOrEmpty(operationId)) return operationId; + // drives does not properly singularize to drive. + Vocabularies.Default.AddSingular("(drive)s$", "$1"); + var segments = operationId.Split('.').ToList(); // The last segment is ignored as a rule. From 753562b8a16195707d089674b83b28df32a3c006 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 30 Mar 2023 23:14:33 +0300 Subject: [PATCH 2/3] Update tests --- .../OpenAPIDocumentCreatorMock.cs | 31 +++++++++++++++++++ OpenAPIService.Test/OpenAPIServiceShould.cs | 25 ++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/OpenAPIService.Test/OpenAPIDocumentCreatorMock.cs b/OpenAPIService.Test/OpenAPIDocumentCreatorMock.cs index e16f2a9a9..dbf60a9a9 100644 --- a/OpenAPIService.Test/OpenAPIDocumentCreatorMock.cs +++ b/OpenAPIService.Test/OpenAPIDocumentCreatorMock.cs @@ -578,6 +578,37 @@ private OpenApiDocument CreateOpenApiDocument() } } }, + ["/drives"] = new OpenApiPathItem() + { + Operations = new Dictionary + { + { + OperationType.Get, new OpenApiOperation + { + Tags = new List + { + { + new OpenApiTag() + { + Name = "drives.drive" + } + } + }, + OperationId = "drives.drive.ListDrive", + Summary = "Get Drive", + Responses = new OpenApiResponses() + { + { + "200", new OpenApiResponse() + { + Description = "Success" + } + } + } + } + } + } + }, ["/security/hostSecurityProfiles"] = new OpenApiPathItem() { Operations = new Dictionary diff --git a/OpenAPIService.Test/OpenAPIServiceShould.cs b/OpenAPIService.Test/OpenAPIServiceShould.cs index eb2c1f8e9..38a80bfde 100644 --- a/OpenAPIService.Test/OpenAPIServiceShould.cs +++ b/OpenAPIService.Test/OpenAPIServiceShould.cs @@ -358,7 +358,7 @@ public void RetrieveAllOperationsAndPaths() subsetOpenApiDocument = _openApiService.ApplyStyle(OpenApiStyle.Plain, subsetOpenApiDocument); // Assert - Assert.Equal(16, subsetOpenApiDocument.Paths.Count); + Assert.Equal(17, subsetOpenApiDocument.Paths.Count); Assert.NotEmpty(subsetOpenApiDocument.Components.Schemas); Assert.NotEmpty(subsetOpenApiDocument.Components.Parameters); Assert.NotEmpty(subsetOpenApiDocument.Components.Responses); @@ -412,6 +412,29 @@ public void ResolveActionFunctionOperationIdsForPowerShellStyle(string url, Oper Assert.Equal(expectedOperationId, operationId); } + [Theory] + [InlineData("drives.drive.ListDrive", "drive_ListDrive", OperationType.Get)] + [InlineData("applications.application.UpdateLogo", "application_SetLogo", OperationType.Put)] + public void SingularizeAndDeduplicateOperationIdsForPowerShellStyle(string operationId, string expectedOperationId, OperationType operationType) + { + // Act + var predicate = _openApiService.CreatePredicate(operationIds: operationId, + tags: null, + url: null, + source: _graphMockSource, + graphVersion: GraphVersion); + + var subsetOpenApiDocument = _openApiService.CreateFilteredDocument(_graphMockSource, Title, GraphVersion, predicate); + subsetOpenApiDocument = _openApiService.ApplyStyle(OpenApiStyle.PowerShell, subsetOpenApiDocument, singularizeOperationIds: true); + var singularizedOpId = subsetOpenApiDocument.Paths + .FirstOrDefault().Value + .Operations[operationType] + .OperationId; + + // Assert + Assert.Equal(expectedOperationId, singularizedOpId); + } + [Fact] public void ResolveStructuredAndCollectionValuedFunctionParameters() { From 3a936b671f37ccf6ab18ed3f59f09a99c3aa78b7 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Fri, 31 Mar 2023 01:34:49 +0300 Subject: [PATCH 3/3] Add missing namespace --- OpenAPIService/PowershellFormatter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenAPIService/PowershellFormatter.cs b/OpenAPIService/PowershellFormatter.cs index 9f011868c..631dc9c9d 100644 --- a/OpenAPIService/PowershellFormatter.cs +++ b/OpenAPIService/PowershellFormatter.cs @@ -3,6 +3,7 @@ // ------------------------------------------------------------------------------------------------------------------------------------------------------ using Humanizer; +using Humanizer.Inflections; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Services;