All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aspnetcore.3.0.controller.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>partial_header}}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
{{#operationResultTask}}
using System.Threading;
using System.Threading.Tasks;
{{/operationResultTask}}
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
{{#useSwashbuckle}}
using Swashbuckle.AspNetCore.Annotations;
using Swashbuckle.AspNetCore.SwaggerGen;
{{/useSwashbuckle}}
{{^isLibrary}}
{{#useNewtonsoft}}
using Newtonsoft.Json;
{{/useNewtonsoft}}
{{^useNewtonsoft}}
using System.Text.Json;
{{/useNewtonsoft}}
{{/isLibrary}}
using {{packageName}}.Attributes;
using {{modelPackage}};

namespace {{apiPackage}}
{ {{#operations}}
    /// 
    /// {{description}}
    /// {{#description}}
    [Description("{{.}}")]{{/description}}
    [ApiController]
    public {{#classModifier}}{{.}} {{/classModifier}}class {{classname}}Controller : ControllerBase
    { {{#operation}}
        /// 
        /// {{summary}}
        /// {{#notes}}
        /// {{.}}{{/notes}}{{#allParams}}
        /// {{description}}{{#isDeprecated}} (deprecated){{/isDeprecated}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}
        /// The cancellation token to cancel the operation.{{/operationIsAsync}}{{/operationResultTask}}{{#responses}}
        /// {{message}}{{/responses}}
        [{{httpMethod}}]
        [Route("{{{basePathWithoutHost}}}{{{path}}}")]
{{#authMethods}}
{{#isApiKey}}
        [Authorize(Policy = "{{name}}")]
{{/isApiKey}}
{{#isBasicBearer}}
        [Authorize{{#scopes}}{{#-first}}(Roles = "{{/-first}}{{scope}}{{^-last}},{{/-last}}{{#-last}}"){{/-last}}{{/scopes}}]
{{/isBasicBearer}}
{{/authMethods}}
        {{#vendorExtensions.x-aspnetcore-consumes}}
        [Consumes({{&vendorExtensions.x-aspnetcore-consumes}})]
        {{/vendorExtensions.x-aspnetcore-consumes}}
        [ValidateModelState]{{#useSwashbuckle}}
        [SwaggerOperation("{{operationId}}")]{{#responses}}{{#dataType}}
        [SwaggerResponse(statusCode: {{code}}, type: typeof({{&dataType}}), description: "{{message}}")]{{/dataType}}{{/responses}}{{/useSwashbuckle}}{{^useSwashbuckle}}{{#responses}}{{#dataType}}
        [ProducesResponseType(statusCode: {{code}}, type: typeof({{&dataType}}))]{{/dataType}}{{/responses}}{{/useSwashbuckle}}
        {{#isDeprecated}}
        [Obsolete]
        {{/isDeprecated}}
        public {{operationModifier}} {{#operationResultTask}}{{#operationIsAsync}}async {{/operationIsAsync}}Task<{{/operationResultTask}}IActionResult{{#operationResultTask}}>{{/operationResultTask}} {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{^-last}}{{^isCookieParam}}, {{/isCookieParam}}{{/-last}}{{#-last}}{{#operationResultTask}}{{#operationIsAsync}}, {{/operationIsAsync}}{{/operationResultTask}}{{/-last}}{{/allParams}}{{#operationResultTask}}{{#operationIsAsync}}CancellationToken cancellationToken{{/operationIsAsync}}{{/operationResultTask}}){{^generateBody}};{{/generateBody}}
        {{#generateBody}}
        {
            {{#cookieParams}}
            var {{paramName}} = Request.Cookies["{{paramName}}"];
            {{/cookieParams}}

{{#responses}}
{{#dataType}}
            //TODO: Uncomment the next line to return response {{code}} or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode({{code}}, default({{&dataType}}));
{{/dataType}}
{{^dataType}}
            //TODO: Uncomment the next line to return response {{code}} or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode({{code}});
{{/dataType}}
{{/responses}}
{{#returnType}}
            string exampleJson = null;
            {{#examples}}
            exampleJson = "{{{example}}}";
            {{/examples}}
            {{#isListCollection}}{{>listReturn}}{{/isListCollection}}{{^isListCollection}}{{#isMap}}{{>mapReturn}}{{/isMap}}{{^isMap}}{{>objectReturn}}{{/isMap}}{{/isListCollection}}
            {{!TODO: defaultResponse, examples, auth, consumes, produces, nickname, externalDocs, imports, security}}
            //TODO: Change the data returned
            return {{#operationResultTask}}{{#operationIsAsync}}await {{/operationIsAsync}}Task.FromResult({{/operationResultTask}}new ObjectResult(example){{#operationResultTask}}){{/operationResultTask}};{{/returnType}}{{^returnType}}
            throw new NotImplementedException();{{/returnType}}
        }
        {{/generateBody}}
        {{/operation}}
    }
{{/operations}}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy