# Is there a way to check if a field is optional?

**URL:** <https://discourse.dry-rb.org/t/is-there-a-way-to-check-if-a-field-is-optional/1629>\
**Category:** dry-types\
**Created:** [March 23, 2023, 6:08am UTC](https://discourse.dry-rb.org/t/is-there-a-way-to-check-if-a-field-is-optional/1629 "2023-03-23T06:08:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![malanderjacob](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@malanderjacob](https://discourse.dry-rb.org/u/malanderjacob)\
**Post date:** [March 23, 2023, 6:08am UTC](https://discourse.dry-rb.org/t/is-there-a-way-to-check-if-a-field-is-optional/1629/1 "2023-03-23T06:08:02Z")

</div>

Hello! I have a class below. If I create an instance of this object, is there a way to check if a field is optional or not? I was hoping to find a method such as user\_object.first\_name.optional? and have it return true but I have not found one in the documentation. Thank you!

class User \< Dry::Struct  
attribute :id, Types::Strict::Integer  
attribute :first\_name, Types::Coercible::String.optional  
end

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/alassek/32/314_2.png) [@alassek](https://discourse.dry-rb.org/u/alassek)\
**Post date:** [March 24, 2023, 4:53pm UTC](https://discourse.dry-rb.org/t/is-there-a-way-to-check-if-a-field-is-optional/1629/2 "2023-03-24T16:53:54Z")

</div>

There isn’t a defined public API for this, but you could make one.

```ruby
User.schema.keys.filter_map { _1.name unless _1.required? }

```
