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 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 %> | ||||
|  |  | |||
|  | @ -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": { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue