Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active Mar 9, 2021
Embed
What would you like to do?
Enabling Open API on Azure Functions
func init MyFunctionApp --worker-runtime dotnet
func new --name DefaultHttpTrigger --language C# --template "HTTP trigger"
public static class DefaultHttpTrigger
{
[FunctionName("DefaultHttpTrigger")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
...
}
}
dotnet add package Microsoft.Azure.WebJobs.Extensions.OpenApi \
--version 0.5.1-preview
public static class DefaultHttpTrigger
{
[OpenApiOperation(operationId: "Run", tags: new[] { "name" })]
[OpenApiParameter(name: "name", In = ParameterLocation.Query, Required = true, Type = of(string), Description = "The **Name** parameter")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Description = "The OK response")]
[FunctionName("DefaultHttpTrigger")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
...
}
}
public static class DefaultHttpTrigger
{
[OpenApiOperation(operationId: "Run", tags: new[] { "name" })]
[OpenApiParameter(name: "name", In = ParameterLocation.Query, Required = true, Type = of(string), Description = "The **Name** parameter")]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Description = "The OK response")]
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)]
[FunctionName("DefaultHttpTrigger")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment