Skip to content

Commit

Permalink
Merge branch 'dev' into release/swagger-2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo committed Jul 19, 2020
2 parents a2ef046 + 91a020d commit 97f0a02
Show file tree
Hide file tree
Showing 33 changed files with 895 additions and 18 deletions.
15 changes: 13 additions & 2 deletions Aliencube.AzureFunctions.Extensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aliencube.AzureFunctions.Fu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aliencube.AzureFunctions.FunctionAppV1IoC", "samples\Aliencube.AzureFunctions.FunctionAppV1IoC\Aliencube.AzureFunctions.FunctionAppV1IoC.csproj", "{7FD855AB-EB0E-42AE-A26D-E164D375D6A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aliencube.AzureFunctions.FunctionAppV2Static", "samples\Aliencube.AzureFunctions.FunctionAppV2Static\Aliencube.AzureFunctions.FunctionAppV2Static.csproj", "{848EDB8F-9C45-462B-A544-EA237774F3BA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aliencube.AzureFunctions.FunctionAppV2Static", "samples\Aliencube.AzureFunctions.FunctionAppV2Static\Aliencube.AzureFunctions.FunctionAppV2Static.csproj", "{848EDB8F-9C45-462B-A544-EA237774F3BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aliencube.AzureFunctions.FunctionAppV2IoC", "samples\Aliencube.AzureFunctions.FunctionAppV2IoC\Aliencube.AzureFunctions.FunctionAppV2IoC.csproj", "{D6C3806E-2685-4E8D-9F4F-7A93E5270891}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aliencube.AzureFunctions.FunctionAppV2IoC", "samples\Aliencube.AzureFunctions.FunctionAppV2IoC\Aliencube.AzureFunctions.FunctionAppV2IoC.csproj", "{D6C3806E-2685-4E8D-9F4F-7A93E5270891}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{56A43630-87E6-4E94-B24A-859258202578}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenApiEndpoints", "OpenApiEndpoints", "{41695443-A292-4909-89A6-2D9846753164}"
ProjectSection(SolutionItems) = preProject
templates\OpenApiEndpints\IOpenApiHttpTriggerContext.cs = templates\OpenApiEndpints\IOpenApiHttpTriggerContext.cs
templates\OpenApiEndpints\OpenApiHttpTrigger.cs = templates\OpenApiEndpints\OpenApiHttpTrigger.cs
templates\OpenApiEndpints\OpenApiHttpTriggerContext.cs = templates\OpenApiEndpints\OpenApiHttpTriggerContext.cs
templates\OpenApiEndpints\OpenApiHttpTriggerV1.cs = templates\OpenApiEndpints\OpenApiHttpTriggerV1.cs
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -220,6 +230,7 @@ Global
{7FD855AB-EB0E-42AE-A26D-E164D375D6A5} = {66D8DEA8-B477-497F-95BB-E8F9A5BAC352}
{848EDB8F-9C45-462B-A544-EA237774F3BA} = {66D8DEA8-B477-497F-95BB-E8F9A5BAC352}
{D6C3806E-2685-4E8D-9F4F-7A93E5270891} = {66D8DEA8-B477-497F-95BB-E8F9A5BAC352}
{41695443-A292-4909-89A6-2D9846753164} = {56A43630-87E6-4E94-B24A-859258202578}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {70FEC644-BB3C-4441-AF91-DC694803C8F2}
Expand Down
23 changes: 23 additions & 0 deletions samples/Aliencube.AzureFunctions.FunctionApp.Models/ApiResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Aliencube.AzureFunctions.FunctionApp.Models
{
/// <summary>
/// This represents the model entity for API response of Swagger Pet Store.
/// </summary>
public class ApiResponse
{
/// <summary>
/// Gets or sets the code.
/// </summary>
public int? Code { get; set; }

/// <summary>
/// Gets or sets the type.
/// </summary>
public string Type { get; set; }

/// <summary>
/// Gets or sets the message.
/// </summary>
public string Message { get; set; }
}
}
18 changes: 18 additions & 0 deletions samples/Aliencube.AzureFunctions.FunctionApp.Models/Category.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Aliencube.AzureFunctions.FunctionApp.Models
{
/// <summary>
/// This represents the model entity for category of Swagger Pet Store.
/// </summary>
public class Category
{
/// <summary>
/// Gets or sets the category ID.
/// </summary>
public long? Id { get; set; }

/// <summary>
/// Gets or sets the name.
/// </summary>
public string Name { get; set; }
}
}
40 changes: 40 additions & 0 deletions samples/Aliencube.AzureFunctions.FunctionApp.Models/Order.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;

namespace Aliencube.AzureFunctions.FunctionApp.Models
{
/// <summary>
/// This represents the model entity for order of Swagger Pet Store.
/// </summary>
public class Order
{
/// <summary>
/// Gets or sets the order ID.
/// </summary>
public long? Id { get; set; }

/// <summary>
/// Gets or sets the pet ID.
/// </summary>
public long? PetId { get; set; }

/// <summary>
/// Gets or sets the quantity.
/// </summary>
public int? Quantity { get; set; }

/// <summary>
/// Gets or seets the date/time shipped.
/// </summary>
public DateTime? ShipDate { get; set; }

/// <summary>
/// Gets or sets the <see cref="OrderStatus"/> value.
/// </summary>
public OrderStatus? Status { get; set; }

/// <summary>
/// Gets or sets the value indicating whether the order is complete or not.
/// </summary>
public bool? Complete { get; set; }
}
}
27 changes: 27 additions & 0 deletions samples/Aliencube.AzureFunctions.FunctionApp.Models/OrderStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Aliencube.AzureFunctions.FunctionApp.Models
{
/// <summary>
/// This specifies the order status.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum OrderStatus
{
/// <summary>
/// Identifies as "placed".
/// </summary>
Placed = 1,

/// <summary>
/// Identifies as "approved".
/// </summary>
Approved = 2,

/// <summary>
/// Identifies as "delivered".
/// </summary>
Delivered = 3
}
}
44 changes: 44 additions & 0 deletions samples/Aliencube.AzureFunctions.FunctionApp.Models/Pet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Generic;

using Newtonsoft.Json;

namespace Aliencube.AzureFunctions.FunctionApp.Models
{
/// <summary>
/// This represents the model entity for pet of Swagger Pet Store.
/// </summary>
public class Pet
{
/// <summary>
/// Gets or sets the pet ID.
/// </summary>
public long? Id { get; set; }

/// <summary>
/// Gets or sets the category.
/// </summary>
public Category Category { get; set; }

/// <summary>
/// Gets or sets the name.
/// </summary>
[JsonRequired]
public string Name { get; set; }

/// <summary>
/// Gets or sets the list of photo URLs.
/// </summary>
[JsonRequired]
public List<string> PhotoUrls { get; set; } = new List<string>();

/// <summary>
/// Gets or sets the list of tags.
/// </summary>
public List<Tag> Tags { get; set; }

/// <summary>
/// Gets or sets the <see cref="PetStatus"/> value.
/// </summary>
public PetStatus? Status { get; set; }
}
}
27 changes: 27 additions & 0 deletions samples/Aliencube.AzureFunctions.FunctionApp.Models/PetStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Aliencube.AzureFunctions.FunctionApp.Models
{
/// <summary>
/// This specifices the pet status.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum PetStatus
{
/// <summary>
/// Identifies as "available".
/// </summary>
Available = 1,

/// <summary>
/// Identifies as "pending".
/// </summary>
Pending = 2,

/// <summary>
/// Identifies as "sold".
/// </summary>
Sold = 3
}
}
18 changes: 18 additions & 0 deletions samples/Aliencube.AzureFunctions.FunctionApp.Models/Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Aliencube.AzureFunctions.FunctionApp.Models
{
/// <summary>
/// This represents the model entity for tag of Swagger Pet Store.
/// </summary>
public class Tag
{
/// <summary>
/// Gets or sets the tag ID.
/// </summary>
public long? Id { get; set; }

/// <summary>
/// Gets or sets the name.
/// </summary>
public string Name { get; set; }
}
}
48 changes: 48 additions & 0 deletions samples/Aliencube.AzureFunctions.FunctionApp.Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace Aliencube.AzureFunctions.FunctionApp.Models
{
/// <summary>
/// This represents the model entity for user of Swagger Pet Store.
/// </summary>
public class User
{
/// <summary>
/// Gets or sets the user ID.
/// </summary>
public long? Id { get; set; }

/// <summary>
/// Gets or sets the username.
/// </summary>
public string Username { get; set; }

/// <summary>
/// Gets or sets the first name.
/// </summary>
public string FirstName { get; set; }

/// <summary>
/// Gets or sets the last name.
/// </summary>
public string LastName { get; set; }

/// <summary>
/// Gets or sets the email.
/// </summary>
public string Email { get; set; }

/// <summary>
/// Gets or sets the password.
/// </summary>
public string Password { get; set; }

/// <summary>
/// Gets or sets the phone number.
/// </summary>
public string Phone { get; set; }

/// <summary>
/// Gets or sets the user status value.
/// </summary>
public int? UserStatus { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,17 @@
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>

<ItemGroup Condition="'$(Configuration)'=='Debug'">
<Compile Include="..\..\templates\OpenApiEndpints\IOpenApiHttpTriggerContext.cs">
<BuildAction>Compile</BuildAction>
</Compile>
<Compile Include="..\..\templates\OpenApiEndpints\OpenApiHttpTriggerContext.cs">
<BuildAction>Compile</BuildAction>
</Compile>
<Compile Include="..\..\templates\OpenApiEndpints\OpenApiHttpTriggerV1.cs">
<BuildAction>Compile</BuildAction>
</Compile>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

using Aliencube.AzureFunctions.Extensions.DependencyInjection;
using Aliencube.AzureFunctions.Extensions.DependencyInjection.Abstractions;
using Aliencube.AzureFunctions.Extensions.OpenApi.Attributes;
using Aliencube.AzureFunctions.Extensions.OpenApi.Enums;
using Aliencube.AzureFunctions.FunctionApp.Models;

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;

namespace Aliencube.AzureFunctions.FunctionAppV1IoC
{
public static class PetStoreHttpTrigger
{
/// <summary>
/// Gets the <see cref="IFunctionFactory"/> instance as an IoC container.
/// </summary>
public static IFunctionFactory Factory = new FunctionFactory<StartUp>();

[FunctionName(nameof(PetStoreHttpTrigger.AddPet))]
[OpenApiOperation(operationId: "addPet", tags: new[] { "pet" }, Summary = "Add a new pet to the store", Description = "This add a new pet to the store.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(Pet), Required = true, Description = "Pet object that needs to be added to the store")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Pet), Summary = "New pet details added", Description = "New pet details added")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.MethodNotAllowed, Summary = "Invalid input", Description = "Invalid input")]
public static async Task<HttpResponseMessage> AddPet(
[HttpTrigger(AuthorizationLevel.Function, "POST", Route = "pet")] HttpRequestMessage req,
ILogger log)
{
return await Task.FromResult(req.CreateResponse(HttpStatusCode.OK)).ConfigureAwait(false);
}

[FunctionName(nameof(PetStoreHttpTrigger.UpdatePet))]
[OpenApiOperation(operationId: "updatePet", tags: new[] { "pet" }, Summary = "Update an existing pet", Description = "This updates an existing pet.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(Pet), Required = true, Description = "Pet object that needs to be updated to the store")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Pet), Summary = "Pet details updated", Description = "Pet details updated")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid ID supplied", Description = "Invalid ID supplied")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.NotFound, Summary = "Pet not found", Description = "Pet not found")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.MethodNotAllowed, Summary = "Validation exception", Description = "Validation exception")]
public static async Task<HttpResponseMessage> UpdatePet(
[HttpTrigger(AuthorizationLevel.Function, "PUT", Route = "pet")] HttpRequestMessage req,
ILogger log)
{
return await Task.FromResult(req.CreateResponse(HttpStatusCode.OK)).ConfigureAwait(false);
}

[FunctionName(nameof(PetStoreHttpTrigger.FindByStatus))]
[OpenApiOperation(operationId: "findPetsByStatus", tags: new[] { "pet" }, Summary = "Finds Pets by status", Description = "Multiple status values can be provided with comma separated strings.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiParameter(name: "status", In = ParameterLocation.Query, Required = true, Type = typeof(List<PetStatus>), Summary = "Pet status value", Description = "Status values that need to be considered for filter", Visibility = OpenApiVisibilityType.Important)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<Pet>), Summary = "successful operation", Description = "successful operation")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid status value", Description = "Invalid status value")]
public static async Task<HttpResponseMessage> FindByStatus(
[HttpTrigger(AuthorizationLevel.Function, "GET", Route = "pet/findByStatus")] HttpRequestMessage req,
ILogger log)
{
return await Task.FromResult(req.CreateResponse(HttpStatusCode.OK)).ConfigureAwait(false);
}

[FunctionName(nameof(PetStoreHttpTrigger.FindByTags))]
[OpenApiOperation(operationId: "findPetsByTags", tags: new[] { "pet" }, Summary = "Finds Pets by tags", Description = "Muliple tags can be provided with comma separated strings.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiParameter(name: "tags", In = ParameterLocation.Query, Required = true, Type = typeof(List<string>), Summary = "Tags to filter by", Description = "Tags to filter by", Visibility = OpenApiVisibilityType.Important)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<Pet>), Summary = "successful operation", Description = "successful operation")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid tag value", Description = "Invalid tag value")]
public static async Task<HttpResponseMessage> FindByTags(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "pet/findByTags")] HttpRequestMessage req,
ILogger log)
{
return await Task.FromResult(req.CreateResponse(HttpStatusCode.OK)).ConfigureAwait(false);
}

[FunctionName(nameof(PetStoreHttpTrigger.GetPetById))]
[OpenApiOperation(operationId: "getPetById", tags: new[] { "pet" }, Summary = "Find pet by ID", Description = "Returns a single pet.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiParameter(name: "petId", In = ParameterLocation.Path, Required = true, Type = typeof(long), Summary = "ID of pet to return", Description = "ID of pet to return", Visibility = OpenApiVisibilityType.Important)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Pet), Summary = "successful operation", Description = "successful operation")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.BadRequest, Summary = "Invalid ID supplied", Description = "Invalid ID supplied")]
[OpenApiResponseWithoutBody(statusCode: HttpStatusCode.NotFound, Summary = "Pet not found", Description = "Pet not found")]
public static async Task<HttpResponseMessage> GetPetById(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "pet/{petId}")] HttpRequestMessage req,
long petId,
ILogger log)
{
return await Task.FromResult(req.CreateResponse(HttpStatusCode.OK)).ConfigureAwait(false);
}
}
}
Loading

0 comments on commit 97f0a02

Please sign in to comment.