bploetz / versionist

A plugin for versioning Rails based RESTful APIs.
MIT License
972 stars 51 forks source link

Versioning Serializers #56

Closed michaelharro closed 10 years ago

michaelharro commented 10 years ago

In our API we have needed to change the format of our responses so we have a need for a different serializer for each version of our API. Is it possible for versionist to manage serializers for each version like it does with controllers?

bploetz commented 10 years ago

The presenters it generates are namespaced to a version just like the controllers are.

michaelharro commented 10 years ago

are the serializers namespaced too?

bploetz commented 10 years ago

What do you mean by "serializers"?

michaelharro commented 10 years ago

They are a part of ActiveModel that we are using in our project to generate json objects to be returned in our API. Here is an example https://github.com/CruGlobal/missionhub/blob/master/app/serializers/address_serializer.rb

bploetz commented 10 years ago

The presenters that versionist generates are just generic classes. While they don't extend ActiveModel::Serializer out of the box, there's nothing preventing you from having them extend ActiveModel::Serializer. So they would end up looking something like this:

class V2::BasePresenter < ActiveModel::Serializer
end

class V2::FooPresenter < V2::BasePresenter
  attributes :whatever
end

Untested, hand-wave, etc......

michaelharro commented 10 years ago

thanks, you have been extremely helpful. we really appreciate your work. ill bring this solution to the team.

bploetz commented 10 years ago

Cool let me know if that doesn't work for some reason.