forked from loafle/openapi-generator-original
Return type for Azure funcs (#12115)
* Azure func return type * Changed to Task<IActionResult<T> * Readme
This commit is contained in:
parent
2df68d9359
commit
d6e194ba3a
@ -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 |
|
||||
|
@ -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<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}}
|
||||
{
|
||||
var method = this.GetType().GetMethod("{{operationId}}");
|
||||
|
||||
return method != null
|
||||
? (await ((Task<IActionResult>)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}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user