Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Error injecting constructor with Unrecognized Type: [null] #43

Closed
lammel opened this issue Dec 28, 2015 · 30 comments · Fixed by #57
Closed

Error injecting constructor with Unrecognized Type: [null] #43

lammel opened this issue Dec 28, 2015 · 30 comments · Fixed by #57

Comments

@lammel
Copy link

lammel commented Dec 28, 2015

CreationException: Unable to create injector, see the following errors:

1) Error injecting constructor, java.lang.IllegalArgumentException: Unrecognized Type: [null]
  at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:33)
  while locating play.modules.swagger.SwaggerPluginImpl
  at play.modules.swagger.SwaggerModule.bindings(SwaggerModule.scala:11):
Binding(interface play.modules.swagger.SwaggerPlugin to ConstructionTarget(class play.modules.swagger.SwaggerPluginImpl) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
  while locating play.modules.swagger.SwaggerPlugin

1 error
        at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:466) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110) ~[guice-4.0.jar:na]
        at com.google.inject.Guice.createInjector(Guice.java:96) ~[guice-4.0.jar:na]
        at com.google.inject.Guice.createInjector(Guice.java:73) ~[guice-4.0.jar:na]
        at com.google.inject.Guice.createInjector(Guice.java:62) ~[guice-4.0.jar:na]
        at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:153) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:150) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:150) ~[play-server_2.11-2.4.6.jar:2.4.6]
        ... 14 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unrecognized Type: [null]
        at com.fasterxml.jackson.databind.type.TypeFactory._constructType(TypeFactory.java:405) ~[jackson-databind-2.5.4.jar:2.5.4]
        at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:354) ~[jackson-databind-2.5.4.jar:2.5.4]
        at com.fasterxml.jackson.databind.ObjectMapper.constructType(ObjectMapper.java:1332) ~[jackson-databind-2.5.4.jar:2.5.4]
        at io.swagger.scala.converter.SwaggerScalaModelConverter.resolveProperty(SwaggerScalaModelConverter.scala:32) ~[swagger-scala-module_2.11-1.0.0.jar:1.0.0]
        at io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:79) ~[swagger-core-1.5.4.jar:1.5.4]
        at io.swagger.converter.ModelConverters.readAsProperty(ModelConverters.java:58) ~[swagger-core-1.5.4.jar:1.5.4]
        at play.modules.swagger.PlayReader.createProperty(PlayReader.java:644) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.PlayReader.getParameters(PlayReader.java:569) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.PlayReader.parseMethod(PlayReader.java:514) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.PlayReader.read(PlayReader.java:136) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.PlayReader.read(PlayReader.java:60) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.PlayReader.read(PlayReader.java:54) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.ApiListingCache$$anonfun$listing$1.apply(ApiListingCache.scala:17) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.ApiListingCache$$anonfun$listing$1.apply(ApiListingCache.scala:11) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at scala.Option.orElse(Option.scala:289) ~[scala-library-2.11.7.jar:na]
        at play.modules.swagger.ApiListingCache$.listing(ApiListingCache.scala:11) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:144) ~[swagger-play2_2.11-1.5.0.jar:1.5.0]
        at play.modules.swagger.SwaggerPluginImpl$$FastClassByGuice$$de7219b8.newInstance(<generated>) ~[guice-4.0.jar:1.5.0]
        at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40) ~[guice-4.0.jar:na]
        at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267) ~[guice-4.0.jar:na]
        at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) ~[guice-4.0.jar:na]
        at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180) ~[guice-4.0.jar:na]
        ... 25 common frames omitted

The stacktrace leads to an error in the resolveProperty method in the SwaggerScalaModelConverter.scala:32. Causing constructType to fail in

val javaType = Json.mapper().constructType(`type`)

So it seems that resolveProperty is the culprit of the issue otherwise (if I misinterpret the stacktrace) a generic error with dependency injection might be also a candidate.

In SwaggerPlugin.scala:33 the dependency injection is done:

class SwaggerPluginImpl @Inject()(lifecycle: ApplicationLifecycle, router: Router, app: Application) extends SwaggerPlugin {

With that very generic failure any help would be greatly appreciated.

@rafax
Copy link

rafax commented Dec 29, 2015

I have the same issue and after some debugging it seems to be caused by the fact that PlayReader tries to compare Parameter.typeName (including package) with Class.simpleName (just the class name)
https://github.com/swagger-api/swagger-play/blob/master/play-2.4/swagger-play2/app/play/modules/swagger/PlayReader.java#L530 (simpleTypeName is the result of Parameter.typeName, which in my case returns the full name)

@fehguy
Copy link
Contributor

fehguy commented Dec 29, 2015

Can you please share some models / case classes that are giving you trouble?

@Antanukas
Copy link
Contributor

I have similar problem:

CreationException: Unable to create injector, see the following errors:

1) Error injecting constructor, java.lang.IllegalArgumentException: Unrecognized Type: [null]
  at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:33)
  while locating play.modules.swagger.SwaggerPluginImpl
  at play.modules.swagger.SwaggerModule.bindings(SwaggerModule.scala:11):
Binding(interface play.modules.swagger.SwaggerPlugin to ConstructionTarget(class play.modules.swagger.SwaggerPluginImpl) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
  while locating play.modules.swagger.SwaggerPlugin
[playground.zip](https://github.com/swagger-api/swagger-play/files/74552/playground.zip)

Code that causes this issue:

case class FieldType(test: String)
@ApiModel(description = "Bad model")
case class Response(
  //Comment this out and everything works
  @(ApiModelProperty @field)(value = "field1", dataType = "controllers.FieldType")
  field1: String)

@Api
class Application extends Controller {


  @ApiOperation(value = "test", response = classOf[Response])
  @ApiImplicitParams(value = Array(
    new ApiImplicitParam(paramType = "body", dataType = "controllers.FieldType")))
  def test = Action {
    Ok("good")
  }

}

You should notice that new ApiImplicitParam(paramType = "body", dataType = "controllers.FieldType"))) doesn't cause this issue but @(ApiModelProperty @field)(value = "field1", dataType = "controllers.FieldType") does. This way I can not implement enums properly.

So far I have tracked that code in swagger-core io.swagger.jackson.ModelResolver returns null here:

    protected JavaType getInnerType(String innerType) {
        try {
            Class<?> innerClass = Class.forName(innerType);
            if (innerClass != null) {
                TypeFactory tf = _mapper.getTypeFactory();
                return tf.constructType(innerClass);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

which later causes error when bootstrapping Guice module.
I think instead of Class.forName(innerType); Thread.currentThread().getContextClassLoader().loadClass(type); should be used

I attached Play project that reproduces this issue
playground.zip

@rafax
Copy link

rafax commented Jan 4, 2016

@fehguy I added a sample project that makes it easy to reproduce the issue https://github.com/rafax/play-swagger-repro

The error seems to be related to my use of custom QueryStringBindable.

@anasawad
Copy link

anasawad commented Jan 7, 2016

I have the same problem, any solutions ?

@mphuff
Copy link

mphuff commented Jan 8, 2016

I am getting the exact same error. None of my models are documented / annotated yet but I'm curious what others find as the problem here.

@rafax
Copy link

rafax commented Jan 15, 2016

My issue was fixed in version 1.5.1, thanks!

@lammel
Copy link
Author

lammel commented Jan 15, 2016

I'm still seeing the same issue after upgrading to swagger-1.5.1 (with
swagger-parser-1.0.16).
None of my models are annotated (only the controllers are).

Unfortunatly the stacktrace does not reveal any hints on where to look in
my models/controllers.

Error injecting constructor, java.lang.IllegalArgumentException:
Unrecognized Type: [null]
  at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:33)
  while locating play.modules.swagger.SwaggerPluginImpl
  at play.modules.swagger.SwaggerModule.bindings(SwaggerModule.scala:11):
Binding(interface play.modules.swagger.SwaggerPlugin to
ConstructionTarget(class play.modules.swagger.SwaggerPluginImpl) eagerly)
(via modules: com.google.inject.util.Modules$OverrideModule ->
play.api.inject.guice.GuiceableModuleConversions$$anon$1)
  while locating play.modules.swagger.SwaggerPlugin

1 error
at
com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:466)
~[guice-4.0.jar:na]
at
com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184)
~[guice-4.0.jar:na]
at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
~[guice-4.0.jar:na]
at com.google.inject.Guice.createInjector(Guice.java:96) ~[guice-4.0.jar:na]
at com.google.inject.Guice.createInjector(Guice.java:73) ~[guice-4.0.jar:na]
Caused by: java.lang.IllegalArgumentException: Unrecognized Type: [null]
at
com.fasterxml.jackson.databind.type.TypeFactory._constructType(TypeFactory.java:405)
~[jackson-databind-2.5.4.jar:2.5.4]
at
com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:354)
~[jackson-databind-2.5.4.jar:2.5.4]
at
com.fasterxml.jackson.databind.ObjectMapper.constructType(ObjectMapper.java:1332)
~[jackson-databind-2.5.4.jar:2.5.4]
at
io.swagger.scala.converter.SwaggerScalaModelConverter.resolveProperty(SwaggerScalaModelConverter.scala:32)
~[swagger-scala-module_2.11-1.0.0.jar:1.0.0]
at
io.swagger.converter.ModelConverterContextImpl.resolveProperty(ModelConverterContextImpl.java:79)
~[swagger-core-1.5.6.jar:1.5.6]

On Fri, Jan 15, 2016 at 10:48 AM, Rafał Gajdulewicz <
notifications@github.com> wrote:

My issue was fixed in version 1.5.1, thanks!


Reply to this email directly or view it on GitHub
#43 (comment)
.

@edvakf
Copy link

edvakf commented Jan 16, 2016

This error occurs to me with a parameter of Option type.

edvakf@cf89dc4

@mphuff
Copy link

mphuff commented Jan 16, 2016

I had to restructure my routes to remove the Option type. That would be nice to support but getting swagger working was more important than supporting Option for me.

1.5.1 fixed a couple of other issues too - thanks everyone!

  • Micah

On Jan 15, 2016, at 5:39 PM, edvakf notifications@github.com wrote:

This error occurs to me with a parameter of Option type.

edvakf/swagger-play@cf89dc4


Reply to this email directly or view it on GitHub.

@vitthala
Copy link

I am getting same error in version 1.5.1.
Is it fixed?

@osbornk
Copy link

osbornk commented Jan 25, 2016

I can confirm this as well.

This route works:
GET /bob com.cmycompany.BobController.bob(x: Option[String] = None)

This does not:
GET /bob com.cmycompany.BobController.bob(x: Option[String] ?= None)

However, the second is what I want. You also don't even need to annotate the method to get this error. Simply annotating the controller with @Api and having any route in the controller with an option without a fixed value is enough to cause this error.

@fehguy
Copy link
Contributor

fehguy commented Feb 5, 2016

This is a tough one. I think we need some help from the community on this issue.

@Arqu
Copy link

Arqu commented Feb 9, 2016

EDIT: Never mind my issue, it was induced by swagger but is not related, I had a flag that was being initialized in the globalsettings section that starts my bindings which relied on play to be running by then and was thus failing, after eliminating that it was smooth sailing.

OP:

Seems like I'm in the same boat, using v1.5.1 this is my stack trace:

play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:

1) Error injecting constructor, java.lang.ExceptionInInitializerError
  at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:33)
  while locating play.modules.swagger.SwaggerPluginImpl
  at play.modules.swagger.SwaggerModule.bindings(SwaggerModule.scala:11):
Binding(interface play.modules.swagger.SwaggerPlugin to ConstructionTarget(class play.modules.swagger.SwaggerPluginImpl) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
  while locating play.modules.swagger.SwaggerPlugin

1 error]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:165) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at scala.Option.map(Option.scala:146) ~[scala-library-2.11.6.jar:na]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at scala.util.Success.flatMap(Try.scala:230) ~[scala-library-2.11.6.jar:na]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:111) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library-2.11.6.jar:na]
        at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.11.6.jar:na]
        at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) ~[na:1.8.0_60]
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_60]
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[na:1.8.0_60]
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[na:1.8.0_60]
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[na:1.8.0_60]
Caused by: com.google.inject.CreationException: Unable to create injector, see the following errors:

1) Error injecting constructor, java.lang.ExceptionInInitializerError
  at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:33)
  while locating play.modules.swagger.SwaggerPluginImpl
  at play.modules.swagger.SwaggerModule.bindings(SwaggerModule.scala:11):
Binding(interface play.modules.swagger.SwaggerPlugin to ConstructionTarget(class play.modules.swagger.SwaggerPluginImpl) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
  while locating play.modules.swagger.SwaggerPlugin

1 error
        at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:466) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110) ~[guice-4.0.jar:na]
        at com.google.inject.Guice.createInjector(Guice.java:96) ~[guice-4.0.jar:na]
        at com.google.inject.Guice.createInjector(Guice.java:73) ~[guice-4.0.jar:na]
        at com.google.inject.Guice.createInjector(Guice.java:62) ~[guice-4.0.jar:na]
        at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:153) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:150) ~[play-server_2.11-2.4.6.jar:2.4.6]
        at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:150) ~[play-server_2.11-2.4.6.jar:2.4.6]
        ... 14 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
        at java.lang.Class.forName0(Native Method) ~[na:1.8.0_60]
        at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_60]
        at play.modules.swagger.util.SwaggerContext$$anonfun$loadClass$1.apply(SwaggerContext.scala:27) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at play.modules.swagger.util.SwaggerContext$$anonfun$loadClass$1.apply(SwaggerContext.scala:24) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at scala.collection.immutable.List.foreach(List.scala:381) ~[scala-library-2.11.6.jar:na]
        at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35) ~[scala-library-2.11.6.jar:na]
        at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45) ~[scala-library-2.11.6.jar:na]
        at play.modules.swagger.util.SwaggerContext$.loadClass(SwaggerContext.scala:24) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at play.modules.swagger.PlayApiScanner$$anonfun$1.applyOrElse(PlayApiScanner.scala:86) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at play.modules.swagger.PlayApiScanner$$anonfun$1.applyOrElse(PlayApiScanner.scala:83) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at scala.collection.immutable.List.collect(List.scala:295) ~[scala-library-2.11.6.jar:na]
        at play.modules.swagger.PlayApiScanner.classes(PlayApiScanner.scala:83) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at play.modules.swagger.ApiListingCache$$anonfun$listing$1.apply(ApiListingCache.scala:15) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at play.modules.swagger.ApiListingCache$$anonfun$listing$1.apply(ApiListingCache.scala:11) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at scala.Option.orElse(Option.scala:289) ~[scala-library-2.11.6.jar:na]
        at play.modules.swagger.ApiListingCache$.listing(ApiListingCache.scala:11) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:160) ~[swagger-play2_2.11-1.5.1.jar:1.5.1]
        at play.modules.swagger.SwaggerPluginImpl$$FastClassByGuice$$de7219b8.newInstance(<generated>) ~[guice-4.0.jar:1.5.1]
        at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40) ~[guice-4.0.jar:na]
        at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267) ~[guice-4.0.jar:na]
        at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) ~[guice-4.0.jar:na]
        at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40) ~[guice-4.0.jar:na]
        at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199) ~[guice-4.0.jar:na]
        at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180) ~[guice-4.0.jar:na]
        ... 25 common frames omitted
Caused by: java.lang.RuntimeException: There is no started application
        at scala.sys.package$.error(package.scala:27) ~[scala-library-2.11.6.jar:na]
        at play.api.Play$$anonfun$current$1.apply(Play.scala:71) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.api.Play$$anonfun$current$1.apply(Play.scala:71) ~[play_2.11-2.4.6.jar:2.4.6]
        at scala.Option.getOrElse(Option.scala:121) ~[scala-library-2.11.6.jar:na]
        at play.api.Play$.current(Play.scala:71) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.api.Play.current(Play.scala) ~[play_2.11-2.4.6.jar:2.4.6]
        at play.Play.isDev(Play.java:31) ~[play_2.11-2.4.6.jar:2.4.6]
        at controllers.core.RestController.<clinit>(RestController.java:40) ~[na:na]
        ... 59 common frames omitted

I've only used swagger on a single location:
@ApiOperation(value = "Get Companies", notes = "", httpMethod = "GET")
for the following routes:

GET            /api/company/                                @controllers.company.CompanyController.getCompany(id: Int ?= -1)
GET            /api/company/:id                             @controllers.company.CompanyController.getCompany(id: Int)

frantuma added a commit to frantuma/swagger-play that referenced this issue Feb 11, 2016
fehguy added a commit that referenced this issue Feb 16, 2016
fix #43 - Parameter types handling
@osbornk
Copy link

osbornk commented Feb 16, 2016

Can we get a release on swagger-play2? Thanks.

@lammel
Copy link
Author

lammel commented Feb 17, 2016

I just test with swagger-play2 1.5.1 and run into the same issue using libraryDependencies (as found in #57):

"io.swagger"   %% "swagger-play2" % "1.5.1",
"io.swagger"      % "swagger-core"               % "1.5.8-SNAPSHOT",
"io.swagger"   %% "swagger-scala-module"       % "1.0.2-SNAPSHOT",

Probably the "?=" syntax in conf/routes is the culprit
@controllers.MyCtrl.getUsers(id: Int, isBad: Option[Boolean] ?= None)

Should this case work already?

On Tue, Feb 16, 2016 at 4:20 PM, osbornk notifications@github.com wrote:

Can we get a release on swagger-play2? Thanks.


Reply to this email directly or view it on GitHub
#43 (comment)
.

@frantuma
Copy link
Member

@lammel tested with your use case, and it should work ok. Possibly you are pointing to older version, please either build yourself or wait for version to be published

@lammel
Copy link
Author

lammel commented Feb 17, 2016

@frantuma: What should I build actually (master of swagger-play2, swagger-module-scala, ...) or which snapshots should I use?

I'd just like to help ensure, that the fix is working and my actual usecase has no other issues lurking around.

@frantuma
Copy link
Member

@lammel you should build master of swagger-play2 adding sonatype snapshots repo to resolvers in build.sbt (scala-module 1.0.2-SNAPSHOT and swagger-core 1.5.8-SNAPSHOT published there)

@trunght
Copy link

trunght commented Feb 23, 2016

@frantuma I still have this error running play 2.4 for Java and swagger-play2 1.5.1
This is my build.sbt config:
"io.swagger" %% "swagger-play2" % "1.5.1",
"io.swagger" % "swagger-core" % "1.5.8-SNAPSHOT",
"io.swagger" %% "swagger-scala-module" % "1.0.2-SNAPSHOT"

This is my route file:
GET /users/home controllers.UsersController.home()
GET /api/v1/status controllers.ApiController.status(user_id: String ?= "")
GET /swagger.json controllers.ApiHelpController.getResources

Another strange thing is if I change the controllers.ApiController.status to controllers.ApiController.report then it will work. (I have both status and report method implemented in ApiController)
Thanks.

@frantuma
Copy link
Member

@trunght I am not sure I get it fully: you mean you have 2 methods status and report with same parameter and only method name changes, and with one it works, and the other not? can you share the controller methods signatures?

@trunght
Copy link

trunght commented Feb 23, 2016

@frantuma: these are my methods:
public Result status(String userId)
public Result report(String userId)

FYI, I coded this ApiController with around 10 methods, today I installed swagger and ran into this bug. So I tried to delete all the routes => run successfully /swagger.json
Add the route for ApiController.status => failed
Remove the route for status, add the route for report => work
Remove both of them and add back the other routes => work
So I guess the problem is around my status api.

Thanks a lot for your help.

@frantuma
Copy link
Member

@trunght I cannot reproduce NPE for your case, but there's indeed a related bug, happening when naming a method "status" (or some other names possibly) in a java controller; We'll have that fixed possibly in next release, as workaround please either rename the method or implement it in scala.

Please see also #43 (comment) to be sure you are using latest version

@trunght
Copy link

trunght commented Feb 25, 2016

Thanks @frantuma changed the name of the method and it works.

@rwijngaa
Copy link

i had to remove the Option(al) parameter in my route to make it work.

So, this does not work:
POST /alert/create controllers.Alerting.create2(applicationId: String, message: String, subject: String, context: play.libs.F.Option[String])

and this does work:
POST /alert/create controllers.Alerting.create2(applicationId: String, message: String, subject: String, context: String)

@metasim
Copy link

metasim commented Apr 18, 2016

Anyone figure out how to get Option[_]al parameters to work? I am also stalled by this problem.

@metasim
Copy link

metasim commented Apr 18, 2016

I see that there's a test (CatController, line 66) attempting to exercise this case. I attempted to replicate it. The test code doesn't go through a routes file, so I'm wondering if the problem requires that scenario to part of the test. IOW, my route has the form:

GET         /stuff                        controllers.Foo.listStuff(nameQuery: Option[String])

I get an exception even if I define my endpoint with:

  @ApiImplicitParams(Array(
    new ApiImplicitParam(name = "nameQuery", value = "Optional substring to search",
      dataType="String", paramType="query")
  ))

Further, if I define dataType to be Option[String], an exception is logged to the console (but rendering still proceeds).

@osbornk
Copy link

osbornk commented Apr 18, 2016

Get the latest swagger-play2 1.5.2. Works great for me now.

@metasim
Copy link

metasim commented Apr 19, 2016

@osbornk 👍 You made my day!

@seance
Copy link

seance commented May 7, 2016

@osbornk Awesome, ran into same problem and found this, works perfectly now!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.