Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d644927
fix Nullable DateTime type to display as date format in specification
choipureum Aug 23, 2021
961996a
Add a testcase for Nullable DateTime type
choipureum Aug 24, 2021
5318e30
Merge branch 'Azure:main' into main
choipureum Aug 29, 2021
07bd093
Merge branch 'Azure:main' into main
choipureum Sep 1, 2021
cadd264
Add DataType Integration Test
choipureum Sep 2, 2021
ef9d50c
Update DateType Integration_Test
choipureum Sep 2, 2021
b0c765d
Modified ContentType for DataType_Integration Test
choipureum Sep 2, 2021
98016f6
Fix tag for DataType Integration Test HttpTrigger
choipureum Sep 2, 2021
7386eb7
Merge branch 'Azure:main' into main
choipureum Sep 2, 2021
6dd4bc5
Merge branch 'Azure:main' into main
choipureum Sep 5, 2021
3be68b4
Merge branch 'Azure:main' into main
choipureum Sep 8, 2021
f598263
Merge branch 'Azure:main' into main
choipureum Sep 15, 2021
6e35cdd
Adding query string/path Examples
choipureum Sep 15, 2021
b1e2a47
Add IntegrationTest : query string/path parameter examples
choipureum Sep 15, 2021
a753273
Fix OpenApiParamter Example keyword
choipureum Sep 16, 2021
ac8eb89
Add string/path Paramter Example Integration Test
choipureum Sep 16, 2021
82f8b68
Update ParameterModelExample
choipureum Sep 16, 2021
d72ca9e
Update query string/path Examples
choipureum Sep 23, 2021
f0c26b4
Fix Conflict
choipureum Sep 23, 2021
1b0c61c
Fix Conflict
choipureum Sep 23, 2021
379cb79
Merge branch 'Azure:main' into main
choipureum Sep 23, 2021
02ca0f4
Merge branch 'Azure:main' into main
choipureum Sep 23, 2021
067cf84
Fix query string/path Examples code
choipureum Sep 24, 2021
8fa4915
Add ParameterExample FakeModel, UnitTest
choipureum Sep 24, 2021
b97e380
Add ParameterExample Integration Tests
choipureum Sep 24, 2021
cfe23f0
Fix OpenApiExampleTests typos
choipureum Sep 24, 2021
7454af6
Merge branch 'Azure:main' into main
choipureum Sep 25, 2021
01c7f39
Add DataTimeOffset type parameter Example
choipureum Sep 25, 2021
5f082e2
Merge branch 'Azure:main' into main
choipureum Oct 1, 2021
7c21d6d
Add guid and bytearray type to parameter example function
choipureum Oct 1, 2021
508b331
Fix openApiExampleFactory
choipureum Oct 1, 2021
3b1f34d
Merge branch 'Azure:main' into main
choipureum Oct 1, 2021
ab318a1
Merge branch 'Azure:main' into main
choipureum Oct 1, 2021
7d74a4f
Merge branch 'Azure:main' into main
choipureum Oct 1, 2021
6c512b7
Merge branch 'Azure:main' into main
choipureum Oct 5, 2021
52a8213
Fix ModelCasing DataMemberAttribute
choipureum Oct 5, 2021
f931eca
Add DataMemberAttribute unit test
choipureum Oct 5, 2021
899933e
Merge branch 'Azure:main' into FixModelCasing
choipureum Oct 12, 2021
e9b5a0e
Change Class Name and testcase
choipureum Oct 12, 2021
1b3ee68
Merge branch 'Azure:main' into FixModelCasing
choipureum Oct 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Reflection;

using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

Expand All @@ -23,11 +23,23 @@ public static bool HasJsonPropertyAttribute(this PropertyInfo element)
}

/// <summary>
/// Gets the name from <see cref="JsonPropertyAttribute"/> instance.
/// Checks whether the given <see cref="PropertyInfo"/> object has <see cref="DataMemberAttribute"/> or not.
/// </summary>
/// <param name="element"><see cref="PropertyInfo"/> instance.</param>
/// <returns>Returns <c>True</c>, if the given <see cref="PropertyInfo"/> object has <see cref="DataMemberAttribute"/>; otherwise, returns <c>False</c>.</returns>
public static bool HasDataMemberAttribute(this PropertyInfo element)
{
var exists = element.ExistsCustomAttribute<DataMemberAttribute>();

return exists;
}

/// <summary>
/// Gets the name from <see cref="JsonPropertyAttribute"/> or <see cref="DataMemberAttribute"/> instance.
/// </summary>
/// <param name="element"><see cref="PropertyInfo"/> instance.</param>
/// <param name="namingStrategy"><see cref="NamingStrategy"/> instance.</param>
/// <returns>Returns the name from <see cref="JsonPropertyAttribute"/> instance.</returns>
/// <returns>Returns the name from <see cref="JsonPropertyAttribute"/> or <see cref="DataMemberAttribute"/> instance.</returns>
public static string GetJsonPropertyName(this PropertyInfo element, NamingStrategy namingStrategy = null)
{
if (namingStrategy.IsNullOrDefault())
Expand All @@ -43,6 +55,14 @@ public static string GetJsonPropertyName(this PropertyInfo element, NamingStrate

}

if (element.HasDataMemberAttribute())
{
var name = element.GetCustomAttribute<DataMemberAttribute>().Name ?? namingStrategy.GetPropertyName(element.Name, hasSpecifiedName: false);

return name;

}

return namingStrategy.GetPropertyName(element.Name, hasSpecifiedName: false);
}
}
Expand Down
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
Copy link
Contributor

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?

{
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create another one for Get_ApplicationJson_JsonPropertyObject_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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create another class/file for JsonPropertyObjectModel for another test?

{
[DataMember(Name = "DataMemberValue1")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're testing the property naming, can we set these property names in some weird ways like DAtAmeMBervALue1 so that it's rendered as expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried a variety of things.Thank you always for the reviews! 😊

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; }

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Runtime.Serialization;

namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes
{
Expand All @@ -25,6 +26,9 @@ public class FakeModel
[JsonProperty]
public string FakePropertyNoAnnotation { get; set; }

[DataMember(Name = "anotherDataMemberFakeProperty")]
public string DataMemberFakeProperty { get; set; }

public object FakeObject { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public void Given_Property_When_GetJsonPropertyName_Invoked_Then_It_Should_Retur
result.Should().Be(jsonPropertyName);
}

[TestMethod]
public void Given_Property_When_GetDataMemberName_Invoked_Then_It_Should_Return_DataMemberName()
{
var name = "DataMemberFakeProperty";
var jsonPropertyName = "anotherDataMemberFakeProperty";
var property = typeof(FakeModel).GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
var namingStrategy = new DefaultNamingStrategy();

var result = PropertyInfoExtensions.GetJsonPropertyName(property, namingStrategy);

result.Should().Be(jsonPropertyName);
}

[TestMethod]
public void Given_Property_When_GetJsonPropertyName_IsEmpty_Then_It_Should_Return_ElementName()
{
Expand Down