You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by "jkevan (via GitHub)" <gi...@apache.org> on 2023/03/23 08:29:14 UTC

[GitHub] [unomi] jkevan commented on a diff in pull request #597: UNOMI-754: new jsonSchema endpoint to be able to validate events and …

jkevan commented on code in PR #597:
URL: https://github.com/apache/unomi/pull/597#discussion_r1145834979


##########
extensions/json-schema/rest/src/main/java/org/apache/unomi/schema/rest/JsonSchemaEndPoint.java:
##########
@@ -114,4 +116,22 @@ public Response save(String jsonSchema) {
     public boolean remove(String id) {
         return schemaService.deleteSchema(id);
     }
+
+    /**
+     * Being able to validate a given event is useful when you want to develop custom events and associated schemas
+     * @param event the event to be validated
+     * @return Validation error messages if there is some
+     */
+    @POST
+    @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
+    @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
+    @Path("/validateEvent")
+    public Collection<ValidationError> validateEvent(String event) {
+        try {
+            return schemaService.validateEvent(event);

Review Comment:
   I'm not sure, the goal of this endpoint is to return the validation errors.
   So even if there is some, the request is valid and should be a 200.
   The response code will be impacted if something goes wrong before doing the validation or in case of unexpected error during the validation process, that's why there is a difference between the exception and the validation errors.
   The separation have been done on purpose.
   
   ValidationException: Something unexpected happen and the validation was not able to be performed
   ValidationError: The validation process is done successfully and we have informations on why the event does not respect the schemas.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@unomi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org