mirror of
https://github.com/LukeHagar/plexterraform.git
synced 2025-12-09 12:37:47 +00:00
ci: regenerated with OpenAPI Doc 0.0.3, Speakeasy CLI 1.129.1
This commit is contained in:
51
internal/validators/JSONParseValidator.go
Normal file
51
internal/validators/JSONParseValidator.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
package validators
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
)
|
||||
|
||||
var _ validator.String = JSONParseValidator{}
|
||||
|
||||
// JSONParseValidator validates if the provided value is of type string and can be parsed as JSON.
|
||||
type JSONParseValidator struct {
|
||||
}
|
||||
|
||||
func (validator JSONParseValidator) Description(ctx context.Context) string {
|
||||
return "value must be parsable as JSON"
|
||||
}
|
||||
|
||||
func (validator JSONParseValidator) MarkdownDescription(ctx context.Context) string {
|
||||
return validator.Description(ctx)
|
||||
}
|
||||
|
||||
func (validator JSONParseValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
|
||||
// Only validate the attribute configuration value if it is known.
|
||||
if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() {
|
||||
return
|
||||
}
|
||||
|
||||
if !json.Valid([]byte(req.ConfigValue.ValueString())) {
|
||||
resp.Diagnostics.Append(validatordiag.InvalidAttributeTypeDiagnostic(
|
||||
req.Path,
|
||||
validator.MarkdownDescription(ctx),
|
||||
req.ConfigValue.ValueString(),
|
||||
))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// IsValidJSON returns an AttributeValidator which ensures that any configured
|
||||
// attribute value:
|
||||
//
|
||||
// - Is a String.
|
||||
// - Is considered valid JSON.
|
||||
//
|
||||
// Null (unconfigured) and unknown (known after apply) values are skipped.
|
||||
func IsValidJSON() validator.String {
|
||||
return JSONParseValidator{}
|
||||
}
|
||||
Reference in New Issue
Block a user