Skip to content
Swagger client generator which is based on the PlayWS library
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Change URL to Play documentation instead of OpenShift documentation f… Aug 14, 2016
clientstub Fix config and add description Oct 18, 2017
codegen Remove the Play version from config Feb 27, 2018
conf Remove the Play version from config Feb 27, 2018
project
scripts Update to Play 2.6 (#11) Oct 16, 2017
.coveralls.yml Play 2.5 support Jun 8, 2016
.gitignore Initial commit Feb 23, 2016
.scalariform.conf Update to Play 2.6 (#11) Oct 16, 2017
.travis.yml
CONTRIBUTING.md Change URL to Play documentation instead of OpenShift documentation f… Aug 14, 2016
LICENSE
README.md Correct the swagger cli version in response to the project dep changes ( Jul 24, 2018
build.sbt Update to Play 2.6 (#11) Oct 16, 2017

README.md

Swagger Codegen - Play Scala Build Status Coverage Status Join the chat at https://gitter.im/mohiva/swagger-codegen-play-scala

A code generator for Swagger which generates API clients with the help of the PlayWS library. This code generator is based on the akka-scala generator included in the Swagger Codegen distribution.

Versions

Project Play
0.1.x 2.4
0.2.x 2.5
master 2.6

Create client

Download swagger codegen executable into the root directory of this project:

wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.3.0/swagger-codegen-cli-2.3.0.jar -O swagger-codegen-cli.jar

Execute the script

scripts/codegen.sh -i ${SWAGGER_SPEC_FILE} -o ${SWAGGER_CLIENT_DIR} -c ${SWAGGER_CONF_FILE}

To run the bundled petstore example:

scripts/codegen.sh -i conf/petstore.yaml -o build -c conf/config.json

Compile the client:

cd build
sbt compile

Config options:

The code generator supports the following config options:

Name Description
modelPackage The package for generated model classes
apiPackage The package for generated api classes
invokerPackage The package for generated root classes
configKeyPath Path under which the config must be defined
projectOrganization Project organization in generated build.sbt
projectName Project name in generated build.sbt
projectVersion Project version in generated build.sbt
scalaVersion The Scala version to use in generated build.sbt

How to use

To use the client you must inject a corresponding API handler into your controller or service. Every API handler itself has a dependency to the ApiInvoker which must be instantiated with the global configuration and an instance of the WSClient. It's the best to wire this dependencies with your preferred DI method.

Every method created for you API handler accepts, additional to the parameters created from the Swagger spec, an optional request config which can be used to override the global config.

Global config

Property Description
url The optional API URL. If this URL is defined then it has precedence over the URL defined in the Swagger spec.
requestTimeout The request timeout. Defaults to 20 seconds.

Request config

Property Description
url The optional API URL. If this URL is defined then it has precedence over the URL defined in the Swagger spec and the global config.
timeout The request timeout. Defaults to None, which means the global config has precedence.

WS Client config

The underlying WSClient can also be configured in your Play configuration.

You can’t perform that action at this time.