-
Notifications
You must be signed in to change notification settings - Fork 95
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
Conversation
a398c00
to
e1cd6db
Compare
@@ -79,6 +81,6 @@ object AvroSinkSingleValueParameter { | |||
isLazyParameter = true, | |||
defaultValue = defaultValue.map(_.expression) | |||
) | |||
SinkSingleValueParameter(parameter) | |||
SinkSingleValueParameter(parameter, new AvroSchemaOutputValidator(schema, ValidationMode.lax)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)) => |
There was a problem hiding this comment.
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("."))) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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...) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dead code
672cd86
to
a9dde9f
Compare
a9dde9f
to
9da5dfa
Compare
9da5dfa
to
c1a34a1
Compare
Closing in favour of #3994 |
No description provided.