class DefaultContractsGenerator implements ContractsGenerator {

  @SuppressWarnings("ResultOfMethodCallIgnored")
  @Override
  public void generate() throws RuntimeException {

    URL[] runtimeUrls = new URL[classpathUrls.size()];
    for (int i = 0; i < classpathUrls.size(); i++) {

      String element = classpathUrls.get(i);

      try {
        runtimeUrls[i] = new File(element).toURI().toURL();
      } catch (MalformedURLException e) {
        throw new RuntimeException("Wrong element in classpath", e);
      }
    }

    if (!checkConfig()) {
      throw new IllegalArgumentException("Cannot found configuration");
    }

    ImmediateClassLoader immediateClassLoader = new ImmediateClassLoader(runtimeUrls,
        Thread.currentThread().getContextClassLoader());

    try {

      Vector allClass = getAllClass(immediateClassLoader);

      for (int i = 0; i < allClass.size(); i++) {

        Class loadClass = (Class) allClass.get(i);
        if (!canProcess(loadClass)) {
          continue;
        }

        OasGenerator oasGenerator = new OasGenerator();
        OpenAPI oas = oasGenerator.generate(loadClass);

        if (oas == null) {
          continue;
        }

        String oasPretty = Yaml.pretty(oas);

        File outputFile = new File(
            outputDir + File.separator + loadClass.getSimpleName() + contractfileType
                .getFileSuffix());

        if (!outputFile.exists()) {
          if (!outputFile.getParentFile().exists()) {
            outputFile.getParentFile().mkdirs();
          }
          outputFile.createNewFile();
        }

        Files.write(Paths.get(outputFile.toURI()), oasPretty.getBytes());
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

}