# Getting dry-types metadata into dry-schema's JSON Schema output

**URL:** <https://discourse.dry-rb.org/t/getting-dry-types-metadata-into-dry-schemas-json-schema-output/1439>\
**Category:** Support\
**Created:** [March 10, 2022, 8:25am UTC](https://discourse.dry-rb.org/t/getting-dry-types-metadata-into-dry-schemas-json-schema-output/1439 "2022-03-10T08:25:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomdalling](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/tomdalling/32/750_2.png) [@tomdalling](https://discourse.dry-rb.org/u/tomdalling)\
**Post date:** [March 10, 2022, 8:25am UTC](https://discourse.dry-rb.org/t/getting-dry-types-metadata-into-dry-schemas-json-schema-output/1439/1 "2022-03-10T08:25:45Z")

</div>

G’day everyone,

We are looking at having types something like this:

```ruby
module Types
  include Dry.Types()

  Email = self::String.meta(
    json_schema: {
      description: "An email address",
      example: "person@example.com",
    }
  )
end

```

Which gets put into a schema like this:

```ruby
schema = Dry::Schema.JSON do
  required(:email).filled(Types::Email)
end

```

And then converted into JSON schema _including the metadata_:

```ruby
Dry::Schema.load_extensions(:json_schema)
schema.json_schema #=>

```

```json
{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "type": "object",
  "properties": {
    "email": {
      "type": "string",
      "description": "An email address",
      "example": "person@example.com"
    }
  },
  "required": [
    "email"
  ]
}

```

To be included in an OpenAPI document.

Having a quick dig through dry-schema, it appears that the type metadata is not carried across to the schema, so there is no simple way to include it in the JSON Schema output. Does that sound correct?

Any ideas how we could achieve this?

---

<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:** [March 15, 2022, 7:49am UTC](https://discourse.dry-rb.org/t/getting-dry-types-metadata-into-dry-schemas-json-schema-output/1439/2 "2022-03-15T07:49:27Z")

</div>

@tomdalling if you extend the compiler so that it has access to type\_schema, then you can look into meta-data too and use that info in the `visit_key` method. When I say `type_schema` I mean this:

```auto
dry-schema> schema.type_schema.to_ast
=> [:lax, [:schema, [[[:key, [:email, false, [:nominal, [String, {:json_schema=>{:description=>"An email address", :example=>"person@example.com"}, :required=>false, :maybe=>false}]]]]], {}, {}]]]

```

---

<div class="post-metadata">

**Author:** ![tomdalling](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/tomdalling/32/750_2.png) [@tomdalling](https://discourse.dry-rb.org/u/tomdalling)\
**Post date:** [March 22, 2022, 1:50am UTC](https://discourse.dry-rb.org/t/getting-dry-types-metadata-into-dry-schemas-json-schema-output/1439/3 "2022-03-22T01:50:47Z")

</div>

Ok cool, thanks for that. Would you be open to a PR that adds this functionality to the `json_schema` extension? /CC @ianks

---

<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:** [March 22, 2022, 7:06am UTC](https://discourse.dry-rb.org/t/getting-dry-types-metadata-into-dry-schemas-json-schema-output/1439/4 "2022-03-22T07:06:59Z")

</div>

Yes, definitely ❤
