Dear all,
This is my first time that I implement a REST API using Scala and Play framework. I created the specification fo the API using swagger editor.
Then, I create a new project that I name myAPI using the command:
`$ activator new myAPI api-first-hand
Fetching the latest list of templates...
OK, application "myAPI" is being created using the "api-first-hand" template.
To run "myAPI" from the command line, "cd myAPI" then:
/Users/rs/myAPI/activator run
To run the test for "myAPI" from the command line, "cd myAPI" then:
/Users/rs/myAPI/activator test
To run the Activator UI for "myAPI" from the command line, "cd myAPI" then:
/Users/rs/myAPI/activator ui`
Afterward, I copy paste the yaml file of the specification in /conf/ and I edit the routes file as follow:
`#Routes
#This file defines all application routes (Higher priority routes first)
#~~~~
GET /spec/:name controllers.Swagger.swaggerSpec(name: String)
GET /list_specs controllers.Swagger.listSpecs
GET / controllers.Assets.versioned(path="/public/swagger", file: Asset = "index.html")
GET /index.html controllers.Assets.versioned(path="/public/swagger", file: Asset = "index.html")
GET /o2c.html controllers.Assets.versioned(path="/public/swagger", file: Asset = "o2c.html")
GET /favicon.ico controllers.Assets.versioned(path="/public/swagger/images", file: Asset = "favicon.ico")
GET /api/*file controllers.Assets.versioned(path="/public/swagger", file: Asset)
#-> /number_validation numbers.validation.yaml.Routes
#-> /string_validation string_formats.validation.yaml.Routes
#-> /cross_spec cross_spec_references.yaml.Routes
#-> /form_data form_data.yaml.Routes
#-> /types type_deduplication.yaml.Routes
#-> /uber uber.api.yaml.Routes
#-> /petstore simple.petstore.api.yaml.Routes
#-> /security security.api.yaml.Routes
#-> /example example.yaml.Routes
-> /opendataapi APISpecification.yaml.Routes`
I position my sefl in the root directory /myAPI and run the sbt command:
$ sbt [info] Loading project definition from /Users/rs/myAPI/project [info] Updating {file:/Users/rs/myAPI/project/}myapi-build... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] Set current project to myAPI (in build file:/Users/rs/myAPI/)
I run the following command and I get these errors when I try to access http://localhost:9000/:
`$ run
[info] Updating {file:/Users/rs/myAPI/}root...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.7, 2.11.0, 2.11.6) -> 2.11.8
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
[warn] There may be incompatibilities among your library dependencies.
[warn] Here are some of the libraries that were evicted:
[warn] * com.fasterxml.jackson.module:jackson-module-scala_2.11:2.6.1 -> 2.7.4
[warn] Run 'evicted' to see detailed eviction warnings
--- (Running the application, auto-reloading is enabled) ---
[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/rs/activator-dist-1.3.12/repository/org.slf4j/slf4j-simple/1.7.12/jars/slf4j-simple.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/rs/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[trace] Stack trace suppressed: run last compile:swaggerParseSpec for the full output.
[error] (compile:swaggerParseSpec) com.fasterxml.jackson.core.JsonParseException: Instantiation of [simple type, class de.zalando.swagger.strictModel$Schema] value failed (java.lang.IllegalArgumentException): requirement failed: Support for object definitions without properties is not implemented yet
[error] at [Source: N/A; line: -1, column: -1] (through reference chain: de.zalando.swagger.Schema["properties"]->com.fasterxml.jackson.module.scala.deser.MapBuilderWrapper["metadata"]) through reference chain: paths โ /line โ get โ responses โ 200 โ schema
[trace] Stack trace suppressed: run last compile:swaggerParseSpec for the full output.
[error] (compile:swaggerParseSpec) com.fasterxml.jackson.core.JsonParseException: Instantiation of [simple type, class de.zalando.swagger.strictModel$Schema] value failed (java.lang.IllegalArgumentException): requirement failed: Support for object definitions without properties is not implemented yet
[error] at [Source: N/A; line: -1, column: -1] (through reference chain: de.zalando.swagger.Schema["properties"]->com.fasterxml.jackson.module.scala.deser.MapBuilderWrapper["metadata"]) through reference chain: paths โ /line โ get โ responses โ 200 โ schema
[error] application -
! @72c4p8dcp - Internal server error, for (GET) [/] ->
play.sbt.PlayExceptions$UnexpectedException: Unexpected exception[JsonParseException: Instantiation of [simple type, class de.zalando.swagger.strictModel$Schema] value failed (java.lang.IllegalArgumentException): requirement failed: Support for object definitions without properties is not implemented yet
at [Source: N/A; line: -1, column: -1] (through reference chain: de.zalando.swagger.Schema["properties"]->com.fasterxml.jackson.module.scala.deser.MapBuilderWrapper["metadata"]) through reference chain: paths โ /line โ get โ responses โ 200 โ schema]
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:51)
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44)
at scala.Option.map(Option.scala:145)
at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44)
at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40)
at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17)
at scala.util.Either$LeftProjection.map(Either.scala:377)
at play.sbt.run.PlayReload$.compile(PlayReload.scala:17)
at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3$$anonfun$2.apply(PlayRun.scala:61)
Caused by: com.fasterxml.jackson.core.JsonParseException: Instantiation of [simple type, class de.zalando.swagger.strictModel$Schema] value failed (java.lang.IllegalArgumentException): requirement failed: Support for object definitions without properties is not implemented yet
at [Source: N/A; line: -1, column: -1] (through reference chain: de.zalando.swagger.Schema["properties"]->com.fasterxml.jackson.module.scala.deser.MapBuilderWrapper["metadata"]) through reference chain: paths โ /line โ get โ responses โ 200 โ schema
at de.zalando.swagger.StrictSwaggerParser$$anonfun$1.apply(StrictParser.scala:76)
at de.zalando.swagger.StrictSwaggerParser$$anonfun$1.apply(StrictParser.scala:71)
at scala.util.control.Exception$Catch$$anon$2.apply(Exception.scala:136)
at scala.util.control.Exception$Catch$$anon$2.apply(Exception.scala:134)
at scala.util.control.Exception$Catch.apply(Exception.scala:105)
at de.zalando.swagger.StrictSwaggerParser.parse(StrictParser.scala:77)
at de.zalando.swagger.SwaggerParser$.readSwaggerModel(SwaggerParser.scala:12)
at de.zalando.play.swagger.sbt.ApiFirstSwaggerParser$$anonfun$swaggerParserSettings$4$$anonfun$apply$1.apply(ApiFirstSwaggerParser.scala:55)
at de.zalando.play.swagger.sbt.ApiFirstSwaggerParser$$anonfun$swaggerParserSettings$4$$anonfun$apply$1.apply(ApiFirstSwaggerParser.scala:55)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
`