Skip to content
This repository has been archived by the owner on Apr 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #161 from zalando/#158_outdated_readme
Browse files Browse the repository at this point in the history
#158 outdated readme
  • Loading branch information
slavaschmidt committed May 28, 2016
2 parents 647600c + d7c6c8f commit 08291df
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 25 deletions.
2 changes: 2 additions & 0 deletions MANTAINERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Slava Schmidt <slavaschmidt@gmx.de>
Marco Borst <marco@splatter.nl>
52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The template project contains following:
* `generated_controllers/example.yaml.scala` - a dummy implementation of the example controller. Will be (re)generated if deleted
* `security/example.yaml.scala` - a marshaller for OAuth2 tokens. Will not be regenerated until
a) deleted or renamed
b) explicitly requested by issuing a `swaggerSecurity` command
b) explicitly requested by issuing a `apiFirstSecurity` command


## Welcome to Play-Swagger
Expand Down Expand Up @@ -86,7 +86,7 @@ Manual generation and compilation of:
is supported in the case if

a) No security extractor or unmarshaller with the same name already exists
b) The developer issues `swaggerSecurity` or `swaggerMarshallers` sbt command
b) The developer issues `apiFirstSecurity` or `apiFirstMarshallers` sbt command

## Run Your Application

Expand Down Expand Up @@ -1006,18 +1006,6 @@ To use the plugin in a plain Play project:
- Add a specification link (`->`) to the play's routes file


## Plugin Project Structure

There are a couple of sub-projects:

* `swagger-model` - A standalone Scala Swagger model and a Jackson parser for it. Can be used by another projects
* `api` - This is the project that's automatically added to the runtime classpath of any projects that use this plugin.
* `compiler` - This is a stand-alone compiler that the plugin uses. It doesn't depend on sbt, and could theoretically
be used to build support for other build systems.
* `plugin` - This is the sbt plugin. It depends on `swagger-model`, `compiler`, and automatically adds `api` to the `libraryDependencies`
of any project that uses it.


## Plugin Architecture

Ths Play-Swagger plugin has a three-tier architecture:
Expand All @@ -1030,6 +1018,32 @@ The separation of the specification and generation tiers allows for plugging in
and generating source code for different frameworks.


## Plugin Project Structure

There are a couple of sub-projects:

* `swagger-model` - A standalone Scala Swagger model and a Jackson parser for it. Can be used by another projects
* `api` - This is the project that's automatically added to the runtime classpath of any projects that use this plugin.
* `swagger-parser` - A converter of the Swagger model to the internal AST of the plugin
* `api-first-core` - This is a core of the plugin with minimal functionality. It includes defining an AST structure and some transformations on AST.
* `play-scala-generator` - The standalone generator for transforming an AST into the skeleton of Play-Scala application.
* `plugin` - A coupble of sbt plugins, one for each tier:
- `ApiFirstSwaggerParser` - a plugin wrapping Swagger parsing part
- `ApiFirstCore` - a wrapper for AST-related functionality
- `ApiFirstPlayScalaCodeGenerator` - a wrapper for the Play-Scala generator

Because of the modular plugin architecture, all modules must be enabled separatly in sbt's build.sbt.
It is also necessary to configure which parser(s) must be used by the plugin, like that:

```scala
lazy val root = (project in file(".")).enablePlugins(PlayScala, ApiFirstCore, ApiFirstPlayScalaCodeGenerator, ApiFirstSwaggerParser)
apiFirstParsers := Seq(ApiFirstSwaggerParser.swaggerSpec2Ast.value).flatten
```

Please take a look at activator template's configuration for complete example.


## Plugin Developing

sbt doesn't allow sub-projects to depend on each other as sbt plugins. To test an sbt plugin, you need a separate
Expand All @@ -1039,11 +1053,11 @@ directory, and run sbt. This project uses an sbt `ProjectRef` to the sbt plugin,

The play-swagger plugin provides a couple of commands useful for development:

* `swaggerPrintDenotations` - outputs a common names of different parts of the AST as they are intended to be used in generated Scala code
* `swaggerPrintRawAstTypes` - outputs all type definitions as they read from the specification before type optimisations
* `swaggerPrintRawAstParameters` - outputs all parameters definitions before type optimisations
* `swaggerPrintFlatAstTypes` - outputs type definitions after type optimisations
* `swaggerPrintFlatAstParameters` - outputs parameter definitions after type optimisations
* `apiFirstPrintDenotations` - outputs a common names of different parts of the AST as they are intended to be used in generated Scala code
* `apiFirstPrintRawAstTypes` - outputs all type definitions as they read from the specification before type optimisations
* `apiFirstPrintRawAstParameters` - outputs all parameters definitions before type optimisations
* `apiFirstPrintFlatAstTypes` - outputs type definitions after type optimisations
* `apiFirstPrintFlatAstParameters` - outputs parameter definitions after type optimisations


## Plugin Testing
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ lazy val swaggerModel = (project in file("swagger-model"))
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.4.4",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.6.1",
"me.andrz.jackson" % "jackson-json-reference-core" % "0.2.1",
"org.scalatest" %% "scalatest" % "2.2.3" % "test"
"org.scalatest" %% "scalatest" % "2.2.6" % "test"
)
)

Expand Down Expand Up @@ -79,7 +79,7 @@ lazy val swaggerParser = (project in file("swagger-parser"))
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.4.4",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.6.1",
"me.andrz.jackson" % "jackson-json-reference-core" % "0.2.1",
"org.scalatest" %% "scalatest" % "2.2.3" % "test"
"org.scalatest" %% "scalatest" % "2.2.6" % "test"
)
)
.dependsOn(swaggerModel, apiFirstCore)
Expand All @@ -101,7 +101,7 @@ lazy val playScalaGenerator = (project in file("play-scala-generator"))
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-library" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalatest" %% "scalatest" % "2.2.3" % "test",
"org.scalatest" %% "scalatest" % "2.2.6" % "test",
"org.scalacheck" %% "scalacheck" % "1.12.5" % "test",
"de.zalando" %% "beard" % "0.0.6"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object ApiFirstCore extends AutoPlugin {

lazy val apiFirstPreparedData = taskKey[Seq[StrictModelWithFile]]("Pairs compilation tasks with models to prepare them for code generation")

lazy val specificationASTs = taskKey[Seq[StrictModelWithFile]]("Specifications converted to ASTs")
lazy val apiFirstParsers = taskKey[Seq[StrictModelWithFile]]("Specifications converted to ASTs")

lazy val apiFirstFlattenAst = taskKey[Seq[StrictModelWithFile]]("Prepares AST by removing duplicate types and flattening it")

Expand Down Expand Up @@ -57,7 +57,7 @@ object ApiFirstCore extends AutoPlugin {

sourcePositionMappers := Seq(),

apiFirstRawData := specificationASTs.value,
apiFirstRawData := apiFirstParsers.value,

apiFirstPreparedData := apiFirstRawData.value map { case (file, model) => (file, AstNormaliser.flattenAST(model)) },

Expand Down
2 changes: 1 addition & 1 deletion plugin/src/sbt-test/swagger/compile/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ libraryDependencies ++= Seq(
"me.jeffmay" %% "play-json-tests" % "1.3.0" % "test"
)

specificationASTs := Seq(ApiFirstSwaggerParser.swaggerSpec2Ast.value).flatten
apiFirstParsers := Seq(ApiFirstSwaggerParser.swaggerSpec2Ast.value).flatten

0 comments on commit 08291df

Please sign in to comment.