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:
parent
f4e89a556a
commit
6e2276cb80
|
@ -55,8 +55,14 @@ module Google
|
||||||
return 'Fixnum' if format == 'uint64'
|
return 'Fixnum' if format == 'uint64'
|
||||||
return TYPE_MAP[type]
|
return TYPE_MAP[type]
|
||||||
when 'array'
|
when 'array'
|
||||||
|
if items == self
|
||||||
|
return sprintf('Array<%s>', qualified_name)
|
||||||
|
end
|
||||||
return sprintf('Array<%s>', items.generated_type)
|
return sprintf('Array<%s>', items.generated_type)
|
||||||
when 'hash'
|
when 'hash'
|
||||||
|
if additional_properties == self
|
||||||
|
return sprintf('Hash<String,%s>', qualified_name)
|
||||||
|
end
|
||||||
return sprintf('Hash<String,%s>', additional_properties.generated_type)
|
return sprintf('Hash<String,%s>', additional_properties.generated_type)
|
||||||
when 'object'
|
when 'object'
|
||||||
return qualified_name
|
return qualified_name
|
||||||
|
|
|
@ -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) %>
|
# <%= block_comment(cls.description, 0, 1) %>
|
||||||
class <%= cls.generated_class_name %><% if cls.base_ref %> < <%= cls.base_ref.generated_type %><% end %>
|
class <%= cls.generated_class_name %><% if cls.base_ref %> < <%= cls.base_ref.generated_type %><% end %>
|
||||||
|
|
|
@ -90,6 +90,9 @@
|
||||||
"hat": {
|
"hat": {
|
||||||
"$ref": "Hat"
|
"$ref": "Hat"
|
||||||
},
|
},
|
||||||
|
"recursiveHat": {
|
||||||
|
"$ref": "RecursiveHat"
|
||||||
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"$ref": "HashLikeThing"
|
"$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": {
|
"TopHat": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
Loading…
Reference in New Issue