javaplayframeworkswaggerswagger-play2

Swagger integration with Play2


I've followed https://github.com/swagger-api/swagger-play/blob/master/play-2.7/swagger-play2/README.md and integrated swagger-play2 version 1.7.1 with my play 2.7 app. When accessing /swagger.json endpoint, I'm getting the following error thrown from swagger library.

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[NullPointerException: null]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:323)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:243)
at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:382)
at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:380)
at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:417)
at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:41)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:64)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:85)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:44)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

Caused by: java.lang.NullPointerException: null
    at play.modules.swagger.ApiListingCache$.$anonfun$listing$1(ApiListingCache.scala:15)
    at scala.Option.orElse(Option.scala:306)
    at play.modules.swagger.ApiListingCache$.listing(ApiListingCache.scala:11)
    at controllers.SwaggerBaseApiController.getResourceListing(ApiHelpController.scala:123)
    at controllers.SwaggerBaseApiController.getResourceListing$(ApiHelpController.scala:109)
    at controllers.ApiHelpController.getResourceListing(ApiHelpController.scala:68)
    at controllers.ApiHelpController.$anonfun$getResources$1(ApiHelpController.scala:75)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:57)
    at play.api.mvc.ActionBuilderImpl.invokeBlock(Action.scala:483)
    at play.api.mvc.ActionBuilderImpl.invokeBlock(Action.scala:481)
    at play.api.mvc.ActionBuilder$$anon$10.apply(Action.scala:420)
    at play.api.mvc.Action.$anonfun$apply$2(Action.scala:97)
    at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$4(Accumulator.scala:175)
    at scala.util.Try$.apply(Try.scala:213)
    at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$3(Accumulator.scala:175)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:57)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:57)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:57)
    at play.api.libs.streams.StrictAccumulator.run(Accumulator.scala:208)
    at play.core.server.AkkaHttpServer.$anonfun$runAction$4(AkkaHttpServer.scala:376)
    at akka.http.scaladsl.util.FastFuture$.strictTransform$1(FastFuture.scala:41)
    at akka.http.scaladsl.util.FastFuture$.$anonfun$transformWith$3(FastFuture.scala:51)

Looks like the SCANNER static field from ScannerFactory is null.

Am i missing anything here? Thanks.


Solution

  • Looks like the problem was with play enabled modules, for some reason, the nested way I enabled modules didn't work. Added a seperate line for play.modules.enabled += "play.modules.swagger.SwaggerModule" worked.