Skip to content
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

feat: add duplicate json key validator #650

Merged
merged 3 commits into from
Sep 21, 2023
Merged

feat: add duplicate json key validator #650

merged 3 commits into from
Sep 21, 2023

Conversation

jar-b
Copy link
Member

@jar-b jar-b commented Sep 12, 2023

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates hashicorp/terraform-provider-aws#33026

Adds a new ValidateNoDuplicateKeys function which walks a JSON object checking for duplicate key names. The intention is for aws-sdk-go-base to contain the core validation logic (ie. provide a JSON string, get back an error) and allow upstream consumers such as the AWS provider to wrap this function and decide whether to return the findings as a diagnostic warning or error.

Also creates a new validation sub-package and moves the one other existing validation function (ValidateRegion) into it.

% make test
go test -timeout=30s -parallel=4 ./...
?       github.com/hashicorp/aws-sdk-go-base/v2/internal/awsconfig      [no test files]
?       github.com/hashicorp/aws-sdk-go-base/v2/internal/constants      [no test files]
?       github.com/hashicorp/aws-sdk-go-base/v2/internal/errs   [no test files]
?       github.com/hashicorp/aws-sdk-go-base/v2/internal/slices [no test files]
?       github.com/hashicorp/aws-sdk-go-base/v2/internal/test   [no test files]
?       github.com/hashicorp/aws-sdk-go-base/v2/mockdata        [no test files]
?       github.com/hashicorp/aws-sdk-go-base/v2/servicemocks    [no test files]
ok      github.com/hashicorp/aws-sdk-go-base/v2 5.960s
ok      github.com/hashicorp/aws-sdk-go-base/v2/diag    0.375s
ok      github.com/hashicorp/aws-sdk-go-base/v2/internal/config 0.460s
ok      github.com/hashicorp/aws-sdk-go-base/v2/internal/endpoints      0.392s
ok      github.com/hashicorp/aws-sdk-go-base/v2/internal/expand 0.646s
ok      github.com/hashicorp/aws-sdk-go-base/v2/logging 0.484s
ok      github.com/hashicorp/aws-sdk-go-base/v2/tfawserr        0.499s
ok      github.com/hashicorp/aws-sdk-go-base/v2/useragent       0.567s
ok      github.com/hashicorp/aws-sdk-go-base/v2/validation      0.514s
cd v2/awsv1shim && go test -timeout=30s -parallel=4 ./...
?       github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/mockdata   [no test files]
ok      github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2    5.142s
ok      github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr   0.580s

@jar-b jar-b requested a review from a team as a code owner September 12, 2023 19:01
@jar-b jar-b force-pushed the f-json-duplicate-keys branch 2 times, most recently from d6edf25 to 350197e Compare September 19, 2023 15:25
Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

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

Looks good! 🚀

One suggestion about function naming

validation/json.go Outdated Show resolved Hide resolved
@jar-b jar-b merged commit 6e0ed6a into main Sep 21, 2023
6 checks passed
@jar-b jar-b deleted the f-json-duplicate-keys branch September 21, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants