带有Play框架的Swagger UI

问题描述 投票:0回答:1

我正在尝试将Swagger UI与我的游戏框架项目集成。

Scala版本:2.12.8播放版本:2.7

下面是我添加的依赖项:

"io.swagger" %% "swagger-play2" % "1.7.1",
"org.webjars" % "swagger-ui" % "3.13.0",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.10.4"

此外,已在application.conf中添加了配置:

play.modules.enabled + =“ play.modules.swagger.SwaggerModule”

对于路由文件,已添加以下路由:

GET         /swagger.json                controllers.ApiHelpController.getResources
GET         /docs/                       controllers.Assets.at(path="/public/swagger-ui",file="index.html")
GET         /docs/*file                  controllers.Assets.at(path="/public/swagger-ui",file)

但是在访问页面http://localhost:9000/swagger.json时出现错误,但出现以下错误:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle (through reference chain: io.swagger.models.Swagger["definitions"]->java.util.LinkedHashMap["RoleResponse"]->io.swagger.models.ModelImpl["properties"]->java.util.LinkedHashMap["code"]->io.swagger.models.properties.StringProperty["readOnly"])
    at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
    at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1191)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter._handleSelfReference(BeanPropertyWriter.java:944)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:721)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:722)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
    at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeOptionalFields(MapSerializer.java:782)
    at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:639)
    at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:722)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
    at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeOptionalFields(MapSerializer.java:782)
    at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:639)
    at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:722)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
    at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1433)
    at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1135)
    at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:1005)
    at io.swagger.util.Json.pretty(Json.java:23)
    at controllers.SwaggerBaseApiController.toJsonString(ApiHelpController.scala:189)
    at controllers.SwaggerBaseApiController.toJsonString$(ApiHelpController.scala:185)
    at controllers.ApiHelpController.toJsonString(ApiHelpController.scala:68)
    at controllers.ApiHelpController.$anonfun$getResources$1(ApiHelpController.scala:76)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:57)
    at play.api.mvc.ActionBuilderImpl.invokeBlock(Action.scala:489)
    at play.api.mvc.ActionBuilderImpl.invokeBlock(Action.scala:487)
    at play.api.mvc.ActionBuilder$$anon$10.apply(Action.scala:426)
    at play.api.mvc.Action.$anonfun$apply$2(Action.scala:98)
    at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$4(Accumulator.scala:184)
    at scala.util.Try$.apply(Try.scala:213)
    at play.api.libs.streams.StrictAccumulator.$anonfun$mapFuture$3(Accumulator.scala:184)
    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:219)
    at play.core.server.AkkaHttpServer.$anonfun$runAction$4(AkkaHttpServer.scala:441)
    at kamon.instrumentation.akka.http.FastFutureTransformWithAdvice$.strictTransform$1(AkkaHttpServerInstrumentation.scala:272)
    at kamon.instrumentation.akka.http.FastFutureTransformWithAdvice$.$anonfun$transformWith$1(AkkaHttpServerInstrumentation.scala:284)
    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:92)
    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:92)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
    at kamon.instrumentation.executor.ExecutorInstrumentation$InstrumentedForkJoinPool$TimingRunnable.run(ExecutorInstrumentation.scala:653)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:49)
    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)

我错过了什么!

而且,想知道将在public / swagger-ui目录下的index.html文件中设置的URL。

将摇摇欲坠与我的游戏项目集成的任何其他方式都将非常有用。

java playframework swagger swagger-ui
1个回答
0
投票
[我认为问题在于您使用的是杰克逊2.10.4,而插件使用的是2.9.9。有同样的问题,但是我正在玩play2.8和swagger-play2-3.0.0(请求支持play 2.8)。您可以尝试将杰克逊库降级到2.9.9,看看是否有帮助?
© www.soinside.com 2019 - 2024. All rights reserved.