Merge pull request #1591 from xhh/clojure-client

[Clojure] Integration tests and config options
This commit is contained in:
wing328
2015-11-20 08:54:03 +08:00
6 changed files with 79 additions and 15 deletions
@@ -1,5 +1,6 @@
package io.swagger.codegen.languages;
import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenOperation;
@@ -13,8 +14,6 @@ import io.swagger.models.Swagger;
import org.apache.commons.lang.StringUtils;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.List;
@@ -23,13 +22,15 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
private static final String PROJECT_DESCRIPTION = "projectDescription";
private static final String PROJECT_VERSION = "projectVersion";
private static final String PROJECT_URL = "projectUrl";
private static final String LICENSE_NAME = "licenseName";
private static final String LICENSE_URL = "licenseUrl";
private static final String PROJECT_LICENSE_NAME = "projectLicenseName";
private static final String PROJECT_LICENSE_URL = "projectLicenseUrl";
private static final String BASE_NAMESPACE = "baseNamespace";
protected String projectName = null;
protected String projectDescription = null;
protected String projectVersion = null;
protected String baseNamespace = null;
protected String sourceFolder = "src";
public ClojureClientCodegen() {
@@ -37,6 +38,21 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
outputFolder = "generated-code" + File.separator + "clojure";
apiTemplateFiles.put("api.mustache", ".clj");
embeddedTemplateDir = templateDir = "clojure";
cliOptions.add(new CliOption(PROJECT_NAME,
"name of the project (Default: generated from info.title or \"swagger-clj-client\")"));
cliOptions.add(new CliOption(PROJECT_DESCRIPTION,
"description of the project (Default: using info.description or \"Client library of <projectNname>\")"));
cliOptions.add(new CliOption(PROJECT_VERSION,
"version of the project (Default: using info.version or \"1.0.0\")"));
cliOptions.add(new CliOption(PROJECT_URL,
"URL of the project (Default: using info.contact.url or not included in project.clj)"));
cliOptions.add(new CliOption(PROJECT_LICENSE_NAME,
"name of the license the project uses (Default: using info.license.name or not included in project.clj)"));
cliOptions.add(new CliOption(PROJECT_LICENSE_URL,
"URL of the license the project uses (Default: using info.license.url or not included in project.clj)"));
cliOptions.add(new CliOption(BASE_NAMESPACE,
"the base/top namespace (Default: generated from projectName)"));
}
@Override
@@ -67,6 +83,9 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
if (additionalProperties.containsKey(PROJECT_VERSION)) {
projectVersion = ((String) additionalProperties.get(PROJECT_VERSION));
}
if (additionalProperties.containsKey(BASE_NAMESPACE)) {
baseNamespace = ((String) additionalProperties.get(BASE_NAMESPACE));
}
if (swagger.getInfo() != null) {
Info info = swagger.getInfo();
@@ -91,11 +110,11 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
}
if (info.getLicense() != null) {
License license = info.getLicense();
if (additionalProperties.get(LICENSE_NAME) == null) {
additionalProperties.put(LICENSE_NAME, license.getName());
if (additionalProperties.get(PROJECT_LICENSE_NAME) == null) {
additionalProperties.put(PROJECT_LICENSE_NAME, license.getName());
}
if (additionalProperties.get(LICENSE_URL) == null) {
additionalProperties.put(LICENSE_URL, license.getUrl());
if (additionalProperties.get(PROJECT_LICENSE_URL) == null) {
additionalProperties.put(PROJECT_LICENSE_URL, license.getUrl());
}
}
}
@@ -110,8 +129,9 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
if (projectDescription == null) {
projectDescription = "Client library of " + projectName;
}
final String baseNamespace = dashize(projectName);
if (baseNamespace == null) {
baseNamespace = dashize(projectName);
}
apiPackage = baseNamespace + ".api";
additionalProperties.put(PROJECT_NAME, projectName);
@@ -1,5 +1,5 @@
{{=< >=}}(ns <package>.<classname>
(:require [<projectName>.core :refer [call-api check-required-params]])
(:require [<baseNamespace>.core :refer [call-api check-required-params]])
(:import (java.io File)))
<#operations><#operation>
(defn <nickname>
@@ -1,8 +1,8 @@
{{=< >=}}(defproject <&projectName> "<&projectVersion>"
:description "<&projectDescription>"<#projectUrl>
:url "<&projectUrl>"</projectUrl><#licenseName>
:license {:name "<&licenseName>"<#licenseUrl>
:url "<&licenseUrl>"</licenseUrl>}</licenseName>
:url "<&projectUrl>"</projectUrl><#projectLicenseName>
:license {:name "<&projectLicenseName>"<#projectLicenseUrl>
:url "<&projectLicenseUrl>"</projectLicenseUrl>}</projectLicenseName>
:dependencies [[org.clojure/clojure "1.7.0"]
[clj-http "2.0.0"]
[cheshire "5.5.0"]])
+13
View File
@@ -305,6 +305,18 @@
<module>samples/client/petstore/android-java</module>
</modules>
</profile>
<profile>
<id>clojure-client</id>
<activation>
<property>
<name>env</name>
<value>clojure</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/clojure</module>
</modules>
</profile>
<profile>
<id>java-client</id>
<activation>
@@ -435,6 +447,7 @@
</activation>
<modules>
<module>samples/client/petstore/android-java</module>
<module>samples/client/petstore/clojure</module>
<module>samples/client/petstore/java/default</module>
<module>samples/client/petstore/java/jersey2</module>
<module>samples/client/petstore/java/okhttp-gson</module>
@@ -1,7 +1,6 @@
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
+32
View File
@@ -0,0 +1,32 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>swagger-petstore-clojure</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Swagger Petstore - Clojure Client</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>lein-test</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>lein</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>