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

Add parameter-based provider-defined function validation #971

Merged
merged 73 commits into from
Apr 15, 2024

Conversation

SBGoods
Copy link
Contributor

@SBGoods SBGoods commented Mar 29, 2024

Closes: #894

Background

Provider-defined functions can accept parameters, or arguments as input. There is an opportunity to provide validation of such parameters in an analogous manner to the validation of values supplied in configuration for attributes, by implementing parameter-based and type-based validation for provider-defined function parameters.

This PR is concerned with the addition of parameter-based validation, which enables provider developers to define custom validators on framework-provided type parameters or on custom parameters.

<Type>Validator Interfaces

This PR adds various <Type>Validator interfaces for custom validators to implement for parameter-based validation

type BoolValidator interface {
	Validate(context.Context, BoolRequest, *BoolResponse)
}

type BoolRequest struct {
	ArgumentPosition int64
	Value types.Bool
}

type BoolResponse struct {
	Error *FuncError
}

ParameterWith<Type>Validators Interfaces

This PR adds various ParameterWith<Type>Validators interfaces for custom parameter types to implement to enable parameter-based validation

type ParameterWithBoolValidators interface {
	Parameter

	BoolValidators() []BoolValidator
}

bendbennett and others added 30 commits March 19, 2024 15:52
…cError and add switch to handle validation.ValidateableParameter interface
…omFloat(), FromBigFloat(), and FromBigInt() functions to handle ValidateableAttribute assertions
…nction parameters in ArgumentsData() function
@SBGoods SBGoods requested a review from bendbennett April 9, 2024 20:20
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

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

LGTM 🚀
Nice job!

Base automatically changed from bendbennett/pdf-parameter-type-validation to main April 12, 2024 07:00
SBGoods added 2 commits April 12, 2024 15:20
# Conflicts:
#	attr/xattr/attribute.go
#	internal/fromproto5/arguments_data.go
#	internal/fromproto5/arguments_data_test.go
#	internal/fromproto6/arguments_data.go
#	internal/fromproto6/arguments_data_test.go
#	website/docs/plugin/framework/validation.mdx
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

LGTM, just two minor comments :shipit:

internal/fromproto5/arguments_data_test.go Outdated Show resolved Hide resolved
website/docs/plugin/framework/validation.mdx Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Great test coverage here! 🥳

@austinvalle austinvalle added this to the v1.8.0 milestone Apr 15, 2024
@SBGoods SBGoods merged commit d36ac87 into main Apr 15, 2024
27 checks passed
@SBGoods SBGoods deleted the SBGoods/pdf-parameter-type-validation branch April 15, 2024 16:06
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 May 16, 2024
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.

function: Consider Parameter-Based Validators
4 participants