From da8176e1703c7459717956f3d5ff377e04e76d13 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Sun, 15 Feb 2015 22:19:26 -0800 Subject: [PATCH] updated templates --- .../src/main/resources/Java/model.mustache | 10 ++--- .../resources/android-java/model.mustache | 22 ++++++---- .../src/main/resources/php/Swagger.mustache | 43 ++++++++++++------- .../src/main/resources/php/api.mustache | 4 +- .../src/main/resources/php/model.mustache | 2 +- .../src/main/resources/python3/api.mustache | 4 +- .../src/main/resources/python3/model.mustache | 2 +- 7 files changed, 51 insertions(+), 36 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/model.mustache b/modules/swagger-codegen/src/main/resources/Java/model.mustache index cbaf1f83d39e..48da4b2c7ffa 100644 --- a/modules/swagger-codegen/src/main/resources/Java/model.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/model.mustache @@ -14,12 +14,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "{{{description}}}") public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{#vars}}{{#isEnum}} - public enum {{datatype}} { + public enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}} }; - private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}} + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}} private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}} - + {{#vars}} /**{{#description}} * {{{description}}}{{/description}}{{#minimum}} @@ -28,10 +28,10 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { **/ @ApiModelProperty(required = {{required}}, value = "{{{description}}}") @JsonProperty("{{name}}") - public {{{datatype}}} {{getter}}() { + public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; } - public void {{setter}}({{{datatype}}} {{name}}) { + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { this.{{name}} = {{name}}; } diff --git a/modules/swagger-codegen/src/main/resources/android-java/model.mustache b/modules/swagger-codegen/src/main/resources/android-java/model.mustache index 0d60aedd0683..48da4b2c7ffa 100644 --- a/modules/swagger-codegen/src/main/resources/android-java/model.mustache +++ b/modules/swagger-codegen/src/main/resources/android-java/model.mustache @@ -4,6 +4,7 @@ package {{package}}; {{/imports}} import com.wordnik.swagger.annotations.*; +import com.fasterxml.jackson.annotation.JsonProperty; {{#models}} {{#model}}{{#description}} @@ -11,12 +12,14 @@ import com.wordnik.swagger.annotations.*; * {{description}} **/{{/description}} @ApiModel(description = "{{{description}}}") -public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{#vars}} - private {{{datatype}}} {{name}} = {{{defaultValue}}};{{#allowableValues}} - - //{{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} }; - {{/min}}{{/allowableValues}}{{/vars}} - +public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { + {{#vars}}{{#isEnum}} + public enum {{datatypeWithEnum}} { + {{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}} + }; + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}} + private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}} + {{#vars}} /**{{#description}} * {{{description}}}{{/description}}{{#minimum}} @@ -24,10 +27,11 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{#vars} * maximum: {{maximum}}{{/maximum}} **/ @ApiModelProperty(required = {{required}}, value = "{{{description}}}") - public {{{datatype}}} {{getter}}() { + @JsonProperty("{{name}}") + public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; } - public void {{setter}}({{{datatype}}} {{name}}) { + public void {{setter}}({{{datatypeWithEnum}}} {{name}}) { this.{{name}} = {{name}}; } @@ -44,4 +48,4 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{#vars} } } {{/model}} -{{/models}} \ No newline at end of file +{{/models}} diff --git a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache index 1aace837b1df..b37bb4c1e832 100644 --- a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache @@ -1,12 +1,22 @@ apiKey = $apiKey; - $this->apiServer = $apiServer; + function __construct($host, $headerName = null, $headerValue = null) { + $this->host = $host; + $this->headerName = $headerName; + $this->headerValue = $headerValue; } /** @@ -48,7 +59,7 @@ class APIClient { } - /** + /** * @param string $resourcePath path to method endpoint * @param string $method method to call * @param array $queryParams parameters to be place in query URL @@ -61,25 +72,25 @@ class APIClient { $headers = array(); - # Allow API key from $headerParams to override default - $added_api_key = False; + # Allow API key from $headerParams to override default + $added_api_key = False; if ($headerParams != null) { foreach ($headerParams as $key => $val) { $headers[] = "$key: $val"; - if ($key == 'api_key') { - $added_api_key = True; + if ($key == $this->headerName) { + $added_api_key = True; } } } - if (! $added_api_key) { - $headers[] = "api_key: " . $this->apiKey; + if (! $added_api_key && $this->headerName != null) { + $headers[] = $this->headerName . ": " . $this->headerValue; } if (strpos($headers['Content-Type'], "multipart/form-data") < 0 and (is_object($postData) or is_array($postData))) { $postData = json_encode($this->sanitizeForSerialization($postData)); } - $url = $this->apiServer . $resourcePath; + $url = $this->host . $resourcePath; $curl = curl_init(); if ($this->curl_timout) { diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index d2349b18522e..e040c6cc5f23 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -1,6 +1,6 @@