Skip to content

Commit

Permalink
Feature/openapi parameters (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo authored Jul 19, 2020
1 parent 56c91e8 commit c2e0727
Show file tree
Hide file tree
Showing 35 changed files with 520 additions and 134 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Aliencube.AzureFunctions.Extensions.OpenApi.Attributes;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

Expand All @@ -12,16 +14,19 @@ public enum OrderStatus
/// <summary>
/// Identifies as "placed".
/// </summary>
[Display("placed")]
Placed = 1,

/// <summary>
/// Identifies as "approved".
/// </summary>
[Display("approved")]
Approved = 2,

/// <summary>
/// Identifies as "delivered".
/// </summary>
[Display("delivered")]
Delivered = 3
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Aliencube.AzureFunctions.Extensions.OpenApi.Attributes;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

Expand All @@ -12,16 +14,19 @@ public enum PetStatus
/// <summary>
/// Identifies as "available".
/// </summary>
[Display("available")]
Available = 1,

/// <summary>
/// Identifies as "pending".
/// </summary>
[Display("pending")]
Pending = 2,

/// <summary>
/// Identifies as "sold".
/// </summary>
[Display("sold")]
Sold = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />
<!--<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />-->
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" />
</ItemGroup>

<ItemGroup>
<!--<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />-->
<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />
<ProjectReference Include="..\Aliencube.AzureFunctions.FunctionApp.Functions\Aliencube.AzureFunctions.FunctionApp.Functions.csproj" />
</ItemGroup>

Expand All @@ -29,10 +29,10 @@
</None>
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
Expand All @@ -21,6 +22,7 @@ public static class PetStoreHttpTrigger
/// <summary>
/// Gets the <see cref="IFunctionFactory"/> instance as an IoC container.
/// </summary>
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "")]
public static IFunctionFactory Factory = new FunctionFactory<StartUp>();

[FunctionName(nameof(PetStoreHttpTrigger.AddPet))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />
<!--<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />-->
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" />
</ItemGroup>

<ItemGroup>
<!--<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />-->
<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />
<ProjectReference Include="..\Aliencube.AzureFunctions.FunctionApp.Models\Aliencube.AzureFunctions.FunctionApp.Models.csproj" />
</ItemGroup>

Expand All @@ -29,10 +29,10 @@
</None>
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />
<!--<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />-->
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" />
</ItemGroup>

<ItemGroup>
<!--<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />-->
<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />
<ProjectReference Include="..\Aliencube.AzureFunctions.FunctionApp.Services\Aliencube.AzureFunctions.FunctionApp.Services.csproj" />
</ItemGroup>

Expand All @@ -29,10 +29,10 @@
</None>
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />
<!--<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />-->
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" />
</ItemGroup>

<ItemGroup>
<!--<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />-->
<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />
<ProjectReference Include="..\Aliencube.AzureFunctions.FunctionApp.Models\Aliencube.AzureFunctions.FunctionApp.Models.csproj" />
</ItemGroup>

Expand All @@ -25,10 +25,10 @@
</None>
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />
<!--<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />-->
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
</ItemGroup>

<ItemGroup>
<!--<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />-->
<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />
<ProjectReference Include="..\Aliencube.AzureFunctions.FunctionApp.Services\Aliencube.AzureFunctions.FunctionApp.Services.csproj" />
</ItemGroup>

Expand All @@ -29,10 +29,10 @@
</None>
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />
<!--<PackageReference Include="Aliencube.AzureFunctions.Extensions.OpenApi" Version="2.0.0.1" />-->
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
</ItemGroup>

<ItemGroup>
<!--<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />-->
<ProjectReference Include="..\..\src\Aliencube.AzureFunctions.Extensions.OpenApi\Aliencube.AzureFunctions.Extensions.OpenApi.csproj" />
<ProjectReference Include="..\Aliencube.AzureFunctions.FunctionApp.Models\Aliencube.AzureFunctions.FunctionApp.Models.csproj" />
</ItemGroup>

Expand All @@ -25,10 +25,10 @@
</None>
</ItemGroup>

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

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static async Task<IActionResult> UpdatePet(

[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(PetStatus), Summary = "Pet status value", Description = "Status values that need to be considered for filter", 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")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

using Aliencube.AzureFunctions.Extensions.OpenApi.Enums;

Expand Down Expand Up @@ -46,6 +46,17 @@ public OpenApiParameterAttribute(string name)
/// </summary>
public virtual ParameterLocation In { get; set; } = ParameterLocation.Path;

/// <summary>
/// Gets or sets the parameter collection delimiter. Default is <see cref="OpenApiParameterCollectionDelimiterType.Comma"/>.
/// </summary>
public virtual OpenApiParameterCollectionDelimiterType CollectionDelimiter { get; set; } = OpenApiParameterCollectionDelimiterType.Comma;

/// <summary>
/// Gets or sets the value indicating whether the same query string parameter can be used multiple times or not.
/// This value is only valid when the <see cref="In"/> parameter value is <see cref="ParameterLocation.Query"/>.
/// </summary>
public virtual bool Explode { get; set; }

/// <summary>
/// Gets or sets the value indicating whether the parameter is required or not. Default is <c>false</c>.
/// </summary>
Expand All @@ -56,4 +67,4 @@ public OpenApiParameterAttribute(string name)
/// </summary>
public virtual OpenApiVisibilityType Visibility { get; set; } = OpenApiVisibilityType.Undefined;
}
}
}
16 changes: 8 additions & 8 deletions src/Aliencube.AzureFunctions.Extensions.OpenApi/Document.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;

#if NET461
using System.Net.Http;
Expand Down Expand Up @@ -42,9 +42,9 @@ public Document(IDocumentHelper helper)
public IDocument InitialiseDocument()
{
this._document = new OpenApiDocument()
{
Components = new OpenApiComponents()
};
{
Components = new OpenApiComponents()
};

return this;
}
Expand Down Expand Up @@ -121,9 +121,9 @@ public IDocument Build(Assembly assembly, NamingStrategy namingStrategy = null)
continue;
}

operation.Parameters = this._helper.GetOpenApiParameters(method, trigger);
operation.RequestBody = this._helper.GetOpenApiRequestBody(method);
operation.Responses = this._helper.GetOpenApiResponses(method);
operation.Parameters = this._helper.GetOpenApiParameters(method, trigger, namingStrategy);
operation.RequestBody = this._helper.GetOpenApiRequestBody(method, namingStrategy);
operation.Responses = this._helper.GetOpenApiResponses(method, namingStrategy);

operations[verb] = operation;
item.Operations = operations;
Expand Down Expand Up @@ -158,4 +158,4 @@ private string Render(OpenApiSpecVersion version, OpenApiFormat format)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public OpenApiOperation GetOpenApiOperation(MethodInfo element, FunctionNameAttr
}

/// <inheritdoc />
public List<OpenApiParameter> GetOpenApiParameters(MethodInfo element, HttpTriggerAttribute trigger)
public List<OpenApiParameter> GetOpenApiParameters(MethodInfo element, HttpTriggerAttribute trigger, NamingStrategy namingStrategy = null)
{
var parameters = element.GetCustomAttributes<OpenApiParameterAttribute>(inherit: false)
.Select(p => p.ToOpenApiParameter())
.Select(p => p.ToOpenApiParameter(namingStrategy))
.ToList();

// This needs to be provided separately.
Expand All @@ -143,7 +143,7 @@ public OpenApiRequestBody GetOpenApiRequestBody(MethodInfo element, NamingStrate
return null;
}

var contents = attributes.ToDictionary(p => p.ContentType, p => p.ToOpenApiMediaType());
var contents = attributes.ToDictionary(p => p.ContentType, p => p.ToOpenApiMediaType(namingStrategy));

if (contents.Any())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Aliencube.AzureFunctions.Extensions.OpenApi.Attributes;
using Aliencube.AzureFunctions.Extensions.OpenApi.Attributes;

namespace Aliencube.AzureFunctions.Extensions.OpenApi.Enums
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Aliencube.AzureFunctions.Extensions.OpenApi.Attributes;

namespace Aliencube.AzureFunctions.Extensions.OpenApi.Enums
{
/// <summary>
/// This specifies the parameter collection delimiter.
/// </summary>
public enum OpenApiParameterCollectionDelimiterType
{
/// <summary>
/// Identifies "comma".
/// </summary>
[Display("comma")]
Comma = 0,

/// <summary>
/// Identifies "space".
/// </summary>
[Display("space")]
Space = 1,

/// <summary>
/// Identifies "pipe".
/// </summary>
[Display("pipe")]
Pipe = 2
}
}
Loading

0 comments on commit c2e0727

Please sign in to comment.