From c59f2b03220885f8fde5a25d47c1d3e12a5410c5 Mon Sep 17 00:00:00 2001 From: Marcin Stefaniuk Date: Wed, 25 May 2016 11:23:11 +0200 Subject: [PATCH] Versioning of generated model (namespace, base context). --- .../swagger/codegen/languages/NancyFXServerCodegen.java | 7 +++++++ .../src/main/resources/nancyfx/Project.mustache | 2 +- .../src/main/resources/nancyfx/api.mustache | 8 ++++---- .../src/main/resources/nancyfx/model.mustache | 2 +- .../src/main/resources/nancyfx/parameters.mustache | 3 +-- 5 files changed, 14 insertions(+), 8 deletions(-) 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 9437344b73..ad04b76cb3 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 @@ -5,6 +5,7 @@ import io.swagger.codegen.CodegenOperation; import io.swagger.codegen.CodegenProperty; import io.swagger.codegen.CodegenType; import io.swagger.codegen.SupportingFile; +import io.swagger.models.Swagger; import io.swagger.models.properties.Property; import io.swagger.models.properties.StringProperty; import org.slf4j.Logger; @@ -144,6 +145,12 @@ public class NancyFXServerCodegen extends AbstractCSharpCodegen { return super.toApiFilename(name) + "Module"; } + @Override + public void preprocessSwagger(Swagger swagger) { + additionalProperties.put("packageContext", sanitizeName(swagger.getBasePath())); + additionalProperties.put("baseContext", swagger.getBasePath()); + } + @Override public String toEnumName(CodegenProperty property) { return sanitizeName(camelize(property.name)) ; diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/Project.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/Project.mustache index 6427c412e9..9962800b0c 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/Project.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/Project.mustache @@ -6,7 +6,7 @@ {{packageGuid}} Library Properties - {{packageName}} + {{packageName}}.{{packageContext}} {{packageTitle}} {{^supportsUWP}} v4.5 diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/api.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/api.mustache index 139149408c..167408e8a3 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/api.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/api.mustache @@ -3,17 +3,17 @@ using Nancy; using Nancy.ModelBinding; using System.Collections.Generic; using Sharpility.Base; -using {{packageName}}.Models; -using {{packageName}}.Utils; +using {{packageName}}.{{packageContext}}.Models; +using {{packageName}}.{{packageContext}}.Utils; using NodaTime; -namespace {{packageName}}.Modules +namespace {{packageName}}.{{packageContext}}.Modules { {{#operations}}{{#operation}}{{#allParams}}{{#isEnum}} {{>innerApiEnum}}{{/isEnum}}{{/allParams}}{{/operation}} public partial class {{classname}}Module : NancyModule { - public {{classname}}Module({{classname}}Service service) : base("") + public {{classname}}Module({{classname}}Service service) : base("{{baseContext}}") { {{#operation}} {{httpMethod}}["{{path}}"] = parameters => { diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/model.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/model.mustache index d6cf40c4d7..fbb08cec64 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/model.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/model.mustache @@ -7,7 +7,7 @@ using NodaTime; {{#models}} {{#model}} -namespace {{packageName}}.Models +namespace {{packageName}}.{{packageContext}}.Models { {{#vars}}{{#isEnum}} {{>innerModelEnum}}{{/isEnum}}{{#items.isEnum}} {{#items}}{{>innerModelEnum}}{{/items}}{{/items.isEnum}}{{/vars}} diff --git a/modules/swagger-codegen/src/main/resources/nancyfx/parameters.mustache b/modules/swagger-codegen/src/main/resources/nancyfx/parameters.mustache index a0b8e326cc..32e615ec24 100644 --- a/modules/swagger-codegen/src/main/resources/nancyfx/parameters.mustache +++ b/modules/swagger-codegen/src/main/resources/nancyfx/parameters.mustache @@ -1,4 +1,3 @@ - using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -8,7 +7,7 @@ using Sharpility.Base; using Sharpility.Extensions; using Sharpility.Util; -namespace {{packageName}}.Utils +namespace {{packageName}}.{{packageContext}}.Utils { internal static class Parameters {