# Required and optional fields

**URL:** <https://discourse.dry-rb.org/t/required-and-optional-fields/523>\
**Category:** dry-types\
**Created:** [March 29, 2018, 2:45pm UTC](https://discourse.dry-rb.org/t/required-and-optional-fields/523 "2018-03-29T14:45:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xero88](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/xero88/32/247_2.png) [@xero88](https://discourse.dry-rb.org/u/xero88)\
**Post date:** [March 29, 2018, 2:45pm UTC](https://discourse.dry-rb.org/t/required-and-optional-fields/523/1 "2018-03-29T14:45:33Z")

</div>

Hi,

I’m trying to deal with optional and required field in my domain entity.  
I have an Article with an required field ‘title’ and an optional field ‘title2’

```
class Article < Dry::Struct
  constructor_type(:schema)

  attribute :title, Types::Strict::String
  attribute :title2, Types::String.optional
end

```

I want those behaviors :

```
Article.new # this should fail (miss title)
Article.new(title: 'ok') # should be success
Article.new(title: 'ok', title2: 'ok') # should be success 

```

I tried multiple constructor\_type, but I cannot found the right one.

Did I miss something ?

---

<div class="post-metadata">

**Author:** ![xero88](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/xero88/32/247_2.png) [@xero88](https://discourse.dry-rb.org/u/xero88)\
**Post date:** [March 29, 2018, 2:56pm UTC](https://discourse.dry-rb.org/t/required-and-optional-fields/523/2 "2018-03-29T14:56:15Z")

</div>

Ok, I found the answer, maybe I could post this to stackoverflow, maybe useful for someone.

```
class Article < Dry::Struct
  constructor_type(:strict_with_defaults)

  attribute :title, Types::Strict::String
  attribute :title2, Types::String.optional.default('')
end

```

Bye!
