mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 11:23:58 +00:00
Introducing service interface and some validation.
This commit is contained in:
parent
37e76f4c68
commit
874509a592
@ -122,6 +122,6 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
|
||||
// Converts, for example, PUT to HttpPut for controller attributes
|
||||
operation.httpMethod = "Http" + operation.httpMethod.substring(0, 1) + operation.httpMethod.substring(1).toLowerCase();
|
||||
operation.httpMethod = operation.httpMethod.substring(0, 1) + operation.httpMethod.substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Swashbuckle.SwaggerGen.Annotations;
|
||||
using Nancy;
|
||||
using {{packageName}}.Models;
|
||||
|
||||
namespace {{packageName}}.Controllers
|
||||
namespace {{packageName}}.Api
|
||||
{ {{#operations}}
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>{{#description}}{{#basePath}}
|
||||
[Route("{{basePath}}")]
|
||||
{{/basePath}}[Description("{{description}}")]{{/description}}
|
||||
public class {{classname}}Controller : Controller
|
||||
{ {{#operation}}
|
||||
|
||||
/// <summary>
|
||||
/// {{#summary}}{{summary}}{{/summary}}
|
||||
/// </summary>
|
||||
{{#notes}}/// <remarks>{{notes}}</remarks>{{/notes}}{{#allParams}}
|
||||
/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}{{#responses}}
|
||||
/// <response code="{{code}}">{{message}}</response>{{/responses}}
|
||||
[{{httpMethod}}]
|
||||
[Route("{{path}}")]
|
||||
[SwaggerOperation("{{operationId}}")]{{#returnType}}
|
||||
[SwaggerResponse(200, type: typeof({{&returnType}}))]{{/returnType}}
|
||||
public {{#returnType}}IActionResult{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
|
||||
{ {{#returnType}}
|
||||
string exampleJson = null;
|
||||
{{#isListCollection}}{{>listReturn}}{{/isListCollection}}{{^isListCollection}}{{#isMapContainer}}{{>mapReturn}}{{/isMapContainer}}{{^isMapContainer}}{{>objectReturn}}{{/isMapContainer}}{{/isListCollection}}
|
||||
{{!TODO: defaultResponse, examples, auth, consumes, produces, nickname, externalDocs, imports, security}}
|
||||
return new ObjectResult(example);{{/returnType}}{{^returnType}}
|
||||
throw new NotImplementedException();{{/returnType}}
|
||||
public sealed class {{classname}}Module : NancyModule
|
||||
{
|
||||
public {{classname}}Module({{classname}}Service service) : base("")
|
||||
{ {{#operation}}
|
||||
{{httpMethod}}["{{path}}"] = parameters =>
|
||||
{
|
||||
// existence validation of obligatory parameters
|
||||
{{#allParams}}{{#required}}
|
||||
if (parameters.{{paramName}} == null) {
|
||||
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{operationId}}");
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
{{#allParams}}{{#isBodyParam}}
|
||||
{{&dataType}} {{paramName}} = Bind<{{&dataType}}>();
|
||||
{{/isBodyParam}}{{#isPathParam}}{{&dataType}} {{paramName}} = parameters.{{paramName}};
|
||||
{{/isPathParam}}{{#isHeaderParam}}{{&dataType}} {{paramName}} = parameters.{{paramName}};
|
||||
{{/isHeaderParam}}{{#isQueryParam}}{{&dataType}} {{paramName}} = parameters.{{paramName}};
|
||||
{{/isQueryParam}}{{/allParams}}
|
||||
return service.{{operationId}}(
|
||||
{{#allParams}}
|
||||
{{paramName}}{{#hasMore}},{{/hasMore}}
|
||||
{{/allParams}}
|
||||
);
|
||||
};
|
||||
{{/operation}}
|
||||
}
|
||||
}
|
||||
|
||||
interface {{classname}}Service
|
||||
{ {{#operation}}
|
||||
public {{#returnType}}{{&returnType}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
{{/operations}}
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
{{#isBodyParam}}[FromBody]{{&dataType}} {{paramName}}{{/isBodyParam}}
|
||||
{{#isBodyParam}}{{&dataType}} {{paramName}}{{/isBodyParam}}
|
@ -1 +1 @@
|
||||
{{#isFormParam}}[FromForm]{{&dataType}} {{paramName}}{{/isFormParam}}
|
||||
{{#isFormParam}}{{&dataType}} {{paramName}}{{/isFormParam}}
|
@ -1 +1 @@
|
||||
{{#isHeaderParam}}[FromHeader]{{&dataType}} {{paramName}}{{/isHeaderParam}}
|
||||
{{#isHeaderParam}}{{&dataType}} {{paramName}}{{/isHeaderParam}}
|
@ -69,15 +69,6 @@ namespace {{packageName}}.Models
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public {{#parent}} new {{/parent}}string ToJson()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if objects are equal
|
||||
/// </summary>
|
||||
|
@ -1 +1 @@
|
||||
{{#isPathParam}}[FromRoute]{{&dataType}} {{paramName}}{{/isPathParam}}
|
||||
{{#isPathParam}}{{&dataType}} {{paramName}}{{/isPathParam}}
|
@ -1 +1 @@
|
||||
{{#isQueryParam}}[FromQuery]{{&dataType}} {{paramName}}{{/isQueryParam}}
|
||||
{{#isQueryParam}}{{&dataType}} {{paramName}}{{/isQueryParam}}
|
Loading…
Reference in New Issue
Block a user