Inject AdditionalProperties flag before validation

Issue #302 resolved
Former user created an issue

Hi, We are using the swagger validtor for openapi 3 contracts.

When we validate a request and/or a response, we would like to have the option to set the additional properties flag to true. But we are not allowed to change the contract.

We wanted to set the flag programatically but impossible to access to AdditionalPropertiesInjectionTransformer which is final in the class SchemaValidator.

Could you help us understand how to set the flag to true.

The responses we receive have more properties but we want to check that existing one in the contract respect the type and format and so on.

if you need more information or an request/response example + contract feel free to ask

Thank you for your help.

Comments (3)

  1. Former user Account Deleted

    Finally we found how to do

    When we instanciate the OpenApiInterationValidator we add the method withLevel allowing us to add properties.

    OpenApiInteractionValidator.createFor("/" + swaggerContract).withLevelResolver(LevelResolver.create()
          .withLevel("validation.schema.additionalProperties",
                ValidationReport.Level.INFO)
          .build()).build();
    

  2. James Navin

    Hi Mehdi. Thanks for raising this. Yes - by default the validator is quite strict about validating unexpected additional properties.

    As you found, you can control it via the standard validation level mechanism. There is also a short-hand way using an existing helper LevelResolverFactory#withAdditionalPropertiesIgnored which makes your code snipped look like:

    OpenApiInteractionValidator
      .createForSpecificationUrl("/my/spec.yaml")
      .withLevelResolver(withAdditionalPropertiesIgnored())
      .build();
    

  3. Log in to comment