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

Validate non-raw editor data against schema #3767

Closed
wants to merge 9 commits into from
Closed

Conversation

mproch
Copy link
Collaborator

@mproch mproch commented Dec 5, 2022

No description provided.

@mproch mproch changed the base branch from staging to release/1.7 December 5, 2022 09:34
@github-actions github-actions bot added client client main fe docs ui and removed client client main fe ui docs labels Dec 5, 2022
@github-actions github-actions bot added the docs label Dec 5, 2022
@mproch mproch marked this pull request as ready for review December 5, 2022 12:25
@@ -79,6 +81,6 @@ object AvroSinkSingleValueParameter {
isLazyParameter = true,
defaultValue = defaultValue.map(_.expression)
)
SinkSingleValueParameter(parameter)
SinkSingleValueParameter(parameter, new AvroSchemaOutputValidator(schema, ValidationMode.lax))
Copy link
Member

Choose a reason for hiding this comment

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

why hardcoded lax here? Is it only used in some legacy code where we don't have this validation mode? If so, IMO we should move it upper to those legacy classes

@@ -41,8 +43,7 @@ object JsonSinkValueParameter {
isLazyParameter = true,
defaultValue = defaultValue.map(_.expression)
)

SinkSingleValueParameter(parameter)
SinkSingleValueParameter(parameter, new JsonSchemaOutputValidator(schema, ValidationMode.lax))
Copy link
Member

Choose a reason for hiding this comment

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

The same as above

}

result should matchPattern {
case Invalid(NonEmptyList(CustomNodeError("response", _, Some("field")), Nil)) =>
Copy link
Member

Choose a reason for hiding this comment

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

Can you add checking of some part of message? Because without this I can't see what exactly this test doing. It is 'trala' and should be 'additionalField'?

override def validateParams(resultTypes: List[(String, BaseDefinedParameter)], prefix: List[String])(implicit nodeId: NodeId): ValidatedNel[ProcessCompilationError, Unit] = {
fields.map { case (fieldName, param) =>
val newPrefix = prefix :+ fieldName
val prefixed = resultTypes.filter(k => k._1.startsWith(newPrefix.mkString(".")))
Copy link
Member

Choose a reason for hiding this comment

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

Uhh, what happened here? Why this "new prefix" is here?

@@ -31,7 +31,7 @@ trait UniversalSchemaSupport {
def typeDefinition(schema: ParsedSchema): TypingResult
def extractSinkValueParameter(schema: ParsedSchema)(implicit nodeId: NodeId): ValidatedNel[ProcessCompilationError, SinkValueParameter]
def sinkValueEncoder(schema: ParsedSchema, mode: ValidationMode): Any => AnyRef
def validateRawOutput(schema: ParsedSchema, t: TypingResult, mode: ValidationMode): ValidatedNel[OutputValidatorError, Unit]
def parameterValidator(schema: ParsedSchema, mode: ValidationMode): SinkValueValidator
Copy link
Member

Choose a reason for hiding this comment

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

Why we need this method if we already have SinkValueParameter which takes responsibility of the validation of this nested fields. Why not to do it in extractSinkValueParameter. Let's keep this class simple because it will be hard to add new schema supports incrementally.

@@ -25,7 +26,7 @@ private[encode] case class AvroSchemaExpected(schema: Schema) extends OutputVali
override def expected: String = AvroSchemaOutputValidatorPrinter.print(schema)
}

class AvroSchemaOutputValidator(validationMode: ValidationMode) extends LazyLogging {
class AvroSchemaOutputValidator(schema: Schema, validationMode: ValidationMode) extends LazyLogging with SinkValueValidator {
Copy link
Member

Choose a reason for hiding this comment

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

Why this schema have to be on class level? It is tricky now, because we pass around nested schemas in private methods.

(SchemaVersionParamName, DefinedEagerParameter(_: String, _)) ::
(SinkKeyParamName, _) ::
(SinkRawEditorParamName, DefinedEagerParameter(true, _)) :: Nil, _) =>
//TODO: use resultType here to show type hints on UI (breaks some tests...)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this comment. resultType in which parameters? rawValueParm?

}

case class SinkSingleValueParameter(value: Parameter) extends SinkValueParameter
case class SinkSingleValueParameter(value: Parameter, validator: SinkValueValidator) extends SinkValueParameter {
override def validateParams(resultTypes: List[(String, BaseDefinedParameter)], prefix: List[String])(implicit nodeId: NodeId): ValidatedNel[ProcessCompilationError, Unit] = resultTypes match {
Copy link
Member

@arkadius arkadius Dec 6, 2022

Choose a reason for hiding this comment

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

I have one confusion about how this validateParams is related to Parameter.typ. Am I right that we do two validations:

  • against this Parameter.typ in our "engine"
  • using validateParams in component?

If so, IMO we should write some comment about this relation eg. that this Parameter.typ should be "wider" than validateParams to not limit this validations.

)

val result = runner.runWithRequests(scenario) { invoker =>
invoker(HttpRequest(HttpMethods.POST, entity = "{}")).rightValue
Copy link
Member

Choose a reason for hiding this comment

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

dead code

@mproch mproch marked this pull request as draft December 6, 2022 14:16
@mproch mproch changed the base branch from release/1.7 to staging December 21, 2022 08:55
@github-actions github-actions bot removed the client client main fe label Dec 21, 2022
@arkadius
Copy link
Member

Closing in favour of #3994

@arkadius arkadius closed this Feb 20, 2023
@coutoPL coutoPL deleted the json_schema_fix branch August 17, 2023 08:55
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