Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active February 8, 2021 07:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save justinyoo/2b4bc731ff8f2cdb5e80e28bd7dff9e7 to your computer and use it in GitHub Desktop.
Creating Custom Connector from Azure Functions with Swagger
namespace FeedReaders.FunctionApp
{
public static class FeedReaderHttpTrigger
{
[FunctionName(nameof(FeedReaderHttpTrigger.GetFeedItemsAsync))]
public static async Task<IActionResult> GetFeedItemsAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "feeds/items")] HttpRequest req,
ILogger log)
{
...
}
[FunctionName(nameof(FeedReaderHttpTrigger.GetFeedItemAsync))]
public async Task<IActionResult> GetFeedItemAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "feeds/item")] HttpRequest req,
ILogger log)
{
...
}
}
}
# PowerShell
(Invoke-WebRequest `
-Uri "https://raw.githubusercontent.com/aliencube/AzureFunctions.Extensions/dev/scripts/Install-OpenApiHttpTriggerTemplates.ps1" `
-UseBasicParsing).Content | Out-File "scripts/Install-OpenApiHttpTriggerTemplates.ps1"
dotnet add <PROJECT> package Microsoft.Azure.WebJobs.Extensions.OpenApi
dotnet add <PROJECT> package Aliencube.AzureFunctions.Extensions.OpenApi
# Bash
curl -X GET "https://raw.githubusercontent.com/aliencube/AzureFunctions.Extensions/dev/scripts/Install-OpenApiHttpTriggerTemplates.sh" > \
"scripts/Install-OpenApiHttpTriggerTemplates.sh"
# Bash
curl -X GET "https://raw.githubusercontent.com/aliencube/AzureFunctions.Extensions/dev/scripts/Install-OpenApiHttpTriggerTemplates.sh" > \
"scripts/Install-OpenApiHttpTriggerTemplates.sh"
chmod +x scripts/Install-OpenApiHttpTriggerTemplates.sh
# PowerShell
scripts/Install-OpenApiHttpTriggerTemplates.ps1 `
-ProjectPath <FUNCTION_APP_PROJECT> `
-Namespace <NAMESPACE>
# PowerShell
scripts/Install-OpenApiHttpTriggerTemplates.ps1 `
-ProjectPath <FUNCTION_APP_PROJECT> `
-Namespace <NAMESPACE>
-IsVersion1
# Bash
./scripts/Install-OpenApiHttpTriggerTemplates.sh \
<FUNCTION_APP_PROJECT> \
<NAMESPACE>
[OpenApiOperation(operationId: "getFeedItems", tags: new[] { "feedItem" }, Summary = "Gets a list of feed items from the given feed", Description = "This operation returns a list of feed items from the given feed URI.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "x-functions-key", In = OpenApiSecurityLocationType.Header)]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(FeedReaderRequest), Description = "Feed reader request payload")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<FeedReaderResponse>), Summary = "List of feed reader response payload")]
[FunctionName(nameof(FeedReaderHttpTrigger.GetFeedItemsAsync))]
public static async Task<IActionResult> GetFeedItemsAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "feeds/items")] HttpRequest req,
ILogger log)
{
...
}
[OpenApiOperation(operationId: "getFeedItem", tags: new[] { "feedItem" }, Summary = "Gets a single feed item from the given feed", Description = "This operation returns a single feed item from the given feed URI.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "x-functions-key", In = OpenApiSecurityLocationType.Header)]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(FeedReaderRequest), Description = "Feed reader request payload")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(FeedReaderResponse), Summary = "Feed reader response payload")]
[FunctionName(nameof(FeedReaderHttpTrigger.GetFeedItemAsync))]
public async Task<IActionResult> GetFeedItemAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "feeds/item")] HttpRequest req,
ILogger log)
{
...
}
[FunctionName(nameof(FeedReaderHttpTrigger.GetFeedItemsAsync))]
[OpenApiOperation(operationId: "getFeedItems", tags: new[] { "feedItem" }, Summary = "Gets a list of feed items from the given feed", Description = "This operation returns a list of feed items from the given feed URI.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(FeedReaderRequest), Description = "Feed reader request payload")]
[OpenApiResponseBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(List<FeedReaderResponse>), Summary = "List of feed reader response payload")]
public static async Task<IActionResult> GetFeedItemsAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "feeds/items")] HttpRequest req,
ILogger log)
{
...
}
[FunctionName(nameof(FeedReaderHttpTrigger.GetFeedItemAsync))]
[OpenApiOperation(operationId: "getFeedItem", tags: new[] { "feedItem" }, Summary = "Gets a single feed item from the given feed", Description = "This operation returns a single feed item from the given feed URI.", Visibility = OpenApiVisibilityType.Important)]
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(FeedReaderRequest), Description = "Feed reader request payload")]
[OpenApiResponseBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(FeedReaderResponse), Summary = "Feed reader response payload")]
public async Task<IActionResult> GetFeedItemAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "feeds/item")] HttpRequest req,
ILogger log)
{
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment