Handle recursive hashes (#621)

This fixes the generator for cases where one of the entries of the
"schemas" object returned by the Discovery service is a recursively
defined map.

Fixes #608
This commit is contained in:
bantini authored and Sai Cheemalapati committed 2017-10-12 10:57:57 -07:00
1 parent f4e89a556a
commit 6e2276cb80
3 files changed
+56 -4

No files matched your search

+9 -3
View File
@@ -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<String,%s>', qualified_name)
end
return sprintf('Hash<String,%s>', 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
@@ -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 %>