stoicflame / enunciate

Build-time enhancement tool for Java-based Web services projects
http://enunciate.webcohesion.com/
Other
481 stars 201 forks source link

Support multiple enunciate configuration without re-scanning the code #611

Open patvong opened 7 years ago

patvong commented 7 years ago

I'm currently using enunciate mainly to be able to use the generated swagger.json file that I process myself to create the HTML document for my APIs. Using the maven plugin, I have multiple executions:

<plugin>
    <groupId>com.webcohesion.enunciate</groupId>
    <artifactId>enunciate-maven-plugin</artifactId>
    <configuration>
        <docsDir>${project.build.directory}/documentation/generated</docsDir>
        <sourcepath-includes>
            <include>
                <groupId>org.springframework.hateoas</groupId>
            </include>
        </sourcepath-includes>
        <sources>
            <source>${project.build.directory}/generated-sources/delombok</source>
        </sources>
    </configuration>
    <executions>
        <execution>
            <id>api-A</id>
            <goals>
                <goal>assemble</goal>
            </goals>
            <configuration>
                <configFile>src/main/resources/enunciate/enunciate-api-A.xml</configFile>
                <docsSubdir>api-A-enunciate</docsSubdir>
            </configuration>
        </execution>
        <execution>
            <id>api-B</id>
            <goals>
                <goal>assemble</goal>
            </goals>
            <configuration>
                <configFile>src/main/resources/enunciate/enunciate-api-B.xml</configFile>
                <docsSubdir>api-B-enunciate</docsSubdir>
            </configuration>
        </execution>
    </executions>
</plugin>

I was wondering if it would be feasible to scan the code only once in order to produce different swagger.json file? Currently it can take 10s to scan the code and I have more than 30 different enunciate configurations on the same code.

stoicflame commented 7 years ago

The problem is that the scanning is also configured via enunciate.xml, so there's currently no way to do this.

Sorry!

stoicflame commented 7 years ago

Actually, instead of closing this, I'll turn this into an enhancement request seeking a sponsor.

patvong commented 7 years ago

What would be the best way to approach this in order to make Enunciate support this use case?

stoicflame commented 7 years ago

It would be a pretty significant shift in the architecture. We'd have to split the scanning and compilation away from the generating engine. We'd probably need two separate configuration files, one for the scanning/compilation and another for the generating engine. We'd have to figure out how to iterate over multiple generation steps.

The work would mostly be done in Enunciate.java.

Instead this kind of process:

Enunciate enunciate  = new Enunciate();
enunciate.setModules(modules);
enunciate.setBuildDir(buildDir);
enunciate.setConfig(config);
enunciate.setSourceFiles(sourceFiles);
enunciate.setClasspath(classpath);
enunciate.run();

It would need to look like this kind of process:

Enunciate enunciate  = new Enunciate();
enunciate.setCompileConfig(compileConfig);
enunciate.setSourceFiles(sourceFiles);
enunciate.setClasspath(classpath);

enunciate.run(() -> {
  EnunciateRun[] runs = ...;
  for (EnunciateRun run : runs) {
    run.setModules(modules);
    run.setBuildDir(buildDir);
    run.setConfig(config);
    run.execute();
  }
})