# Is it possible to embedd another validation schema in a new one? (\*\*not\*\* nest)

**URL:** <https://discourse.dry-rb.org/t/is-it-possible-to-embedd-another-validation-schema-in-a-new-one-not-nest/616>\
**Category:** Uncategorized\
**Created:** [August 23, 2018, 12:11am UTC](https://discourse.dry-rb.org/t/is-it-possible-to-embedd-another-validation-schema-in-a-new-one-not-nest/616 "2018-08-23T00:11:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![i2chris](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/i2chris/32/268_2.png) [@i2chris](https://discourse.dry-rb.org/u/i2chris)\
**Post date:** [August 23, 2018, 12:11am UTC](https://discourse.dry-rb.org/t/is-it-possible-to-embedd-another-validation-schema-in-a-new-one-not-nest/616/1 "2018-08-23T00:11:36Z")

</div>

Let’s say if I have this schema:

```auto
      Schema = Dry::Validation.Params do
        required(:company_id).filled(:int?)
        required(:names).filled(:array?)
        optional(:company_branch_id).maybe(:int?)
      end

```

Can I embed it into another schema that contains high levels rules?  
The result of this embedding would create a schema like this:

```auto
      NewSchema = Dry::Validation.Params do
        required(:company_id).filled(:int?)
        required(:names).filled(:array?)
        optional(:company_branch_id).maybe(:int?)
        validate(..) do 
        end
        rule(...) do 
        end
      end

```

I could imagine it working something like this:

```auto
      NewSchema = Dry::Validation.Params do
        schema(Schema)
        validate(..) do 
        end
        rule(...) do 
        end
      end

```

I know solniss mentioned that it will be easily possible in the new 1.0 dry-validation/dry-schema, but is there a way to do it now?

---

<div class="post-metadata">

**Author:** ![alexandru-calinoiu](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/alexandru-calinoiu/32/98_2.png) [@alexandru-calinoiu](https://discourse.dry-rb.org/u/alexandru-calinoiu)\
**Post date:** [August 29, 2018, 1:32pm UTC](https://discourse.dry-rb.org/t/is-it-possible-to-embedd-another-validation-schema-in-a-new-one-not-nest/616/2 "2018-08-29T13:32:34Z")

</div>

Hey,

When you say embed I thought that you where referring to [https://dry-rb.org/gems/dry-validation/reusing-schemas/](https://dry-rb.org/gems/dry-validation/reusing-schemas/)

But I think you need a base schema like:

```auto
class AppSchema < Dry::Validation::Schema
  configure do |config|
    config.messages_file = '/my/app/config/locales/en.yml'
    config.messages = :i18n
  end

  def email?(value)
    true
  end

  define! do
    # define common rules, if any
  end
end

# now you can build other schemas on top of the base one:
Dry::Validation.Schema(AppSchema) do
  # define your rules
end

```

More on the topic here [https://dry-rb.org/gems/dry-validation/basics/working-with-schemas/](https://dry-rb.org/gems/dry-validation/basics/working-with-schemas/)
