Skip to content

feat: Null Value Support #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Nov 4, 2023

Conversation

getBoolean
Copy link
Contributor

@getBoolean getBoolean commented Oct 29, 2023

Closes #25

Annotation options Envied.allowOptionalFields and EnviedField.optional have been added to allow nullable fields. Optional fields are disabled by default. Below is an excerpt from the readme.

Optional Environment Variables

Enable allowOptionalFields to allow nullable types. When a default
value is not provided and the type is nullable, the generator will
assign the value to null instead of throwing an exception.

By default, optional fields are not enabled because it could be
confusing while debugging. If a field is nullable and a default
value is not provided, it will not throw an exception if it is
missing an environment variable.

For example, this could be useful if you are using an analytics service
for an open-source app, but you don't want to require users or contributors
to provide an API key if they build the app themselves.

@Envied(allowOptionalFields: true)
abstract class Env {
    @EnviedField()
    static const String? optionalServiceApiKey = _Env.optionalServiceApiKey;
}

Optional fields can also be enabled on a per-field basis by setting

@EnviedField(optional: true)

@getBoolean getBoolean changed the title Feature: Null Value Support feat: Null Value Support Oct 29, 2023
Copy link
Collaborator

@techouse techouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work. I've added some comments. 🤓

@techouse techouse self-assigned this Oct 29, 2023
@techouse techouse added the enhancement New feature or request label Oct 29, 2023
@getBoolean
Copy link
Contributor Author

getBoolean commented Oct 30, 2023

Thanks for the feedback!

Please check that #66 (comment) and #66 (comment) was resolved correctly.

@techouse
Copy link
Collaborator

Please check that #66 (comment) and #66 (comment) was resolved correctly.

Looks like it. I'll make a proper review later in the evening or tomorrow.

`optional` vs `nullable` was confusing me, `allowOptional` and `isNullable` are much better names
Copy link
Collaborator

@techouse techouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some more comments.

@techouse
Copy link
Collaborator

techouse commented Nov 1, 2023

Looks good. 👍🏻 I'll leave the PR open for a few more days in case you decide to add more stuff to it.

@petercinibulk care to take a look?

@techouse techouse merged commit 0d08946 into petercinibulk:main Nov 4, 2023
@getBoolean getBoolean deleted the feature/null_value_support branch November 4, 2023 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Null Value Support
2 participants