-
Notifications
You must be signed in to change notification settings - Fork 197
Fix Data Member Attribute json Serialized Model Casing Applied[#212] #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 37 commits
d644927
961996a
5318e30
07bd093
cadd264
ef9d50c
b0c765d
98016f6
7386eb7
6dd4bc5
3be68b4
f598263
6e35cdd
b1e2a47
a753273
ac8eb89
82f8b68
d72ca9e
f0c26b4
1b0c61c
379cb79
02ca0f4
067cf84
8fa4915
b97e380
cfe23f0
7454af6
01c7f39
5f082e2
7c21d6d
508b331
3b1f34d
ab318a1
7d74a4f
6c512b7
52a8213
f931eca
899933e
e9b5a0e
1b3ee68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| 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_DataMember_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<JObject>(json); | ||
| } | ||
|
|
||
| [DataTestMethod] | ||
| [DataRow("/get-applicationjson-datamember", "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-datamember", "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-datamember", "get", "200", "application/json", "dataMemberObjectModel")] | ||
| 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"]; | ||
|
|
||
| var @ref = content[contentType]["schema"]["$ref"]; | ||
|
|
||
| @ref.Value<string>().Should().Be($"#/components/schemas/{reference}"); | ||
| } | ||
|
|
||
| [DataTestMethod] | ||
| [DataRow("dataMemberObjectModel", "object")] | ||
| public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchema(string @ref, string refType) | ||
| { | ||
| var schemas = this._doc["components"]["schemas"]; | ||
|
|
||
| var schema = schemas[@ref]; | ||
|
|
||
| schema.Should().NotBeNull(); | ||
| schema.Value<string>("type").Should().Be(refType); | ||
| } | ||
|
|
||
| [DataTestMethod] | ||
| [DataRow("dataMemberObjectModel", "object", "DataMemberValue1", "string", null)] | ||
| [DataRow("dataMemberObjectModel", "object", "DataMemberValue2", "integer", "int32")] | ||
| [DataRow("dataMemberObjectModel", "object", "DataMemberValue3", "string", "date-time")] | ||
| [DataRow("dataMemberObjectModel", "object", "DataMemberValue4", "boolean", null)] | ||
| [DataRow("dataMemberObjectModel", "object", "DataMemberValue5", "number", "double")] | ||
| public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchemaProperty(string @ref, string refType, string propertyName, string propertyType, string propertyFormat) | ||
| { | ||
| var properties = this._doc["components"]["schemas"][@ref]["properties"]; | ||
|
|
||
| var value = properties[propertyName]; | ||
|
|
||
| value.Should().NotBeNull(); | ||
| value.Value<string>("type").Should().Be(propertyType); | ||
| value.Value<string>("format").Should().Be(propertyFormat); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| 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.Azure.WebJobs.Extensions.OpenApi.TestApp.Models; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp | ||
| { | ||
| public static class Get_ApplicationJson_DataMemberObject_HttpTrigger | ||
|
||
| { | ||
| [FunctionName(nameof(Get_ApplicationJson_DataMemberObject_HttpTrigger))] | ||
| [OpenApiOperation(operationId: nameof(Get_ApplicationJson_DataMemberObject_HttpTrigger.Get_ApplicationJson_DataMemberObject), tags: new[] { "datamember" })] | ||
| [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(DataMemberObjectModel), Description = "The OK response")] | ||
| public static async Task<IActionResult> Get_ApplicationJson_DataMemberObject( | ||
| [HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-datamember")] HttpRequest req, | ||
| ILogger log) | ||
| { | ||
| var result = new OkResult(); | ||
|
|
||
| return await Task.FromResult(result).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using Newtonsoft.Json; | ||
| using System; | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp.Models | ||
| { | ||
| public class DataMemberObjectModel | ||
|
||
| { | ||
| [DataMember(Name = "DataMemberValue1")] | ||
|
||
| public string DataMemberValue1 { get; set; } | ||
|
|
||
| [DataMember(Name = "DataMemberValue2")] | ||
| public int DataMemberValue2 { get; set; } | ||
|
|
||
| [DataMember(Name = "DataMemberValue3")] | ||
| public DateTime DataMemberValue3 { get; set; } | ||
|
|
||
| [DataMember(Name = "DataMemberValue4")] | ||
| public bool DataMemberValue4 { get; set; } | ||
|
|
||
| [DataMember(Name = "DataMemberValue5")] | ||
| public double DataMemberValue5 { get; set; } | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create another test class,
Get_ApplicationJson_JsonProperty_Tests?