swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

swagger-gradle-plugin with multiple configurations

Open emsigler opened this issue 4 years ago • 5 comments

We're using the swagger-gradle-plugin to generate oas specs from our source. We need to generate two different specs by varying the resourcePackages that the task is configured with. In one case, we want to reference additional packages.

We've tried to define a new task with a different configuration from the resolve task that the plugin adds that looks like the following.

task(resolveFull, type: io.swagger.v3.plugins.gradle.tasks.ResolveTask)

However, when executing the task I'm getting this NPE

Caused by: java.lang.NullPointerException
        at io.swagger.v3.plugins.gradle.tasks.ResolveTask.resolve(ResolveTask.java:328)

Which seems to correspond with to this code.

 Set<URL> buildUrls = StreamSupport.stream(getBuildClasspath().spliterator(), false).map(f -> {

Is it possible to run the ResolveTask without going through the swagger-gralde-plugin? Any suggestions on how we could configure gradle to run the resolve task with different configurations?

Thanks,

emsigler avatar Dec 08 '20 00:12 emsigler

Thanks for reporting this; it would need further investigations,however a workaround to avoid the null pointer is explicitly providing a buildClasspath parameter to the resolveFull task, like:

task(resolveFull, type: io.swagger.v3.plugins.gradle.tasks.ResolveTask) {
...
classpath = ...
buildClasspath = classpath
...

possibly also adding different contextId parameters to the 2 tasks could be needed in some scenarios

A full example:

resolve {
    outputFileName = 'PetStoreAPI'
    outputFormat = 'JSON'
    prettyPrint = 'TRUE'
    contextId = 'resolve'
    classpath = sourceSets.main.runtimeClasspath
    resourcePackages = ['my.firstpackage']
    outputDir = outputDir = file('resolveout')
}

task(resolveFull, type: io.swagger.v3.plugins.gradle.tasks.ResolveTask) {
   outputFileName = 'PetStoreAPI'
    outputFormat = 'JSON'
    prettyPrint = 'TRUE'
    contextId = 'resolvefull'
    classpath = sourceSets.main.runtimeClasspath
	buildClasspath = classpath
    resourcePackages = ['my.secondpackage']
    outputDir = outputDir = file('resolvefullout')
}

frantuma avatar Dec 08 '20 11:12 frantuma

Thanks for the example. Works great!

emsigler avatar Dec 09 '20 17:12 emsigler

When I try to run the resolveFull task, I get:

java.lang.ClassNotFoundException: io.swagger.v3.jaxrs2.integration.SwaggerLoader

The original 'resolve' task works fine so it seems weird that there would be a classpath issue for a "subtask"

What am I missing?

task(resolveFull, type: io.swagger.v3.plugins.gradle.tasks.ResolveTask) {
    contextId = 'resolvefull'
    classpath = sourceSets.main.runtimeClasspath
    buildClasspath = classpath
    outputFileName = 'full_swagger'
    outputFormat = 'JSON'
    prettyPrint = 'TRUE'
    resourcePackages = ['packageNameHere']
    outputDir = file('./')
}

joseFilA avatar Mar 24 '22 21:03 joseFilA

Adding implementation 'io.swagger.core.v3:swagger-jaxrs2' to the dependencies solved the issue.

joseFilA avatar Mar 24 '22 21:03 joseFilA