Skip to content

Commit

Permalink
Fix Ember warnings about embedded data not being present on APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
GUI committed Apr 23, 2017
1 parent 3e01914 commit 27bf988
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/api-umbrella/web-app/app/models/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,17 @@ def roles
roles.uniq!
roles
end

def serializable_hash(options = nil)
hash = super(options)
# Ensure all embedded relationships are at least null in the JSON output
# (rather than not being present), or else Ember-Data's serialization
# throws warnings.
hash["rewrites"] ||= nil
hash["servers"] ||= nil
hash["settings"] ||= nil
hash["sub_settings"] ||= nil
hash["url_matches"] ||= nil
hash
end
end
12 changes: 12 additions & 0 deletions src/api-umbrella/web-app/app/models/api/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ def set_transition_starts_on_publish
end
end

def serializable_hash(options = nil)
hash = super(options)
# Ensure all embedded relationships are at least null in the JSON output
# (rather than not being present), or else Ember-Data's serialization
# throws warnings.
hash["default_response_headers"] ||= nil
hash["headers"] ||= nil
hash["override_response_headers"] ||= nil
hash["rate_limits"] ||= nil
hash
end

private

def read_headers_string(field)
Expand Down
9 changes: 9 additions & 0 deletions src/api-umbrella/web-app/app/models/api/sub_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ class Api::SubSettings

# Nested attributes
accepts_nested_attributes_for :settings

def serializable_hash(options = nil)
hash = super(options)
# Ensure all embedded relationships are at least null in the JSON output
# (rather than not being present), or else Ember-Data's serialization
# throws warnings.
hash["settings"] ||= nil
hash
end
end
9 changes: 9 additions & 0 deletions src/api-umbrella/web-app/app/models/api_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ def api_key_hides_at
@api_key_hides_at ||= self.created_at + 2.weeks
end

def serializable_hash(options = nil)
hash = super(options)
# Ensure all embedded relationships are at least null in the JSON output
# (rather than not being present), or else Ember-Data's serialization
# throws warnings.
hash["settings"] ||= nil
hash
end

private

def normalize_terms_and_conditions
Expand Down

0 comments on commit 27bf988

Please sign in to comment.