diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java index 029f46ed1b5..a6a021407a4 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/NancyFXServerCodegen.java @@ -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(); } } diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/api.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/api.mustache index e9c5c919898..d29b750c9e5 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/api.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/api.mustache @@ -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}} - /// - /// {{description}} - /// {{#description}}{{#basePath}} - [Route("{{basePath}}")] - {{/basePath}}[Description("{{description}}")]{{/description}} - public class {{classname}}Controller : Controller - { {{#operation}} - /// - /// {{#summary}}{{summary}}{{/summary}} - /// - {{#notes}}/// {{notes}}{{/notes}}{{#allParams}} - /// {{description}}{{/allParams}}{{#responses}} - /// {{message}}{{/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}} } diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/bodyParam.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/bodyParam.mustache index 02b0fa1d2de..0d354f2365e 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/bodyParam.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/bodyParam.mustache @@ -1 +1 @@ -{{#isBodyParam}}[FromBody]{{&dataType}} {{paramName}}{{/isBodyParam}} \ No newline at end of file +{{#isBodyParam}}{{&dataType}} {{paramName}}{{/isBodyParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/formParam.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/formParam.mustache index 1e743e1e4c7..1a15c1d7639 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/formParam.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/formParam.mustache @@ -1 +1 @@ -{{#isFormParam}}[FromForm]{{&dataType}} {{paramName}}{{/isFormParam}} \ No newline at end of file +{{#isFormParam}}{{&dataType}} {{paramName}}{{/isFormParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/headerParam.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/headerParam.mustache index e61cadb1131..86bb6608230 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/headerParam.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/headerParam.mustache @@ -1 +1 @@ -{{#isHeaderParam}}[FromHeader]{{&dataType}} {{paramName}}{{/isHeaderParam}} \ No newline at end of file +{{#isHeaderParam}}{{&dataType}} {{paramName}}{{/isHeaderParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/model.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/model.mustache index 08aaed01f3d..7df65b03b41 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/model.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/model.mustache @@ -69,15 +69,6 @@ namespace {{packageName}}.Models return sb.ToString(); } - /// - /// Returns the JSON string presentation of the object - /// - /// JSON string presentation of the object - public {{#parent}} new {{/parent}}string ToJson() - { - return JsonConvert.SerializeObject(this, Formatting.Indented); - } - /// /// Returns true if objects are equal /// diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/pathParam.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/pathParam.mustache index 5aa27eb4cb3..5139812e1ef 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/pathParam.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/pathParam.mustache @@ -1 +1 @@ -{{#isPathParam}}[FromRoute]{{&dataType}} {{paramName}}{{/isPathParam}} \ No newline at end of file +{{#isPathParam}}{{&dataType}} {{paramName}}{{/isPathParam}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/queryParam.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/queryParam.mustache index 42ce87a2b7f..8af670122a8 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/queryParam.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/queryParam.mustache @@ -1 +1 @@ -{{#isQueryParam}}[FromQuery]{{&dataType}} {{paramName}}{{/isQueryParam}} \ No newline at end of file +{{#isQueryParam}}{{&dataType}} {{paramName}}{{/isQueryParam}} \ No newline at end of file