diff --git a/docs/generators/csharp-netcore-functions.md b/docs/generators/csharp-netcore-functions.md index 7b5dadf6f78..febe9120c6b 100644 --- a/docs/generators/csharp-netcore-functions.md +++ b/docs/generators/csharp-netcore-functions.md @@ -1,7 +1,9 @@ --- 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 | Property | Value | Notes | diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore-functions/function.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore-functions/function.mustache index 76d12702820..95e3a4274cc 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore-functions/function.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore-functions/function.mustache @@ -11,20 +11,22 @@ using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums; using Microsoft.Extensions.Logging; using Microsoft.OpenApi.Models; using Newtonsoft.Json; +using Org.OpenAPITools.Models; namespace {{apiPackage}} { {{#operations}} public partial {{#classModifier}}{{classModifier}} {{/classModifier}}class {{classname}} { {{#operation}} [FunctionName("{{classname}}_{{operationId}}")] - public async Task _{{operationId}}([HttpTrigger(AuthorizationLevel.Anonymous, "{{httpMethod}}", Route = "{{{apiBasePath}}}{{{path}}}")]HttpRequest req, ExecutionContext context{{#allParams}}{{#isPathParam}}, {{>pathParam}}{{/isPathParam}}{{/allParams}}){{^generateBody}};{{/generateBody}} + public async Task> _{{operationId}}([HttpTrigger(AuthorizationLevel.Anonymous, "{{httpMethod}}", Route = "{{{apiBasePath}}}{{{path}}}")]HttpRequest req, ExecutionContext context{{#allParams}}{{#isPathParam}}, {{>pathParam}}{{/isPathParam}}{{/allParams}}){{^generateBody}};{{/generateBody}} {{#generateBody}} { var method = this.GetType().GetMethod("{{operationId}}"); - - return method != null - ? (await ((Task)method.Invoke(this, new object[] { req, context{{#allParams}}{{#isPathParam}}, {{>paramName}}{{/isPathParam}}{{/allParams}} })).ConfigureAwait(false)) - : new StatusCodeResult((int)HttpStatusCode.NotImplemented); + if(method == null) + { + return new StatusCodeResult((int)HttpStatusCode.NotImplemented); + } + return (await ((Task<{{{returnType}}}>)method.Invoke(this, new object[] { req, context, id })).ConfigureAwait(false)); } {{/generateBody}} {{/operation}}