Skip to content

Commit

Permalink
Api collection OPTIONS Enhancement to expose list of supported subcol…
Browse files Browse the repository at this point in the history
…lections

OPTIONS /api/vms

{
  ....
  "subcollections" : [
    "accounts",
    "custom_attributes",
    ...
  ]
  "data" : {
  }
}

This enhancement is necessary for continuing work
on the API Client to support subcollections.
  • Loading branch information
abellotti committed Jan 27, 2017
1 parent 3860236 commit 2395855
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ def render_options(resource, data = {})
collection.virtual_reflections.keys.collect(&:to_s)).sort
}
end
options[:subcollections] = Array(collection_config[resource].subcollections).sort
options[:data] = data
render :json => options
end
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/api/arbitration_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@

attributes = (ArbitrationRule.attribute_names - ArbitrationRule.virtual_attribute_names).sort.as_json
reflections = (ArbitrationRule.reflections.keys | ArbitrationRule.virtual_reflections.keys.collect(&:to_s)).sort
subcollections = Array(Api::ApiConfig.collections[:arbitration_rules].subcollections).collect(&:to_s).sort
expected = {
'attributes' => attributes,
'virtual_attributes' => ArbitrationRule.virtual_attribute_names.sort.as_json,
'relationships' => reflections,
'subcollections' => subcollections,
'data' => {
'field_values' => ArbitrationRule.field_values
}
Expand Down
1 change: 1 addition & 0 deletions spec/requests/api/querying_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ def create_vms_by_name(names)
'attributes' => (Vm.attribute_names - Vm.virtual_attribute_names).sort.as_json,
'virtual_attributes' => Vm.virtual_attribute_names.sort.as_json,
'relationships' => (Vm.reflections.keys | Vm.virtual_reflections.keys.collect(&:to_s)).sort,
'subcollections' => Array(Api::ApiConfig.collections[:vms].subcollections).collect(&:to_s).sort,
'data' => {}
}
run_options(vms_url)
Expand Down

0 comments on commit 2395855

Please sign in to comment.