- edited description
Specify the SchemaValidator when creating the OpenApiInteractionValidator
I would like to be able to configure the list of transformations performed on the SchemaObject
by the SchemaValidator
object, at its creation.
Moreover, I need to be able to pass an instance of SchemaValidator
at the creation of the OpenApiInteractionValidator
object.
The interest of being able to control the composition of the transformation chain is measured when one wants to integrate a transformer in the middle of it. For example, a transformer that can resolve the AllOf
elements present in the API specification and thus be able to use additionalProperties: true
without limitation.
For example:
public static class Builder {
...
public Builder withCustomSchemaValidator(final BiFunction<OpenAPI, MessageResolver, SchemaValidator> validator) {
requireNonNull(validator, "A JSON schema validator is required");
this.schemaValidator = validator;
return this;
}
...
public OpenApiInteractionValidator build() {
if (api == null) {
this.api = new OpenApiLoader().loadApi(specSource, authData);
}
final MessageResolver messageResolver = new MessageResolver(levelResolver);
if (schemaValidator == null) {
schemaValidator = SchemaValidator::new;
}
return new OpenApiInteractionValidator(
api,
basePathOverride,
messageResolver,
whitelist,
customRequestValidators,
customResponseValidators,
schemaValidator.apply(api, messageResolver));
}
...
}
OpenApiInteractionValidator.createForSpecificationUrl("openapi.yaml")
.withLevelResolver(LevelResolver.create()
.withLevel("validation.schema.additionalProperties", ValidationReport.Level.IGNORE)
.withLevel("validation.request.body.schema.additionalProperties", ValidationReport.Level.INFO)
.build())
.withCustomSchemaValidator { api, messages ->
SchemaValidator(api, messages, listOf(
SchemaDefinitionsInjectionTransformer.getInstance(),
SchemaRefInjectionTransformer.getInstance(),
AdditionalPropertiesInjectionTransformer.getInstance(),
RequiredFieldTransformer.getInstance()))
}
.build()
Thanks for your feedback,
Kind regards
Comments (3)
-
reporter -
reporter -
Bump, we are currently forking the library exposing the list of transformers to disable the AdditionalPropertiesInjectionTransformer. Having the ability to customize this behaviour would be useful.
- Log in to comment