Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No more Exports #1345

Merged
merged 5 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions api/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module Properties
attr_reader :exclude
attr_reader :async
attr_reader :readonly
attr_reader :exports
attr_reader :transport
# Documentation references
attr_reader :references
Expand All @@ -66,6 +65,7 @@ module Properties
attr_reader :input # If true, resource is not updatable as a whole unit
attr_reader :min_version # Minimum API version this resource is in
attr_reader :update_mask
attr_reader :has_self_link
end

include Properties
Expand Down Expand Up @@ -184,8 +184,6 @@ def validate
check :exclude, type: :boolean
check :kind, type: String

check :exports, type: Array,
item_type: [String, Api::Type::FetchedExternal, Api::Type::SelfLink]
check :self_link, type: String
check :self_link_query, type: Api::Resource::ResponseList
check :readonly, type: :boolean
Expand All @@ -202,6 +200,8 @@ def validate
check :input, type: :boolean
check :min_version, type: String

check :has_self_link, type: :boolean, default: false

set_variables(@parameters, :__resource)
set_variables(@properties, :__resource)

Expand Down Expand Up @@ -248,17 +248,6 @@ def required_properties
all_user_properties.select(&:required)
end

def exported_properties
return [] if @exports.nil?

from_api = @exports.select { |e| e.is_a?(Api::Type::FetchedExternal) }
.each { |e| e.resource = self }
prop_names = @exports - from_api
all_user_properties.select { |p| prop_names.include?(p.name) }
.concat(from_api)
.sort_by(&:name)
end

# TODO(alexstephen): Update test_constants to use this function.
# Returns all of the properties that are a part of the self_link or
# collection URLs
Expand Down Expand Up @@ -298,16 +287,6 @@ def decoder?
!@transport&.decoder.nil?
end

# Returns true if this resource needs access to the saved API response
# This response is stored in the @fetched variable
# Requires:
# config: The config for an object
# object: An Api::Resource object
def save_api_results?
exported_properties.any? { |p| p.is_a? Api::Type::FetchedExternal } \
|| access_api_results
end

def min_version
if @min_version.nil?
@__product.default_version
Expand Down
6 changes: 4 additions & 2 deletions api/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def validate
end

def property
props = resource_ref.exported_properties
props = resource_ref.all_user_properties
.select { |prop| prop.name == @imports }
return props.first unless props.empty?
raise "#{@imports} does not exist on #{@resource}" if props.empty?
Expand Down Expand Up @@ -523,7 +523,9 @@ def check_resource_ref_exists
end

def check_resource_ref_property_exists
exported_props = resource_ref.exported_properties
exported_props = resource_ref.all_user_properties
exported_props << Api::Type::String.new('selfLink') \
if resource_ref.has_self_link
raise "'#{@imports}' does not exist on '#{@resource}'" \
if exported_props.none? { |p| p.name == @imports }
end
Expand Down
Loading