From ff5b1c86ba449278c3a0a819f0195290ea407b3a Mon Sep 17 00:00:00 2001 From: xhh Date: Mon, 16 Nov 2015 23:04:17 +0800 Subject: [PATCH] Set project URL and license from spec --- .../languages/ClojureClientCodegen.java | 25 ++++++++++++- .../src/main/resources/clojure/api.mustache | 37 ++++++++++--------- .../main/resources/clojure/project.mustache | 11 +++--- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ClojureClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ClojureClientCodegen.java index 1c7b6ab3f2df..0277c2d90773 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ClojureClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ClojureClientCodegen.java @@ -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 diff --git a/modules/swagger-codegen/src/main/resources/clojure/api.mustache b/modules/swagger-codegen/src/main/resources/clojure/api.mustache index 37107435e7b9..474a1fc37cf5 100644 --- a/modules/swagger-codegen/src/main/resources/clojure/api.mustache +++ b/modules/swagger-codegen/src/main/resources/clojure/api.mustache @@ -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}} \ No newline at end of file +{{=< >=}} +(ns . + (:require [.core :refer [call-api check-required-params]])) +<#operations><#operation> +(defn + "<&summary><#notes> + <¬es>"<#hasOptionalParams> + ([<#allParams><#required> ] (<#allParams><#required> nil)) + <#hasOptionalParams>([<#allParams><#required> <#hasOptionalParams>{:keys [<#allParams><^required> ]}]<#hasRequiredParams> + <#hasOptionalParams> (check-required-params<#allParams><#required> ) + <#hasOptionalParams> (call-api "" : + <#hasOptionalParams> {:path-params {<#pathParams>"" } + <#hasOptionalParams> :header-params {<#headerParams>"" } + <#hasOptionalParams> :query-params {<#queryParams>"" } + <#hasOptionalParams> :form-params {<#formParams>"" }<#bodyParam> + <#hasOptionalParams> :body-param + <#hasOptionalParams> :content-types [<#consumes>""<#hasMore> ] + <#hasOptionalParams> :accepts [<#produces>""<#hasMore> ]}))<#hasOptionalParams>) + \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/clojure/project.mustache b/modules/swagger-codegen/src/main/resources/clojure/project.mustache index ac01fb571524..75e870714a73 100644 --- a/modules/swagger-codegen/src/main/resources/clojure/project.mustache +++ b/modules/swagger-codegen/src/main/resources/clojure/project.mustache @@ -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>"<#licenseName> + :license {:name "<&licenseName>"<#licenseUrl> + :url "<&licenseUrl>"} :dependencies [[org.clojure/clojure "1.7.0"] [clj-http "2.0.0"] [cheshire "5.5.0"]])