diff --git a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_DictionaryObject_Tests.cs b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_DictionaryObject_Tests.cs index b0b2f18c..aca1db13 100644 --- a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_DictionaryObject_Tests.cs +++ b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_DictionaryObject_Tests.cs @@ -26,7 +26,7 @@ public async Task Init() } [DataTestMethod] - [DataRow("/get-applicationjson-dictionary", "get", "200")] + [DataRow("/get-applicationjson-dictionaryobject", "get", "200")] public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string path, string operationType, string responseCode) { var responses = this._doc["paths"][path][operationType]["responses"]; @@ -35,7 +35,7 @@ public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string } [DataTestMethod] - [DataRow("/get-applicationjson-dictionary", "get", "200", "application/json")] + [DataRow("/get-applicationjson-dictionaryobject", "get", "200", "application/json")] public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentType(string path, string operationType, string responseCode, string contentType) { var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"]; @@ -44,7 +44,7 @@ public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContent } [DataTestMethod] - [DataRow("/get-applicationjson-dictionary", "get", "200", "application/json", "dictionaryObjectModel")] + [DataRow("/get-applicationjson-dictionaryobject", "get", "200", "application/json", "dictionaryObjectModel")] public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchema(string path, string operationType, string responseCode, string contentType, string reference) { var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"]; diff --git a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_Dictionary_Tests.cs b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_Dictionary_Tests.cs new file mode 100644 index 00000000..b677c539 --- /dev/null +++ b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_Dictionary_Tests.cs @@ -0,0 +1,109 @@ +using System; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; + +using FluentAssertions; + +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests +{ + [TestClass] + [TestCategory(Constants.TestCategory)] + public class Get_ApplicationJson_Dictionary_Tests + { + private static HttpClient http = new HttpClient(); + + private JObject _doc; + + [TestInitialize] + public async Task Init() + { + var json = await http.GetStringAsync(Constants.OpenApiDocEndpoint).ConfigureAwait(false); + this._doc = JsonConvert.DeserializeObject(json); + } + + [DataTestMethod] + [DataRow("/get-applicationjson-dictionary")] + [DataRow("/get-applicationjson-dictionary-idictionary")] + [DataRow("/get-applicationjson-dictionary-ireadonlydictionary")] + [DataRow("/get-applicationjson-dictionary-keyvaluepair")] + public void Given_OpenApiDocument_Then_It_Should_Return_Path(string path) + { + var paths = this._doc["paths"]; + + paths.Value(path).Should().NotBeNull(); + } + + [DataTestMethod] + [DataRow("/get-applicationjson-dictionary", "get")] + [DataRow("/get-applicationjson-dictionary-idictionary", "get")] + [DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get")] + [DataRow("/get-applicationjson-dictionary-keyvaluepair", "get")] + public void Given_OpenApiDocument_Then_It_Should_Return_OperationType(string path, string operationType) + { + var pathItem = this._doc["paths"][path]; + + pathItem.Value(operationType).Should().NotBeNull(); + } + + [DataTestMethod] + [DataRow("/get-applicationjson-dictionary", "get", "200")] + [DataRow("/get-applicationjson-dictionary-idictionary", "get", "200")] + [DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get", "200")] + [DataRow("/get-applicationjson-dictionary-keyvaluepair", "get", "200")] + public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string path, string operationType, string responseCode) + { + var responses = this._doc["paths"][path][operationType]["responses"]; + + responses[responseCode].Should().NotBeNull(); + } + + [DataTestMethod] + [DataRow("/get-applicationjson-dictionary", "get", "200", "application/json")] + [DataRow("/get-applicationjson-dictionary-idictionary", "get", "200", "application/json")] + [DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get", "200", "application/json")] + [DataRow("/get-applicationjson-dictionary-keyvaluepair", "get", "200", "application/json")] + public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentType(string path, string operationType, string responseCode, string contentType) + { + var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"]; + + content[contentType].Should().NotBeNull(); + } + + [DataTestMethod] + [DataRow("/get-applicationjson-dictionary", "get", "200", "application/json", "object")] + [DataRow("/get-applicationjson-dictionary-idictionary", "get", "200", "application/json","object")] + [DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get", "200", "application/json", "object")] + [DataRow("/get-applicationjson-dictionary-keyvaluepair", "get", "200", "application/json", "object")] + public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchemaType(string path, string operationType, string responseCode, string contentType, string itemType) + { + var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"]; + var schema = content[contentType]["schema"]; + + var type = schema["type"]; + + type.Value().Should().Be(itemType); + } + + [DataTestMethod] + [DataRow("/get-applicationjson-dictionary", "get", "200", "application/json", "object", "string")] + [DataRow("/get-applicationjson-dictionary-idictionary", "get", "200", "application/json", "object", "integer")] + [DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get", "200", "application/json", "object", "number")] + [DataRow("/get-applicationjson-dictionary-keyvaluepair", "get", "200", "application/json", "object", "boolean")] + public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchemaPropertiesType(string path, string operationType, string responseCode, string contentType, string dataType, string itemType) + { + var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"]; + var schema = content[contentType]["schema"]; + + var additionaltype = schema["additionalProperties"]["type"]; + + additionaltype.Value().Should().Be(itemType); + } + + } +} \ No newline at end of file diff --git a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Get_ApplicationJson_DictionaryObject_HttpTrigger.cs b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Get_ApplicationJson_DictionaryObject_HttpTrigger.cs index 1e5bb5db..465ba73e 100644 --- a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Get_ApplicationJson_DictionaryObject_HttpTrigger.cs +++ b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Get_ApplicationJson_DictionaryObject_HttpTrigger.cs @@ -16,7 +16,7 @@ public class Get_ApplicationJson_DictionaryObject_HttpTrigger [OpenApiOperation(operationId: nameof(Get_ApplicationJson_DictionaryObject_HttpTrigger.Get_ApplicationJson_DictionaryObject), tags: new[] { "dictionary" })] [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(DictionaryObjectModel), Description = "The OK response")] public static async Task Get_ApplicationJson_DictionaryObject( - [HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary")] HttpRequest req, + [HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionaryobject")] HttpRequest req, ILogger log) { var result = new OkResult(); diff --git a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Get_ApplicationJson_Dictionary_HttpTrigger.cs b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Get_ApplicationJson_Dictionary_HttpTrigger.cs new file mode 100644 index 00000000..a2d03773 --- /dev/null +++ b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Get_ApplicationJson_Dictionary_HttpTrigger.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using System.Net; +using System.Threading.Tasks; + +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes; +using Microsoft.Extensions.Logging; + +namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp +{ + public class Get_ApplicationJson_Dictionary_HttpTrigger + { + [FunctionName(nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary))] + [OpenApiOperation(operationId: nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary), tags: new[] { "dictionary" })] + [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Dictionary), Description = "The OK response")] + public static async Task Get_ApplicationJson_Dictionary( + [HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary")] HttpRequest req, + ILogger log) + { + var result = new OkResult(); + + return await Task.FromResult(result).ConfigureAwait(false); + } + + [FunctionName(nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_IDictionary))] + [OpenApiOperation(operationId: nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_IDictionary), tags: new[] { "dictionary" })] + [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(IDictionary), Description = "The OK response")] + public static async Task Get_ApplicationJson_Dictionary_IDictionary( + [HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary-idictionary")] HttpRequest req, + ILogger log) + { + var result = new OkResult(); + + return await Task.FromResult(result).ConfigureAwait(false); + } + + [FunctionName(nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_IReadOnlyDictionary))] + [OpenApiOperation(operationId: nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_IReadOnlyDictionary), tags: new[] { "dictionary" })] + [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(IReadOnlyDictionary), Description = "The OK response")] + public static async Task Get_ApplicationJson_Dictionary_IReadOnlyDictionary( + [HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary-ireadonlydictionary")] HttpRequest req, + ILogger log) + { + var result = new OkResult(); + + return await Task.FromResult(result).ConfigureAwait(false); + } + + [FunctionName(nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_KeyValuePair))] + [OpenApiOperation(operationId: nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_KeyValuePair), tags: new[] { "dictionary" })] + [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(KeyValuePair), Description = "The OK response")] + public static async Task Get_ApplicationJson_Dictionary_KeyValuePair( + [HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary-keyvaluepair")] HttpRequest req, + ILogger log) + { + var result = new OkResult(); + + return await Task.FromResult(result).ConfigureAwait(false); + } + } + +}