Update generator to correctly handle int64/uint64 types as fixnum/bignum instead of strings
This commit is contained in:
parent
2c190e9745
commit
39d0a164b5
|
@ -21,6 +21,7 @@ require 'google/apis/core/upload'
|
|||
require 'google/apis/core/download'
|
||||
require 'google/apis/options'
|
||||
require 'googleauth'
|
||||
require 'httpclient'
|
||||
|
||||
module Google
|
||||
module Apis
|
||||
|
|
|
@ -72,6 +72,10 @@ module Google
|
|||
options[:render_filter] = ->(value, _doc, *_args) { value.nil? ? nil : Base64.urlsafe_encode64(value) }
|
||||
options[:parse_filter] = ->(fragment, _doc, *_args) { Base64.urlsafe_decode64(fragment) }
|
||||
end
|
||||
if options[:numeric_string]
|
||||
options[:render_filter] = ->(value, _doc, *_args) { value.nil? ? nil : value.to_s}
|
||||
options[:parse_filter] = ->(fragment, _doc, *_args) { fragment.to_i }
|
||||
end
|
||||
if options[:type] == DateTime
|
||||
options[:render_filter] = ->(value, _doc, *_args) { value.nil? ? nil : value.is_a?(DateTime) ? value.rfc3339(3) : value.to_s }
|
||||
options[:parse_filter] = ->(fragment, _doc, *_args) { DateTime.parse(fragment) }
|
||||
|
|
|
@ -51,6 +51,8 @@ module Google
|
|||
when 'string', 'boolean', 'number', 'integer', 'any'
|
||||
return 'DateTime' if format == 'date-time'
|
||||
return 'Date' if format == 'date'
|
||||
return 'Fixnum' if format == 'int64'
|
||||
return 'Fixnum' if format == 'uint64'
|
||||
return TYPE_MAP[type]
|
||||
when 'array'
|
||||
return sprintf('Array<%s>', items.generated_type)
|
||||
|
|
|
@ -33,7 +33,7 @@ class <%= cls.generated_class_name %>
|
|||
<% elsif property.type == 'array' -%>
|
||||
collection :<%= property.generated_name %>, as: '<%= property.name %>'<%= include('representation_type', :lead => ', ', :type => property.items, :api => api) %>
|
||||
<% else -%>
|
||||
property :<%= property.generated_name %>,<% if property.format == 'byte' %> :base64 => true,<%end%> as: '<%= property.name %>'<%= include('representation_type', :lead => ', ', :type => property, :api => api) %>
|
||||
property :<%= property.generated_name %>,<% if ['uint64', 'int64'].include?(property.format) %> :numeric_string => true,<%end%><% if property.format == 'byte' %> :base64 => true,<%end%> as: '<%= property.name %>'<%= include('representation_type', :lead => ', ', :type => property, :api => api) %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
|
|
|
@ -33,6 +33,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
|||
attr_accessor :date_value
|
||||
attr_accessor :nil_date_value
|
||||
attr_accessor :bytes_value
|
||||
attr_accessor :big_value
|
||||
attr_accessor :items
|
||||
attr_accessor :child
|
||||
attr_accessor :children
|
||||
|
@ -51,6 +52,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
|||
property :date_value, as: 'dateValue', type: DateTime
|
||||
property :nil_date_value, as: 'nullDateValue', type: DateTime
|
||||
property :bytes_value, as: 'bytesValue', base64: true
|
||||
property :big_value, as: 'bigValue', numeric_string: true
|
||||
property :items
|
||||
property :child, class: klass do
|
||||
property :value
|
||||
|
@ -106,6 +108,10 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
|||
it 'serializes object collections' do
|
||||
expect(json).to be_json_eql(%([{"value" : "child"}])).at_path('children')
|
||||
end
|
||||
|
||||
it 'serializes numeric strings' do
|
||||
expect(json).to be_json_eql(%("1208925819614629174706176")).at_path('bigValue')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with model object' do
|
||||
|
@ -124,6 +130,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
|||
model.child.value = 'child'
|
||||
model.children = [model.child]
|
||||
model.nil_date_value = nil
|
||||
model.big_value = 1208925819614629174706176
|
||||
model
|
||||
end
|
||||
|
||||
|
@ -143,6 +150,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
|||
boolean_value_true: true,
|
||||
boolean_value_false: false,
|
||||
bytes_value: 'Hello world',
|
||||
big_value: 1208925819614629174706176,
|
||||
items: [1, 2, 3],
|
||||
child: {
|
||||
value: 'child'
|
||||
|
@ -165,6 +173,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
|
|||
"numericValue": 123,
|
||||
"dateValue": "2015-05-01T12:00:00+00:00",
|
||||
"bytesValue": "SGVsbG8gd29ybGQ=",
|
||||
"bigValue": "1208925819614629174706176",
|
||||
"items": [1,2,3],
|
||||
"child": {"value" : "hello"},
|
||||
"children": [{"value" : "hello"}]
|
||||
|
@ -204,5 +213,10 @@ EOF
|
|||
it 'serializes object collections' do
|
||||
expect(model.children[0].value).to eql 'hello'
|
||||
end
|
||||
|
||||
it 'deserializes numeric strings' do
|
||||
expect(model.big_value).to eql 1208925819614629174706176
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue