@Test public void testValidate() { OpenAPI openAPI = loadRelative("petstore-tag-not-provided.yaml"); OasSpecValidator oasSpecValidator = oasSpecValidatorFactory.create( singleOption(OpenApiTagsSizeGteValidator.CONFIG_KEY, "1") ); List<OasViolation> violations = oasSpecValidator.validate(createContext(openAPI), openAPI); assertThat(violations).hasSize(1); assertThat(violations).containsExactly(createViolation(OpenApiTagsSizeGteValidator.ERROR + "1", "tags", TAG)); }
@Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { if (CollectionUtils.size(openAPI.getTags()) < expectedSize) { return singletonList(new OasViolation(location.property("tags", OasObjectType.TAG), ERROR + expectedSize)); } return emptyList(); }
OpenApiTagsSizeGteValidator implements OpenApiValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { if (CollectionUtils.size(openAPI.getTags()) < expectedSize) { return singletonList(new OasViolation(location.property("tags", OasObjectType.TAG), ERROR + expectedSize)); } return emptyList(); } }
OpenApiTagsSizeGteValidator implements OpenApiValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { if (CollectionUtils.size(openAPI.getTags()) < expectedSize) { return singletonList(new OasViolation(location.property("tags", OasObjectType.TAG), ERROR + expectedSize)); } return emptyList(); } OpenApiTagsSizeGteValidator(int expectedSize); }
OpenApiTagsSizeGteValidator implements OpenApiValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { if (CollectionUtils.size(openAPI.getTags()) < expectedSize) { return singletonList(new OasViolation(location.property("tags", OasObjectType.TAG), ERROR + expectedSize)); } return emptyList(); } OpenApiTagsSizeGteValidator(int expectedSize); @Override List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI); }
OpenApiTagsSizeGteValidator implements OpenApiValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI) { if (CollectionUtils.size(openAPI.getTags()) < expectedSize) { return singletonList(new OasViolation(location.property("tags", OasObjectType.TAG), ERROR + expectedSize)); } return emptyList(); } OpenApiTagsSizeGteValidator(int expectedSize); @Override List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, OpenAPI openAPI); static final String CONFIG_KEY; static final String ERROR; }