From f76a789a49abd11774df9611a3cd8e03ec8e4efe Mon Sep 17 00:00:00 2001 From: Testo Nakada Date: Fri, 16 Oct 2015 09:18:48 -0700 Subject: [PATCH] - make Meta generator take the swagger code gen version - generate the class name correctly if the name contains hyphen --- .../src/main/java/io/swagger/codegen/cmd/Meta.java | 13 ++++++++++--- .../src/main/resources/codegen/pom.mustache | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java index c75181c51cd..ca06652b942 100644 --- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java +++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java @@ -1,6 +1,7 @@ package io.swagger.codegen.cmd; import ch.lambdaj.function.convert.Converter; +import com.google.common.base.CaseFormat; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.samskivert.mustache.Mustache; @@ -9,7 +10,6 @@ import io.airlift.airline.Option; import io.swagger.codegen.DefaultGenerator; import io.swagger.codegen.SupportingFile; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +55,7 @@ public class Meta implements Runnable { final File targetDir = new File(outputFolder); LOG.info("writing to folder [{}]", targetDir.getAbsolutePath()); - String mainClass = StringUtils.capitalize(name) + "Generator"; + String mainClass = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name) + "Generator"; List supportingFiles = ImmutableList.of( new SupportingFile("pom.mustache", "", "pom.xml"), @@ -68,11 +68,18 @@ public class Meta implements Runnable { "src/main/resources/META-INF/services", "io.swagger.codegen.CodegenConfig") ); + String swaggerVersion = this.getClass().getPackage().getImplementationVersion(); + // if the code is running outside of the jar (i.e. from the IDE), it will not have the version available. + // let's default it with something. + if (swaggerVersion==null) { + swaggerVersion = "2.1.3"; + } Map data = new ImmutableMap.Builder() .put("generatorPackage", targetPackage) .put("generatorClass", mainClass) .put("name", name) - .put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass).build(); + .put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass) + .put("swaggerCodegenVersion", swaggerVersion).build(); with(supportingFiles).convert(processFiles(targetDir, data)); diff --git a/modules/swagger-codegen/src/main/resources/codegen/pom.mustache b/modules/swagger-codegen/src/main/resources/codegen/pom.mustache index 29a980a5091..30f1b14872c 100644 --- a/modules/swagger-codegen/src/main/resources/codegen/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/codegen/pom.mustache @@ -95,8 +95,8 @@ - 2.1.3 + {{swaggerCodegenVersion}} 1.0.0 4.8.1 - \ No newline at end of file +