I have done everything the github documentation mentioned:
added plugin:
addSbtPlugin("com.iheart" %% "sbt-play-swagger" % "0.7.3")
added to my root:
lazy val root = (project in file(".")).enablePlugins(PlayScala, SwaggerPlugin) //enable plugin
added a base swagger.yml
added the library:
libraryDependencies += "org.webjars" % "swagger-ui" % "2.2.0"
added those to my routes:
### NoDocs ###
GET /docs/swagger-ui/*file controllers.Assets.at(path:String="/public/lib/swagger-ui", file:String)
### NoDocs ###
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
and added some swagger annotation to my routes.
now when I run the app and go to http://localhost:9000/docs/swagger-ui/index.html?url=/assets/swagger.json im supposed to see something, and all I see is a green screen...
so weird, is there something missing in the doc?
Based on your version of play-swagger it looks like you're using it with Play 2.6. This version of Play introduces Content Security Policy (CSP) headers by default. There is a known issue with Play 2.6's CSP headers and play-swagger.
If you look in your browser console you should see some CSP errors logged. If this is the case you may need to disable the headers by adding the following to your application.conf file.
play.filters.headers.contentSecurityPolicy = null
We are working on an improvement to Play's Content Security Policy header implementation so that third-party libraries like play-swagger should work more seamlessly in the future.
Related
I'm using ScalaPB (version 0.11.1) and plugin sbt-protoc (version 1.0.3) to try to compile an old project with ProtocolBuffers in Scala 2.12. Reading the documentation, I want to set the file property preserve_unknown_fields to false. But my question is, where? Where do I need to set this flag? On the .proto file?
I've also tried to include the flag as a package-scoped option by creating a package.proto file next to my other .proto file, with the following content (as it is specified here):
import "scalapb/scalapb.proto";
package eur.astrata.eu.bigdata.tpms.protobuf;
option (scalapb.options) = {
preserve_unknown_fields: false
};
But when trying to compile, I get the following error:
[libprotobuf WARNING T:\src\github\protobuf\src\google\protobuf\compiler\parser.cc:648] No syntax specified for the proto file: package.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
scalapb/scalapb.proto: File not found.
package.proto:1:1: Import "scalapb/scalapb.proto" was not found or had errors.
I've also tried with syntax = "proto3"; at the beginning but it doesn't work.
Any help would be greatly appreciated.
From the docs:
If you are using sbt-protoc and importing protos like
scalapb/scalapb.proto, or common protocol buffers like
google/protobuf/wrappers.proto:
Add the following to your build.sbt:
libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf"
This tells sbt-protoc to extract protos from this jar (and all its dependencies,
which includes Google's common protos), and make them available in the
include path that is passed to protoc.
It is important to add that by setting preserve_unknown_fields to false you are turning off a protobuf feature that could prevent data loss when different parts of a distributed system are not running the same version of the schema.
For example, suppose I have a file project/CodeGeneration.scala that generates "managed" source-code, and suppose that object (CodeGeneration) needs to leverage a third-party library -- say jsoup...
import org.jsoup._
object CodeGeneration {
def generateCode = /* Generate code using jsoup... */
}
Simply adding a line for jsoup to your libraryDependencies in build.sbt doesn't do the trick; it leads to a compilation error complaining about the missing jsoup object/namespace.
So, (how) can one access this dependency from "meta" code -- code that generates other code?
It seems the solution is to leverage sbt's "recursive" nature, and put an additional build.sbt file in the project directory. So, for example, project/build.sbt might look like this:
libraryDependencies += "org.jsoup" % "jsoup" % "1.11.2"
There's more detail in sbt's official documentation.
I have a regular project (not play) and I want to create docker image for this project....how can I do it?
I tried something like this:
dockerRepository := Some("docker-docker-local.artifactoryonline.com")
dockerUpdateLatest := true
dockerEntrypoint := Seq("bin/%s" format executableScriptName.value, "-J-Xms1024M", "-J-Xmx2048m", "-J-server")
but dockerRepository,dockerUpdateLatest and dockerEntrypoint are not familiare in my proj, I need to import something but I dont know what.
I also have a jfrog account to save my artifactory (this is why I added the url).
What is the best way to do it?
thanksss!#
You'll need to add an sbt plugin that supports Docker image creation to your build. Check out sbt-native-packager. To use it, add it to your project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.6")
Then in your build.sbt, enable Docker support
enablePlugins(DockerPlugin)
After that, your settings should be recognized, and you have the following tasks available:
docker:publishLocal
Build a Docker image
docker:publish
Build image and publish to configured repository
See the full documentation at http://www.scala-sbt.org/sbt-native-packager/ and http://www.scala-sbt.org/sbt-native-packager/formats/docker.html
There's also a mailing list: https://groups.google.com/forum/?hl=en#!forum/sbt-native-packager
I am using WartRemover in a play project. I want to exclude routes file (generated code from it) from Wartremover scanning. I added following but it still scans play routes generated code.
wartremoverExcluded ++= Seq("com.xxx.controllers.ReverseMyController","com.xxx.controllers.javascript.ReverseMyController","com.xxx.controllers.ref.ReverseMyController")
And it still shows wart errors from the generated code for routes play file. for e.g.
warn] /xxx/conf/routes:23: Inferred type containing Nothing
warn] PUT /service/myendpoint com.xxx.controllers.MyController.postMyData
and same for many more routes defined in the routes file.
How to exclude routes from wartremover scan?
Have you tried putting -Xprint:typer in scalacOptions to see which package is the issue. It seems to work for me when I ignore the following
wartremoverExcluded ++= Seq("Routes", "controllers.ref")
It looks like this question was asked in the context of wartremover 0.11, but if anyone finds themselves here looking for a solution for 0.12, this works for me:
wartremoverExcluded += sourceManaged.value / "main" / "routes_reverseRouting.scala"
wartremoverExcluded += sourceManaged.value / "main" / "routes_routing.scala"
In play framework (2.2.1 & sbt 0.13) I have an IntegrationSpec that brings up a TestServer. I need to be able to set SSL specific System Properties for the TestServer. So far the only way I have been able to set it up correctly is passing them as command line properties like below
play -Djavax.net.ssl.keyStore=... -Djavax.net.ssl.keyStorePassword=.... -D... test
I want the tests to run simply using play test. For that in Build.scala I configured SBT javaOptions as follows
val main = play.Project(appName, appVersion, appDependencies).settings(
Keys.fork in Test := false,
javaOptions in Test += "-Dconfig.file=conf/application.test.conf")
And in application.test.conf I set all the system properties. With this the TestServer is not even using application.test.conf. I was not able to figure out why. So I thought I will try the following:
play -Dconfig.file=conf/application.test.conf test
The TestServer did use application.test.conf but none of the system properties (javax.net.ssl.keyStore="..." etc.) configured in the file were being used.
So I have two questions
How to have this running only using play test? . (I do not want to pass a long Map of properties to FakeApplication in TestServer).
When I run play -Dconfig.file=conf/application.test.conf test, why are the system properties configured in application.test.conf not being used?
I'm not sure if this works for setting a property for reading the configuration file, but you can set your individual properties with System.setProperty like this:
System.setProperty("application.secret","psssst!")