-
Notifications
You must be signed in to change notification settings - Fork 12
Create new public method CirceValidator#compileJsonSchema #269
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
Conversation
|
@gleb-lobov I don't quite understand why these are the two methods you want to make public. Comparing with the Enrich PR snowplow/enrich-private#151, it seems to me the functionality you need to import/replace is this part where you convert from circe Json into networknet JsonSchema. So the corresponding function in iglu-scala-client is |
|
@istreeter I was following the public method I can move the |
OK I think I get what you're saying. In your Enrich PR snowplow/enrich-private#151 there are two different places where you have written code which could be replaced by iglu-scala-client: 1. Validating an entity against the schema This function here where you validate the entity against the schema. I agree that But... I don't think that implementation is a problem in Enrich. I mean, it's just two lines of code. I don't think you benefit much from importing the implementation from iglu-scala-client (for {
jacksonJson <- circeToJackson(data, maxJsonDepth).toOption
} yield schema.validate(jacksonJson).isEmpty).getOrElse(false)2. Compiling the json schema This function here where you compile the json schema. In this case the Enrich implementation adds a lot of overhead. e.g. you were forced to re-define So this is the functionality which I think we should look to import from iglu-scala-client. And this is why I think you need |
Yeah, I can skip it, but it would be nice to not even call
You are absolutely right that this is more problematic, and I have to bring a lot. My idea was that if the def compileJsonSchema(data: Json, schema: Json): Either[ValidatorError, Unit] =
for {
jacksonJson <- circeToJackson(schema, Int.MaxValue).leftMap(_.toInvalidSchema)
schema <- evaluateSchema(jacksonJson)
_ <- validateOnReadySchema(schema, data, Int.MaxValue)
} yield ()
that is just a copy of a CirceValidator#validate I think the confusion is because Im looking at CirceValidator#validate and you are looking at CirceValidator.WithCaching#validate Form the looks of it, I don't see any difference, since we'll not use caching. Let me know if I should make |
|
But for compiling the jsonschema you cannot have this signature def compileJsonSchema(data: Json, schema: Json): Either[ValidatorError, Unit]...because you don't have the |
|
Yeah, you're right, sorry, blind copy-paste This is what I've meant(ignore the left channel, just converting everything to string so it compiles) def compileJsonSchema(circe: Json): Either[String, JsonSchema] =
for {
jacksonJson <- circeToJackson(circe, Int.MaxValue).leftMap(_.message)
schema <- evaluateSchema(jacksonJson).leftMap(_.toString)
} yield schema |
|
Sorry ignore that comment I wrote the wrong thing. |
|
OK I understand what you're saying now. So And from point of view of designing the public API... it should probably live in the top-level object (like you said) and have a name like |
modules/core/src/main/scala/com.snowplowanalytics.iglu/client/validator/CirceValidator.scala
Show resolved
Hide resolved
|
@istreeter yeah, I see now what you mean. I've moved the The |
|
Thanks @gleb-lobov I think the Regarding
I think your function |
|
@istreeter good note about the error string manipulation, I didn't think about this. I've made the |
istreeter
left a comment
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.
This all looks good now. I will merge this into develop for you, and I will tag a pre-release version which you can import into Enrich. We can turn it into a proper release after everything is tested in Enrich.
|
@gleb-lobov 4.1.0-M2 is now published to Sonatype, so you can import it into Enrich. |
Would clean up this enrich PR