Optional Fields
Some objects have fields that are required, and others that are optional.
Difference Between Required and Optional Fields
Required
: These fields must be present in the object. If they are not, an error will be returned.Optional
: These fields can be omitted from the object.
Practical Example
Let's take as an example this object called profile
.
yml
profile: # Object
Arguments
Field | Type | Description | Required |
---|---|---|---|
username | string | The username of the user. | ✅ |
email | string | The email address of the user. | ✅ |
about_me | string | The user's about me. | ❌ |
Practical Examples
yml
profile:
username: "John Doe"
email: "johndoe@example.com"
# Both "username" and "email" fields, which are required, are present
# As a result, the object is valid
yml
profile:
username: "John Doe"
email: "johndoe@example.com"
about_me: "I am a software developer"
# Both "username" and "email" fields, which are required, are present
# And the "about_me" field, which is optional, is also present
# As a result, the object is valid
yml
profile:
about_me: "I am a software developer"
# The "about_me" field, which is optional, is present
# But the "username" and "email" fields, which are required, are not present
# As a result, the object is invalid
yml
profile:
username: "John Doe"
about_me: "I am a software developer"
# The "username" field, which is required, is present
# The "about_me" field, which is optional, is present
# But the "email" field, which is required, is not present
# As a result, the object is invalid
yml
profile:
email: "johndoe@example.com"
about_me: "I am a software developer"
# The "email" field, which is required, is present
# The "about_me" field, which is optional, is present
# But the "username" field, which is required, is not present
# As a result, the object is invalid
All required fields (username
and email
) must be present in the profile
object. Otherwise, the object is invalid.