# Validating against a partial schema

**URL:** <https://discourse.dry-rb.org/t/validating-against-a-partial-schema/434>\
**Category:** dry-validation\
**Created:** [December 13, 2017, 12:19pm UTC](https://discourse.dry-rb.org/t/validating-against-a-partial-schema/434 "2017-12-13T12:19:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yewton](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/yewton/32/185_2.png) [@yewton](https://discourse.dry-rb.org/u/yewton)\
**Post date:** [December 13, 2017, 12:19pm UTC](https://discourse.dry-rb.org/t/validating-against-a-partial-schema/434/1 "2017-12-13T12:19:02Z")

</div>

Same context as: [https://github.com/dry-rb/dry-validation/issues/261](https://github.com/dry-rb/dry-validation/issues/261)

So I tried to enable partial validation by adding the method below to `Dry::Validation::Schema`:

```
def only(*rules)
  self.class.new(self.class.rules.select { |rule| rules.include?(rule.name) }, options)
end

```

It seems to work in a simple use case:

```
[49] pry(main)> schema = Dry::Validation.Schema { required(:name).filled; required(:age).maybe(:int?) }
[50] pry(main)> schema.({}).errors
=> {:name=>["is missing"], :age=>["is missing"]}
[51] pry(main)> schema.only(:name).({}).errors
=> {:name=>["is missing"]}
[52] pry(main)> schema.only(:age).({}).errors
=> {:age=>["is missing"]}
[53] pry(main)> schema.only(:age).(age: '1').errors
=> {:age=>["must be an integer"]}
[54] pry(main)> schema.only(:name).(name: 'foo', age: '1').errors
=> {}

```

So is this a reasonable implementation to achieve validating against a partial schema…?

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [January 9, 2018, 7:26pm UTC](https://discourse.dry-rb.org/t/validating-against-a-partial-schema/434/2 "2018-01-09T19:26:08Z")

</div>

Yes, that’s actually pretty sweet. I’ll keep this in mind when working on dry-validation 1.0.0.
