Dry-validation: Schema definition inspect


Hi, this is more a question than an issue. I’m currently using dry-validation to validate API requests parameters. Is there a way to return the schema definition in a format like a Hash or Json?

Let say I have this definition:

schema = Dry::Validation.Schema do 
  required(:ic_type).filled(:int?, included_in?: [0,1,3])

I would like to retrieve something like this:

schema.to_hash => { ic_type: {required: true, type: 'int', included_in: [0,1,3] } }

How can I accomplish this? I want to reuse the schemas to provide information to clients so they can build, for example, input forms depending on required or missing fields.

I tried with JSON Schemas before discovering Dry-Validation, but I had hard times trying to work with nested and complex schemas (this was probably a layer 8 issue more than a library limitation)



I’m going to use the #messages method on the resultto provide information about the schema.


I think your problem is similar to https://github.com/dry-rb/dry-validation/issues/67