Open ueberfuhr opened 3 weeks ago
The only way to avoid the exception is to disable validation for optional fields:
OpenApiSpecification apiSpecification = OpenApiSpecification.from(
Resources.create("classpath:META-INF/resources/openapi.yml")
);
apiSpecification.setValidateOptionalFields(false);
But this will disable the complete validation. It should be possible to validate those fields if they are not null. So we need a possibility to influence the control message, which requires an extension to the validation matches. This could be one of the following ideas:
@null()@
(which has the inverse semantic of @ignore()
?) and a combination with or
required
parameter)Another unpleasant thing is that, in the case of disabled validation of optional fields, the control message only contains the required fields, which will fail if the JSON validator is in strict mode. I guess, it should not fail, if we disable validation of optional fields, because they are declared in the OpenAPI.
Agreed, we need to make the null
value validation more robust. Thank you for reporting this! In case you have some time to implement your ideas contributions are very welcome! Many thanks!
Citrus Version 4.2.1
Expected behavior When receiving a response with nullable JSON properties, they should only be validated if they have a value.
Actual behavior Instead, we get an NPE.
Test case sample This is the return type in OpenAPI:
and the corresponding JSON response: