@Test public void testValidate() { OpenAPI openAPI = loadRelative("petstore-paths-lower-camel-case.yaml"); OasSpecValidator oasSpecValidator = oasSpecValidatorFactory.create( singleOption(PathsKeyCaseValidator.CONFIG_KEY, "lower-camel-case") ); List<OasViolation> violations = oasSpecValidator.validate(createContext(openAPI), openAPI); assertThat(violations).containsExactlyInAnyOrder( createViolation( PathsKeyCaseValidator.ERROR + "lower-camel-case", "paths", PATHS, "/pets/{PetId}", PATH_ITEM ), createViolation( PathsKeyCaseValidator.ERROR + "lower-camel-case", "paths", PATHS, "/Pets", PATH_ITEM ) ); }
@Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Paths oasObject) { List<OasViolation> violations = new ArrayList<>(); Set<String> paths = oasObject.keySet(); for (String path : paths) { if (!matchCamelCase(path)) { OasObjectPropertyLocation pathLoc = location.property(path, OasObjectType.PATH_ITEM); violations.add(new OasViolation(pathLoc, ERROR + expectedCase)); } } return violations; }
PathsKeyCaseValidator implements PathsValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Paths oasObject) { List<OasViolation> violations = new ArrayList<>(); Set<String> paths = oasObject.keySet(); for (String path : paths) { if (!matchCamelCase(path)) { OasObjectPropertyLocation pathLoc = location.property(path, OasObjectType.PATH_ITEM); violations.add(new OasViolation(pathLoc, ERROR + expectedCase)); } } return violations; } }
PathsKeyCaseValidator implements PathsValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Paths oasObject) { List<OasViolation> violations = new ArrayList<>(); Set<String> paths = oasObject.keySet(); for (String path : paths) { if (!matchCamelCase(path)) { OasObjectPropertyLocation pathLoc = location.property(path, OasObjectType.PATH_ITEM); violations.add(new OasViolation(pathLoc, ERROR + expectedCase)); } } return violations; } PathsKeyCaseValidator(String expectedCase); }
PathsKeyCaseValidator implements PathsValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Paths oasObject) { List<OasViolation> violations = new ArrayList<>(); Set<String> paths = oasObject.keySet(); for (String path : paths) { if (!matchCamelCase(path)) { OasObjectPropertyLocation pathLoc = location.property(path, OasObjectType.PATH_ITEM); violations.add(new OasViolation(pathLoc, ERROR + expectedCase)); } } return violations; } PathsKeyCaseValidator(String expectedCase); @Override List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Paths oasObject); }
PathsKeyCaseValidator implements PathsValidator { @Override public List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Paths oasObject) { List<OasViolation> violations = new ArrayList<>(); Set<String> paths = oasObject.keySet(); for (String path : paths) { if (!matchCamelCase(path)) { OasObjectPropertyLocation pathLoc = location.property(path, OasObjectType.PATH_ITEM); violations.add(new OasViolation(pathLoc, ERROR + expectedCase)); } } return violations; } PathsKeyCaseValidator(String expectedCase); @Override List<OasViolation> validate(OasValidationContext context, OasObjectPropertyLocation location, Paths oasObject); static final String CONFIG_KEY; static final String ERROR; }