-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Azure Functions isolated worker parameter builder
- Loading branch information
Showing
13 changed files
with
569 additions
and
48 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
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
47 changes: 47 additions & 0 deletions
47
...ions/DependencyInjection/OpenApiAzureFunctionsWorkerHostingServiceCollectionExtensions.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,47 @@ | ||
// <copyright file="OpenApiAzureFunctionsWorkerHostingServiceCollectionExtensions.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
using System; | ||
|
||
using Menes; | ||
using Menes.Hosting.AzureFunctionsWorker; | ||
using Menes.Internal; | ||
|
||
using Microsoft.Azure.Functions.Worker.Http; | ||
|
||
/// <summary> | ||
/// Extensions to register open api request hosting for <see cref="HttpRequestData"/> and <see cref="HttpResponseData"/>. | ||
/// </summary> | ||
public static class OpenApiAzureFunctionsWorkerHostingServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Adds <see cref="HttpRequestData"/> / <see cref="HttpResponseData"/> middleware-based hosting. | ||
/// </summary> | ||
/// <typeparam name="TContext">The type of the OpenApi context.</typeparam> | ||
/// <param name="services">The service collection to configure.</param> | ||
/// <param name="configureHost">A function to configure the host.</param> | ||
/// <param name="configureEnvironment">A function to configure the environment.</param> | ||
/// <returns>The configured service collection.</returns> | ||
public static IServiceCollection AddOpenApiAzureFunctionsWorkerHosting<TContext>( | ||
this IServiceCollection services, | ||
Action<IOpenApiHostConfiguration>? configureHost, | ||
Action<IOpenApiConfiguration>? configureEnvironment = null) | ||
where TContext : class, IOpenApiContext, new() | ||
{ | ||
services.AddSingleton<IResponseOutputBuilder<IHttpResponseDataResult>, PocoHttpResponseDataOutputBuilder>(); | ||
services.AddSingleton<IResponseOutputBuilder<IHttpResponseDataResult>, OpenApiResultHttpResponseDataOutputBuilder>(); | ||
services.AddSingleton<IOpenApiResultBuilder<IHttpResponseDataResult>, OpenApiHttpResponseDataResultBuilder>(); | ||
|
||
services.AddSingleton<IOpenApiContextBuilder<HttpRequestData>, OpenApiContextBuilder<HttpRequestData, TContext>>(); | ||
services.AddSingleton<IOpenApiParameterBuilder<HttpRequestData>, HttpRequestDataParameterBuilder>(); | ||
|
||
services.AddOpenApiHosting<HttpRequestData, HttpResponseData>( | ||
configureHost, | ||
configureEnvironment); | ||
|
||
return services; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
Solutions/Menes.Specs/Features/ParameterBuilders/HttpRequestDataParameterBuilder.feature
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,41 @@ | ||
@perScenarioContainer | ||
|
||
Feature: Azure Functions HttpRequestData Parameter Builder | ||
In order to implement a web API that can run in Azure Functions with the isolated worker model | ||
As a developer | ||
I want Menes to be able to extract inputs from requests wrapped as HttpRequestData | ||
|
||
Scenario: Body | ||
Given I have constructed the OpenAPI specification with a request body of type array, containing items of type 'integer' | ||
When I try to parse the value '[1,2,3,4,5]' as the HttpRequestData body | ||
Then the parameter body should be [1,2,3,4,5] of type System.String | ||
|
||
Scenario Outline: Cookie | ||
Given I have constructed the OpenAPI specification with a cookie parameter with name 'openApiBoolean', type 'boolean', and format '' | ||
When I try to parse the value '<Value>' as the cookie 'openApiBoolean' in an HttpRequestData | ||
Then the parameter openApiBoolean should be <ExpectedValue> of type System.Boolean | ||
|
||
Examples: | ||
| Value | ExpectedValue | | ||
| true | true | | ||
| false | false | | ||
|
||
Scenario Outline: Header | ||
Given I have constructed the OpenAPI specification with a header parameter with name 'openApiBoolean', type 'boolean', and format '' | ||
When I try to parse the value '<Value>' as the header 'openApiBoolean' in an HttpRequestData | ||
Then the parameter openApiBoolean should be <ExpectedValue> of type System.Boolean | ||
|
||
Examples: | ||
| Value | ExpectedValue | | ||
| true | true | | ||
| false | false | | ||
|
||
Scenario Outline: Query | ||
Given I have constructed the OpenAPI specification with a query parameter with name 'openApiBoolean', type 'boolean', and format '' | ||
When I try to parse the value '<Value>' as the query parameter 'openApiBoolean' in an HttpRequestData | ||
Then the parameter openApiBoolean should be <ExpectedValue> of type System.Boolean | ||
|
||
Examples: | ||
| Value | ExpectedValue | | ||
| true | true | | ||
| false | false | |
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.