aspnetcore.2.0.controller.mustache Maven / Gradle / Ivy
{{>partial_header}}
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
{{#useSwashbuckle}}
using Swashbuckle.AspNetCore.SwaggerGen;
{{/useSwashbuckle}}
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using {{packageName}}.Attributes;
using {{packageName}}.Models;
namespace {{packageName}}.Controllers
{ {{#operations}}
///
/// {{description}}
/// {{#description}}
[Description("{{description}}")]{{/description}}
public class {{classname}}Controller : Controller
{ {{#operation}}
///
/// {{#summary}}{{summary}}{{/summary}}
/// {{#notes}}
/// {{notes}} {{/notes}}{{#allParams}}
/// {{description}}{{/allParams}}{{#responses}}
/// {{message}} {{/responses}}
[{{httpMethod}}]
[Route("{{{basePathWithoutHost}}}{{{path}}}")]
[ValidateModelState]{{#useSwashbuckle}}
[SwaggerOperation("{{operationId}}")]{{#responses}}{{#dataType}}
[SwaggerResponse(statusCode: {{code}}, type: typeof({{&dataType}}), description: "{{message}}")]{{/dataType}}{{^dataType}}{{/dataType}}{{/responses}}{{/useSwashbuckle}}
public virtual IActionResult {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{^-last}}, {{/-last}}{{/allParams}})
{ {{#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 new ObjectResult(example);{{/returnType}}{{^returnType}}
throw new NotImplementedException();{{/returnType}}
}
{{/operation}}
}
{{/operations}}
}