Return type for Azure funcs (#12115)

* Azure func return type

* Changed to Task<IActionResult<T>

* Readme
This commit is contained in:
Abrhm7786 2022-04-20 17:41:24 +01:00 committed by GitHub
parent 2df68d9359
commit d6e194ba3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -1,7 +1,9 @@
--- ---
title: Documentation for the csharp-netcore-functions Generator title: Documentation for the csharp-netcore-functions Generator
--- ---
## DESCRIPTION
Creates Azure function templates on top of the models/converters created by the C# codegens. This function is contained in a partial class. Default Get/Create/Patch/Post etc. methods are created with an underscore prefix. The assumption is that when the function is implemented, the partial class will be completed with another partial class. The implementing code should be located in a method of the same name, only without the underscore prefix. If no such method is found then the function will throw a Not Implemented exception. This setup allows the endpoints to be specified in the schema at build time, and separated from the implementing function.
## METADATA ## METADATA
| Property | Value | Notes | | Property | Value | Notes |

View File

@ -11,20 +11,22 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
using Org.OpenAPITools.Models;
namespace {{apiPackage}} namespace {{apiPackage}}
{ {{#operations}} { {{#operations}}
public partial {{#classModifier}}{{classModifier}} {{/classModifier}}class {{classname}} public partial {{#classModifier}}{{classModifier}} {{/classModifier}}class {{classname}}
{ {{#operation}} { {{#operation}}
[FunctionName("{{classname}}_{{operationId}}")] [FunctionName("{{classname}}_{{operationId}}")]
public async Task<IActionResult> _{{operationId}}([HttpTrigger(AuthorizationLevel.Anonymous, "{{httpMethod}}", Route = "{{{apiBasePath}}}{{{path}}}")]HttpRequest req, ExecutionContext context{{#allParams}}{{#isPathParam}}, {{>pathParam}}{{/isPathParam}}{{/allParams}}){{^generateBody}};{{/generateBody}} public async Task<ActionResult<{{{returnType}}}>> _{{operationId}}([HttpTrigger(AuthorizationLevel.Anonymous, "{{httpMethod}}", Route = "{{{apiBasePath}}}{{{path}}}")]HttpRequest req, ExecutionContext context{{#allParams}}{{#isPathParam}}, {{>pathParam}}{{/isPathParam}}{{/allParams}}){{^generateBody}};{{/generateBody}}
{{#generateBody}} {{#generateBody}}
{ {
var method = this.GetType().GetMethod("{{operationId}}"); var method = this.GetType().GetMethod("{{operationId}}");
if(method == null)
return method != null {
? (await ((Task<IActionResult>)method.Invoke(this, new object[] { req, context{{#allParams}}{{#isPathParam}}, {{>paramName}}{{/isPathParam}}{{/allParams}} })).ConfigureAwait(false)) return new StatusCodeResult((int)HttpStatusCode.NotImplemented);
: new StatusCodeResult((int)HttpStatusCode.NotImplemented); }
return (await ((Task<{{{returnType}}}>)method.Invoke(this, new object[] { req, context, id })).ConfigureAwait(false));
} }
{{/generateBody}} {{/generateBody}}
{{/operation}} {{/operation}}