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

A way to extend an exiting API via concern #554

Merged
merged 1 commit into from
Aug 21, 2017
Merged

Conversation

iNecas
Copy link
Member

@iNecas iNecas commented Aug 20, 2017

Sometimes, it's needed to extend an existing controller method with additional
parameters (usually when extending exiting API from plugins/rails engines).
The concern can be also used for this purposed, using update_api method.
The params defined in this block are merged with the params of the original method
in the controller this concern is included to.

module Concerns
  module OauthConcern
    extend Apipie::DSL::Concern

    update_api(:create, :update) do
      param :user, Hash do
        param :oauth, String, :desc => 'oauth param'
      end
    end
  end
end

The concern needs to be included to the controller after the methods are defined
(either at the end of the class, or by using Controller.send(:include, Concerns::OauthConcern).

@iNecas
Copy link
Member Author

iNecas commented Aug 20, 2017

@ares does this fit your needs?

@iNecas
Copy link
Member Author

iNecas commented Aug 20, 2017

Fixes #330

@ares
Copy link

ares commented Aug 21, 2017

Looks great!

@ares
Copy link

ares commented Aug 21, 2017

And works for my use case

Sometimes, it's needed to extend an existing controller method with additional
parameters (usually when extending exiting API from plugins/rails engines).
The concern can be also used for this purposed, using `update_api` method.
The params defined in this block are merged with the params of the original method
in the controller this concern is included to.

```ruby
module Concerns
  module OauthConcern
    extend Apipie::DSL::Concern

    update_api(:create, :update) do
 param :user, Hash do
   param :oauth, String, :desc => 'oauth param'
 end
    end
  end
end
```

The concern needs to be included to the controller after the methods are defined
(either at the end of the class, or by using `Controller.send(:include, Concerns::OauthConcern)`.
@iNecas
Copy link
Member Author

iNecas commented Aug 21, 2017

Thanks for review and tests. Merging

@iNecas iNecas merged commit cfb4219 into Apipie:master Aug 21, 2017
@iNecas iNecas deleted the update_api branch August 21, 2017 20:52
@iNecas
Copy link
Member Author

iNecas commented Aug 21, 2017

apipie-0.5.2 released, including this change.

@stbenjam
Copy link
Contributor

🙌 Yay! Thanks @iNecas !!

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.

3 participants