@Test public void testValidate() { OpenAPI openAPI = loadRelative("petstore-operation-tags-reference.yaml"); OasSpecValidator oasSpecValidator = oasSpecValidatorFactory.create( singleOption(OperationTagsReferenceValidator.CONFIG_KEY, "true") ); List<OasViolation> violations = oasSpecValidator.validate(createContext(openAPI), openAPI); assertThat(violations).containsExactly( createViolation(OperationTagsReferenceValidator.ERROR, "paths", PATHS, "/pets", PATH_ITEM, "get", OPERATION, "tags[0]", null)); }
@Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Operation oasObject) { List<String> tags = oasObject.getTags(); if (CollectionUtils.isEmpty(tags)) { return emptyList(); } List<OasViolation> violations = new ArrayList<>(); Set<String> globalTagNames = getGlobalTagNames(context.getOpenAPI()); for (int i = 0; i < tags.size(); i++) { String tagName = tags.get(i); if (!globalTagNames.contains(tagName)) { violations.add( new OasViolation(location.property("tags[" + i + "]"), ERROR)); } } return violations; }
OperationTagsReferenceValidator implements OperationValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Operation oasObject) { List<String> tags = oasObject.getTags(); if (CollectionUtils.isEmpty(tags)) { return emptyList(); } List<OasViolation> violations = new ArrayList<>(); Set<String> globalTagNames = getGlobalTagNames(context.getOpenAPI()); for (int i = 0; i < tags.size(); i++) { String tagName = tags.get(i); if (!globalTagNames.contains(tagName)) { violations.add( new OasViolation(location.property("tags[" + i + "]"), ERROR)); } } return violations; } }
OperationTagsReferenceValidator implements OperationValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Operation oasObject) { List<String> tags = oasObject.getTags(); if (CollectionUtils.isEmpty(tags)) { return emptyList(); } List<OasViolation> violations = new ArrayList<>(); Set<String> globalTagNames = getGlobalTagNames(context.getOpenAPI()); for (int i = 0; i < tags.size(); i++) { String tagName = tags.get(i); if (!globalTagNames.contains(tagName)) { violations.add( new OasViolation(location.property("tags[" + i + "]"), ERROR)); } } return violations; }  }
OperationTagsReferenceValidator implements OperationValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Operation oasObject) { List<String> tags = oasObject.getTags(); if (CollectionUtils.isEmpty(tags)) { return emptyList(); } List<OasViolation> violations = new ArrayList<>(); Set<String> globalTagNames = getGlobalTagNames(context.getOpenAPI()); for (int i = 0; i < tags.size(); i++) { String tagName = tags.get(i); if (!globalTagNames.contains(tagName)) { violations.add( new OasViolation(location.property("tags[" + i + "]"), ERROR)); } } return violations; }  @Override List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location,
    Operation oasObject); Set<String> getGlobalTagNames(OpenAPI openAPI); }
OperationTagsReferenceValidator implements OperationValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Operation oasObject) { List<String> tags = oasObject.getTags(); if (CollectionUtils.isEmpty(tags)) { return emptyList(); } List<OasViolation> violations = new ArrayList<>(); Set<String> globalTagNames = getGlobalTagNames(context.getOpenAPI()); for (int i = 0; i < tags.size(); i++) { String tagName = tags.get(i); if (!globalTagNames.contains(tagName)) { violations.add( new OasViolation(location.property("tags[" + i + "]"), ERROR)); } } return violations; }  @Override List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location,
    Operation oasObject); Set<String> getGlobalTagNames(OpenAPI openAPI); static final String CONFIG_KEY; static final String ERROR; }