2016-01-06 58 views
1

我試圖在現有Play Framework 2.4應用程序中將Swagger從1.3升級到1.5.x。將swagger-play2升級到1.5.0後出現錯誤

我已經改變了依賴於

"io.swagger" % "swagger-jaxrs" % "1.5.4" 
"io.swagger" %% "swagger-play2" % "1.5.0" 

,改變了進口com.wordnik.swaggerio.swagger並添加

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

到application.conf。

它全部編譯並運行,但是當我嘗試訪問api-docs時,出現以下異常。

com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: io.swagger.models.Swagger["paths"]) 
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210) 
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177) 
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:199) 
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:683) 
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157) 
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:130) 
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1387) 
at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1088) 
at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:960) 
at io.swagger.util.Json.pretty(Json.java:23) 
at controllers.SwaggerBaseApiController.toJsonString(ApiHelpController.scala:197) 
at controllers.ApiHelpController$$anonfun$getResource$1.apply(ApiHelpController.scala:89) 
at controllers.ApiHelpController$$anonfun$getResource$1.apply(ApiHelpController.scala:83) 
at play.api.mvc.ActionBuilder$$anonfun$apply$16.apply(Action.scala:408) 
at play.api.mvc.ActionBuilder$$anonfun$apply$16.apply(Action.scala:407) 
at play.api.mvc.Action$.invokeBlock(Action.scala:533) 
at play.api.mvc.Action$.invokeBlock(Action.scala:530) 
at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:493) 
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) 
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:105) 
at play.utils.Threads$.withContextClassLoader(Threads.scala:21) 
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:104) 
at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:103) 
at scala.Option.map(Option.scala:146) 
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:103) 
at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:96) 
at play.api.libs.iteratee.DoneIteratee$$anonfun$mapM$2.apply(Iteratee.scala:741) 
at play.api.libs.iteratee.DoneIteratee$$anonfun$mapM$2.apply(Iteratee.scala:741) 
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) 
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) 
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:39) 
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:399) 
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) 
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) 
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) 
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) 
Caused by: java.lang.NullPointerException 
at scala.collection.convert.Wrappers$JMapWrapperLike$$anon$2.<init>(Wrappers.scala:281) 
at scala.collection.convert.Wrappers$JMapWrapperLike$class.iterator(Wrappers.scala:280) 
at scala.collection.convert.Wrappers$JMapWrapper.iterator(Wrappers.scala:298) 
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) 
at scala.collection.AbstractIterable.foreach(Iterable.scala:54) 
at scala.collection.MapLike$FilteredKeys.foreach(MapLike.scala:231) 
at scala.collection.TraversableOnce$class.size(TraversableOnce.scala:105) 
at scala.collection.AbstractTraversable.size(Traversable.scala:104) 
at scala.collection.convert.Wrappers$MapWrapper.size(Wrappers.scala:169) 
at java.util.AbstractMap$1.size(AbstractMap.java:349) 
at java.util.AbstractCollection.toArray(AbstractCollection.java:136) 
at java.util.ArrayList.addAll(ArrayList.java:577) 
at io.swagger.models.Swagger.getPaths(Swagger.java:266) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:654) 
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675) 
     ... 32 more 
[error] 12:42:04.504 swagger - api listing for path /booking not found 

它看起來像問題是,io.swagger.models.Swagger.paths爲空,但應包含每個@Api註解類一個條目。我如何讓SwaggerModule正確地初始化路徑?

+0

你發現這個問題的任何解決方案? – martinscmb

+1

我實際上做的是停止使用SwaggerModule。我現在擁有的swagger yaml文件,我使用swagger spec來維護,並編寫簡單的播放控制器來滿足這些規範。 –

回答

0

已經爲我被宣告依賴於傑克遜合作的解決方案2.8.2明確:

"com.fasterxml.jackson.core" % "jackson-databind" % "2.8.2", 
"com.fasterxml.jackson.module" % "jackson-module-scala_2.11" % "2.8.2" 

至於我發現它不與2.7.x和2.6.x.工作

相關問題