Skip to content

Commit 87b88bb

Browse files
committed
feat: create strong typed return values of API methods and handle cookie parameters correctly
1 parent 3a25e9e commit 87b88bb

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/resources/aspnetcore-di/controller.mustache

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace {{apiPackage}}
2929
/// <param name="{{paramName}}">{{description}}{{#isDeprecated}} (deprecated){{/isDeprecated}}</param>{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}
3030
/// <param name="cancellationToken">The cancellation token to cancel the operation.</param>{{/operationIsAsync}}{{/operationResultTask}}{{#responses}}
3131
/// <response code="{{code}}">{{message}}</response>{{/responses}}
32-
public {{#operationResultTask}}Task<{{/operationResultTask}}IActionResult{{#operationResultTask}}>{{/operationResultTask}} {{operationId}}({{#allParams}}{{&dataType}} {{paramName}}{{^-last}}, {{/-last}}{{#-last}}{{#operationResultTask}}{{#operationIsAsync}}, {{/operationIsAsync}}{{/operationResultTask}}{{/-last}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}CancellationToken cancellationToken{{/operationIsAsync}}{{/operationResultTask}});
32+
public {{>returnType}} {{operationId}}({{#allParams}}{{&dataType}} {{paramName}}{{^-last}}, {{/-last}}{{#-last}}{{#operationResultTask}}{{#operationIsAsync}}, {{/operationIsAsync}}{{/operationResultTask}}{{/-last}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}CancellationToken cancellationToken{{/operationIsAsync}}{{/operationResultTask}});
3333
{{/operation}}
3434
}
3535
{{/operations}}
@@ -63,9 +63,15 @@ namespace {{apiPackage}}
6363
{{#isDeprecated}}
6464
[Obsolete]
6565
{{/isDeprecated}}
66-
public {{#operationIsAsync}}async {{/operationIsAsync}}{{#operationResultTask}}Task<{{/operationResultTask}}IActionResult{{#operationResultTask}}>{{/operationResultTask}} {{operationId}}({{#allParams}}{{>params/pathParam}}{{>params/queryParam}}{{>params/bodyParam}}{{>params/formParam}}{{>params/headerParam}}{{^-last}}{{^isCookieParam}}, {{/isCookieParam}}{{/-last}}{{#-last}}{{#operationResultTask}}{{#operationIsAsync}}, {{/operationIsAsync}}{{/operationResultTask}}{{/-last}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}CancellationToken cancellationToken{{/operationIsAsync}}{{/operationResultTask}})
66+
public {{#operationIsAsync}}async {{/operationIsAsync}}{{>returnType}} {{operationId}}({{#allParams}}{{>params/pathParam}}{{>params/queryParam}}{{>params/bodyParam}}{{>params/formParam}}{{>params/headerParam}}{{^-last}}{{^isCookieParam}}, {{/isCookieParam}}{{/-last}}{{#-last}}{{#operationResultTask}}{{#operationIsAsync}}, {{/operationIsAsync}}{{/operationResultTask}}{{/-last}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}CancellationToken cancellationToken{{/operationIsAsync}}{{/operationResultTask}})
6767
{
68-
return {{#operationIsAsync}}await {{/operationIsAsync}}_impl.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}{{^isCookieParam}}, {{/isCookieParam}}{{/-last}}{{#-last}}{{#operationResultTask}}{{#operationIsAsync}}, {{/operationIsAsync}}{{/operationResultTask}}{{/-last}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}CancellationToken cancellationToken{{/operationIsAsync}}{{/operationResultTask}});
68+
{{#cookieParams}}
69+
var {{paramName}} = Request.Cookies["{{paramName}}"];
70+
{{#-last}}
71+
72+
{{/-last}}
73+
{{/cookieParams}}
74+
return {{#operationIsAsync}}await {{/operationIsAsync}}_impl.{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{#-last}}{{#operationResultTask}}{{#operationIsAsync}}, {{/operationIsAsync}}{{/operationResultTask}}{{/-last}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}CancellationToken cancellationToken{{/operationIsAsync}}{{/operationResultTask}});
6975
}
7076

7177
{{/operation}}

0 commit comments

Comments
 (0)