diff --git a/README.md b/README.md index 02235604a..a18c00723 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,9 @@ var document = new OpenApiDocument { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", Responses = new OpenApiResponses diff --git a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs index df632b78a..f263dae0e 100644 --- a/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs +++ b/src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text; using System.Text.RegularExpressions; using Humanizer; @@ -53,11 +54,11 @@ public override void Visit(IOpenApiSchema schema) public override void Visit(IOpenApiPathItem pathItem) { - if (pathItem.Operations.TryGetValue(OperationType.Put, out var value) && + if (pathItem.Operations.TryGetValue(HttpMethod.Put, out var value) && value.OperationId != null) { var operationId = value.OperationId; - pathItem.Operations[OperationType.Put].OperationId = ResolvePutOperationId(operationId); + pathItem.Operations[HttpMethod.Put].OperationId = ResolvePutOperationId(operationId); } base.Visit(pathItem); diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index 692e35c0d..e0cce5896 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -256,9 +256,9 @@ private static async Task GetOpenApiAsync(HidiOptions options, return document; } - private static Func? FilterOpenApiDocument(string? filterByOperationIds, string? filterByTags, Dictionary> requestUrls, OpenApiDocument document, ILogger logger) + private static Func? FilterOpenApiDocument(string? filterByOperationIds, string? filterByTags, Dictionary> requestUrls, OpenApiDocument document, ILogger logger) { - Func? predicate = null; + Func? predicate = null; using (logger.BeginScope("Create Filter")) { diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs index fe0d5bdef..d69f06473 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiPathItem.cs @@ -1,5 +1,6 @@ - + using System.Collections.Generic; +using System.Net.Http; using Microsoft.OpenApi.Interfaces; namespace Microsoft.OpenApi.Models.Interfaces; @@ -13,7 +14,7 @@ public interface IOpenApiPathItem : IOpenApiDescribedElement, IOpenApiSummarized /// /// Gets the definition of operations on this path. /// - public IDictionary Operations { get; } + public IDictionary Operations { get; } /// /// An alternative server array to service all operations in this path. diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index f3baa5743..1d4be44ad 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Net.Http; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; @@ -22,8 +23,8 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenA public string Description { get; set; } /// - public IDictionary Operations { get; set; } - = new Dictionary(); + public IDictionary Operations { get; set; } + = new Dictionary(); /// public IList Servers { get; set; } = []; @@ -39,7 +40,7 @@ public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenA /// /// The operation type kind. /// The operation item. - public void AddOperation(OperationType operationType, OpenApiOperation operation) + public void AddOperation(HttpMethod operationType, OpenApiOperation operation) { Operations[operationType] = operation; } @@ -57,7 +58,7 @@ internal OpenApiPathItem(IOpenApiPathItem pathItem) Utils.CheckArgumentNull(pathItem); Summary = pathItem.Summary ?? Summary; Description = pathItem.Description ?? Description; - Operations = pathItem.Operations != null ? new Dictionary(pathItem.Operations) : null; + Operations = pathItem.Operations != null ? new Dictionary(pathItem.Operations) : null; Servers = pathItem.Servers != null ? new List(pathItem.Servers) : null; Parameters = pathItem.Parameters != null ? new List(pathItem.Parameters) : null; Extensions = pathItem.Extensions != null ? new Dictionary(pathItem.Extensions) : null; @@ -92,10 +93,10 @@ public void SerializeAsV2(IOpenApiWriter writer) // operations except "trace" foreach (var operation in Operations) { - if (operation.Key != OperationType.Trace) + if (operation.Key != HttpMethod.Trace) { writer.WriteOptionalObject( - operation.Key.GetDisplayName(), + operation.Key.Method.ToLowerInvariant(), operation.Value, (w, o) => o.SerializeAsV2(w)); } @@ -135,7 +136,7 @@ internal virtual void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersio foreach (var operation in Operations) { writer.WriteOptionalObject( - operation.Key.GetDisplayName(), + operation.Key.Method.ToLowerInvariant(), operation.Value, callback); } diff --git a/src/Microsoft.OpenApi/Models/OperationType.cs b/src/Microsoft.OpenApi/Models/OperationType.cs deleted file mode 100644 index ed3457353..000000000 --- a/src/Microsoft.OpenApi/Models/OperationType.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Attributes; - -namespace Microsoft.OpenApi.Models -{ - /// - /// Operation type. - /// - public enum OperationType - { - /// - /// A definition of a GET operation on this path. - /// - [Display("get")] Get, - - /// - /// A definition of a PUT operation on this path. - /// - [Display("put")] Put, - - /// - /// A definition of a POST operation on this path. - /// - [Display("post")] Post, - - /// - /// A definition of a DELETE operation on this path. - /// - [Display("delete")] Delete, - - /// - /// A definition of a OPTIONS operation on this path. - /// - [Display("options")] Options, - - /// - /// A definition of a HEAD operation on this path. - /// - [Display("head")] Head, - - /// - /// A definition of a PATCH operation on this path. - /// - [Display("patch")] Patch, - - /// - /// A definition of a TRACE operation on this path. - /// - [Display("trace")] Trace - } -} diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs index 038e1cb13..d56d07c21 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Net.Http; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Writers; @@ -64,7 +65,7 @@ public string Description } /// - public IDictionary Operations { get => Target?.Operations; } + public IDictionary Operations { get => Target?.Operations; } /// public IList Servers { get => Target?.Servers; } diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs index b1e0da7a8..822f2d4ce 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader.ParseNodes; @@ -18,13 +19,17 @@ internal static partial class OpenApiV2Deserializer { private static readonly FixedFieldMap _pathItemFixedFields = new() { - {"get", (o, n, t) => o.AddOperation(OperationType.Get, LoadOperation(n, t))}, - {"put", (o, n, t) => o.AddOperation(OperationType.Put, LoadOperation(n, t))}, - {"post", (o, n, t) => o.AddOperation(OperationType.Post, LoadOperation(n, t))}, - {"delete", (o, n, t) => o.AddOperation(OperationType.Delete, LoadOperation(n, t))}, - {"options", (o, n, t) => o.AddOperation(OperationType.Options, LoadOperation(n, t))}, - {"head", (o, n, t) => o.AddOperation(OperationType.Head, LoadOperation(n, t))}, - {"patch", (o, n, t) => o.AddOperation(OperationType.Patch, LoadOperation(n, t))}, + {"get", (o, n, t) => o.AddOperation(HttpMethod.Get, LoadOperation(n, t))}, + {"put", (o, n, t) => o.AddOperation(HttpMethod.Put, LoadOperation(n, t))}, + {"post", (o, n, t) => o.AddOperation(HttpMethod.Post, LoadOperation(n, t))}, + {"delete", (o, n, t) => o.AddOperation(HttpMethod.Delete, LoadOperation(n, t))}, + {"options", (o, n, t) => o.AddOperation(HttpMethod.Options, LoadOperation(n, t))}, + {"head", (o, n, t) => o.AddOperation(HttpMethod.Head, LoadOperation(n, t))}, +#if NETSTANDARD2_1_OR_GREATER + {"patch", (o, n, t) => o.AddOperation(HttpMethod.Patch, LoadOperation(n, t))}, +#else + {"patch", (o, n, t) => o.AddOperation(new HttpMethod("PATCH"), LoadOperation(n, t))}, +#endif { "parameters", LoadPathParameters @@ -62,13 +67,15 @@ private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node, var requestBody = CreateRequestBody(node.Context, bodyParameter); foreach (var opPair in pathItem.Operations.Where(x => x.Value.RequestBody is null)) { - switch (opPair.Key) + if (opPair.Key == HttpMethod.Post || opPair.Key == HttpMethod.Put +#if NETSTANDARD2_1_OR_GREATER + || opPair.Key == HttpMethod.Patch +#else + || opPair.Key == new HttpMethod("PATCH") +#endif + ) { - case OperationType.Post: - case OperationType.Put: - case OperationType.Patch: - opPair.Value.RequestBody = requestBody; - break; + opPair.Value.RequestBody = requestBody; } } } @@ -80,17 +87,20 @@ private static void LoadPathParameters(OpenApiPathItem pathItem, ParseNode node, var requestBody = CreateFormBody(node.Context, formParameters); foreach (var opPair in pathItem.Operations.Where(x => x.Value.RequestBody is null)) { - switch (opPair.Key) + if (opPair.Key == HttpMethod.Post || opPair.Key == HttpMethod.Put +#if NETSTANDARD2_1_OR_GREATER + || opPair.Key == HttpMethod.Patch +#else + || opPair.Key == new HttpMethod("PATCH") +#endif + ) { - case OperationType.Post: - case OperationType.Put: - case OperationType.Patch: - opPair.Value.RequestBody = requestBody; - break; + opPair.Value.RequestBody = requestBody; } } } } + } } } diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiPathItemDeserializer.cs index baaf5babc..c855fa55c 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiPathItemDeserializer.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System; +using System.Net.Http; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -26,14 +27,18 @@ internal static partial class OpenApiV3Deserializer "description", (o, n, _) => o.Description = n.GetScalarValue() }, - {"get", (o, n, t) => o.AddOperation(OperationType.Get, LoadOperation(n, t))}, - {"put", (o, n, t) => o.AddOperation(OperationType.Put, LoadOperation(n, t))}, - {"post", (o, n, t) => o.AddOperation(OperationType.Post, LoadOperation(n, t))}, - {"delete", (o, n, t) => o.AddOperation(OperationType.Delete, LoadOperation(n, t))}, - {"options", (o, n, t) => o.AddOperation(OperationType.Options, LoadOperation(n, t))}, - {"head", (o, n, t) => o.AddOperation(OperationType.Head, LoadOperation(n, t))}, - {"patch", (o, n, t) => o.AddOperation(OperationType.Patch, LoadOperation(n, t))}, - {"trace", (o, n, t) => o.AddOperation(OperationType.Trace, LoadOperation(n, t))}, + {"get", (o, n, t) => o.AddOperation(HttpMethod.Get, LoadOperation(n, t))}, + {"put", (o, n, t) => o.AddOperation(HttpMethod.Put, LoadOperation(n, t))}, + {"post", (o, n, t) => o.AddOperation(HttpMethod.Post, LoadOperation(n, t))}, + {"delete", (o, n, t) => o.AddOperation(HttpMethod.Delete, LoadOperation(n, t))}, + {"options", (o, n, t) => o.AddOperation(HttpMethod.Options, LoadOperation(n, t))}, + {"head", (o, n, t) => o.AddOperation(HttpMethod.Head, LoadOperation(n, t))}, +#if NETSTANDARD2_1_OR_GREATER + {"patch", (o, n, t) => o.AddOperation(HttpMethod.Patch, LoadOperation(n, t))}, +#else + {"patch", (o, n, t) => o.AddOperation(new HttpMethod("PATCH"), LoadOperation(n, t))}, +#endif + {"trace", (o, n, t) => o.AddOperation(HttpMethod.Trace, LoadOperation(n, t))}, {"servers", (o, n, t) => o.Servers = n.CreateList(LoadServer, t)}, {"parameters", (o, n, t) => o.Parameters = n.CreateList(LoadParameter, t)} }; diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs index 391a34bf6..21da96d3d 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiPathItemDeserializer.cs @@ -1,4 +1,5 @@ using System; +using System.Net.Http; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -28,14 +29,18 @@ internal static partial class OpenApiV31Deserializer o.Description = n.GetScalarValue(); } }, - {"get", (o, n, t) => o.AddOperation(OperationType.Get, LoadOperation(n, t))}, - {"put", (o, n, t) => o.AddOperation(OperationType.Put, LoadOperation(n, t))}, - {"post", (o, n, t) => o.AddOperation(OperationType.Post, LoadOperation(n, t))}, - {"delete", (o, n, t) => o.AddOperation(OperationType.Delete, LoadOperation(n, t))}, - {"options", (o, n, t) => o.AddOperation(OperationType.Options, LoadOperation(n, t))}, - {"head", (o, n, t) => o.AddOperation(OperationType.Head, LoadOperation(n, t))}, - {"patch", (o, n, t) => o.AddOperation(OperationType.Patch, LoadOperation(n, t))}, - {"trace", (o, n, t) => o.AddOperation(OperationType.Trace, LoadOperation(n, t))}, + {"get", (o, n, t) => o.AddOperation(HttpMethod.Get, LoadOperation(n, t))}, + {"put", (o, n, t) => o.AddOperation(HttpMethod.Put, LoadOperation(n, t))}, + {"post", (o, n, t) => o.AddOperation(HttpMethod.Post, LoadOperation(n, t))}, + {"delete", (o, n, t) => o.AddOperation(HttpMethod.Delete, LoadOperation(n, t))}, + {"options", (o, n, t) => o.AddOperation(HttpMethod.Options, LoadOperation(n, t))}, + {"head", (o, n, t) => o.AddOperation(HttpMethod.Head, LoadOperation(n, t))}, +#if NETSTANDARD2_1_OR_GREATER + {"patch", (o, n, t) => o.AddOperation(HttpMethod.Patch, LoadOperation(n, t))}, +#else + {"patch", (o, n, t) => o.AddOperation(new HttpMethod("PATCH"), LoadOperation(n, t))}, +#endif + {"trace", (o, n, t) => o.AddOperation(HttpMethod.Trace, LoadOperation(n, t))}, {"servers", (o, n, t) => o.Servers = n.CreateList(LoadServer, t)}, {"parameters", (o, n, t) => o.Parameters = n.CreateList(LoadParameter, t)} }; diff --git a/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs b/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs index 448542c10..b17195c3b 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiFilterService.cs @@ -1,10 +1,11 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Net.Http; using System.Text.RegularExpressions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -25,13 +26,13 @@ public static class OpenApiFilterService /// A dictionary of requests from a postman collection. /// The input OpenAPI document. /// A predicate. - public static Func CreatePredicate( + public static Func CreatePredicate( string operationIds = null, string tags = null, Dictionary> requestUrls = null, OpenApiDocument source = null) { - Func predicate; + Func predicate; ValidateFilters(requestUrls, operationIds, tags); if (operationIds != null) { @@ -59,7 +60,7 @@ public static class OpenApiFilterService /// The target . /// A predicate function. /// A partial OpenAPI document. - public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Func predicate) + public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Func predicate) { // Fetch and copy title, graphVersion and server info from OpenApiDoc var components = source.Components is null @@ -107,7 +108,7 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun if (result.CurrentKeys.Operation != null) { - pathItem.Operations.Add((OperationType)result.CurrentKeys.Operation, result.Operation); + pathItem.Operations.Add(result.CurrentKeys.Operation, result.Operation); if (result.Parameters?.Any() ?? false) { @@ -147,7 +148,7 @@ public static OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(Dictionary GetOpenApiOperations(OpenApiUrlTreeNode rootNode, string relativeUrl, string label) + private static IDictionary GetOpenApiOperations(OpenApiUrlTreeNode rootNode, string relativeUrl, string label) { if (relativeUrl.Equals("/", StringComparison.Ordinal) && rootNode.HasOperations(label)) { @@ -156,7 +157,7 @@ private static IDictionary GetOpenApiOperations var urlSegments = relativeUrl.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); - IDictionary operations = null; + IDictionary operations = null; var targetChild = rootNode; @@ -224,7 +225,7 @@ private static IDictionary GetOpenApiOperations return operations; } - private static IList FindOperations(OpenApiDocument sourceDocument, Func predicate) + private static IList FindOperations(OpenApiDocument sourceDocument, Func predicate) { var search = new OperationSearch(predicate); var walker = new OpenApiWalker(search); @@ -344,7 +345,7 @@ private static void ValidateFilters(IDictionary> requestUrl } } - private static Func GetOperationIdsPredicate(string operationIds) + private static Func GetOperationIdsPredicate(string operationIds) { if (operationIds == "*") { @@ -357,7 +358,7 @@ private static void ValidateFilters(IDictionary> requestUrl } } - private static Func GetTagsPredicate(string tags) + private static Func GetTagsPredicate(string tags) { var tagsArray = tags.Split(','); if (tagsArray.Length == 1) @@ -371,7 +372,7 @@ private static void ValidateFilters(IDictionary> requestUrl } } - private static Func GetRequestUrlsPredicate(Dictionary> requestUrls, OpenApiDocument source) + private static Func GetRequestUrlsPredicate(Dictionary> requestUrls, OpenApiDocument source) { var operationTypes = new List(); if (source != null) @@ -404,7 +405,7 @@ private static void ValidateFilters(IDictionary> requestUrl return (path, operationType, _) => operationTypes.Contains(operationType + path); } - private static List GetOperationTypes(IDictionary openApiOperations, List url, string path) + private static List GetOperationTypes(IDictionary openApiOperations, List url, string path) { // Add the available ops if they are in the postman collection. See path.Value return openApiOperations.Where(ops => url.Contains(ops.Key.ToString().ToUpper())) diff --git a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs index e4420c3c3..aae8527d7 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; @@ -127,7 +128,7 @@ public virtual void Visit(OpenApiServerVariable serverVariable) /// /// Visits the operations. /// - public virtual void Visit(IDictionary operations) + public virtual void Visit(IDictionary operations) { } diff --git a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs index 76947f381..b9b053c96 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiWalker.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiWalker.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -561,7 +562,7 @@ internal void Walk(IOpenApiPathItem pathItem, bool isComponent = false) /// /// Visits dictionary of /// - internal void Walk(IDictionary operations) + internal void Walk(IDictionary operations) { if (operations == null) { @@ -574,7 +575,7 @@ internal void Walk(IDictionary operations) foreach (var operation in operations) { _visitor.CurrentKeys.Operation = operation.Key; - Walk(operation.Key.GetDisplayName(), () => Walk(operation.Value)); + Walk(operation.Key.Method.ToLowerInvariant(), () => Walk(operation.Value)); _visitor.CurrentKeys.Operation = null; } } @@ -1262,7 +1263,7 @@ public class CurrentKeys /// /// Current Operation Type /// - public OperationType? Operation { get; set; } + public HttpMethod Operation { get; set; } /// /// Current Response Status Code diff --git a/src/Microsoft.OpenApi/Services/OperationSearch.cs b/src/Microsoft.OpenApi/Services/OperationSearch.cs index c726ac966..d3199f38c 100644 --- a/src/Microsoft.OpenApi/Services/OperationSearch.cs +++ b/src/Microsoft.OpenApi/Services/OperationSearch.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -14,7 +15,7 @@ namespace Microsoft.OpenApi.Services /// public class OperationSearch : OpenApiVisitorBase { - private readonly Func _predicate; + private readonly Func _predicate; private readonly List _searchResults = new(); /// @@ -26,7 +27,7 @@ public class OperationSearch : OpenApiVisitorBase /// The OperationSearch constructor. /// /// A predicate function. - public OperationSearch(Func predicate) + public OperationSearch(Func predicate) { _predicate = predicate ?? throw new ArgumentNullException(nameof(predicate)); } @@ -70,7 +71,7 @@ public override void Visit(IList parameters) base.Visit(parameters); } - private static CurrentKeys CopyCurrentKeys(CurrentKeys currentKeys, OperationType operationType) + private static CurrentKeys CopyCurrentKeys(CurrentKeys currentKeys, HttpMethod operationType) { return new() { diff --git a/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs b/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs index 784f06172..734c514c3 100644 --- a/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs +++ b/src/Microsoft.OpenApi/Validations/OpenApiValidator.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Net.Http; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -155,7 +156,7 @@ public void AddWarning(OpenApiValidatorWarning warning) /// public override void Visit(OpenApiOperation operation) => Validate(operation); /// - public override void Visit(IDictionary operations) => Validate(operations, operations.GetType()); + public override void Visit(IDictionary operations) => Validate(operations, operations.GetType()); /// public override void Visit(IDictionary headers) => Validate(headers, headers.GetType()); /// diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs index da6d8c61e..49b020a10 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Formatters/PowerShellFormatterTests.cs @@ -10,16 +10,23 @@ namespace Microsoft.OpenApi.Hidi.Tests.Formatters { public class PowerShellFormatterTests { + public static IEnumerable TestCases + { + get + { + yield return new object[] { "drives.drive.ListDrive", "drive_ListDrive", HttpMethod.Get }; + yield return new object[] { "print.taskDefinitions.tasks.GetTrigger", "print.taskDefinition.task_GetTrigger", HttpMethod.Get }; + yield return new object[] { "groups.sites.termStore.groups.GetSets", "group.site.termStore.group_GetSet", HttpMethod.Get }; + yield return new object[] { "external.industryData.ListDataConnectors", "external.industryData_ListDataConnector", HttpMethod.Get }; + yield return new object[] { "applications.application.UpdateLogo", "application_SetLogo", HttpMethod.Put }; + yield return new object[] { "identityGovernance.lifecycleWorkflows.workflows.workflow.activate", "identityGovernance.lifecycleWorkflow.workflow_activate", HttpMethod.Post }; + yield return new object[] { "directory.GetDeletedItems.AsApplication", "directory_GetDeletedItemAsApplication", HttpMethod.Get }; + yield return new object[] { "education.users.GetCount-6be9", "education.user_GetCount", HttpMethod.Get }; + } + } [Theory] - [InlineData("drives.drive.ListDrive", "drive_ListDrive", OperationType.Get)] - [InlineData("print.taskDefinitions.tasks.GetTrigger", "print.taskDefinition.task_GetTrigger", OperationType.Get)] - [InlineData("groups.sites.termStore.groups.GetSets", "group.site.termStore.group_GetSet", OperationType.Get)] - [InlineData("external.industryData.ListDataConnectors", "external.industryData_ListDataConnector", OperationType.Get)] - [InlineData("applications.application.UpdateLogo", "application_SetLogo", OperationType.Put)] - [InlineData("identityGovernance.lifecycleWorkflows.workflows.workflow.activate", "identityGovernance.lifecycleWorkflow.workflow_activate", OperationType.Post)] - [InlineData("directory.GetDeletedItems.AsApplication", "directory_GetDeletedItemAsApplication", OperationType.Get)] - [InlineData("education.users.GetCount-6be9", "education.user_GetCount", OperationType.Get)] - public void FormatOperationIdsInOpenAPIDocument(string operationId, string expectedOperationId, OperationType operationType, string path = "/foo") + [MemberData(nameof(TestCases))] + public void FormatOperationIdsInOpenAPIDocument(string operationId, string expectedOperationId, HttpMethod operationType, string path = "/foo") { // Arrange var openApiDocument = new OpenApiDocument @@ -29,7 +36,7 @@ public void FormatOperationIdsInOpenAPIDocument(string operationId, string expec Paths = new() { { path, new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { operationType, new() { OperationId = operationId } } } @@ -89,7 +96,7 @@ public void ResolveFunctionParameters() var walker = new OpenApiWalker(powerShellFormatter); walker.Walk(openApiDocument); - var idsParameter = openApiDocument.Paths["/foo"].Operations[OperationType.Get].Parameters?.Where(static p => p.Name == "ids").FirstOrDefault(); + var idsParameter = openApiDocument.Paths["/foo"].Operations[HttpMethod.Get].Parameters?.Where(static p => p.Name == "ids").FirstOrDefault(); // Assert Assert.Null(idsParameter?.Content); @@ -106,10 +113,10 @@ private static OpenApiDocument GetSampleOpenApiDocument() Paths = new() { { "/foo", new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new() + HttpMethod.Get, new() { OperationId = "Foo.GetFoo", Parameters = diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs index 753f2e9d9..57d2d5098 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiFilterServiceTests.cs @@ -83,11 +83,11 @@ public void TestPredicateFiltersUsingRelativeRequestUrls() Paths = new() { {"/foo", new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - { OperationType.Get, new() }, - { OperationType.Patch, new() }, - { OperationType.Post, new() } + { HttpMethod.Get, new() }, + { HttpMethod.Patch, new() }, + { HttpMethod.Post, new() } } } } @@ -104,9 +104,9 @@ public void TestPredicateFiltersUsingRelativeRequestUrls() var predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: openApiDocument); // Then - Assert.True(predicate("/foo", OperationType.Get, null)); - Assert.True(predicate("/foo", OperationType.Post, null)); - Assert.False(predicate("/foo", OperationType.Patch, null)); + Assert.True(predicate("/foo", HttpMethod.Get, null)); + Assert.True(predicate("/foo", HttpMethod.Post, null)); + Assert.False(predicate("/foo", HttpMethod.Patch, null)); } [Fact] @@ -121,10 +121,10 @@ public void CreateFilteredDocumentUsingPredicateFromRequestUrl() { ["/test/{id}"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - { OperationType.Get, new() }, - { OperationType.Patch, new() } + { HttpMethod.Get, new() }, + { HttpMethod.Patch, new() } }, Parameters = [ @@ -241,7 +241,7 @@ public async Task CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly( var doc = (await OpenApiDocument.LoadAsync(stream, "yaml", settings)).Document; // validated the tags are read as references - var openApiOperationTags = doc.Paths["/items"].Operations[OperationType.Get].Tags?.ToArray(); + var openApiOperationTags = doc.Paths["/items"].Operations[HttpMethod.Get].Tags?.ToArray(); Assert.NotNull(openApiOperationTags); Assert.Single(openApiOperationTags); Assert.True(openApiOperationTags[0].UnresolvedReference); @@ -249,7 +249,7 @@ public async Task CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly( var predicate = OpenApiFilterService.CreatePredicate(operationIds: operationIds); var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(doc, predicate); - var response = subsetOpenApiDocument.Paths["/items"].Operations[OperationType.Get]?.Responses?["200"]; + var response = subsetOpenApiDocument.Paths["/items"].Operations[HttpMethod.Get]?.Responses?["200"]; var responseHeader = response?.Headers["x-custom-header"]; var mediaTypeExample = response?.Content["application/json"]?.Examples?.First().Value; var targetHeaders = subsetOpenApiDocument.Components?.Headers; @@ -266,7 +266,7 @@ public async Task CopiesOverAllReferencedComponentsToTheSubsetDocumentCorrectly( Assert.NotNull(targetExamples); Assert.Single(targetExamples); // validated the tags of the trimmed document are read as references - var trimmedOpenApiOperationTags = subsetOpenApiDocument.Paths["/items"].Operations[OperationType.Get].Tags?.ToArray(); + var trimmedOpenApiOperationTags = subsetOpenApiDocument.Paths["/items"].Operations[HttpMethod.Get].Tags?.ToArray(); Assert.NotNull(trimmedOpenApiOperationTags); Assert.Single(trimmedOpenApiOperationTags); Assert.True(trimmedOpenApiOperationTags[0].UnresolvedReference); diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index c23222eb6..ec306bc55 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -45,9 +45,9 @@ public void CreateFilteredDocumentOnMinimalOpenApi() { ["/test"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation() + [HttpMethod.Get] = new OpenApiOperation() } } } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs index 0da220427..0cc1bc2fb 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/OpenApiDocumentMock.cs @@ -51,10 +51,10 @@ public static OpenApiDocument CreateOpenApiDocument() { ["/"] = new OpenApiPathItem() // root path { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "graphService.GetGraphService", Responses = new() @@ -72,10 +72,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [getTeamsActivityByPeriodPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "reports.getTeamsUserActivityCounts", Summary = "Invoke function getTeamsUserActivityUserCounts", @@ -137,10 +137,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [getTeamsActivityByDatePath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "reports.getTeamsUserActivityUserDetail-a3f1", Summary = "Invoke function getTeamsUserActivityUserDetail", @@ -200,10 +200,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [usersPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "users.user.ListUser", Summary = "Get entities from users", @@ -246,10 +246,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [usersByIdPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "users.user.GetUser", Summary = "Get entity from users by key", @@ -274,7 +274,7 @@ public static OpenApiDocument CreateOpenApiDocument() } }, { - OperationType.Patch, new OpenApiOperation + HttpMethod.Patch, new OpenApiOperation { OperationId = "users.user.UpdateUser", Summary = "Update entity in users", @@ -293,10 +293,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [messagesByIdPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "users.GetMessages", Summary = "Get messages from users", @@ -340,10 +340,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [administrativeUnitRestorePath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Post, new OpenApiOperation + HttpMethod.Post, new OpenApiOperation { OperationId = "administrativeUnits.restore", Summary = "Invoke action restore", @@ -391,10 +391,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [logoPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Put, new OpenApiOperation + HttpMethod.Put, new OpenApiOperation { OperationId = "applications.application.UpdateLogo", Summary = "Update media content for application in applications", @@ -413,10 +413,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [securityProfilesPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "security.ListHostSecurityProfiles", Summary = "Get hostSecurityProfiles from security", @@ -459,10 +459,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [communicationsCallsKeepAlivePath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Post, new OpenApiOperation + HttpMethod.Post, new OpenApiOperation { OperationId = "communications.calls.call.keepAlive", Summary = "Invoke action keepAlive", @@ -507,10 +507,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [eventsDeltaPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "groups.group.events.event.calendar.events.delta", Summary = "Invoke function delta", @@ -594,10 +594,10 @@ public static OpenApiDocument CreateOpenApiDocument() }, [refPath] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "applications.GetRefCreatedOnBehalfOf", Summary = "Get ref of createdOnBehalfOf from applications" @@ -678,23 +678,23 @@ public static OpenApiDocument CreateOpenApiDocument() } } }; - document.Paths[getTeamsActivityByPeriodPath].Operations[OperationType.Get].Tags = new HashSet {new OpenApiTagReference("reports.Functions", document)}; - document.Paths[getTeamsActivityByDatePath].Operations[OperationType.Get].Tags = new HashSet {new OpenApiTagReference("reports.Functions", document)}; - document.Paths[usersPath].Operations[OperationType.Get].Tags = new HashSet {new OpenApiTagReference("users.user", document)}; - document.Paths[usersByIdPath].Operations[OperationType.Get].Tags = new HashSet {new OpenApiTagReference("users.user", document)}; - document.Paths[usersByIdPath].Operations[OperationType.Patch].Tags = new HashSet {new OpenApiTagReference("users.user", document)}; - document.Paths[messagesByIdPath].Operations[OperationType.Get].Tags = new HashSet {new OpenApiTagReference("users.message", document)}; - document.Paths[administrativeUnitRestorePath].Operations[OperationType.Post].Tags = new HashSet {new OpenApiTagReference("administrativeUnits.Actions", document)}; - document.Paths[logoPath].Operations[OperationType.Put].Tags = new HashSet {new OpenApiTagReference("applications.application", document)}; - document.Paths[securityProfilesPath].Operations[OperationType.Get].Tags = new HashSet {new OpenApiTagReference("security.hostSecurityProfile", document)}; - document.Paths[communicationsCallsKeepAlivePath].Operations[OperationType.Post].Tags = new HashSet {new OpenApiTagReference("communications.Actions", document)}; - document.Paths[eventsDeltaPath].Operations[OperationType.Get].Tags = new HashSet {new OpenApiTagReference("groups.Functions", document)}; - document.Paths[refPath].Operations[OperationType.Get].Tags = new HashSet {new OpenApiTagReference("applications.directoryObject", document)}; - ((OpenApiSchema)document.Paths[usersPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.user", document); - document.Paths[usersByIdPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.user", document); - document.Paths[messagesByIdPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.message", document); - ((OpenApiSchema)document.Paths[securityProfilesPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.networkInterface", document); - ((OpenApiSchema)document.Paths[eventsDeltaPath].Operations[OperationType.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.event", document); + document.Paths[getTeamsActivityByPeriodPath].Operations[HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("reports.Functions", document)}; + document.Paths[getTeamsActivityByDatePath].Operations[HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("reports.Functions", document)}; + document.Paths[usersPath].Operations[HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("users.user", document)}; + document.Paths[usersByIdPath].Operations[HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("users.user", document)}; + document.Paths[usersByIdPath].Operations[HttpMethod.Patch].Tags = new HashSet {new OpenApiTagReference("users.user", document)}; + document.Paths[messagesByIdPath].Operations[HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("users.message", document)}; + document.Paths[administrativeUnitRestorePath].Operations[HttpMethod.Post].Tags = new HashSet {new OpenApiTagReference("administrativeUnits.Actions", document)}; + document.Paths[logoPath].Operations[HttpMethod.Put].Tags = new HashSet {new OpenApiTagReference("applications.application", document)}; + document.Paths[securityProfilesPath].Operations[HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("security.hostSecurityProfile", document)}; + document.Paths[communicationsCallsKeepAlivePath].Operations[HttpMethod.Post].Tags = new HashSet {new OpenApiTagReference("communications.Actions", document)}; + document.Paths[eventsDeltaPath].Operations[HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("groups.Functions", document)}; + document.Paths[refPath].Operations[HttpMethod.Get].Tags = new HashSet {new OpenApiTagReference("applications.directoryObject", document)}; + ((OpenApiSchema)document.Paths[usersPath].Operations[HttpMethod.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.user", document); + document.Paths[usersByIdPath].Operations[HttpMethod.Get].Responses!["200"].Content[applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.user", document); + document.Paths[messagesByIdPath].Operations[HttpMethod.Get].Responses!["200"].Content[applicationJsonMediaType].Schema = new OpenApiSchemaReference("microsoft.graph.message", document); + ((OpenApiSchema)document.Paths[securityProfilesPath].Operations[HttpMethod.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.networkInterface", document); + ((OpenApiSchema)document.Paths[eventsDeltaPath].Operations[HttpMethod.Get].Responses!["200"].Content[applicationJsonMediaType].Schema!.Properties["value"]).Items = new OpenApiSchemaReference("microsoft.graph.event", document); return document; } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs index be5921e54..f76e3311c 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; using FluentAssertions; @@ -143,7 +144,7 @@ public async Task ShouldParseProducesInAnyOrder() { Operations = { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Responses = { @@ -167,7 +168,7 @@ public async Task ShouldParseProducesInAnyOrder() } } }, - [OperationType.Post] = new() + [HttpMethod.Post] = new() { Responses = { @@ -189,7 +190,7 @@ public async Task ShouldParseProducesInAnyOrder() } } }, - [OperationType.Patch] = new() + [HttpMethod.Patch] = new() { Responses = { @@ -242,7 +243,7 @@ public async Task ShouldAssignSchemaToAllResponses() }; var errorSchema = new OpenApiSchemaReference("Error", result.Document); - var responses = result.Document.Paths["/items"].Operations[OperationType.Get].Responses; + var responses = result.Document.Paths["/items"].Operations[HttpMethod.Get].Responses; foreach (var response in responses) { var targetSchema = response.Key == "200" ? (IOpenApiSchema)successSchema : errorSchema; @@ -284,7 +285,7 @@ public async Task ParseDocumentWithDefaultContentTypeSettingShouldSucceed() settings.AddYamlReader(); var actual = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithEmptyProduces.yaml"), settings); - var mediaType = actual.Document.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content; + var mediaType = actual.Document.Paths["/example"].Operations[HttpMethod.Get].Responses["200"].Content; Assert.Contains("application/json", mediaType); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs index 00c4faaeb..cd62c27be 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; +using System.Net.Http; using System.Text; using System.Text.Json.Nodes; using System.Threading.Tasks; @@ -523,9 +524,9 @@ public async Task SerializesBodyReferencesWorks() }; openApiDocument.Paths.Add("/users", new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Post] = operation + [HttpMethod.Post] = operation } }); openApiDocument.AddComponent("UserRequest", new OpenApiRequestBody diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs index 412a74dde..b3ebdc3dc 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Reader.ParseNodes; using Microsoft.OpenApi.Reader.V2; @@ -40,7 +41,7 @@ public class OpenApiPathItemTests ], Operations = { - [OperationType.Put] = new() + [HttpMethod.Put] = new() { Summary = "Puts a pet in the store with form data", Description = "", @@ -135,7 +136,7 @@ public class OpenApiPathItemTests } } }, - [OperationType.Post] = new() + [HttpMethod.Post] = new() { Summary = "Posts a pet in the store with form data", Description = "", @@ -274,8 +275,8 @@ public void ParsePathItemWithFormDataPathParameterShouldSucceed() // 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.True(pathItem.Operations[HttpMethod.Put].RequestBody != null); + Assert.True(pathItem.Operations[HttpMethod.Post].RequestBody != null); Assert.Equal(2, pathItem.Operations.Count(o => o.Value.RequestBody != null)); } [Fact] @@ -293,8 +294,8 @@ public void ParsePathItemBodyDataPathParameterShouldSucceed() // 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.True(pathItem.Operations[HttpMethod.Put].RequestBody != null); + Assert.True(pathItem.Operations[HttpMethod.Post].RequestBody != null); Assert.Equal(2, pathItem.Operations.Count(o => o.Value.RequestBody != null)); } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs index eebebbb6b..2cab4c37b 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs @@ -13,6 +13,7 @@ using VerifyXunit; using Microsoft.OpenApi.Models.Interfaces; using System; +using System.Net.Http; namespace Microsoft.OpenApi.Readers.Tests.V31Tests { @@ -112,9 +113,9 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() { ["pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", @@ -175,7 +176,7 @@ public async Task ParseDocumentWithWebhooksShouldSucceed() } } }, - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody { @@ -302,9 +303,9 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds() { ["pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", @@ -365,7 +366,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds() } } }, - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody { @@ -441,7 +442,7 @@ public async Task ParseDocumentWithPatternPropertiesInSchemaWorks() { // Arrange and Act var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithPatternPropertiesInSchema.yaml"), SettingsFixture.ReaderSettings); - var actualSchema = result.Document.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema; + var actualSchema = result.Document.Paths["/example"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"].Schema; var expectedSchema = new OpenApiSchema { @@ -471,7 +472,7 @@ public async Task ParseDocumentWithPatternPropertiesInSchemaWorks() }; // Serialization - var mediaType = result.Document.Paths["/example"].Operations[OperationType.Get].Responses["200"].Content["application/json"]; + var mediaType = result.Document.Paths["/example"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"]; var expectedMediaType = @"schema: patternProperties: @@ -499,9 +500,9 @@ public async Task ParseDocumentWithReferenceByIdGetsResolved() // Arrange and Act var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "docWithReferenceById.yaml"), SettingsFixture.ReaderSettings); - var responseSchema = result.Document.Paths["/resource"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema; - var requestBodySchema = result.Document.Paths["/resource"].Operations[OperationType.Post].RequestBody.Content["application/json"].Schema; - var parameterSchema = result.Document.Paths["/resource"].Operations[OperationType.Get].Parameters[0].Schema; + var responseSchema = result.Document.Paths["/resource"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"].Schema; + var requestBodySchema = result.Document.Paths["/resource"].Operations[HttpMethod.Post].RequestBody.Content["application/json"].Schema; + var parameterSchema = result.Document.Paths["/resource"].Operations[HttpMethod.Get].Parameters[0].Schema; // Assert Assert.Equal(JsonSchemaType.Object, responseSchema.Type); @@ -524,7 +525,7 @@ public async Task ExternalDocumentDereferenceToOpenApiDocumentUsingJsonPointerWo // Act var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "externalRefByJsonPointer.yaml"), settings); - var responseSchema = result.Document.Paths["/resource"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema; + var responseSchema = result.Document.Paths["/resource"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"].Schema; // Assert result.Document.Workspace.Contains("./externalResource.yaml"); @@ -548,7 +549,7 @@ public async Task ParseExternalDocumentDereferenceToOpenApiDocumentByIdWorks() var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "externalRefById.yaml"), settings); var doc2 = (await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "externalResource.yaml"), SettingsFixture.ReaderSettings)).Document; - var requestBodySchema = result.Document.Paths["/resource"].Operations[OperationType.Get].Parameters[0].Schema; + var requestBodySchema = result.Document.Paths["/resource"].Operations[HttpMethod.Get].Parameters[0].Schema; result.Document.Workspace.RegisterComponents(doc2); // Assert diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs index cca7e002d..93b5677e7 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiCallbackTests.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Expressions; using Microsoft.OpenApi.Models; @@ -33,7 +34,7 @@ public async Task ParseBasicCallbackShouldSucceed() { Operations = { - [OperationType.Post] = + [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody @@ -67,7 +68,7 @@ public async Task ParseCallbackWithReferenceShouldSucceed() // Assert var path = result.Document.Paths.First().Value; - var subscribeOperation = path.Operations[OperationType.Post]; + var subscribeOperation = path.Operations[HttpMethod.Post]; var callback = subscribeOperation.Callbacks["simpleHook"]; @@ -81,7 +82,7 @@ public async Task ParseCallbackWithReferenceShouldSucceed() { [RuntimeExpression.Build("$request.body#/url")]= new OpenApiPathItem { Operations = { - [OperationType.Post] = new OpenApiOperation() + [HttpMethod.Post] = new OpenApiOperation() { RequestBody = new OpenApiRequestBody { @@ -117,7 +118,7 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed() // Assert var path = result.Document.Paths.First().Value; - var subscribeOperation = path.Operations[OperationType.Post]; + var subscribeOperation = path.Operations[HttpMethod.Post]; Assert.Equivalent( new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 }, result.Diagnostic); @@ -131,7 +132,7 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed() { [RuntimeExpression.Build("$request.body#/url")]= new OpenApiPathItem { Operations = { - [OperationType.Post] = new OpenApiOperation() + [HttpMethod.Post] = new OpenApiOperation() { RequestBody = new OpenApiRequestBody { @@ -166,7 +167,7 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed() { [RuntimeExpression.Build("/simplePath")]= new OpenApiPathItem { Operations = { - [OperationType.Post] = new OpenApiOperation() + [HttpMethod.Post] = new OpenApiOperation() { RequestBody = new OpenApiRequestBody { @@ -202,7 +203,7 @@ public async Task ParseMultipleCallbacksWithReferenceShouldSucceed() { [RuntimeExpression.Build(@"http://example.com?transactionId={$request.body#/id}&email={$request.body#/email}")] = new OpenApiPathItem { Operations = { - [OperationType.Post] = new OpenApiOperation() + [HttpMethod.Post] = new OpenApiOperation() { RequestBody = new OpenApiRequestBody { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index 77eceb66d..bc17c02fb 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -302,9 +302,9 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", @@ -387,7 +387,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() } } }, - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", @@ -444,9 +444,9 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() }, ["/pets/{id}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns a user based on a single ID, if the user does not have access to the pet", @@ -507,7 +507,7 @@ public async Task ParseStandardPetStoreDocumentShouldSucceed() } } }, - [OperationType.Delete] = new OpenApiOperation + [HttpMethod.Delete] = new OpenApiOperation { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", @@ -721,9 +721,9 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Tags = new HashSet { @@ -811,7 +811,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } } }, - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { Tags = new HashSet { @@ -885,9 +885,9 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() }, ["/pets/{id}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns a user based on a single ID, if the user does not have access to the pet", @@ -948,7 +948,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() } } }, - [OperationType.Delete] = new OpenApiOperation + [HttpMethod.Delete] = new OpenApiOperation { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", @@ -1033,8 +1033,8 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed() actual.Document.Should().BeEquivalentTo(expected, options => options .IgnoringCyclicReferences() - .Excluding(x => x.Paths["/pets"].Operations[OperationType.Get].Tags) - .Excluding(x => x.Paths["/pets"].Operations[OperationType.Post].Tags) + .Excluding(ctx => ctx.Path.Contains("Paths[\"/pets\"].Operations[HttpMethod.Get].Tags")) + .Excluding(ctx => ctx.Path.Contains("Paths[\"/pets\"].Operations[HttpMethod.Post].Tags")) .Excluding(x => x.Workspace) .Excluding(y => y.BaseUri)); @@ -1144,7 +1144,7 @@ public async Task ParseDocumentWithJsonSchemaReferencesWorks() // Act var result = await OpenApiDocument.LoadAsync(stream, OpenApiConstants.Yaml, SettingsFixture.ReaderSettings); - var actualSchema = result.Document.Paths["/users/{userId}"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema; + var actualSchema = result.Document.Paths["/users/{userId}"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"].Schema; var expectedSchema = new OpenApiSchemaReference("User", result.Document); // Assert @@ -1223,7 +1223,7 @@ public async Task ParsesDoubleHopReferences() var (document, _) = await OpenApiDocument.LoadAsync(stream); Assert.NotNull(document); - var petReferenceInResponse = Assert.IsType(document.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema); + var petReferenceInResponse = Assert.IsType(document.Paths["/pets"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"].Schema); Assert.Equal("A reference to a pet reference", petReferenceInResponse.Description, StringComparer.OrdinalIgnoreCase); var petReference = Assert.IsType(petReferenceInResponse.Target); Assert.Equal("A reference to a pet", petReference.Description, StringComparer.OrdinalIgnoreCase); @@ -1272,9 +1272,9 @@ public async Task SerializesDoubleHopeReferences() document.AddComponent("PetReference", petSchemaReference); document.Paths.Add("/pets", new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Summary = "Returns all pets", Responses = @@ -1338,9 +1338,9 @@ public async Task ParseDocWithRefsUsingProxyReferencesSucceeds() { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Summary = "Returns all pets", Parameters = @@ -1392,9 +1392,9 @@ public async Task ParseDocWithRefsUsingProxyReferencesSucceeds() // Act var doc = (await OpenApiDocument.LoadAsync(stream, settings: SettingsFixture.ReaderSettings)).Document; - var actualParam = doc.Paths["/pets"].Operations[OperationType.Get].Parameters[0]; + var actualParam = doc.Paths["/pets"].Operations[HttpMethod.Get].Parameters[0]; var outputDoc = (await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0)).MakeLineBreaksEnvironmentNeutral(); - var expectedParam = expected.Paths["/pets"].Operations[OperationType.Get].Parameters[0]; + var expectedParam = expected.Paths["/pets"].Operations[HttpMethod.Get].Parameters[0]; var expectedParamReference = Assert.IsType(expectedParam); var actualParamReference = Assert.IsType(actualParam); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs index 661ca508d..1dd9ecce3 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiOperationTests.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using System.Threading.Tasks; using FluentAssertions; @@ -24,7 +25,7 @@ public async Task OperationWithSecurityRequirementShouldReferenceSecurityScheme( { var result = await OpenApiDocument.LoadAsync(Path.Combine(SampleFolderPath, "securedOperation.yaml"), SettingsFixture.ReaderSettings); - var securityScheme = result.Document.Paths["/"].Operations[OperationType.Get].Security[0].Keys.First(); + var securityScheme = result.Document.Paths["/"].Operations[HttpMethod.Get].Security[0].Keys.First(); Assert.Equivalent(result.Document.Components.SecuritySchemes.First().Value, securityScheme); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs index 33ebb0267..fd27c9416 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiParameterTests.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Microsoft.OpenApi.Models.Interfaces; using Microsoft.OpenApi.Models.References; +using System.Net.Http; namespace Microsoft.OpenApi.Readers.Tests.V3Tests { @@ -330,9 +331,9 @@ public void ParseParameterWithReferenceWorks() { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index 7d57294c2..9205541cd 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -16,6 +16,7 @@ using FluentAssertions.Equivalency; using Microsoft.OpenApi.Models.References; using System.Threading.Tasks; +using System.Net.Http; namespace Microsoft.OpenApi.Readers.Tests.V3Tests { @@ -119,9 +120,9 @@ public void ParsePathFragmentShouldSucceed() new OpenApiPathItem { Summary = "externally referenced path item", - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation() + [HttpMethod.Get] = new OpenApiOperation() { Responses = new OpenApiResponses { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs index fc232fa3a..2bc407557 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.IO; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Expressions; using Microsoft.OpenApi.Models; @@ -25,7 +26,7 @@ public class OpenApiCallbackTests { Operations = { - [OperationType.Post] = + [HttpMethod.Post] = new() { RequestBody = new OpenApiRequestBody() @@ -65,7 +66,7 @@ public class OpenApiCallbackTests { Operations = { - [OperationType.Post] = + [HttpMethod.Post] = new() { RequestBody = new OpenApiRequestBody() diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs index 379dc0c4f..b0607f57e 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; @@ -235,9 +236,9 @@ public class OpenApiComponentsTests { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody { diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index b286839ac..76102456e 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Extensions; @@ -232,9 +233,9 @@ public class OpenApiDocumentTests { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", @@ -317,7 +318,7 @@ public class OpenApiDocumentTests } } }, - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", @@ -374,9 +375,9 @@ public class OpenApiDocumentTests }, ["/pets/{id}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns a user based on a single ID, if the user does not have access to the pet", @@ -437,7 +438,7 @@ public class OpenApiDocumentTests } } }, - [OperationType.Delete] = new OpenApiOperation + [HttpMethod.Delete] = new OpenApiOperation { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", @@ -608,9 +609,9 @@ public class OpenApiDocumentTests { ["/pets"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", @@ -693,7 +694,7 @@ public class OpenApiDocumentTests } } }, - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", @@ -750,9 +751,9 @@ public class OpenApiDocumentTests }, ["/pets/{id}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Description = "Returns a user based on a single ID, if the user does not have access to the pet", @@ -813,7 +814,7 @@ public class OpenApiDocumentTests } } }, - [OperationType.Delete] = new OpenApiOperation + [HttpMethod.Delete] = new OpenApiOperation { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", @@ -880,9 +881,9 @@ public class OpenApiDocumentTests { ["newPet"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody { @@ -956,9 +957,9 @@ public class OpenApiDocumentTests { ["/add/{operand1}/{operand2}"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { OperationId = "addByOperand1AndByOperand2", Parameters = new List @@ -1067,9 +1068,9 @@ public class OpenApiDocumentTests { ["/pets"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Description = "Returns all pets from the system that the user has access to", OperationId = "findPets", @@ -1152,7 +1153,7 @@ public class OpenApiDocumentTests } } }, - [OperationType.Post] = new() + [HttpMethod.Post] = new() { Description = "Creates a new pet in the store. Duplicates are allowed", OperationId = "addPet", @@ -1209,9 +1210,9 @@ public class OpenApiDocumentTests }, ["/pets/{id}"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Description = "Returns a user based on a single ID, if the user does not have access to the pet", @@ -1272,7 +1273,7 @@ public class OpenApiDocumentTests } } }, - [OperationType.Delete] = new() + [HttpMethod.Delete] = new() { Description = "deletes a single pet based on the ID supplied", OperationId = "deletePet", @@ -1534,9 +1535,9 @@ public async Task SerializeDocumentWithReferenceButNoComponents() { ["/"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Responses = new OpenApiResponses { @@ -1555,7 +1556,7 @@ public async Task SerializeDocumentWithReferenceButNoComponents() } } }; - document.Paths["/"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema = new OpenApiSchemaReference("test", document); + document.Paths["/"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"].Schema = new OpenApiSchemaReference("test", document); // Act var actual = await document.SerializeAsync(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json); @@ -1707,9 +1708,9 @@ public async Task SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollec { ["/foo"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Parameters = [ @@ -1774,9 +1775,9 @@ public async Task SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue() { ["/foo"] = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new OpenApiOperation + [HttpMethod.Get] = new OpenApiOperation { Parameters = [ @@ -1855,9 +1856,9 @@ public void SerializeExamplesDoesNotThrowNullReferenceException() { ["test"] = new OpenApiPathItem() { - Operations = new Dictionary() + Operations = new Dictionary() { - [OperationType.Post] = new OpenApiOperation + [HttpMethod.Post] = new OpenApiOperation { RequestBody = new OpenApiRequestBody() { @@ -1991,7 +1992,7 @@ public async Task SerializeV31DocumentWithRefsInWebhooksWorks() var writer = new OpenApiYamlWriter(stringWriter, new OpenApiWriterSettings { InlineLocalReferences = true }); var webhooks = doc.Webhooks["pets"].Operations; - webhooks[OperationType.Get].SerializeAsV31(writer); + webhooks[HttpMethod.Get].SerializeAsV31(writer); var actual = stringWriter.ToString(); Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), actual.MakeLineBreaksEnvironmentNeutral()); } diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs index b9f31f9e9..37cf0498a 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiCallbackReferenceTests.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; @@ -148,13 +149,13 @@ public void CallbackReferenceResolutionWorks() Assert.NotEmpty(_externalCallbackReference.PathItems); Assert.Single(_externalCallbackReference.PathItems); Assert.Equal("{$request.body#/callbackUrl}", _externalCallbackReference.PathItems.First().Key.Expression); - Assert.Equal(OperationType.Post, _externalCallbackReference.PathItems.FirstOrDefault().Value.Operations.FirstOrDefault().Key);; + Assert.Equal(HttpMethod.Post, _externalCallbackReference.PathItems.FirstOrDefault().Value.Operations.FirstOrDefault().Key);; // Local reference resolution works Assert.NotEmpty(_localCallbackReference.PathItems); Assert.Single(_localCallbackReference.PathItems); Assert.Equal("{$request.body#/callbackUrl}", _localCallbackReference.PathItems.First().Key.Expression); - Assert.Equal(OperationType.Post, _localCallbackReference.PathItems.FirstOrDefault().Value.Operations.FirstOrDefault().Key); ; + Assert.Equal(HttpMethod.Post, _localCallbackReference.PathItems.FirstOrDefault().Value.Operations.FirstOrDefault().Key); ; } [Theory] diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiPathItemReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiPathItemReferenceTests.cs index a6930cf8c..f46f6867d 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiPathItemReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiPathItemReferenceTests.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; @@ -101,13 +102,13 @@ public OpenApiPathItemReferenceTests() public void PathItemReferenceResolutionWorks() { // Assert - Assert.Equal([OperationType.Get, OperationType.Post, OperationType.Delete], + Assert.Equal([HttpMethod.Get, HttpMethod.Post, HttpMethod.Delete], _localPathItemReference.Operations.Select(o => o.Key)); Assert.Equal(3, _localPathItemReference.Operations.Count); Assert.Equal("Local reference: User path item description", _localPathItemReference.Description); Assert.Equal("Local reference: User path item summary", _localPathItemReference.Summary); - Assert.Equal([OperationType.Get, OperationType.Post, OperationType.Delete], + Assert.Equal([HttpMethod.Get, HttpMethod.Post, HttpMethod.Delete], _externalPathItemReference.Operations.Select(o => o.Key)); Assert.Equal("External reference: User path item description", _externalPathItemReference.Description); Assert.Equal("External reference: User path item summary", _externalPathItemReference.Summary); diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiTagReferenceTest.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiTagReferenceTest.cs index 3fdd43d4b..e00927989 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiTagReferenceTest.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiTagReferenceTest.cs @@ -4,6 +4,7 @@ using System; using System.Globalization; using System.IO; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; @@ -79,7 +80,7 @@ public void TagReferenceResolutionWorks() Assert.Equal("user", _openApiTagReference.Name); Assert.Equal("Operations about users.", _openApiTagReference.Description); Assert.True(_openApiTagReference2.UnresolvedReference);// the target is null - var operationTags = _openApiDocument.Paths["/users/{userId}"].Operations[OperationType.Get].Tags; + var operationTags = _openApiDocument.Paths["/users/{userId}"].Operations[HttpMethod.Get].Tags; Assert.Null(operationTags); // the operation tags are not loaded due to the invalid syntax at the operation level(should be a list of strings) } diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 74afafa5a..13fdf06fe 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -390,7 +390,7 @@ namespace Microsoft.OpenApi.Models.Interfaces } public interface IOpenApiPathItem : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReadOnlyExtensible, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable, Microsoft.OpenApi.Interfaces.IShallowCopyable, Microsoft.OpenApi.Models.Interfaces.IOpenApiDescribedElement, Microsoft.OpenApi.Models.Interfaces.IOpenApiSummarizedElement { - System.Collections.Generic.IDictionary Operations { get; } + System.Collections.Generic.IDictionary Operations { get; } System.Collections.Generic.IList Parameters { get; } System.Collections.Generic.IList Servers { get; } } @@ -945,11 +945,11 @@ namespace Microsoft.OpenApi.Models public OpenApiPathItem() { } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; set; } - public System.Collections.Generic.IDictionary Operations { get; set; } + public System.Collections.Generic.IDictionary Operations { get; set; } public System.Collections.Generic.IList Parameters { get; set; } public System.Collections.Generic.IList Servers { get; set; } public string Summary { get; set; } - public void AddOperation(Microsoft.OpenApi.Models.OperationType operationType, Microsoft.OpenApi.Models.OpenApiOperation operation) { } + public void AddOperation(System.Net.Http.HttpMethod operationType, Microsoft.OpenApi.Models.OpenApiOperation operation) { } public Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem CreateShallowCopy() { } public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } @@ -1144,25 +1144,6 @@ namespace Microsoft.OpenApi.Models public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public enum OperationType - { - [Microsoft.OpenApi.Attributes.Display("get")] - Get = 0, - [Microsoft.OpenApi.Attributes.Display("put")] - Put = 1, - [Microsoft.OpenApi.Attributes.Display("post")] - Post = 2, - [Microsoft.OpenApi.Attributes.Display("delete")] - Delete = 3, - [Microsoft.OpenApi.Attributes.Display("options")] - Options = 4, - [Microsoft.OpenApi.Attributes.Display("head")] - Head = 5, - [Microsoft.OpenApi.Attributes.Display("patch")] - Patch = 6, - [Microsoft.OpenApi.Attributes.Display("trace")] - Trace = 7, - } public enum ParameterLocation { [Microsoft.OpenApi.Attributes.Display("query")] @@ -1331,7 +1312,7 @@ namespace Microsoft.OpenApi.Models.References public OpenApiPathItemReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument = null, string externalResource = null) { } public string Description { get; set; } public System.Collections.Generic.IDictionary Extensions { get; } - public System.Collections.Generic.IDictionary Operations { get; } + public System.Collections.Generic.IDictionary Operations { get; } public System.Collections.Generic.IList Parameters { get; } public System.Collections.Generic.IList Servers { get; } public string Summary { get; set; } @@ -1561,7 +1542,7 @@ namespace Microsoft.OpenApi.Services public string Extension { get; } public string Header { get; } public string Link { get; set; } - public Microsoft.OpenApi.Models.OperationType? Operation { get; set; } + public System.Net.Http.HttpMethod Operation { get; set; } public string Path { get; set; } public string Response { get; set; } public string ServerVariable { get; } @@ -1581,9 +1562,9 @@ namespace Microsoft.OpenApi.Services } public static class OpenApiFilterService { - public static Microsoft.OpenApi.Models.OpenApiDocument CreateFilteredDocument(Microsoft.OpenApi.Models.OpenApiDocument source, System.Func predicate) { } + public static Microsoft.OpenApi.Models.OpenApiDocument CreateFilteredDocument(Microsoft.OpenApi.Models.OpenApiDocument source, System.Func predicate) { } public static Microsoft.OpenApi.Services.OpenApiUrlTreeNode CreateOpenApiUrlTreeNode(System.Collections.Generic.Dictionary sources) { } - public static System.Func CreatePredicate(string operationIds = null, string tags = null, System.Collections.Generic.Dictionary> requestUrls = null, Microsoft.OpenApi.Models.OpenApiDocument source = null) { } + public static System.Func CreatePredicate(string operationIds = null, string tags = null, System.Collections.Generic.Dictionary> requestUrls = null, Microsoft.OpenApi.Models.OpenApiDocument source = null) { } } public class OpenApiReferenceError : Microsoft.OpenApi.Models.OpenApiError { @@ -1645,7 +1626,7 @@ namespace Microsoft.OpenApi.Services public virtual void Visit(Microsoft.OpenApi.Models.OpenApiServerVariable serverVariable) { } public virtual void Visit(Microsoft.OpenApi.Models.OpenApiTag tag) { } public virtual void Visit(Microsoft.OpenApi.Models.References.OpenApiTagReference tag) { } - public virtual void Visit(System.Collections.Generic.IDictionary operations) { } + public virtual void Visit(System.Collections.Generic.IDictionary operations) { } public virtual void Visit(System.Collections.Generic.IDictionary callbacks) { } public virtual void Visit(System.Collections.Generic.IDictionary examples) { } public virtual void Visit(System.Collections.Generic.IDictionary headers) { } @@ -1683,7 +1664,7 @@ namespace Microsoft.OpenApi.Services } public class OperationSearch : Microsoft.OpenApi.Services.OpenApiVisitorBase { - public OperationSearch(System.Func predicate) { } + public OperationSearch(System.Func predicate) { } public System.Collections.Generic.IList SearchResults { get; } public override void Visit(Microsoft.OpenApi.Models.Interfaces.IOpenApiPathItem pathItem) { } public override void Visit(System.Collections.Generic.IList parameters) { } @@ -1743,7 +1724,7 @@ namespace Microsoft.OpenApi.Validations public override void Visit(Microsoft.OpenApi.Models.OpenApiServer server) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiServerVariable serverVariable) { } public override void Visit(Microsoft.OpenApi.Models.OpenApiTag tag) { } - public override void Visit(System.Collections.Generic.IDictionary operations) { } + public override void Visit(System.Collections.Generic.IDictionary operations) { } public override void Visit(System.Collections.Generic.IDictionary callbacks) { } public override void Visit(System.Collections.Generic.IDictionary examples) { } public override void Visit(System.Collections.Generic.IDictionary headers) { } diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs index 33296cfed6..3292a6990 100644 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Services/OpenApiUrlTreeNodeTests.cs @@ -1,9 +1,10 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; using System.Collections.Generic; using System.IO; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Services; @@ -20,24 +21,24 @@ public class OpenApiUrlTreeNodeTests { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new(), + [HttpMethod.Get] = new(), } }, ["/houses"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new(), - [OperationType.Post] = new() + [HttpMethod.Get] = new(), + [HttpMethod.Post] = new() } }, ["/cars"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Post] = new() + [HttpMethod.Post] = new() } } } @@ -148,10 +149,10 @@ public void AttachPathWorks() var pathItem1 = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "motorcycles.ListMotorcycle", Responses = new() @@ -173,10 +174,10 @@ public void AttachPathWorks() var pathItem2 = new OpenApiPathItem { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "computers.ListComputer", Responses = new() @@ -240,10 +241,10 @@ public void HasOperationsWorks() ["/houses"] = new OpenApiPathItem(), ["/cars/{car-id}"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "cars.GetCar", Responses = new() @@ -268,10 +269,10 @@ public void HasOperationsWorks() { ["/cars/{car-id}"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation + HttpMethod.Get, new OpenApiOperation { OperationId = "cars.GetCar", Responses = new() @@ -286,7 +287,7 @@ public void HasOperationsWorks() } }, { - OperationType.Put, new OpenApiOperation + HttpMethod.Put, new OpenApiOperation { OperationId = "cars.UpdateCar", Responses = new() diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs index d11786d5b..90f88e378 100644 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs +++ b/test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Net.Http; using System.Text.Json; using System.Text.Json.Nodes; using Microsoft.OpenApi.Any; @@ -38,7 +39,7 @@ public void ResponseMustHaveADescription() { Operations = { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Responses = { diff --git a/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs b/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs index b9a73da40..1828ca470 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/OpenApiReferenceValidationTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -38,9 +39,9 @@ public void ReferencedSchemaShouldOnlyBeValidatedOnce() { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Responses = new() { @@ -92,9 +93,9 @@ public void UnresolvedSchemaReferencedShouldNotBeValidated() { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Responses = new() { diff --git a/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs b/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs index 44febe633..ee7252d42 100644 --- a/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Visitors/InheritanceTests.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Runtime.CompilerServices; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; @@ -28,7 +29,7 @@ public void ExpectedVirtualsInvolved() visitor.Visit(default(OpenApiPaths)); visitor.Visit(default(IOpenApiPathItem)); visitor.Visit(default(OpenApiServerVariable)); - visitor.Visit(default(IDictionary)); + visitor.Visit(default(IDictionary)); visitor.Visit(default(OpenApiOperation)); visitor.Visit(default(IList)); visitor.Visit(default(IOpenApiParameter)); @@ -142,7 +143,7 @@ public override void Visit(OpenApiServerVariable serverVariable) base.Visit(serverVariable); } - public override void Visit(IDictionary operations) + public override void Visit(IDictionary operations) { EncodeCall(); base.Visit(operations); diff --git a/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs b/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs index a2f66e0c8..feee331af 100644 --- a/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -68,9 +69,9 @@ public void LocatePathOperationContentSchema() var doc = new OpenApiDocument(); doc.Paths.Add("/test", new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Responses = new() { @@ -110,7 +111,7 @@ public void LocatePathOperationContentSchema() }, locator.Locations); - Assert.Equivalent(new List { "/test", "Get", "200", "application/json" }, locator.Keys); + Assert.Equivalent(new List { "/test", "GET", "200", "application/json" }, locator.Keys); } [Fact] @@ -177,9 +178,9 @@ public void LocateReferences() { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary + Operations = new Dictionary { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Responses = new() { diff --git a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs index 8c5478cf7..02c1cf07c 100644 --- a/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Net.Http; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; @@ -27,9 +28,9 @@ public void OpenApiWorkspacesCanAddComponentsFromAnotherDocument() { ["/"] = new OpenApiPathItem() { - Operations = new Dictionary() + Operations = new Dictionary() { - [OperationType.Get] = new OpenApiOperation() + [HttpMethod.Get] = new OpenApiOperation() { Responses = new OpenApiResponses() { @@ -156,7 +157,7 @@ public static OpenApiDocument CreatePathItem(this OpenApiDocument document, stri return document; } - public static OpenApiPathItem CreateOperation(this OpenApiPathItem parent, OperationType opType, Action config) + public static OpenApiPathItem CreateOperation(this OpenApiPathItem parent, HttpMethod opType, Action config) { var child = new OpenApiOperation(); config(child); diff --git a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs index 669f4cb13..1f4d45e81 100644 --- a/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs +++ b/test/Microsoft.OpenApi.Tests/Writers/OpenApiYamlWriterTests.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; @@ -390,7 +391,7 @@ public void WriteInlineSchema() // Act doc.SerializeAsV3(writer); - var mediaType = doc.Paths["/"].Operations[OperationType.Get].Responses["200"].Content["application/json"]; + var mediaType = doc.Paths["/"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"]; var actual = outputString.GetStringBuilder().ToString(); // Assert @@ -456,7 +457,7 @@ private static OpenApiDocument CreateDocWithSimpleSchemaToInline() ["/"] = new OpenApiPathItem() { Operations = { - [OperationType.Get] = new() + [HttpMethod.Get] = new() { Responses = { ["200"] = new OpenApiResponse()