-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[dev guide] Add docs on optional schema arguments #12371
[dev guide] Add docs on optional schema arguments #12371
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! Very helpful!! We also have IgnoreAllErrors
option as well. It is aded by #12089
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few changes. Thank you for adding this!
} | ||
---- | ||
<1> `Required` will explicitly mark a field as non-optional. | ||
<2> If a field has no Schema Option set, it is equivalent to `Required`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why "Schema Option" is capitalized here. Generally we only capitalize proper nouns. I would change this to say, "If no schema option is set, the field is required."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More than likely, I was looking at the code, which is capitalized, and my brain just translated it to words that way, hah.
} | ||
---- | ||
<1> `Required` will explicitly mark a field as non-optional. | ||
<2> If a field has no Schema Option set, it is equivalent to `Required`. | ||
<3> `Optional` You can also explicitly mark a field as not required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<3> `Optional` You can also explicitly mark a field as not required. | |
<3> Marks the field as optional. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand why you are being precise here, but I think the content is harder to read when you swap between using "non-optional" and "not required." Except in situations where it's important to know that a setting is explicit (like you do later on where you say "field explicitly marked as required
"), I would simply refer to a fields as required or optional. I'll suggest edits with this notion in mind. I hope I'm understanding things correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, I was struggling to word that in a way that didn't seem repetitive.
<2> If a field has no Schema Option set, it is equivalent to `Required`. | ||
<3> `Optional` You can also explicitly mark a field as not required. | ||
<4> By default, `Apply` will fail and return an error if any field not marked as optional is missing. Using the optional second argument, you can specify how `Apply` handles different fields of the schema. The possible values are: | ||
- `AllRequired` is the default behavior. Return an error if any field not marked as optional is missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `AllRequired` is the default behavior. Return an error if any field not marked as optional is missing. | |
- `AllRequired` is the default behavior. Returns an error if any required field is missing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to disambiguate further, you could add "...any required field is missing, including fields that are required because no schema option is set."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yah, that's what I was trying to get across. Thanks!
<4> By default, `Apply` will fail and return an error if any field not marked as optional is missing. Using the optional second argument, you can specify how `Apply` handles different fields of the schema. The possible values are: | ||
- `AllRequired` is the default behavior. Return an error if any field not marked as optional is missing. | ||
- `FailOnRequired` will fail if a field explicitly marked as `required` is missing. | ||
- `NotFoundKeys(cb func([]string))` will pass a callback function that will be called with the list of missing keys, for more fine-grained error handling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence was a little hard to parse on first reading. Would it be accurate to say "...will pass a callback function that returns a list of missing keys for more fine-grained error handling."
Codecov Report
@@ Coverage Diff @@
## master #12371 +/- ##
==========================================
- Coverage 57.96% 57.92% -0.04%
==========================================
Files 933 930 -3
Lines 57453 57339 -114
==========================================
- Hits 33302 33215 -87
+ Misses 21085 21065 -20
+ Partials 3066 3059 -7
Continue to review full report at Codecov.
|
codecov, what are you doing Anyways, thanks @dedemorton ! I struggle with how to grammatically format lists, hah. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! We could also add some godocs to the package, but this can be done in a separate PR.
} | ||
---- | ||
<1> Marks a field as required. | ||
<2> If a field has no schema option set, it is equivalent to `Required`. | ||
<3> Marks the field as optional. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odacremolbap added a new option to ignore all errors of an specific field (#12089), it may worth to mention it here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IgnoreAllErrors
option, it is aded by #12089
Yep, @jsoriano I added a mention about the |
Also, do you have an idea of where we should add godocs for this? Just to |
Oh, but take into account that this is an option for the fields (like it could be in
It could be added to the |
Okay, having I also added a doc example for |
jenkins, test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
* add docs on optional schema arguments
This is a response to #7335, as it adds a great deal of functionality to the
schema
library and none of it seems to be documented.This PR expands the
schema.Apply
example to the beats developer guide with documented usage of the various optional arguments now available inschema.Apply
There's a few undressed things here:
NotFoundKeys
but I'm still trying to figure it out.