与 Play2 的 Swagger 集成

Swagger integration with Play2

我已关注 https://github.com/swagger-api/swagger-play/blob/master/play-2.7/swagger-play2/README.md 并将 swagger-play2 版本 1.7.1 与我的 play 2.7 应用程序集成。访问 /swagger.json 端点时,我从 swagger 库中抛出以下错误。

play.api.http.HttpErrorHandlerExceptions$$anon: 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.applyOrElse(AkkaHttpServer.scala:382)
at play.core.server.AkkaHttpServer$$anonfun.applyOrElse(AkkaHttpServer.scala:380)
at scala.concurrent.Future.$anonfun$recoverWith(Future.scala:417)
at scala.concurrent.impl.Promise.$anonfun$transformWith(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(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(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(ApiHelpController.scala:75)
    at scala.Function1.$anonfun$andThen(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.apply(Action.scala:420)
    at play.api.mvc.Action.$anonfun$apply(Action.scala:97)
    at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture(Accumulator.scala:175)
    at scala.util.Try$.apply(Try.scala:213)
    at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture(Accumulator.scala:175)
    at scala.Function1.$anonfun$andThen(Function1.scala:57)
    at scala.Function1.$anonfun$andThen(Function1.scala:57)
    at scala.Function1.$anonfun$andThen(Function1.scala:57)
    at play.api.libs.streams.StrictAccumulator.run(Accumulator.scala:208)
    at play.core.server.AkkaHttpServer.$anonfun$runAction(AkkaHttpServer.scala:376)
    at akka.http.scaladsl.util.FastFuture$.strictTransform(FastFuture.scala:41)
    at akka.http.scaladsl.util.FastFuture$.$anonfun$transformWith(FastFuture.scala:51)

看起来 ScannerFactory 中的 SCANNER 静态字段为空。

我在这里遗漏了什么吗?谢谢

看起来问题出在启用播放的模块上,出于某种原因,我启用模块的 nested 方式不起作用。为 play.modules.enabled += "play.modules.swagger.SwaggerModule" worked.

添加了单独的一行