diff --git a/.gitignore b/.gitignore
index 3ff09c17cea..adea0e97125 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,6 +56,7 @@ samples/client/petstore/qt5cpp/PetStore/Makefile
#Java/Android
**/.gradle
samples/client/petstore/java/hello.txt
+samples/client/petstore/java/okhttp-gson/hello.txt
samples/client/petstore/java/jersey2-java8/hello.txt
samples/client/petstore/android/default/hello.txt
samples/client/petstore/android/volley/.gradle/
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java
index fbf2a0f009f..2af4a5f0dc1 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java
@@ -1695,7 +1695,7 @@ public class DefaultCodegen {
// set default value for variable with inner enum
if (property.defaultValue != null) {
- property.defaultValue = property.defaultValue.replace(property.items.baseType, toEnumName(property.items));
+ property.defaultValue = property.defaultValue.replace(baseItem.baseType, toEnumName(baseItem));
}
}
diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
index f951a745dcb..e6574f5ffd6 100644
--- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
+++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml
@@ -1158,15 +1158,16 @@ definitions:
enum:
- fish
- crab
- array_array_enum:
- type: array
- items:
- type: array
- items:
- type: string
- enum:
- - Cat
- - Dog
+ # comment out the following as 2d array of enum is not supported at the moment
+ #array_array_enum:
+ # type: array
+ # items:
+ # type: array
+ # items:
+ # type: string
+ # enum:
+ # - Cat
+ # - Dog
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
diff --git a/samples/client/petstore/java/okhttp-gson/docs/EnumArrays.md b/samples/client/petstore/java/okhttp-gson/docs/EnumArrays.md
new file mode 100644
index 00000000000..30d341de8a8
--- /dev/null
+++ b/samples/client/petstore/java/okhttp-gson/docs/EnumArrays.md
@@ -0,0 +1,27 @@
+
+# EnumArrays
+
+## Properties
+Name | Type | Description | Notes
+------------ | ------------- | ------------- | -------------
+**justEnum** | [**JustEnumEnum**](#JustEnumEnum) | | [optional]
+**arrayEnum** | [**List<ArrayEnumEnum>**](#List<ArrayEnumEnum>) | | [optional]
+
+
+
+## Enum: JustEnumEnum
+Name | Value
+---- | -----
+BIRD | "bird"
+EAGLE | "eagle"
+
+
+
+## Enum: List<ArrayEnumEnum>
+Name | Value
+---- | -----
+FISH | "fish"
+CRAB | "crab"
+
+
+
diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/EnumArrays.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/EnumArrays.java
new file mode 100644
index 00000000000..9745bf4a488
--- /dev/null
+++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/EnumArrays.java
@@ -0,0 +1,173 @@
+/**
+ * Swagger Petstore
+ * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
+ *
+ * OpenAPI spec version: 1.0.0
+ * Contact: apiteam@swagger.io
+ *
+ * NOTE: This class is auto generated by the swagger code generator program.
+ * https://github.com/swagger-api/swagger-codegen.git
+ * Do not edit the class manually.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package io.swagger.client.model;
+
+import java.util.Objects;
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * EnumArrays
+ */
+
+public class EnumArrays {
+ /**
+ * Gets or Sets justEnum
+ */
+ public enum JustEnumEnum {
+ @SerializedName("bird")
+ BIRD("bird"),
+
+ @SerializedName("eagle")
+ EAGLE("eagle");
+
+ private String value;
+
+ JustEnumEnum(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(value);
+ }
+ }
+
+ @SerializedName("just_enum")
+ private JustEnumEnum justEnum = null;
+
+ /**
+ * Gets or Sets arrayEnum
+ */
+ public enum ArrayEnumEnum {
+ @SerializedName("fish")
+ FISH("fish"),
+
+ @SerializedName("crab")
+ CRAB("crab");
+
+ private String value;
+
+ ArrayEnumEnum(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(value);
+ }
+ }
+
+ @SerializedName("array_enum")
+ private List arrayEnum = new ArrayList();
+
+ public EnumArrays justEnum(JustEnumEnum justEnum) {
+ this.justEnum = justEnum;
+ return this;
+ }
+
+ /**
+ * Get justEnum
+ * @return justEnum
+ **/
+ @ApiModelProperty(example = "null", value = "")
+ public JustEnumEnum getJustEnum() {
+ return justEnum;
+ }
+
+ public void setJustEnum(JustEnumEnum justEnum) {
+ this.justEnum = justEnum;
+ }
+
+ public EnumArrays arrayEnum(List arrayEnum) {
+ this.arrayEnum = arrayEnum;
+ return this;
+ }
+
+ public EnumArrays addArrayEnumItem(ArrayEnumEnum arrayEnumItem) {
+ this.arrayEnum.add(arrayEnumItem);
+ return this;
+ }
+
+ /**
+ * Get arrayEnum
+ * @return arrayEnum
+ **/
+ @ApiModelProperty(example = "null", value = "")
+ public List getArrayEnum() {
+ return arrayEnum;
+ }
+
+ public void setArrayEnum(List arrayEnum) {
+ this.arrayEnum = arrayEnum;
+ }
+
+
+ @Override
+ public boolean equals(java.lang.Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ EnumArrays enumArrays = (EnumArrays) o;
+ return Objects.equals(this.justEnum, enumArrays.justEnum) &&
+ Objects.equals(this.arrayEnum, enumArrays.arrayEnum);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(justEnum, arrayEnum);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("class EnumArrays {\n");
+
+ sb.append(" justEnum: ").append(toIndentedString(justEnum)).append("\n");
+ sb.append(" arrayEnum: ").append(toIndentedString(arrayEnum)).append("\n");
+ sb.append("}");
+ return sb.toString();
+ }
+
+ /**
+ * Convert the given object to string with each line indented by 4 spaces
+ * (except the first line).
+ */
+ private String toIndentedString(java.lang.Object o) {
+ if (o == null) {
+ return "null";
+ }
+ return o.toString().replace("\n", "\n ");
+ }
+}
+
diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/EnumArrays.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/EnumArrays.md
index 7b7fd741898..b3b0c1574ff 100644
--- a/samples/client/petstore/php/SwaggerClient-php/docs/Model/EnumArrays.md
+++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/EnumArrays.md
@@ -5,7 +5,6 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**just_enum** | **string** | | [optional]
**array_enum** | **string[]** | | [optional]
-**array_array_enum** | [**string[][]**](array.md) | | [optional]
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php
index bfbc95128c5..f245fc28df4 100644
--- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php
+++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php
@@ -67,8 +67,7 @@ class EnumArrays implements ArrayAccess
*/
protected static $swaggerTypes = array(
'just_enum' => 'string',
- 'array_enum' => 'string[]',
- 'array_array_enum' => 'string[][]'
+ 'array_enum' => 'string[]'
);
public static function swaggerTypes()
@@ -82,8 +81,7 @@ class EnumArrays implements ArrayAccess
*/
protected static $attributeMap = array(
'just_enum' => 'just_enum',
- 'array_enum' => 'array_enum',
- 'array_array_enum' => 'array_array_enum'
+ 'array_enum' => 'array_enum'
);
public static function attributeMap()
@@ -97,8 +95,7 @@ class EnumArrays implements ArrayAccess
*/
protected static $setters = array(
'just_enum' => 'setJustEnum',
- 'array_enum' => 'setArrayEnum',
- 'array_array_enum' => 'setArrayArrayEnum'
+ 'array_enum' => 'setArrayEnum'
);
public static function setters()
@@ -112,8 +109,7 @@ class EnumArrays implements ArrayAccess
*/
protected static $getters = array(
'just_enum' => 'getJustEnum',
- 'array_enum' => 'getArrayEnum',
- 'array_array_enum' => 'getArrayArrayEnum'
+ 'array_enum' => 'getArrayEnum'
);
public static function getters()
@@ -125,8 +121,6 @@ class EnumArrays implements ArrayAccess
const JUST_ENUM_EAGLE = 'eagle';
const ARRAY_ENUM_FISH = 'fish';
const ARRAY_ENUM_CRAB = 'crab';
- const ARRAY_ARRAY_ENUM_CAT = 'Cat';
- const ARRAY_ARRAY_ENUM_DOG = 'Dog';
@@ -154,18 +148,6 @@ class EnumArrays implements ArrayAccess
];
}
- /**
- * Gets allowable values of the enum
- * @return string[]
- */
- public function getArrayArrayEnumAllowableValues()
- {
- return [
- self::ARRAY_ARRAY_ENUM_CAT,
- self::ARRAY_ARRAY_ENUM_DOG,
- ];
- }
-
/**
* Associative array for storing property values
@@ -181,7 +163,6 @@ class EnumArrays implements ArrayAccess
{
$this->container['just_enum'] = isset($data['just_enum']) ? $data['just_enum'] : null;
$this->container['array_enum'] = isset($data['array_enum']) ? $data['array_enum'] : null;
- $this->container['array_array_enum'] = isset($data['array_array_enum']) ? $data['array_array_enum'] : null;
}
/**
@@ -265,31 +246,6 @@ class EnumArrays implements ArrayAccess
return $this;
}
-
- /**
- * Gets array_array_enum
- * @return string[][]
- */
- public function getArrayArrayEnum()
- {
- return $this->container['array_array_enum'];
- }
-
- /**
- * Sets array_array_enum
- * @param string[][] $array_array_enum
- * @return $this
- */
- public function setArrayArrayEnum($array_array_enum)
- {
- $allowed_values = array('Cat', 'Dog');
- if (!in_array($array_array_enum, $allowed_values)) {
- throw new \InvalidArgumentException("Invalid value for 'array_array_enum', must be one of 'Cat', 'Dog'");
- }
- $this->container['array_array_enum'] = $array_array_enum;
-
- return $this;
- }
/**
* Returns true if offset exists. False otherwise.
* @param integer $offset Offset
diff --git a/samples/client/petstore/ruby/README.md b/samples/client/petstore/ruby/README.md
index 08b3048a79b..81ab585ab5f 100644
--- a/samples/client/petstore/ruby/README.md
+++ b/samples/client/petstore/ruby/README.md
@@ -8,7 +8,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
- API version: 1.0.0
- Package version: 1.0.0
-- Build date: 2016-08-01T21:53:35.575+08:00
+- Build date: 2016-08-03T00:39:31.384+08:00
- Build package: class io.swagger.codegen.languages.RubyClientCodegen
## Installation
diff --git a/samples/client/petstore/ruby/docs/EnumArrays.md b/samples/client/petstore/ruby/docs/EnumArrays.md
new file mode 100644
index 00000000000..70302d71ef8
--- /dev/null
+++ b/samples/client/petstore/ruby/docs/EnumArrays.md
@@ -0,0 +1,9 @@
+# Petstore::EnumArrays
+
+## Properties
+Name | Type | Description | Notes
+------------ | ------------- | ------------- | -------------
+**just_enum** | **String** | | [optional]
+**array_enum** | **Array<String>** | | [optional]
+
+
diff --git a/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb b/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb
new file mode 100644
index 00000000000..d0c35ddd576
--- /dev/null
+++ b/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb
@@ -0,0 +1,243 @@
+=begin
+#Swagger Petstore
+
+#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
+
+OpenAPI spec version: 1.0.0
+Contact: apiteam@swagger.io
+Generated by: https://github.com/swagger-api/swagger-codegen.git
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+=end
+
+require 'date'
+
+module Petstore
+
+ class EnumArrays
+ attr_accessor :just_enum
+
+ attr_accessor :array_enum
+
+ class EnumAttributeValidator
+ attr_reader :datatype
+ attr_reader :allowable_values
+
+ def initialize(datatype, allowable_values)
+ @allowable_values = allowable_values.map do |value|
+ case datatype.to_s
+ when /Integer/i
+ value.to_i
+ when /Float/i
+ value.to_f
+ else
+ value
+ end
+ end
+ end
+
+ def valid?(value)
+ !value || allowable_values.include?(value)
+ end
+ end
+
+ # Attribute mapping from ruby-style variable name to JSON key.
+ def self.attribute_map
+ {
+ :'just_enum' => :'just_enum',
+ :'array_enum' => :'array_enum'
+ }
+ end
+
+ # Attribute type mapping.
+ def self.swagger_types
+ {
+ :'just_enum' => :'String',
+ :'array_enum' => :'Array'
+ }
+ end
+
+ # Initializes the object
+ # @param [Hash] attributes Model attributes in the form of hash
+ def initialize(attributes = {})
+ return unless attributes.is_a?(Hash)
+
+ # convert string to symbol for hash key
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
+
+ if attributes.has_key?(:'just_enum')
+ self.just_enum = attributes[:'just_enum']
+ end
+
+ if attributes.has_key?(:'array_enum')
+ if (value = attributes[:'array_enum']).is_a?(Array)
+ self.array_enum = value
+ end
+ end
+
+ end
+
+ # Show invalid properties with the reasons. Usually used together with valid?
+ # @return Array for valid properies with the reasons
+ def list_invalid_properties
+ invalid_properties = Array.new
+ return invalid_properties
+ end
+
+ # Check to see if the all the properties in the model are valid
+ # @return true if the model is valid
+ def valid?
+ just_enum_validator = EnumAttributeValidator.new('String', ["bird", "eagle"])
+ return false unless just_enum_validator.valid?(@just_enum)
+ return true
+ end
+
+ # Custom attribute writer method checking allowed values (enum).
+ # @param [Object] just_enum Object to be assigned
+ def just_enum=(just_enum)
+ validator = EnumAttributeValidator.new('String', ["bird", "eagle"])
+ unless validator.valid?(just_enum)
+ fail ArgumentError, "invalid value for 'just_enum', must be one of #{validator.allowable_values}."
+ end
+ @just_enum = just_enum
+ end
+
+ # Checks equality by comparing each attribute.
+ # @param [Object] Object to be compared
+ def ==(o)
+ return true if self.equal?(o)
+ self.class == o.class &&
+ just_enum == o.just_enum &&
+ array_enum == o.array_enum
+ end
+
+ # @see the `==` method
+ # @param [Object] Object to be compared
+ def eql?(o)
+ self == o
+ end
+
+ # Calculates hash code according to all attributes.
+ # @return [Fixnum] Hash code
+ def hash
+ [just_enum, array_enum].hash
+ end
+
+ # Builds the object from hash
+ # @param [Hash] attributes Model attributes in the form of hash
+ # @return [Object] Returns the model itself
+ def build_from_hash(attributes)
+ return nil unless attributes.is_a?(Hash)
+ self.class.swagger_types.each_pair do |key, type|
+ if type =~ /^Array<(.*)>/i
+ # check to ensure the input is an array given that the the attribute
+ # is documented as an array but the input is not
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
+ end
+ elsif !attributes[self.class.attribute_map[key]].nil?
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
+ end
+
+ self
+ end
+
+ # Deserializes the data based on type
+ # @param string type Data type
+ # @param string value Value to be deserialized
+ # @return [Object] Deserialized data
+ def _deserialize(type, value)
+ case type.to_sym
+ when :DateTime
+ DateTime.parse(value)
+ when :Date
+ Date.parse(value)
+ when :String
+ value.to_s
+ when :Integer
+ value.to_i
+ when :Float
+ value.to_f
+ when :BOOLEAN
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
+ true
+ else
+ false
+ end
+ when :Object
+ # generic object (usually a Hash), return directly
+ value
+ when /\AArray<(?.+)>\z/
+ inner_type = Regexp.last_match[:inner_type]
+ value.map { |v| _deserialize(inner_type, v) }
+ when /\AHash<(?.+), (?.+)>\z/
+ k_type = Regexp.last_match[:k_type]
+ v_type = Regexp.last_match[:v_type]
+ {}.tap do |hash|
+ value.each do |k, v|
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
+ end
+ end
+ else # model
+ temp_model = Petstore.const_get(type).new
+ temp_model.build_from_hash(value)
+ end
+ end
+
+ # Returns the string representation of the object
+ # @return [String] String presentation of the object
+ def to_s
+ to_hash.to_s
+ end
+
+ # to_body is an alias to to_hash (backward compatibility)
+ # @return [Hash] Returns the object in the form of hash
+ def to_body
+ to_hash
+ end
+
+ # Returns the object in the form of hash
+ # @return [Hash] Returns the object in the form of hash
+ def to_hash
+ hash = {}
+ self.class.attribute_map.each_pair do |attr, param|
+ value = self.send(attr)
+ next if value.nil?
+ hash[param] = _to_hash(value)
+ end
+ hash
+ end
+
+ # Outputs non-array value in the form of hash
+ # For object, use to_hash. Otherwise, just return the value
+ # @param [Object] value Any valid value
+ # @return [Hash] Returns the value in the form of hash
+ def _to_hash(value)
+ if value.is_a?(Array)
+ value.compact.map{ |v| _to_hash(v) }
+ elsif value.is_a?(Hash)
+ {}.tap do |hash|
+ value.each { |k, v| hash[k] = _to_hash(v) }
+ end
+ elsif value.respond_to? :to_hash
+ value.to_hash
+ else
+ value
+ end
+ end
+
+ end
+
+end
diff --git a/samples/client/petstore/ruby/spec/models/enum_arrays_spec.rb b/samples/client/petstore/ruby/spec/models/enum_arrays_spec.rb
new file mode 100644
index 00000000000..992eb750d30
--- /dev/null
+++ b/samples/client/petstore/ruby/spec/models/enum_arrays_spec.rb
@@ -0,0 +1,67 @@
+=begin
+#Swagger Petstore
+
+#This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
+
+OpenAPI spec version: 1.0.0
+Contact: apiteam@swagger.io
+Generated by: https://github.com/swagger-api/swagger-codegen.git
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+=end
+
+require 'spec_helper'
+require 'json'
+require 'date'
+
+# Unit tests for Petstore::EnumArrays
+# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
+# Please update as you see appropriate
+describe 'EnumArrays' do
+ before do
+ # run before each test
+ @instance = Petstore::EnumArrays.new
+ end
+
+ after do
+ # run after each test
+ end
+
+ describe 'test an instance of EnumArrays' do
+ it 'should create an instact of EnumArrays' do
+ expect(@instance).to be_instance_of(Petstore::EnumArrays)
+ end
+ end
+ describe 'test attribute "array_enum"' do
+ it 'should work' do
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
+ #validator = Petstore::EnumTest::EnumAttributeValidator.new('Array', [])
+ #validator.allowable_values.each do |value|
+ # expect { @instance.array_enum = value }.not_to raise_error
+ #end
+ end
+ end
+
+ describe 'test attribute "array_array_enum"' do
+ it 'should work' do
+ # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
+ #validator = Petstore::EnumTest::EnumAttributeValidator.new('Array>', [])
+ #validator.allowable_values.each do |value|
+ # expect { @instance.array_array_enum = value }.not_to raise_error
+ #end
+ end
+ end
+
+end
+