Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active March 9, 2021 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/2516ec59b204e2bbf85181620f1d0aea to your computer and use it in GitHub Desktop.
Save justinyoo/2516ec59b204e2bbf85181620f1d0aea to your computer and use it in GitHub Desktop.
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