add omitempty to json tag for struct fields that are optional #314
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I audited the repo looking for options struct fields to update for omitempty json tag:
The fields that are not required should have the tag because if their values are null then the fields will get omitted from the encoding.
The fields that are required should not have the tag.
This PR is bringing those two types of changes.
I have added omitempty to
Two url filter tags that are optional: https://www.terraform.io/cloud-docs/api-docs/admin/users#query-parameters
One shh key attribute said to be optional: https://www.terraform.io/cloud-docs/api-docs/oauth-tokens#request-body
And I have removed omitempty from three fields that are required. For those fields, I didn't need to look in the documentation to find out if they are optional or not. Right there, in the same go file, I can see that we are running a validation check (options.valid()) to verify that those fields are not empty values.
There will be a follow up PR where I'll be adding a few more options.valid() for ListOptions that have required fields so we can match the other ones that already have this validation.
Testing plan
External links
Output from tests (HashiCorp employees only)