diff --git a/lib/google/apis/generator/model.rb b/lib/google/apis/generator/model.rb index d819a68e7..30f381c61 100644 --- a/lib/google/apis/generator/model.rb +++ b/lib/google/apis/generator/model.rb @@ -55,8 +55,14 @@ module Google return 'Fixnum' if format == 'uint64' return TYPE_MAP[type] when 'array' + if items == self + return sprintf('Array<%s>', qualified_name) + end return sprintf('Array<%s>', items.generated_type) when 'hash' + if additional_properties == self + return sprintf('Hash', qualified_name) + end return sprintf('Hash', additional_properties.generated_type) when 'object' return qualified_name @@ -81,16 +87,16 @@ module Google return [] if parameters.nil? parameters.values.select { |param| param.location == 'query' } end - + def required_parameters return [] if parameter_order.nil? || parameters.nil? parameter_order.map { |name| parameters[name] }.select { |param| param.location == 'path' || param.required } end - + def optional_query_parameters query_parameters.select { |param| param.required != true } end - + end class RestResource diff --git a/lib/google/apis/generator/templates/_class.tmpl b/lib/google/apis/generator/templates/_class.tmpl index 5658483d3..44a193979 100644 --- a/lib/google/apis/generator/templates/_class.tmpl +++ b/lib/google/apis/generator/templates/_class.tmpl @@ -1,4 +1,4 @@ -<% if cls.type == 'object' -%> +<% if cls.type == 'object' || (cls.type == 'hash' && cls.properties.length > 0) -%> # <%= block_comment(cls.description, 0, 1) %> class <%= cls.generated_class_name %><% if cls.base_ref %> < <%= cls.base_ref.generated_type %><% end %> diff --git a/spec/fixtures/files/test_api.json b/spec/fixtures/files/test_api.json index 29a46871a..fad3f1d96 100644 --- a/spec/fixtures/files/test_api.json +++ b/spec/fixtures/files/test_api.json @@ -90,6 +90,9 @@ "hat": { "$ref": "Hat" }, + "recursiveHat": { + "$ref": "RecursiveHat" + }, "properties": { "$ref": "HashLikeThing" }, @@ -131,6 +134,49 @@ ] } }, + "RecursiveHat": { + "id": "RecursiveHat", + "type": "object", + "properties": { + "bool": { + "type": "boolean", + "description": "The bool value." + }, + "double": { + "type": "number", + "description": "The double value.", + "format": "double" + }, + "image": { + "$ref": "Image", + "description": "The image value." + }, + "int": { + "type": "integer", + "description": "The int value.", + "format": "int32" + }, + "kind": { + "type": "string", + "description": "The kind, fixed to \"test#recursiveHat\".", + "default": "test#recursiveHat" + }, + "list": { + "type": "array", + "description": "The list of typed values.", + "items": { + "$ref": "RecursiveHat" + } + }, + "string": { + "type": "string", + "description": "The string value." + } + }, + "additionalProperties": { + "$ref": "RecursiveHat" + } + }, "TopHat": { "type": "object", "properties": {