Vertx 4.4.4 SchemaParser deprecation

157 Views Asked by At

I am using vertx 4.4.4 and tried to use the following code snippet

SchemaParser parser = SchemaParser.createDraft7SchemaParser(
      SchemaRouter.create(vertx, new SchemaRouterOptions()));

I get a deprecation warning for SchemaParser, SchemaRouter, SchemaRouterOptions

I tried to read through the docs to find what is the suggested approach but could not find it.

I later use the parser in the following code

router.post("/demo")
      .handler(new BodyHandlerImpl())
      .handler(ValidationHandlerBuilder.create(parser)
        .body(Bodies.json(objectSchemaBuilder))
          .body(Bodies.formUrlEncoded(objectSchemaBuilder))
        .build())
      .handler(this::greet);
1

There are 1 best solutions below

2
tsegismont On

SchemaParser is deprecated in favor of SchemaRepository.

First, create the repository:

SchemaRepository sr = SchemaRepository.create(new JsonSchemaOptions().setDraft(Draft.DRAFT7));

Then use it in the ValidationHandlerBuilder:

router.post("/demo")
  .handler(BodyHandler.create())
  .handler(ValidationHandlerBuilder.create(sr)
    .body(Bodies.json(objectSchemaBuilder))
    .body(Bodies.formUrlEncoded(objectSchemaBuilder))
    .build())
  .handler(this::greet);