-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
216 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/Aliencube.AzureFunctions.Extensions.OpenApi/Attributes/OpenApiResponseBodyAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...liencube.AzureFunctions.Extensions.OpenApi/Attributes/OpenApiResponseWithBodyAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Net; | ||
|
||
namespace Aliencube.AzureFunctions.Extensions.OpenApi.Attributes | ||
{ | ||
/// <summary> | ||
/// This represents the attribute entity for HTTP triggers to define response body payload. | ||
/// </summary> | ||
|
||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)] | ||
public class OpenApiResponseWithBodyAttribute : OpenApiPayloadAttribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OpenApiResponseWithBodyAttribute"/> class. | ||
/// </summary> | ||
/// <param name="statusCode">HTTP status code.</param> | ||
/// <param name="contentType">Content type.</param> | ||
/// <param name="bodyType">Type of payload.</param> | ||
public OpenApiResponseWithBodyAttribute(HttpStatusCode statusCode, string contentType, Type bodyType) | ||
: base(contentType, bodyType) | ||
{ | ||
this.StatusCode = statusCode; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the HTTP status code value. | ||
/// </summary> | ||
public virtual HttpStatusCode StatusCode { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the summary. | ||
/// </summary> | ||
public virtual string Summary { get; set; } | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ncube.AzureFunctions.Extensions.OpenApi/Attributes/OpenApiResponseWithoutBodyAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Net; | ||
|
||
namespace Aliencube.AzureFunctions.Extensions.OpenApi.Attributes | ||
{ | ||
/// <summary> | ||
/// This represents the attribute entity for HTTP triggers to define response body payload. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)] | ||
public class OpenApiResponseWithoutBodyAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OpenApiResponseWithoutBodyAttribute"/> class. | ||
/// </summary> | ||
/// <param name="statusCode">HTTP status code.</param> | ||
public OpenApiResponseWithoutBodyAttribute(HttpStatusCode statusCode) | ||
{ | ||
this.StatusCode = statusCode; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the HTTP status code value. | ||
/// </summary> | ||
public virtual HttpStatusCode StatusCode { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the summary. | ||
/// </summary> | ||
public virtual string Summary { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the description. | ||
/// </summary> | ||
public virtual string Description { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...eFunctions.Extensions.OpenApi/Extensions/OpenApiResponseWithoutBodyAttributeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Aliencube.AzureFunctions.Extensions.OpenApi.Attributes; | ||
|
||
using Microsoft.OpenApi.Any; | ||
using Microsoft.OpenApi.Models; | ||
|
||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace Aliencube.AzureFunctions.Extensions.OpenApi.Extensions | ||
{ | ||
/// <summary> | ||
/// This represents the extension entity for <see cref="OpenApiResponseWithoutBodyAttribute"/>. | ||
/// </summary> | ||
public static class OpenApiResponseWithoutBodyAttributeExtensions | ||
{ | ||
/// <summary> | ||
/// Converts <see cref="OpenApiResponseWithoutBodyAttribute"/> to <see cref="OpenApiResponse"/>. | ||
/// </summary> | ||
/// <param name="attribute"><see cref="OpenApiResponseWithoutBodyAttribute"/> instance.</param> | ||
/// <param name="namingStrategy"><see cref="NamingStrategy"/> instance to create the JSON schema from .NET Types.</param> | ||
/// <returns><see cref="OpenApiResponse"/> instance.</returns> | ||
public static OpenApiResponse ToOpenApiResponse(this OpenApiResponseWithoutBodyAttribute attribute, NamingStrategy namingStrategy = null) | ||
{ | ||
attribute.ThrowIfNullOrDefault(); | ||
|
||
var description = string.IsNullOrWhiteSpace(attribute.Description) | ||
? "No description" | ||
: attribute.Description; | ||
var response = new OpenApiResponse() | ||
{ | ||
Description = description, | ||
}; | ||
|
||
if (!string.IsNullOrWhiteSpace(attribute.Summary)) | ||
{ | ||
var summary = new OpenApiString(attribute.Summary); | ||
|
||
response.Extensions.Add("x-ms-summary", summary); | ||
} | ||
|
||
return response; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.