forked from loafle/openapi-generator-original
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
|
// 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;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using Nancy;
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNet.Mvc;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Swashbuckle.SwaggerGen.Annotations;
|
|
||||||
using {{packageName}}.Models;
|
using {{packageName}}.Models;
|
||||||
|
|
||||||
namespace {{packageName}}.Controllers
|
namespace {{packageName}}.Api
|
||||||
{ {{#operations}}
|
{ {{#operations}}
|
||||||
/// <summary>
|
|
||||||
/// {{description}}
|
|
||||||
/// </summary>{{#description}}{{#basePath}}
|
|
||||||
[Route("{{basePath}}")]
|
|
||||||
{{/basePath}}[Description("{{description}}")]{{/description}}
|
|
||||||
public class {{classname}}Controller : Controller
|
|
||||||
{ {{#operation}}
|
|
||||||
|
|
||||||
/// <summary>
|
public sealed class {{classname}}Module : NancyModule
|
||||||
/// {{#summary}}{{summary}}{{/summary}}
|
{
|
||||||
/// </summary>
|
public {{classname}}Module({{classname}}Service service) : base("")
|
||||||
{{#notes}}/// <remarks>{{notes}}</remarks>{{/notes}}{{#allParams}}
|
{ {{#operation}}
|
||||||
/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}{{#responses}}
|
{{httpMethod}}["{{path}}"] = parameters =>
|
||||||
/// <response code="{{code}}">{{message}}</response>{{/responses}}
|
{
|
||||||
[{{httpMethod}}]
|
// existence validation of obligatory parameters
|
||||||
[Route("{{path}}")]
|
{{#allParams}}{{#required}}
|
||||||
[SwaggerOperation("{{operationId}}")]{{#returnType}}
|
if (parameters.{{paramName}} == null) {
|
||||||
[SwaggerResponse(200, type: typeof({{&returnType}}))]{{/returnType}}
|
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{operationId}}");
|
||||||
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}}
|
|
||||||
}
|
}
|
||||||
|
{{/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}}
|
{{/operation}}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface {{classname}}Service
|
||||||
|
{ {{#operation}}
|
||||||
|
public {{#returnType}}{{&returnType}}{{/returnType}}{{^returnType}}void{{/returnType}} {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{>formParam}}{{>headerParam}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||||
|
{{/operation}}
|
||||||
|
}
|
||||||
|
|
||||||
{{/operations}}
|
{{/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();
|
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>
|
/// <summary>
|
||||||
/// Returns true if objects are equal
|
/// Returns true if objects are equal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1 +1 @@
|
|||||||
{{#isPathParam}}[FromRoute]{{&dataType}} {{paramName}}{{/isPathParam}}
|
{{#isPathParam}}{{&dataType}} {{paramName}}{{/isPathParam}}
|
@ -1 +1 @@
|
|||||||
{{#isQueryParam}}[FromQuery]{{&dataType}} {{paramName}}{{/isQueryParam}}
|
{{#isQueryParam}}{{&dataType}} {{paramName}}{{/isQueryParam}}
|
Loading…
x
Reference in New Issue
Block a user