@Test public void testValidate() { OpenAPI openAPI = loadRelative("petstore-security-empty.yaml"); OasSpecValidator oasSpecValidator = oasSpecValidatorFactory.create( singleOption(OpenApiSecuritySizeEqValidator.CONFIG_KEY, "0") ); List<OasViolation> violations = oasSpecValidator.validate(createContext(openAPI), openAPI); assertThat(violations) .containsExactly( createViolation(OpenApiSecuritySizeEqValidator.ERROR + "0", "security", SECURITY_REQUIREMENT)); }
@Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { int size = CollectionUtils.size(openAPI.getSecurity()); if (size != expectedSize) { return singletonList( new OasViolation(location.property("security", SECURITY_REQUIREMENT), ERROR + expectedSize)); } return emptyList(); }
OpenApiSecuritySizeEqValidator implements OpenApiValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { int size = CollectionUtils.size(openAPI.getSecurity()); if (size != expectedSize) { return singletonList( new OasViolation(location.property("security", SECURITY_REQUIREMENT), ERROR + expectedSize)); } return emptyList(); } }
OpenApiSecuritySizeEqValidator implements OpenApiValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { int size = CollectionUtils.size(openAPI.getSecurity()); if (size != expectedSize) { return singletonList( new OasViolation(location.property("security", SECURITY_REQUIREMENT), ERROR + expectedSize)); } return emptyList(); } OpenApiSecuritySizeEqValidator(int expectedSize); }
OpenApiSecuritySizeEqValidator implements OpenApiValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { int size = CollectionUtils.size(openAPI.getSecurity()); if (size != expectedSize) { return singletonList( new OasViolation(location.property("security", SECURITY_REQUIREMENT), ERROR + expectedSize)); } return emptyList(); } OpenApiSecuritySizeEqValidator(int expectedSize); @Override List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location,
    OpenAPI openAPI); }
OpenApiSecuritySizeEqValidator implements OpenApiValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { int size = CollectionUtils.size(openAPI.getSecurity()); if (size != expectedSize) { return singletonList( new OasViolation(location.property("security", SECURITY_REQUIREMENT), ERROR + expectedSize)); } return emptyList(); } OpenApiSecuritySizeEqValidator(int expectedSize); @Override List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location,
    OpenAPI openAPI); static final String CONFIG_KEY; static final String ERROR; }