-
Notifications
You must be signed in to change notification settings - Fork 141
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
Generic Objects Subcollection #57
Generic Objects Subcollection #57
Conversation
}, | ||
'associations' => { | ||
'vms' => [ | ||
{ 'href' => api_vm_url(nil, vm.id) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with these helpers, you can simply pass in the object, i.e. api_vm_url(nil, vm)
get(api_generic_object_definition_generic_object_url(nil, object_def.id, object.id), :params => {:associations => 'vms'}) | ||
|
||
expected = { | ||
'href' => api_generic_object_definition_generic_object_url(nil, object_def.id, object.id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment throughout, with these helpers just the object so ...(nil, object_def, object)
module Subcollections | ||
module GenericObjects | ||
def generic_objects_query_resource(object_definition) | ||
object_definition.generic_objects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the generic object definition has no generic object, is this nil here ? what is returned by API ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abellotti if it has no generic objects, it just returns an empty array, so the api returns "resources": []
@@ -0,0 +1,40 @@ | |||
module Api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should go in a new folder: app/controllers/api/mixins/
and dropping the BaseController in the module hierarchy, it would just be a submodule of the
class including the mixin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abellotti I explained a bit more in the PR description, but I have been looking into this (which is why it's still WIP) ...however, without the BaseController module hierarchy and with it in app/controllers/api/mixins
, it has been creating sporadic test failures that I have been trying to figure out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to have to do with the way things are loaded, but haven't figured out the solution just yet.
@@ -114,6 +120,10 @@ def build_generic_object_definition_options | |||
|
|||
private | |||
|
|||
def generic_objects_request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not quite sure what this does. why is it needed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, it's a bit funky, but basically this controller needs to have the before_action
hooks to allow for the subcollection to set the associations
for requests such as GET /api/generic_object_definitions/:id/generic_objects?associations=vms
as well as to set the hook to set @additional_attributes
...we don't want to set the hooks unless the subject is generic_objects
, so this method is the if
condition on the hook. updated the name to is_generic_objects_request
. Any other naming ideas?
@abellotti exhibit A of sporadic test failures. Thought everything was fine with the mixin, finally, but Travis is now having failures I don't get locally 😭 |
@miq-bot assign @abellotti |
@@ -1,5 +1,11 @@ | |||
module Api | |||
class GenericObjectDefinitionsController < BaseController | |||
include Api::Mixins::GenericObjects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In short, I think you needed the Api
qualification because the classic UI has a top-level Mixins
namespace. If something in there gets loaded first, it will break the autoloading of this module. I'm proposing that the classic UI not do that and put their mixins in their own namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @imtayadeway !!! ✨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you could use include_concern Mixins::GenericObjects
which I guess is the standard way that we deal with this problem (and may convey to the next person that there is some kind of contention over the Mixins
namespace)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@imtayadeway unfortunately I tried this, and the API is not happy :(
This pull request is not mergeable. Please rebase and repush. |
@abellotti can we get this merged please? it is blocking other Generic Object items |
just squashed some commits. |
LGTM!! |
ping @imtayadeway can we borrow your 👀 please ? |
This pull request is not mergeable. Please rebase and repush. |
return property attributes by default and return specified associations move mixin to its own folder move include from the sub collection to the collection
Checked commits jntullo/manageiq-api@27d50e2~...ff531b4 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
let(:vm) { FactoryGirl.create(:vm_amazon) } | ||
|
||
before do | ||
object_def.add_property_attribute('is_something', 'boolean') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extensive setup here seems to suggest that the GO API is missing something....perhaps we could at a later point create a factory, or a builder, or at least enhance the factory girl definition to help simplify this process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, some factories for "simple" objects with dummy attributes would be useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @imtayadeway for your review 🙇 |
This PR adds a Generic Objects Subcollection on the Generic Object Definition
Usage
GET /api/generic_object_definitions/:id/generic_objects
will return the collection of generic objects of that definition type:
GET /api/generic_object_definitions/:id/generic_objects/:id
will return property attributes by default:
can specify
associations
on the request, ie:GET /api/generic_object_definitions/:id/generic_objects/:id?associations=vms,services
returns:
GET /api/services/:id/generic_objects
GET /api/services/:id?expand=resources,generic_objects&attributes=generic_objects.generic_object_definition
POST /api/generic_object_definitions/:id/generic_objects
it can create a new generic object for the specified generic object definition:
Background
There is shared code between the generic objects controller and the generic objects subcollection. The code is tightly coupled with the controllers, and therefore not suitable for a service, which was the design choice behind the mixin.When writing the mixin, the initial intent was to not have it as a part of BaseController, it was instead to haveApi::Mixins::GenericObjects
, however, this caused sporadic test failures when included asinclude Mixins::GenericObjects
. I think this may require greater refactoring to achieve it asApi::Mixins
, which might be better suited in another PR.