I was searching about building Rails APIs and how to right apply some versioning on model validations.
Suppose there is a model and a route like these ones:
class Person < ApplicationRecord
validates :name, presence: true
end
namespace :v1
resources :people
end
So, my model is validating if name
is present.
But, if I want to release a new version of my API with a new validation on Person
to make, for example, a job
field mandatory, as this one:
class Person < ApplicationRecord
validates :name, presence: true
validates :job, presence: true
end
If I make it this way, I would break my V1 endpoint. So, is there a good practice to make it without breaking my previous V1 endpoint? Or should I drop this validations out of model and make it on request parameter level?
I've saw some gems that makes it at model level but I would like to know if there is some pattern for it without using any additional gem.