Set project URL and license from spec

This commit is contained in:
xhh
2015-11-16 23:04:17 +08:00
parent cd8cfc50ed
commit ff5b1c86ba
3 changed files with 48 additions and 25 deletions
@@ -6,7 +6,9 @@ import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.Contact;
import io.swagger.models.Info;
import io.swagger.models.License;
import io.swagger.models.Swagger;
import org.apache.commons.lang.StringUtils;
@@ -20,6 +22,9 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
private static final String PROJECT_NAME = "projectName";
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 BASE_NAMESPACE = "baseNamespace";
protected String projectName = null;
@@ -69,14 +74,30 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
// when projectName is not specified, generate it from info.title
projectName = dashize(info.getTitle());
}
if (projectVersion == null && info.getVersion() != null) {
if (projectVersion == null) {
// when projectVersion is not specified, use info.version
projectVersion = info.getVersion();
}
if (projectDescription == null && info.getDescription() != null) {
if (projectDescription == null) {
// when projectDescription is not specified, use info.description
projectDescription = info.getDescription();
}
if (info.getContact() != null) {
Contact contact = info.getContact();
if (additionalProperties.get(PROJECT_URL) == null) {
additionalProperties.put(PROJECT_URL, contact.getUrl());
}
}
if (info.getLicense() != null) {
License license = info.getLicense();
if (additionalProperties.get(LICENSE_NAME) == null) {
additionalProperties.put(LICENSE_NAME, license.getName());
}
if (additionalProperties.get(LICENSE_URL) == null) {
additionalProperties.put(LICENSE_URL, license.getUrl());
}
}
}
// default values
@@ -1,18 +1,19 @@
(ns {{{package}}}.{{{classname}}}
(:require [{{{projectName}}}.core :refer [call-api check-required-params]]))
{{#operations}}{{#operation}}
(defn {{{nickname}}}
"{{{summary}}}{{#notes}}
{{{notes}}}{{/notes}}"{{#hasOptionalParams}}
([{{#allParams}}{{#required}}{{{paramName}}} {{/required}}{{/allParams}}] ({{{nickname}}}{{#allParams}} {{#required}}{{{paramName}}}{{/required}}{{/allParams}} nil)){{/hasOptionalParams}}
{{#hasOptionalParams}}({{/hasOptionalParams}}[{{#allParams}}{{#required}}{{{paramName}}} {{/required}}{{/allParams}}{{#hasOptionalParams}} {:keys [{{#allParams}}{{^required}}{{{paramName}}} {{/required}}{{/allParams}}]}{{/hasOptionalParams}}]{{#hasRequiredParams}}
{{#hasOptionalParams}} {{/hasOptionalParams}}(check-required-params{{#allParams}}{{#required}} {{{paramName}}}{{/required}}{{/allParams}}){{/hasRequiredParams}}
{{#hasOptionalParams}} {{/hasOptionalParams}}(call-api "{{{path}}}" :{{{httpMethod}}}
{{#hasOptionalParams}} {{/hasOptionalParams}} {:path-params { {{#pathParams}}"{{{baseName}}}" {{{paramName}}} {{/pathParams}} }
{{#hasOptionalParams}} {{/hasOptionalParams}} :header-params { {{#headerParams}}"{{{baseName}}}" {{{paramName}}} {{/headerParams}} }
{{#hasOptionalParams}} {{/hasOptionalParams}} :query-params { {{#queryParams}}"{{{baseName}}}" {{{paramName}}} {{/queryParams}} }
{{#hasOptionalParams}} {{/hasOptionalParams}} :form-params { {{#formParams}}"{{{baseName}}}" {{{paramName}}} {{/formParams}} }{{#bodyParam}}
{{#hasOptionalParams}} {{/hasOptionalParams}} :body-param {{{paramName}}}{{/bodyParam}}
{{#hasOptionalParams}} {{/hasOptionalParams}} :content-types [{{#consumes}}"{{mediaType}}"{{#hasMore}} {{/hasMore}}{{/consumes}}]
{{#hasOptionalParams}} {{/hasOptionalParams}} :accepts [{{#produces}}"{{mediaType}}"{{#hasMore}} {{/hasMore}}{{/produces}}]})){{#hasOptionalParams}}){{/hasOptionalParams}}
{{/operation}}{{/operations}}
{{=< >=}}
(ns <package>.<classname>
(:require [<projectName>.core :refer [call-api check-required-params]]))
<#operations><#operation>
(defn <nickname>
"<&summary><#notes>
<&notes></notes>"<#hasOptionalParams>
([<#allParams><#required><paramName> </required></allParams>] (<nickname><#allParams><#required> <paramName></required></allParams> nil))</hasOptionalParams>
<#hasOptionalParams>(</hasOptionalParams>[<#allParams><#required><paramName> </required></allParams><#hasOptionalParams>{:keys [<#allParams><^required><paramName> </required></allParams>]}</hasOptionalParams>]<#hasRequiredParams>
<#hasOptionalParams> </hasOptionalParams>(check-required-params<#allParams><#required> <paramName></required></allParams>)</hasRequiredParams>
<#hasOptionalParams> </hasOptionalParams>(call-api "<path>" :<httpMethod>
<#hasOptionalParams> </hasOptionalParams> {:path-params {<#pathParams>"<baseName>" <paramName> </pathParams>}
<#hasOptionalParams> </hasOptionalParams> :header-params {<#headerParams>"<baseName>" <paramName> </headerParams>}
<#hasOptionalParams> </hasOptionalParams> :query-params {<#queryParams>"<baseName>" <paramName> </queryParams>}
<#hasOptionalParams> </hasOptionalParams> :form-params {<#formParams>"<baseName>" <paramName> </formParams>}<#bodyParam>
<#hasOptionalParams> </hasOptionalParams> :body-param <paramName></bodyParam>
<#hasOptionalParams> </hasOptionalParams> :content-types [<#consumes>"<mediaType>"<#hasMore> </hasMore></consumes>]
<#hasOptionalParams> </hasOptionalParams> :accepts [<#produces>"<mediaType>"<#hasMore> </hasMore></produces>]}))<#hasOptionalParams>)</hasOptionalParams>
</operation></operations>
@@ -1,8 +1,9 @@
(defproject {{{projectName}}} "{{{projectVersion}}}"
:description "{{{projectDescription}}}"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
{{=< >=}}
(defproject <&projectName> "<&projectVersion>"
:description "<&projectDescription>"<#projectUrl>
:url "<&projectUrl>"</projectUrl><#licenseName>
:license {:name "<&licenseName>"<#licenseUrl>
:url "<&licenseUrl>"</licenseUrl>}</licenseName>
:dependencies [[org.clojure/clojure "1.7.0"]
[clj-http "2.0.0"]
[cheshire "5.5.0"]])