Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -22,9 +22,9 @@ public static class DummyHttpTrigger
[OpenApiParameter(name: "name", In = ParameterLocation.Query, Required = true, Type = typeof(string), Summary = "Dummy name", Description = "Dummy name", Visibility = OpenApiVisibilityType.Important)]
[OpenApiParameter(name: "switch", In = ParameterLocation.Query, Required = true, Type = typeof(bool), Summary = "Dummy switch", Description = "Dummy switch", Visibility = OpenApiVisibilityType.Important, Deprecated = true)]
[OpenApiParameter(name: "onoff", In = ParameterLocation.Path, Required = true, Type = typeof(StringEnum), Summary = "Dummy switch", Description = "Dummy switch", Visibility = OpenApiVisibilityType.Important)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<DummyResponseModel>), Summary = "List of the dummy responses", Description = "This returns the list of dummy responses", HeaderType = typeof(DummyResponseHeaderType))]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.NotFound, Summary = "Name not found", Description = "Name parameter is not found", HeaderType = typeof(DummyResponseHeaderType))]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid switch", Description = "Switch parameter is not valid", HeaderType = typeof(DummyResponseHeaderType))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<DummyResponseModel>), Summary = "List of the dummy responses", Description = "This returns the list of dummy responses", CustomHeaderType = typeof(DummyResponseHeader))]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.NotFound, Summary = "Name not found", Description = "Name parameter is not found", CustomHeaderType = typeof(DummyResponseHeader))]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid switch", Description = "Switch parameter is not valid", CustomHeaderType = typeof(DummyResponseHeader))]
public static async Task<IActionResult> GetDummies(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "dummies/{onoff}")] HttpRequest req,
string onoff,
Expand All @@ -43,8 +43,8 @@ public static async Task<IActionResult> GetDummies(
[OpenApiOperation(operationId: "addDummy", tags: new[] { "dummy" }, Summary = "Adds a dummy", Description = "This adds a dummy.", Visibility = OpenApiVisibilityType.Advanced, Deprecated = true)]
[OpenApiSecurity("openid_auth", SecuritySchemeType.OpenIdConnect, OpenIdConnectUrl = "https://example.com/.well-known/openid-configuration", OpenIdConnectScopes = "pets_read, pets_write, admin")]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(DummyRequestModel), Required = true, Description = "Dummy request model")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(DummyResponseModel), Summary = "Dummy response", Description = "This returns the dummy response", HeaderType = typeof(DummyResponseHeaderType))]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid request payload", Description = "Request payload is not valid", HeaderType = typeof(DummyResponseHeaderType))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(DummyResponseModel), Summary = "Dummy response", Description = "This returns the dummy response", CustomHeaderType = typeof(DummyResponseHeader))]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid request payload", Description = "Request payload is not valid", CustomHeaderType = typeof(DummyResponseHeader))]
public static async Task<IActionResult> AddDummy(
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "dummies")] HttpRequest req,
ILogger log)
Expand All @@ -59,8 +59,8 @@ public static async Task<IActionResult> AddDummy(
[OpenApiOperation(operationId: "updateDummies", tags: new[] { "dummy" }, Summary = "Updates a list of dummies", Description = "This updates a list of dummies.", Visibility = OpenApiVisibilityType.Advanced)]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(DummyListModel), Required = true, Description = "Dummy list model")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<DummyStringModel>), Summary = "Dummy response", Description = "This returns the dummy response", HeaderType = typeof(DummyResponseHeaderType))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(DummyStringModel), Summary = "Dummy response", Description = "This returns the dummy response", Deprecated = true, HeaderType = typeof(DummyResponseHeaderType))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<DummyStringModel>), Summary = "Dummy response", Description = "This returns the dummy response", CustomHeaderType = typeof(DummyResponseHeader))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(DummyStringModel), Summary = "Dummy response", Description = "This returns the dummy response", Deprecated = true, CustomHeaderType = typeof(DummyResponseHeader))]
public static async Task<IActionResult> UpdateDummies(
[HttpTrigger(AuthorizationLevel.Function, "PUT", Route = "dummies")] HttpRequest req,
ILogger log)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;

using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core;
using Microsoft.OpenApi.Models;

namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3Static.ResponseHeaders
{
public class DummyResponseHeaderType : IOpenApiResponseHeaderType
public class DummyResponseHeader : IOpenApiCustomResponseHeader
{
public Dictionary<string, OpenApiHeader> Headers { get; set; } = new Dictionary<string, OpenApiHeader>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public OpenApiResponseWithBodyAttribute(HttpStatusCode statusCode, string conten
/// <summary>
/// Gets or sets the type containing the collection of the additional response headers.
/// </summary>
public virtual Type HeaderType { get; set; }
public virtual Type CustomHeaderType { get; set; }

/// <summary>
/// Gets or sets the summary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public OpenApiResponseWithoutBodyAttribute(HttpStatusCode statusCode)
/// <summary>
/// Gets or sets the type containing the collection of the additional response headers.
/// </summary>
public virtual Type HeaderType { get; set; }
public virtual Type CustomHeaderType { get; set; }

/// <summary>
/// Gets or sets the summary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;

using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -41,9 +40,9 @@ public static OpenApiResponse ToOpenApiResponse(this OpenApiResponseWithBodyAttr
Content = content,
};

if (attribute.HeaderType.HasInterface<IOpenApiResponseHeaderType>())
if (attribute.CustomHeaderType.HasInterface<IOpenApiCustomResponseHeader>())
{
var header = Activator.CreateInstance(attribute.HeaderType) as IOpenApiResponseHeaderType;
var header = Activator.CreateInstance(attribute.CustomHeaderType) as IOpenApiCustomResponseHeader;

response.Headers = header.Headers;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;

using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;

Expand Down Expand Up @@ -39,9 +38,9 @@ public static OpenApiResponse ToOpenApiResponse(this OpenApiResponseWithoutBodyA
response.Extensions.Add("x-ms-summary", summary);
}

if (attribute.HeaderType.HasInterface<IOpenApiResponseHeaderType>())
if (attribute.CustomHeaderType.HasInterface<IOpenApiCustomResponseHeader>())
{
var header = Activator.CreateInstance(attribute.HeaderType) as IOpenApiResponseHeaderType;
var header = Activator.CreateInstance(attribute.CustomHeaderType) as IOpenApiCustomResponseHeader;

response.Headers = header.Headers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

using Microsoft.OpenApi.Models;

namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core
{
/// <summary>
/// This provides interfaces to classes implementing OpenAPI response object.
/// </summary>
public interface IOpenApiResponseHeaderType
public interface IOpenApiCustomResponseHeader
{
/// <summary>
/// Gets or sets the collection of the <see cref="OpenApiHeader"/> instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes
{
public static class FakeFunctions
{
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<FakeClassModel>), Summary = "List of the fake responses", Description = "This returns the list of fake responses", HeaderType = typeof(FakeResponseHeaderType))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<FakeClassModel>), Summary = "List of the fake responses", Description = "This returns the list of fake responses", CustomHeaderType = typeof(FakeResponseHeader))]
public static void GetFakes()
{
}

[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(FakeClassModel), Required = true, Description = "Fake request model")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(FakeClassModel), Summary = "Fake response", Description = "This returns the fake response", HeaderType = typeof(FakeResponseHeaderType))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(FakeClassModel), Summary = "Fake response", Description = "This returns the fake response", CustomHeaderType = typeof(FakeResponseHeader))]
public static void AddFakes()
{
}

[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(FakeListModel), Required = true, Description = "Fake list model")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<FakeStringModel>), Summary = "Fake response", Description = "This returns the fake response", HeaderType = typeof(FakeResponseHeaderType))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(FakeStringModel), Summary = "Fake response", Description = "This returns the fake response", Deprecated = true, HeaderType = typeof(FakeResponseHeaderType))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<FakeStringModel>), Summary = "Fake response", Description = "This returns the fake response", CustomHeaderType = typeof(FakeResponseHeader))]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(FakeStringModel), Summary = "Fake response", Description = "This returns the fake response", Deprecated = true, CustomHeaderType = typeof(FakeResponseHeader))]
public static void UpdateFakes()
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Collections.Generic;

using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.OpenApi.Models;

namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes
{
public class FakeResponseHeaderType : IOpenApiResponseHeaderType
public class FakeResponseHeader : IOpenApiCustomResponseHeader
{
/// <inheritdoc/>
public Dictionary<string, OpenApiHeader> Headers { get; set; } = new Dictionary<string, OpenApiHeader>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void Given_Parameters_When_Instantiated_Then_It_Should_Return_Value(HttpS
}

[DataTestMethod]
[DataRow("Lorem Ipsum", "Hello World", true, typeof(FakeResponseHeaderType))]
[DataRow("Lorem Ipsum", "Hello World", false, typeof(FakeResponseHeaderType))]
[DataRow("Lorem Ipsum", "Hello World", true, typeof(FakeResponseHeader))]
[DataRow("Lorem Ipsum", "Hello World", false, typeof(FakeResponseHeader))]
public void Given_Properties_When_Instantiated_Then_It_Should_Return_Value(string summary, string description, bool deprecated, Type headerType)
{
var statusCode = HttpStatusCode.OK;
Expand All @@ -48,13 +48,13 @@ public void Given_Properties_When_Instantiated_Then_It_Should_Return_Value(strin
Summary = summary,
Description = description,
Deprecated = deprecated,
HeaderType = headerType,
CustomHeaderType = headerType,
};

attribute.Summary.Should().Be(summary);
attribute.Description.Should().Be(description);
attribute.Deprecated.Should().Be(deprecated);
attribute.HeaderType.Should().Be(headerType);
attribute.CustomHeaderType.Should().Be(headerType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public void Given_Parameters_When_Instantiated_Then_It_Should_Return_Value()
}

[DataTestMethod]
[DataRow("Hello World", "Lorem Ipsum", typeof(FakeResponseHeaderType))]
[DataRow("Hello World", "Lorem Ipsum", typeof(FakeResponseHeader))]
public void Given_Properties_When_Instantiated_Then_It_Should_Return_Value(string summary, string description, Type headerType)
{
var statusCode = HttpStatusCode.OK;
var attribute = new OpenApiResponseWithoutBodyAttribute(statusCode)
{
Summary = summary,
Description = description,
HeaderType = headerType,
CustomHeaderType = headerType,
};

attribute.Summary.Should().Be(summary);
attribute.Description.Should().Be(description);
attribute.HeaderType.Should().Be(headerType);
attribute.CustomHeaderType.Should().Be(headerType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Given_Null_When_ToOpenApiResponse_Invoked_Then_It_Should_Throw_Excep
}

[DataTestMethod]
[DataRow("Lorem Ipsum", "Hello World", typeof(FakeResponseHeaderType))]
[DataRow("Lorem Ipsum", "Hello World", typeof(FakeResponseHeader))]
public void Given_Properties_When_ToOpenApiResponse_Invoked_Then_It_Should_Return_Value(string summary, string description, Type headerType)
{
var statusCode = HttpStatusCode.OK;
Expand All @@ -33,7 +33,7 @@ public void Given_Properties_When_ToOpenApiResponse_Invoked_Then_It_Should_Retur
{
Summary = summary,
Description = description,
HeaderType = headerType,
CustomHeaderType = headerType,
};

var result = OpenApiResponseWithBodyAttributeExtensions.ToOpenApiResponse(attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public void Given_Null_When_ToOpenApiResponse_Invoked_Then_It_Should_Throw_Excep
}

[DataTestMethod]
[DataRow("Lorem Ipsum", "Hello World", typeof(FakeResponseHeaderType))]
[DataRow("Lorem Ipsum", "Hello World", typeof(FakeResponseHeader))]
public void Given_Properties_When_ToOpenApiResponse_Invoked_Then_It_Should_Return_Value(string summary, string description, Type headerType)
{
var statusCode = HttpStatusCode.OK;
var attribute = new OpenApiResponseWithoutBodyAttribute(statusCode)
{
Summary = summary,
Description = description,
HeaderType = headerType,
CustomHeaderType = headerType,
};

var result = OpenApiResponseWithoutBodyAttributeExtensions.ToOpenApiResponse(attribute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using FluentAssertions;

using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -142,35 +141,35 @@ public void Given_Type_When_IsReferentialType_Invoked_Then_It_Should_Return_Resu
[TestMethod]
public void Given_Null_When_HasInterface_Invoked_Then_It_Should_Return_False()
{
var result = TypeExtensions.HasInterface<IOpenApiResponseHeaderType>(null);
var result = TypeExtensions.HasInterface<IOpenApiCustomResponseHeader>(null);
result.Should().BeFalse();

result = TypeExtensions.HasInterface(null, "IOpenApiResponseHeaderType");
result = TypeExtensions.HasInterface(null, "IOpenApiCustomResponseHeader");
result.Should().BeFalse();
}

[TestMethod]
public void Given_Invalid_TypeReference_When_HasInterface_Invoked_Then_It_Should_Return_Result()
{
var result = TypeExtensions.HasInterface<IOpenApiResponseHeaderType>(typeof(FakeModel));
var result = TypeExtensions.HasInterface<IOpenApiCustomResponseHeader>(typeof(FakeModel));

result.Should().BeFalse();
}

[TestMethod]
public void Given_Valid_TypeReference_When_HasInterface_Invoked_Then_It_Should_Return_Result()
{
var result = TypeExtensions.HasInterface<IOpenApiResponseHeaderType>(typeof(FakeResponseHeaderType));
var result = TypeExtensions.HasInterface<IOpenApiCustomResponseHeader>(typeof(FakeResponseHeader));

result.Should().BeTrue();
}

[DataTestMethod]
[DataRow(typeof(FakeModel), false)]
[DataRow(typeof(FakeResponseHeaderType), true)]
[DataRow(typeof(FakeResponseHeader), true)]
public void Given_Type_When_HasInterface_Invoked_Then_It_Should_Return_Result(Type type, bool expected)
{
var result = TypeExtensions.HasInterface(type, "IOpenApiResponseHeaderType");
var result = TypeExtensions.HasInterface(type, "IOpenApiCustomResponseHeader");

result.Should().Be(expected);
}
Expand Down