Created
August 13, 2021 12:28
-
-
Save justinyoo/32474da3f9e512b6ab4e34192fbbb4b8 to your computer and use it in GitHub Desktop.
Azure Functions OpenAPI on .NET 5
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
public static void Main() | |
{ | |
var host = new HostBuilder() | |
// πππππ Remove this line below πππππ | |
.ConfigureFunctionsWorkerDefaults() | |
// πππππ Remove this line above πππππ | |
.Build(); | |
host.Run(); | |
} |
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
public static void Main() | |
{ | |
var host = new HostBuilder() | |
// πππππ Add these lines below πππππ | |
.ConfigureFunctionsWorkerDefaults(worker => worker.UseNewtonsoftJson()) | |
.ConfigureOpenApi() | |
// πππππ Add these lines above πππππ | |
.Build(); | |
host.Run(); | |
} |
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
// πππππ Add OpenAPI related decorators below πππππ | |
[OpenApiOperation(operationId: "greeting", tags: new[] { "greeting" }, Summary = "Greetings", Description = "This shows a welcome message.", Visibility = OpenApiVisibilityType.Important)] | |
[OpenApiSecurity("function_key", SecuritySchemeType.ApiKey, Name = "code", In = OpenApiSecurityLocationType.Query)] | |
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "text/plain", bodyType: typeof(string), Summary = "The response", Description = "This returns the response")] | |
// πππππ Add OpenAPI related decorators above πππππ | |
[Function("Function1")] | |
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, | |
FunctionContext executionContext) | |
{ | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment