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 json string validator #164

Closed

Conversation

teddylear
Copy link

Adding validator similar to this func from sdk v2 and it's tests for validating a string is valid json. I'm not sure where to edit the changelog, so please let me know or feel free to edit this PR.

Testing

╰─ go test -v -cover -timeout=120s -parallel=4 -run="TestIsJsonValidator" ./stringvalidator/json_test.go
=== RUN   TestIsJsonValidator
=== PAUSE TestIsJsonValidator
=== CONT  TestIsJsonValidator
=== RUN   TestIsJsonValidator/empty
=== PAUSE TestIsJsonValidator/empty
=== RUN   TestIsJsonValidator/empty_brackets
=== PAUSE TestIsJsonValidator/empty_brackets
=== RUN   TestIsJsonValidator/null
=== PAUSE TestIsJsonValidator/null
=== RUN   TestIsJsonValidator/valid_json
=== PAUSE TestIsJsonValidator/valid_json
=== RUN   TestIsJsonValidator/Invalid_1
=== PAUSE TestIsJsonValidator/Invalid_1
=== RUN   TestIsJsonValidator/Invalid_2
=== PAUSE TestIsJsonValidator/Invalid_2
=== RUN   TestIsJsonValidator/Invalid_3
=== PAUSE TestIsJsonValidator/Invalid_3
=== RUN   TestIsJsonValidator/Invalid_4
=== PAUSE TestIsJsonValidator/Invalid_4
=== RUN   TestIsJsonValidator/unknown
=== PAUSE TestIsJsonValidator/unknown
=== CONT  TestIsJsonValidator/empty
=== CONT  TestIsJsonValidator/Invalid_2
=== CONT  TestIsJsonValidator/empty_brackets
=== CONT  TestIsJsonValidator/null
=== CONT  TestIsJsonValidator/Invalid_4
=== CONT  TestIsJsonValidator/valid_json
=== CONT  TestIsJsonValidator/Invalid_3
=== CONT  TestIsJsonValidator/Invalid_1
=== CONT  TestIsJsonValidator/unknown
--- PASS: TestIsJsonValidator (0.00s)
    --- PASS: TestIsJsonValidator/empty (0.00s)
    --- PASS: TestIsJsonValidator/null (0.00s)
    --- PASS: TestIsJsonValidator/Invalid_4 (0.00s)
    --- PASS: TestIsJsonValidator/Invalid_2 (0.00s)
    --- PASS: TestIsJsonValidator/Invalid_3 (0.00s)
    --- PASS: TestIsJsonValidator/Invalid_1 (0.00s)
    --- PASS: TestIsJsonValidator/empty_brackets (0.00s)
    --- PASS: TestIsJsonValidator/unknown (0.00s)
    --- PASS: TestIsJsonValidator/valid_json (0.00s)
PASS
coverage: [no statements]
ok      command-line-arguments  0.137s  coverage: [no statements]

@teddylear teddylear requested a review from a team as a code owner September 21, 2023 23:51
@bflad bflad self-assigned this Sep 22, 2023
@bflad
Copy link
Contributor

bflad commented Sep 22, 2023

Hi @teddylear 👋 Thank you for this contribution.

As noted in the repository README:

This Go module is not intended to define all possible validations. In particular, many validators that relate to specific string formats, encodings, and other specifics should instead be implemented separately in custom attribute types

To that end, custom JSON types are available in the separate terraform-plugin-framework-jsontypes Go module: https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework-jsontypes

If those custom types do not satisfy this use case, please open an issue in that repository.

@bflad bflad closed this Sep 22, 2023
@teddylear
Copy link
Author

@bflad Would it be possible in another PR to link these other validator repos that are ran by Hashicorp in the README of this repo? It's non-obvious where these other validators are and if they even exist. In most Hashicorp docs regarding framework validators only point to this repo.

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2023
@bflad
Copy link
Contributor

bflad commented Oct 30, 2023

@teddylear sorry for the delayed response -- submitted #173

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants