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

Fix apidoc position of Puppet plugin #151

Merged
merged 2 commits into from
Jun 9, 2021

Conversation

nadjaheitmann
Copy link
Collaborator

@nadjaheitmann nadjaheitmann commented May 21, 2021

This fixes #147

@nadjaheitmann nadjaheitmann force-pushed the fix_apidoc branch 2 times, most recently from 4c83e3f to e5f8353 Compare May 21, 2021 12:39
@nadjaheitmann nadjaheitmann changed the title Fix apidoc WIP: Fix apidoc May 21, 2021
@nadjaheitmann nadjaheitmann changed the title WIP: Fix apidoc Fix apidoc May 21, 2021
@nadjaheitmann nadjaheitmann changed the title Fix apidoc Fix apidoc position of Puppet plugin May 21, 2021
@@ -3,7 +3,8 @@ module Api
module V2
class BaseController < ::Api::V2::BaseController
resource_description do
api_version '2'
resource_id 'foreman_puppet_base'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the id of the resource used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used by Apipie to distinguish between the classes and get the documentation correctly, as far as I can tell.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should change the resource_id of the BaseController and the one of the LookupsCommonController to have a pp_ prefix such that all of the resource_ids are consistent.

@nadjaheitmann
Copy link
Collaborator Author

With this PR, the API entries appear in addition to the core entries. Is this okay or should they replace the core entries?

@timogoebel
Copy link
Member

timogoebel commented May 28, 2021

With this PR, the API entries appear in addition to the core entries. Is this okay or should they replace the core entries?

I believe when the plugin is installed, the core models and controllers don't work anymore and the endpoints from this plugin should be used.

@nadjaheitmann nadjaheitmann changed the title Fix apidoc position of Puppet plugin WIP: Fix apidoc position of Puppet plugin May 28, 2021
@nadjaheitmann
Copy link
Collaborator Author

nadjaheitmann commented May 28, 2021

I believe when the plugin is installed, the core models and controllers don't work anymore and the endpoints from this plugin should be used.

As of now, @ezr-ondrej said that the old routes are redirected to the new ones. But in any case, I think it makes more sense to remove the old apidoc entries or at least mark them as deprecated as it gives the impression that both can be used in parallel. I will fix that.

@timogoebel
Copy link
Member

I'm wondering if we can add something to the CI to verify all relevant fields are properly documented.

@nadjaheitmann
Copy link
Collaborator Author

I'm wondering if we can add something to the CI to verify all relevant fields are properly documented.

This would be very helpful indeed as comparing all API entries manually is very tedious. I will think about it. Let me know if you have an idea how to do it.

@nadjaheitmann
Copy link
Collaborator Author

nadjaheitmann commented Jun 1, 2021

As of now, @ezr-ondrej said that the old routes are redirected to the new ones.

Correction: Old routes are not redirected, yet, but end up at the core API. Do we want to fix this?

[I|app|e93963d1] Started GET "/api/puppetclasses" for 192.168.121.1 at 2021-06-01 06:45:45 +0000$
[I|app|e93963d1] Processing by Api::V2::PuppetclassesController#index as JSON

With this PR, the documentation of the core API is overwritten, such that only new routes are shown. Moreover, resource_id stays the same as in core for all commands, such that e.g. Hammer can automatically use the new routes instead of the old ones.

The PR fixes #147 that were caused mostly by resource_id inconsistencies between Foreman core and the plugin.

@timogoebel
Copy link
Member

Correction: Old routes are not redirected, yet, but end up at the core API. Do we want to fix this?

Yes, I think we should. We could also just disable the core routes. I think we should just make sure this is actually worth the effort. I can see a lot of tests in core break if we implement this.

Let me know if you have an idea how to do it.

I think it should be fairly easy to get all relevant API controllers (e.g. via the routes) and all the actions. We then need possible parameters that we could get from the parameter filters. And to finish it up, the documentation dsl should give us a list of all already documented parameters.

@nadjaheitmann
Copy link
Collaborator Author

Yes, I think we should. We could also just disable the core routes. I think we should just make sure this is actually worth the effort. I can see a lot of tests in core break if we implement this.

I will open a new issue for this.

I think it should be fairly easy to get all relevant API controllers (e.g. via the routes) and all the actions. We then need possible parameters that we could get from the parameter filters. And to finish it up, the documentation dsl should give us a list of all already documented parameters.

Let me give it a try. I guess it makes sense to have the tests as part of this PR? But I have not seen tests for apidoc completion before, so could be a new issue as well...

@timogoebel
Copy link
Member

But I have not seen tests for apidoc completion before, so could be a new issue as well...

I'd recommend a separate issue.

@nadjaheitmann nadjaheitmann changed the title WIP: Fix apidoc position of Puppet plugin Fix apidoc position of Puppet plugin Jun 1, 2021
@nadjaheitmann
Copy link
Collaborator Author

Is there anything that needs fixing for this PR?

Copy link
Member

@timogoebel timogoebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@@ -1,10 +1,9 @@
module ForemanPuppet
module Api
module V2
class BaseController < ::Api::V2::BaseController
class PuppetBaseController < ::Api::V2::BaseController
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other reason for renaming the controllers, or do you just feel it's a better name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that the resource_id of any controller is generated from the name of the controller. As there already exist a controller named BaseController in Foreman core, there is a name clash. It is okay for the controllers that should be overwritten anyways, but not for the ones that should remain in Foreman core.

@kamils-iRonin kamils-iRonin merged commit 1737600 into theforeman:master Jun 9, 2021
@kamils-iRonin
Copy link
Member

Thanks @nadjaheitmann 👍

@nadjaheitmann nadjaheitmann deleted the fix_apidoc branch June 9, 2021 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API inconsistencies
4 participants