public List validateSchemas()

in src/main/java/com/amazonaws/schemamanager/analyze/SchemaAnalyzerImpl.java [118:179]


	public List<ValidationError> validateSchemas(List<RepoSchema> newSchemas) {
		
		if (newSchemas == null) return null;
		
		List<ValidationError> errors = new LinkedList<>();
		
		Map<String, List<String>> nameAndPath = new HashMap<>();
		final List<RepoSchema> validSchemas = new LinkedList<>();
		
		newSchemas.forEach(s -> {
			if (s.getSchema() == null) {
				errors.add(new ValidationError("Validation failed for schema file %s. Error: %s", s.getPath(), "Cannot parse the file."));
				return;
			}
			String path = s.getPath();
			
			
			String schemaName = s.getSchema().name();
			nameAndPath.computeIfAbsent(schemaName, n -> new LinkedList<String>()).add(path);
			try {
				s.getSchema().validate();
				validSchemas.add(s);
			}catch(Exception e) {
				errors.add(new ValidationError("Validation failed for schema file %s. Error: %s", s.getPath(), e.getMessage()));
			}
		});
		
		// if dups aren't allowed, add error, otherwise print warning to the logs only:
		nameAndPath.forEach((name, paths) ->{
			if (paths != null && paths.size() > 1){
				if (config.getAllowSchemaNameDuplicates()) {
					log.warn(String.format("Duplicated names found! Name: %s, files with this name: ", String.join(",", paths)));
				}else {
					errors.add(new ValidationError("Duplicated names found! Name: %s, files with this name: ", String.join(",", paths)));
				}
			}
		});
		
		// checking for schema name duplicates and subject name duplicates would usually give similar results, but may vary.
		// Not always subject name is the same as schema name, and there may be multiple subjects per schema.
		// another confusion may come from different projects' repositories
		Map<String, List<RepoSchema>> allSubjects = new HashMap<>();
		validSchemas.forEach(s -> {
			RepoUtils.schemaToSubjectMap(s, allSubjects);
		});
		allSubjects.forEach((subj, schemas) ->{
			if (schemas.size() > 1) {
				if (config.getAllowSchemaNameDuplicates()) {
					log.warn(String.format("Duplicated subjects found! Subject: %s, files with this subject: ", 
							String.join(",", schemas.stream().map(RepoSchema::getPath).collect(Collectors.toList())) ));
				}else {
					log.error(String.format("Duplicated names found! Name: %s, files with this name: ", 
							String.join(",", schemas.stream().map(RepoSchema::getPath).collect(Collectors.toList()))));
					errors.add(new ValidationError("Duplicated names found! Name: %s, files with this name: ", 
							String.join(",", schemas.stream().map(RepoSchema::getPath).collect(Collectors.toList()))));
				}

			}
		});
		
		return errors;
	}