diff --git a/api/product.rb b/api/product.rb index 82a43baff263..cc3fa323adc0 100644 --- a/api/product.rb +++ b/api/product.rb @@ -34,6 +34,10 @@ def api_name name.downcase end + def to_s + JSON.pretty_generate(self) + end + def to_json(opts = nil) json_out = {} diff --git a/api/resource.rb b/api/resource.rb index b38a3a72e1b0..400463336c87 100644 --- a/api/resource.rb +++ b/api/resource.rb @@ -135,6 +135,10 @@ def validate end end + def to_s + JSON.pretty_generate(self) + end + def to_json(opts = nil) # ignore fields that will contain references to parent resources ignored_fields = %i[@__product @__parent @__resource @api_name @collection_url_response] diff --git a/api/type.rb b/api/type.rb index 59be95f90b80..85b4987457b9 100644 --- a/api/type.rb +++ b/api/type.rb @@ -83,7 +83,7 @@ def to_json(opts = nil) instance_variables.each do |v| if v == :@conflicts && instance_variable_get(v).empty? # ignore empty conflict arrays - elsif instance_variable_get(v) == false + elsif instance_variable_get(v) == false || instance_variable_get(v).nil? # ignore false booleans as non-existence indicates falsey elsif !ignored_fields.include? v json_out[v] = instance_variable_get(v)