mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 19:33:55 +00:00
commit
24268661af
@ -1,3 +0,0 @@
|
||||
language: scala
|
||||
scala:
|
||||
- 2.10.0
|
11
LICENSE
11
LICENSE
@ -1,11 +0,0 @@
|
||||
Copyright 2014 Reverb Technologies, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
246
README.md
246
README.md
@ -1,246 +0,0 @@
|
||||
# Swagger Code Generator
|
||||
|
||||
[![Build Status](https://travis-ci.org/wordnik/swagger-codegen.png)](https://travis-ci.org/wordnik/swagger-codegen)
|
||||
|
||||
## Overview
|
||||
This is the swagger codegen project, which allows generation of client libraries automatically from a
|
||||
Swagger-compliant server.
|
||||
|
||||
## What's Swagger?
|
||||
|
||||
The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swager removes the guesswork in calling the service.
|
||||
|
||||
|
||||
Check out [Swagger-Spec](https://github.com/wordnik/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
||||
|
||||
|
||||
### Prerequisites
|
||||
You need the following installed and available in your $PATH:
|
||||
|
||||
* [Java 1.7](http://java.oracle.com)
|
||||
|
||||
Note! Some folks have had issues with OOM errors with java version "1.6.0_51". It's strongly suggested that you upgrade to 1.7!
|
||||
|
||||
* [Apache maven 3.0.3 or greater](http://maven.apache.org/)
|
||||
|
||||
* [Scala 2.9.1](http://www.scala-lang.org)
|
||||
|
||||
* [sbt (only download if you're building on Windows)](http://www.scala-sbt.org/)
|
||||
|
||||
You also need to add the scala binary to your PATH.
|
||||
|
||||
After cloning the project, you need to build it from source with this command:
|
||||
|
||||
```
|
||||
./sbt assembly
|
||||
```
|
||||
|
||||
or for Windows...
|
||||
|
||||
```
|
||||
sbt assembly
|
||||
```
|
||||
|
||||
|
||||
### To generate a sample client library
|
||||
You can build a client against Wordnik's [petstore](http://petstore.swagger.wordnik.com) API as follows:
|
||||
|
||||
```
|
||||
./bin/scala-petstore.sh
|
||||
```
|
||||
|
||||
This will run the script in [samples/client/petstore/ScalaPetstoreCodegen.scala](https://github.com/wordnik/swagger-codegen/blob/master/samples/client/petstore/scala/ScalaPetstoreCodegen.scala) and create the client. You can then
|
||||
compile and run the client, as well as unit tests against it:
|
||||
|
||||
```
|
||||
cd samples/client/petstore/scala
|
||||
mvn package
|
||||
```
|
||||
|
||||
Other languages have petstore samples, too:
|
||||
```
|
||||
./bin/flash-petstore.sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/objc-petstore.sh
|
||||
./bin/php-petstore.sh
|
||||
./bin/python-petstore.sh
|
||||
./bin/python3-petstore.sh
|
||||
./bin/ruby-petstore.sh
|
||||
```
|
||||
|
||||
### Generating libraries from your server
|
||||
It's just as easy--you can either run the default generators:
|
||||
|
||||
```
|
||||
./bin/runscala.sh com.wordnik.swagger.codegen.BasicScalaGenerator http://petstore.swagger.wordnik.com/api/api-docs special-key
|
||||
```
|
||||
|
||||
Replace `Scala` with `Flash`, `Java`, `Objc`, `PHP`, `Python`, `Python3`, `Ruby`.
|
||||
|
||||
You will probably want to override some of the defaults--like packages, etc. For doing this, just create a scala
|
||||
script with the overrides you want. Follow [ScalaPetstoreCodegen](https://github.com/wordnik/swagger-codegen/blob/master/samples/client/petstore/scala/ScalaPetstoreCodegen.scala) as an example:
|
||||
|
||||
For example, create `src/main/scala/MyCodegen.scala` with these contents:
|
||||
|
||||
```scala
|
||||
import com.wordnik.swagger.codegen.BasicScalaGenerator
|
||||
|
||||
object MyCodegen extends BasicScalaGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "scala"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "client/scala/src/main/scala"
|
||||
|
||||
// api invoker package
|
||||
override def invokerPackage = "com.myapi.client"
|
||||
|
||||
// package for models
|
||||
override def modelPackage = Some("com.myapi.client.model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage = Some("com.myapi.client.api")
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("apiInvoker.mustache", destinationDir + java.io.File.separator + packageName.replaceAll("\\.", java.io.File.separator), "ApiInvoker.scala"),
|
||||
("pom.mustache", destinationDir, "pom.xml")
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
Now you can generate your client like this:
|
||||
|
||||
```
|
||||
./bin/runscala.sh src/main/scala/MyCodegen.scala http://my.api.com/resources.json super-secret-key
|
||||
```
|
||||
|
||||
w00t! Thanks to the scala interpretor, you didn't even need to recompile.
|
||||
|
||||
### Modifying the client library format
|
||||
Don't like the default swagger client syntax? Want a different language supported? No problem! Swagger codegen
|
||||
processes mustache templates with the [scalate](http://scalate.fusesource.org/) engine. You can modify our templates or
|
||||
make your own.
|
||||
|
||||
You can look at `src/main/resources/${your-language}` for examples. To make your own templates, create your own files
|
||||
and override the `templateDir` in your script to point to the right place. It actually is that easy.
|
||||
|
||||
### Where is Javascript???
|
||||
See our [javascript library](http://github.com/wordnik/swagger.js)--it's completely dynamic and doesn't require
|
||||
static code generation.
|
||||
There is a third-party component called [swagger-js-codegen](https://github.com/wcandillon/swagger-js-codegen) that can generate angularjs or nodejs source code from a swagger specification.
|
||||
|
||||
|
||||
#### Generating a client from flat files (i.e. no remote server calls)
|
||||
If you don't want to call your server, you can save the swagger spec files into a directory and pass an argument
|
||||
to the code generator like this:
|
||||
|
||||
```
|
||||
-DfileMap=/path/to/resource-listing
|
||||
```
|
||||
|
||||
Or for example:
|
||||
```
|
||||
./bin/java-petstore-filemap.sh
|
||||
```
|
||||
|
||||
Which simple passes `-DfileMap=src/test/resources/petstore` as an argument. Great for creating libraries on your
|
||||
ci server... or while coding on an airplane.
|
||||
|
||||
### Validating your swagger spec
|
||||
You can use the validation tool to see that your server is creating a proper spec file. If you want to learn
|
||||
more about the spec file and format, please see [swagger-core](https://github.com/wordnik/swagger-core/wiki). This
|
||||
tool will read the server and generate a report of any violations of the spec. If there are violations, the
|
||||
client codegen and ui may not work correctly.
|
||||
|
||||
To validate an api and write output to ./swagger-errors.html:
|
||||
|
||||
```
|
||||
./bin/validate.sh http://petstore.swagger.wordnik.com/api/api-docs "specia-key" ./swagger-errors.html
|
||||
```
|
||||
|
||||
### Generating static api documentation
|
||||
If you need to make static pages or don't want the sandbox of the swagger-ui, you can use the codegen to build them. Remember, the engine is just using mustache templates--the output format is your call.
|
||||
|
||||
```
|
||||
./bin/static-docs.sh
|
||||
```
|
||||
|
||||
Will produce the output here:
|
||||
|
||||
```
|
||||
https://github.com/wordnik/swagger-codegen/tree/master/samples/docs/swagger-static-docs
|
||||
```
|
||||
|
||||
which is based on these templates:
|
||||
|
||||
```
|
||||
https://github.com/wordnik/swagger-codegen/tree/master/src/main/resources/swagger-static
|
||||
```
|
||||
|
||||
and looks like this
|
||||
|
||||
![Image](https://raw.github.com/wordnik/swagger-codegen/master/samples/docs/swagger-static-docs/static-docs.png)
|
||||
|
||||
### To build a server stub
|
||||
|
||||
You can also use the codegen to generate a server for a couple different frameworks. Take a look here:
|
||||
|
||||
* [javascript node.js Server generator](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/node)
|
||||
|
||||
* [ruby sinatra generator](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/sinatra)
|
||||
|
||||
* [scala scalatra generator](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/scalatra)
|
||||
|
||||
* [java jax-rs generator](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/java-jaxrs)
|
||||
|
||||
|
||||
### Migrating from Swagger 1.1 to 1.2 format
|
||||
|
||||
If you've spent time hand-crafting your swagger spec files, you can use the [SpecConverter](https://github.com/wordnik/swagger-codegen/blob/master/src/main/scala/com/wordnik/swagger/codegen/SpecConverter.scala) to do the dirty work. For example:
|
||||
|
||||
```bash
|
||||
$ ./bin/update-spec.sh http://developer.wordnik.com/v4/resources.json wordnik-developer
|
||||
writing file wordnik-developer/api-docs
|
||||
calling: http://developer.wordnik.com/v4/account.json
|
||||
calling: http://developer.wordnik.com/v4/word.json
|
||||
calling: http://developer.wordnik.com/v4/words.json
|
||||
calling: http://developer.wordnik.com/v4/wordList.json
|
||||
calling: http://developer.wordnik.com/v4/wordLists.json
|
||||
writing file wordnik-developer/account
|
||||
writing file wordnik-developer/word
|
||||
writing file wordnik-developer/words
|
||||
writing file wordnik-developer/wordList
|
||||
writing file wordnik-developer/wordLists
|
||||
```
|
||||
|
||||
Will read the 1.1 spec from wordnik developer and write it into the folder called `wordnik-developer`.
|
||||
|
||||
|
||||
### To build the codegen library
|
||||
|
||||
This will create the swagger-codegen library from source.
|
||||
|
||||
```
|
||||
./sbt assembly
|
||||
```
|
||||
|
||||
Note! The templates are included in the library generated. If you want to modify the templates, you'll need to
|
||||
either repackage the library OR modify your codegen script to use a file path!
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Copyright 2014 Wordnik, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@ -1,8 +0,0 @@
|
||||
val version = scala.util.Properties.scalaPropOrElse("version.number", "unknown").toString match {
|
||||
case "2.10.0" => "2.10"
|
||||
case "2.10.2" => "2.10"
|
||||
case "2.10.3" => "2.10"
|
||||
case "2.10.4" => "2.10"
|
||||
case e: String => e
|
||||
}
|
||||
println(version)
|
@ -1,37 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
./bin/java-wordnik-api.sh
|
||||
./bin/php-wordnik-api.sh
|
||||
./bin/python3-wordnik-api.sh
|
||||
./bin/objc-wordnik-api.sh
|
||||
./bin/python-wordnik-api.sh
|
||||
./bin/scala-wordnik-api.sh
|
||||
|
||||
./bin/android-java-petstore.sh
|
||||
./bin/csharp-petstore.sh
|
||||
./bin/flash-petstore.sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/objc-petstore.sh
|
||||
./bin/php-petstore.sh
|
||||
./bin/python-petstore.sh
|
||||
./bin/python3-petstore.sh
|
||||
./bin/ruby-petstore.sh
|
||||
./bin/scala-petstore.sh
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/csharp/CsharpPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties "
|
||||
ags="$@ samples/client/petstore/flash/FlashPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DfileMap=src/test/resources/petstore-1.2/api-docs -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/java/JavaPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/java/JavaPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files/resources.json"
|
||||
ags="$@ samples/client/wordnik-api/java/JavaWordnikApiCodegen.scala http://api.wordnik.com/v4/resources.json"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,34 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
version="$(scala ./bin/Version.scala)"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/objc/ObjcPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files/resources.json"
|
||||
ags="$@ samples/client/wordnik-api/objc/ObjcWordnikApiCodegen.scala http://api.wordnik.com/v4/resources.json"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/php/PHPPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files/resources.json"
|
||||
ags="$@ samples/client/wordnik-api/php/PHPWordnikApiCodegen.scala http://api.wordnik.com/v4/resources.json"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/python/PythonPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files/resources.json"
|
||||
ags="$@ samples/client/wordnik-api/python/PythonWordnikApiCodegen.scala http://api.wordnik.com/v4/resources.json"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/python3/Python3PetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files/resources.json"
|
||||
ags="$@ samples/client/wordnik-api/python3/Python3WordnikApiCodegen.scala http://api.wordnik.com/v4/resources.json"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/ruby/RubyPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,31 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=2.10 #$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
ags="com.wordnik.swagger.codegen.ScalaAsyncClientGenerator $@"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
java -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/scala/ScalaPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files/resources.json"
|
||||
ags="$@ samples/client/wordnik-api/scala/ScalaWordnikApiCodegen.scala http://api.wordnik.com/v4/resources.json"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,32 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties "
|
||||
ags="$@ com.wordnik.swagger.codegen.SwaggerDocGenerator http://petstore.swagger.wordnik.com/api/api-docs"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,31 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
ags="com.wordnik.swagger.codegen.SpecConverter $@"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,31 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
ags="com.wordnik.swagger.codegen.spec.Validator $@"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar ]; then
|
||||
scala -cp target/scala-$SCALA_RUNNER_VERSION/*assembly*.jar $ags
|
||||
else
|
||||
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
|
||||
fi
|
@ -1,56 +0,0 @@
|
||||
fs = require('fs')
|
||||
yaml = require('js-yaml')
|
||||
|
||||
var args = process.argv.splice(2);
|
||||
|
||||
if(args.length == 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var arg0 = args[0];
|
||||
var outputdir = ".";
|
||||
|
||||
if(args.length > 1) {
|
||||
outputdir = args[1];
|
||||
}
|
||||
|
||||
var file = fs.lstatSync(arg0);
|
||||
|
||||
if(file.isFile()) {
|
||||
convert(arg0, outputdir);
|
||||
}
|
||||
else if (file.isDirectory()) {
|
||||
var files = fs.readdirSync(arg0);
|
||||
files.map(function(item) {
|
||||
var filename = arg0 + "/" + item;
|
||||
var file = fs.lstatSync(filename);
|
||||
if(file.isFile()) {
|
||||
convert(filename, outputdir);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function convert(filename, outputdir) {
|
||||
console.log("converting " + filename);
|
||||
fs.readFile(filename, "utf8", function (err, data) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
var js = yaml.load(data);
|
||||
var prettyJs = JSON.stringify(js, undefined, 2);
|
||||
var outputFilename = outputdir + "/" + filename.split("/").pop().replace(".yml", "") + ".json";
|
||||
console.log("writing to " + outputFilename);
|
||||
fs.writeFile(outputFilename, prettyJs, function(err) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
136
build.sbt
136
build.sbt
@ -1,136 +0,0 @@
|
||||
import xml.Group
|
||||
import AssemblyKeys._
|
||||
|
||||
organization := "com.wordnik"
|
||||
|
||||
name := "swagger-codegen"
|
||||
|
||||
version := "2.0.18-SNAPSHOT"
|
||||
|
||||
crossVersion := CrossVersion.full
|
||||
|
||||
javacOptions ++= Seq("-target", "1.6", "-source", "1.6", "-Xlint:unchecked", "-Xlint:deprecation")
|
||||
|
||||
scalacOptions ++= Seq("-optimize", "-unchecked", "-deprecation", "-Xcheckinit", "-encoding", "utf8")
|
||||
|
||||
crossScalaVersions := Seq("2.10.0", "2.10.1", "2.10.2", "2.10.3", "2.10.4", "2.11.0", "2.11.1")
|
||||
|
||||
scalaVersion := "2.10.4"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"org.json4s" %% "json4s-jackson" % "3.2.10",
|
||||
"io.backchat.inflector" %% "scala-inflector" % "1.3.5",
|
||||
"commons-io" % "commons-io" % "2.3",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
|
||||
"org.rogach" %% "scallop" % "0.9.5",
|
||||
"junit" % "junit" % "4.11" % "test",
|
||||
"org.scalatest" %% "scalatest" % "2.1.7" % "test"
|
||||
)
|
||||
|
||||
libraryDependencies <+= scalaVersion {
|
||||
case v if v.startsWith("2.9") =>
|
||||
"org.fusesource.scalate" % "scalate-core_2.9" % "1.6.1"
|
||||
case v if v.startsWith("2.10") =>
|
||||
"org.scalatra.scalate" %% "scalate-core" % "1.7.0"
|
||||
case v if v.startsWith("2.11") =>
|
||||
"org.scalatra.scalate" %% "scalate-core" % "1.7.0"
|
||||
}
|
||||
|
||||
libraryDependencies ++= {
|
||||
scalaVersion.toString match {
|
||||
case v if v.startsWith("2.10") || v.startsWith("2.11") => Seq("org.scala-lang" % "scala-reflect" % v)
|
||||
case _ => Seq()
|
||||
}
|
||||
}
|
||||
|
||||
resolvers += "Typesafe releases" at "http://repo.typesafe.com/typesafe/releases"
|
||||
|
||||
packageOptions <+= (name, version, organization) map {
|
||||
(title, version, vendor) =>
|
||||
Package.ManifestAttributes(
|
||||
"Created-By" -> "Simple Build Tool",
|
||||
"Built-By" -> System.getProperty("user.name"),
|
||||
"Build-Jdk" -> System.getProperty("java.version"),
|
||||
"Specification-Title" -> title,
|
||||
"Specification-Version" -> version,
|
||||
"Specification-Vendor" -> vendor,
|
||||
"Implementation-Title" -> title,
|
||||
"Implementation-Version" -> version,
|
||||
"Implementation-Vendor-Id" -> vendor,
|
||||
"Implementation-Vendor" -> vendor
|
||||
)
|
||||
}
|
||||
|
||||
publishTo <<= (version) { version: String =>
|
||||
if (version.trim.endsWith("SNAPSHOT"))
|
||||
Some("Sonatype Nexus Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots")
|
||||
else
|
||||
Some("Sonatype Nexus Releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
|
||||
}
|
||||
|
||||
// publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
|
||||
|
||||
artifact in (Compile, assembly) ~= { art =>
|
||||
art.copy(`classifier` = Some("assembly"))
|
||||
}
|
||||
|
||||
addArtifact(artifact in (Compile, assembly), assembly)
|
||||
|
||||
publishMavenStyle := true
|
||||
|
||||
publishArtifact in Test := false
|
||||
|
||||
pomIncludeRepository := { x => false }
|
||||
|
||||
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
|
||||
|
||||
homepage := Some(new URL("https://github.com/wordnik/swagger-codegen"))
|
||||
|
||||
parallelExecution in Test := false
|
||||
|
||||
startYear := Some(2009)
|
||||
|
||||
licenses := Seq(("Apache License 2.0", new URL("http://www.apache.org/licenses/LICENSE-2.0.html")))
|
||||
|
||||
pomExtra <<= (pomExtra, name, description) {(pom, name, desc) => pom ++ Group(
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:wordnik/swagger-codegen.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:wordnik/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/wordnik/swagger-codegen</url>
|
||||
</scm>
|
||||
<issueManagement>
|
||||
<system>github</system>
|
||||
<url>https://github.com/wordnik/swagger-codegen/issues</url>
|
||||
</issueManagement>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>rpidikiti</id>
|
||||
<name>Ramesh Pidikiti</name>
|
||||
<email>ramesh@wordnik.com</email>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>ayush</id>
|
||||
<name>Ayush Gupta</name>
|
||||
<email>ayush@glugbot.com</email>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>fehguy</id>
|
||||
<name>Tony Tam</name>
|
||||
<email>fehguy@gmail.com</email>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>casualjim</id>
|
||||
<name>Ivan Porto Carrero</name>
|
||||
<url>http://flanders.co.nz/</url>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>radius314</id>
|
||||
<name>Danny Gershman</name>
|
||||
<email>danny.gershman@gmail.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
)}
|
||||
|
||||
assemblySettings
|
||||
|
||||
// jarName in assembly := "swagger-codegen.jar"
|
@ -1,124 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>5</version>
|
||||
</parent>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen-distribution</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<name>swagger-codegen-distribution</name>
|
||||
<url>https://github.com/wordnik/swagger-codegen</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:wordnik/swagger-codegen.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:wordnik/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/wordnik/swagger-codegen</url>
|
||||
</scm>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>fehguy</id>
|
||||
<name>Tony Tam</name>
|
||||
<email>fehguy@gmail.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
<issueManagement>
|
||||
<system>github</system>
|
||||
<url>https://github.com/wordnik/swagger-codegen/issues</url>
|
||||
</issueManagement>
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>wordnik-api</name>
|
||||
<archive>https://groups.google.com/forum/#!forum/wordnik-api</archive>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>distro-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/distribution.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>src-dependencies</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>unpack-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<includeGroupIds>com.wordnik</includeGroupIds>
|
||||
<includeArtifactIds>text-data</includeArtifactIds>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen_2.9.1</artifactId>
|
||||
<version>${swagger.codegen.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger.codegen.version>2.0.2-SNAPSHOT</swagger.codegen.version>
|
||||
</properties>
|
||||
</project>
|
@ -1,29 +0,0 @@
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<id>distribution</id>
|
||||
<baseDirectory>swagger-codegen</baseDirectory>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<scope>compile</scope>
|
||||
<outputDirectory>target/lib</outputDirectory>
|
||||
<includes>
|
||||
<include>*:jar:*</include>
|
||||
</includes>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>../bin</directory>
|
||||
<includes>
|
||||
<include>*.*</include>
|
||||
</includes>
|
||||
<outputDirectory>bin</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
16
package.json
16
package.json
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "swagger-yaml",
|
||||
"version": "2.0.1",
|
||||
"description": "Converts yaml to swagger json",
|
||||
"author": {
|
||||
"name": "Tony Tam",
|
||||
"email": "fehguy@gmail.com",
|
||||
"url": "http://developer.wordnik.com"
|
||||
},
|
||||
"license": "Apache",
|
||||
"readmeFilename": "README.md",
|
||||
"dependencies": {
|
||||
"json2yaml": "~1.0",
|
||||
"js-yaml": "~3.0"
|
||||
}
|
||||
}
|
428
pom.xml
Normal file
428
pom.xml
Normal file
@ -0,0 +1,428 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>wordnik-swagger-codegen</name>
|
||||
<version>2.1.0-SNAPSHOT</version>
|
||||
<url>https://github.com/wordnik/swagger-codegen</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:wordnik/swagger-codegen.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:wordnik/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/wordnik/swagger-codegen</url>
|
||||
</scm>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>fehguy</id>
|
||||
<name>Tony Tam</name>
|
||||
<email>fehguy@gmail.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
<issueManagement>
|
||||
<system>github</system>
|
||||
<url>https://github.com/wordnik/swagger-codegen/issues</url>
|
||||
</issueManagement>
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>swagger-swaggersocket</name>
|
||||
<archive>https://groups.google.com/forum/#!forum/swagger-swaggersocket</archive>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<build>
|
||||
<testSourceDirectory>src/test/scala</testSourceDirectory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.jvnet.wagon-svn</groupId>
|
||||
<artifactId>wagon-svn</artifactId>
|
||||
<version>1.8</version>
|
||||
</extension>
|
||||
<extension>
|
||||
<groupId>org.apache.maven.wagon</groupId>
|
||||
<artifactId>wagon-ssh-external</artifactId>
|
||||
<version>1.0-alpha-6</version>
|
||||
</extension>
|
||||
<extension>
|
||||
<groupId>org.apache.maven.wagon</groupId>
|
||||
<artifactId>wagon-webdav</artifactId>
|
||||
<version>1.0-beta-1</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<directory>target</directory>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
<goal>compile</goal>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<configuration>
|
||||
<recompileMode>incremental</recompileMode>
|
||||
</configuration>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx384m</jvmArg>
|
||||
</jvmArgs>
|
||||
<args>
|
||||
<arg>-target:jvm-1.6</arg>
|
||||
<arg>-deprecation</arg>
|
||||
</args>
|
||||
<launchers>
|
||||
<launcher>
|
||||
<id>run-scalatest</id>
|
||||
<mainClass>org.scalatest.tools.Runner</mainClass>
|
||||
<args>
|
||||
<arg>-p</arg>
|
||||
<arg>${project.build.testOutputDirectory}</arg>
|
||||
</args>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx512m</jvmArg>
|
||||
</jvmArgs>
|
||||
</launcher>
|
||||
</launchers>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<source>1.6</source>
|
||||
<encoding>UTF-8</encoding>
|
||||
<maxmemory>1g</maxmemory>
|
||||
<links>
|
||||
<link>http://java.sun.com/javase/6/docs/api/</link>
|
||||
</links>
|
||||
<excludePackageNames>${javadoc.package.exclude}</excludePackageNames>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.0</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<mode>development</mode>
|
||||
<url>${project.url}</url>
|
||||
<implementation-version>${project.version}</implementation-version>
|
||||
<package>com.wordnik</package>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<configuration>
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
<goals>sign</goals>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-servlet</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release-profile</id>
|
||||
<properties>
|
||||
<skipTests>true</skipTests>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration />
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/main/scala</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>release-sign-artifacts</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>performRelease</name>
|
||||
<value>true</value>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
<reporting>
|
||||
<outputDirectory>target/site</outputDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<debug>true</debug>
|
||||
<links>
|
||||
<link>http://java.sun.com/javaee/5/docs/api</link>
|
||||
<link>http://java.sun.com/j2se/1.5.0/docs/api</link>
|
||||
</links>
|
||||
<excludePackageNames />
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jxr-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<reportSets>
|
||||
<reportSet>
|
||||
<reports>
|
||||
<report>project-team</report>
|
||||
</reports>
|
||||
</reportSet>
|
||||
</reportSets>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>swagger-core</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.samskivert</groupId>
|
||||
<artifactId>jmustache</artifactId>
|
||||
<version>${jmustache-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-tools-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>${felix-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-ext</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>${commons-lang-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>${commons-cli-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.11</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>2.3.4</felix-version>
|
||||
<swagger-core-version>1.5.0-SNAPSHOT</swagger-core-version>
|
||||
<scala-test-version>2.1.4</scala-test-version>
|
||||
<commons-io-version>2.3</commons-io-version>
|
||||
<commons-cli-version>1.2</commons-cli-version>
|
||||
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<commons-lang-version>2.4</commons-lang-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
|
||||
<jmustache-version>1.9</jmustache-version>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
@ -1 +0,0 @@
|
||||
sbt.version=0.13.0
|
@ -1,5 +0,0 @@
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.2")
|
||||
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.1")
|
||||
|
||||
resolvers += "Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases"
|
518
sbt
518
sbt
@ -1,518 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# A more capable sbt runner, coincidentally also called sbt.
|
||||
# Author: Paul Phillips <paulp@typesafe.com>
|
||||
|
||||
# todo - make this dynamic
|
||||
declare -r sbt_release_version=0.12.4
|
||||
declare -r sbt_beta_version=0.13.0-RC4
|
||||
declare -r sbt_snapshot_version=0.13.0-SNAPSHOT
|
||||
|
||||
declare sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
|
||||
declare scala_version java_home sbt_explicit_version
|
||||
declare verbose debug quiet noshare batch trace_level log_level
|
||||
declare sbt_saved_stty
|
||||
|
||||
echoerr () { [[ -z $quiet ]] && echo "$@" >&2; }
|
||||
vlog () { [[ -n "$verbose$debug" ]] && echoerr "$@"; }
|
||||
dlog () { [[ -n $debug ]] && echoerr "$@"; }
|
||||
|
||||
# we'd like these set before we get around to properly processing arguments
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
-q|-quiet) quiet=true ;;
|
||||
-d|-debug) debug=true ;;
|
||||
-v|-verbose) verbose=true ;;
|
||||
*) ;;
|
||||
esac
|
||||
done
|
||||
|
||||
build_props_sbt () {
|
||||
if [[ -r project/build.properties ]]; then
|
||||
versionLine=$(grep ^sbt.version project/build.properties | tr -d '\r')
|
||||
versionString=${versionLine##sbt.version=}
|
||||
echo "$versionString"
|
||||
fi
|
||||
}
|
||||
|
||||
update_build_props_sbt () {
|
||||
local ver="$1"
|
||||
local old=$(build_props_sbt)
|
||||
|
||||
if [[ $ver == $old ]]; then
|
||||
return
|
||||
elif [[ -r project/build.properties ]]; then
|
||||
perl -pi -e "s/^sbt\.version=.*\$/sbt.version=${ver}/" project/build.properties
|
||||
grep -q '^sbt.version=' project/build.properties || echo "sbt.version=${ver}" >> project/build.properties
|
||||
|
||||
echoerr !!!
|
||||
echoerr !!! Updated file project/build.properties setting sbt.version to: $ver
|
||||
echoerr !!! Previous value was: $old
|
||||
echoerr !!!
|
||||
fi
|
||||
}
|
||||
|
||||
sbt_version () {
|
||||
if [[ -n $sbt_explicit_version ]]; then
|
||||
echo $sbt_explicit_version
|
||||
else
|
||||
local v=$(build_props_sbt)
|
||||
if [[ -n $v ]]; then
|
||||
echo $v
|
||||
else
|
||||
echo $sbt_release_version
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# restore stty settings (echo in particular)
|
||||
onSbtRunnerExit() {
|
||||
[[ -n $sbt_saved_stty ]] || return
|
||||
dlog ""
|
||||
dlog "restoring stty: $sbt_saved_stty"
|
||||
stty $sbt_saved_stty
|
||||
unset sbt_saved_stty
|
||||
}
|
||||
|
||||
# save stty and trap exit, to ensure echo is reenabled if we are interrupted.
|
||||
trap onSbtRunnerExit EXIT
|
||||
sbt_saved_stty=$(stty -g 2>/dev/null)
|
||||
dlog "Saved stty: $sbt_saved_stty"
|
||||
|
||||
# this seems to cover the bases on OSX, and someone will
|
||||
# have to tell me about the others.
|
||||
get_script_path () {
|
||||
local path="$1"
|
||||
[[ -L "$path" ]] || { echo "$path" ; return; }
|
||||
|
||||
local target=$(readlink "$path")
|
||||
if [[ "${target:0:1}" == "/" ]]; then
|
||||
echo "$target"
|
||||
else
|
||||
echo "$(dirname $path)/$target"
|
||||
fi
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "Aborting: $@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
make_url () {
|
||||
groupid="$1"
|
||||
category="$2"
|
||||
version="$3"
|
||||
|
||||
echo "http://typesafe.artifactoryonline.com/typesafe/ivy-$category/$groupid/sbt-launch/$version/sbt-launch.jar"
|
||||
}
|
||||
|
||||
readarr () {
|
||||
while read ; do
|
||||
eval "$1+=(\"$REPLY\")"
|
||||
done
|
||||
}
|
||||
|
||||
init_default_option_file () {
|
||||
local overriding_var=${!1}
|
||||
local default_file=$2
|
||||
if [[ ! -r "$default_file" && $overriding_var =~ ^@(.*)$ ]]; then
|
||||
local envvar_file=${BASH_REMATCH[1]}
|
||||
if [[ -r $envvar_file ]]; then
|
||||
default_file=$envvar_file
|
||||
fi
|
||||
fi
|
||||
echo $default_file
|
||||
}
|
||||
|
||||
declare -r default_jvm_opts="-Dfile.encoding=UTF8 -XX:MaxPermSize=256m -Xms512m -Xmx1g -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC"
|
||||
declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy"
|
||||
declare -r latest_28="2.8.2"
|
||||
declare -r latest_29="2.9.3"
|
||||
declare -r latest_210="2.10.0"
|
||||
|
||||
declare -r script_path=$(get_script_path "$BASH_SOURCE")
|
||||
declare -r script_dir="$(dirname $script_path)"
|
||||
declare -r script_name="$(basename $script_path)"
|
||||
|
||||
# some non-read-onlies set with defaults
|
||||
declare java_cmd=java
|
||||
declare sbt_opts_file=$(init_default_option_file SBT_OPTS .sbtopts)
|
||||
declare jvm_opts_file=$(init_default_option_file JVM_OPTS .jvmopts)
|
||||
|
||||
# pull -J and -D options to give to java.
|
||||
declare -a residual_args
|
||||
declare -a java_args
|
||||
declare -a scalac_args
|
||||
declare -a sbt_commands
|
||||
|
||||
# args to jvm/sbt via files or environment variables
|
||||
declare -a extra_jvm_opts extra_sbt_opts
|
||||
|
||||
# if set, use JAVA_HOME over java found in path
|
||||
[[ -e "$JAVA_HOME/bin/java" ]] && java_cmd="$JAVA_HOME/bin/java"
|
||||
|
||||
# directory to store sbt launchers
|
||||
declare sbt_launch_dir="$HOME/.sbt/launchers"
|
||||
[[ -d "$sbt_launch_dir" ]] || mkdir -p "$sbt_launch_dir"
|
||||
[[ -w "$sbt_launch_dir" ]] || sbt_launch_dir="$(mktemp -d -t sbt_extras_launchers)"
|
||||
|
||||
build_props_scala () {
|
||||
if [[ -r project/build.properties ]]; then
|
||||
versionLine=$(grep ^build.scala.versions project/build.properties)
|
||||
versionString=${versionLine##build.scala.versions=}
|
||||
echo ${versionString%% .*}
|
||||
fi
|
||||
}
|
||||
|
||||
execRunner () {
|
||||
# print the arguments one to a line, quoting any containing spaces
|
||||
[[ $verbose || $debug ]] && echo "# Executing command line:" && {
|
||||
for arg; do
|
||||
if [[ -n "$arg" ]]; then
|
||||
if printf "%s\n" "$arg" | grep -q ' '; then
|
||||
printf "\"%s\"\n" "$arg"
|
||||
else
|
||||
printf "%s\n" "$arg"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
}
|
||||
|
||||
if [[ -n $batch ]]; then
|
||||
# the only effective way I've found to avoid sbt hanging when backgrounded.
|
||||
exec 0<&-
|
||||
( "$@" & )
|
||||
# I'm sure there's some way to get our hands on the pid and wait for it
|
||||
# but it exceeds my present level of ambition.
|
||||
else
|
||||
{ "$@"; }
|
||||
fi
|
||||
}
|
||||
|
||||
sbt_groupid () {
|
||||
case $(sbt_version) in
|
||||
0.7.*) echo org.scala-tools.sbt ;;
|
||||
0.10.*) echo org.scala-tools.sbt ;;
|
||||
0.11.[12]) echo org.scala-tools.sbt ;;
|
||||
*) echo org.scala-sbt ;;
|
||||
esac
|
||||
}
|
||||
|
||||
sbt_artifactory_list () {
|
||||
local version0=$(sbt_version)
|
||||
local version=${version0%-SNAPSHOT}
|
||||
local url="http://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/$(sbt_groupid)/sbt-launch/"
|
||||
dlog "Looking for snapshot list at: $url "
|
||||
|
||||
curl -s --list-only "$url" | \
|
||||
grep -F $version | \
|
||||
perl -e 'print reverse <>' | \
|
||||
perl -pe 's#^<a href="([^"/]+).*#$1#;'
|
||||
}
|
||||
|
||||
make_release_url () {
|
||||
make_url $(sbt_groupid) releases $(sbt_version)
|
||||
}
|
||||
|
||||
# argument is e.g. 0.13.0-SNAPSHOT
|
||||
# finds the actual version (with the build id) at artifactory
|
||||
make_snapshot_url () {
|
||||
for ver in $(sbt_artifactory_list); do
|
||||
local url=$(make_url $(sbt_groupid) snapshots $ver)
|
||||
dlog "Testing $url"
|
||||
curl -s --head "$url" >/dev/null
|
||||
dlog "curl returned: $?"
|
||||
echo "$url"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
jar_url () {
|
||||
case $(sbt_version) in
|
||||
0.7.*) echo "http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.7.jar" ;;
|
||||
*-SNAPSHOT) make_snapshot_url ;;
|
||||
*) make_release_url ;;
|
||||
esac
|
||||
}
|
||||
|
||||
jar_file () {
|
||||
case $1 in
|
||||
0.13.*) echo "$sbt_launch_dir/$1/sbt-launch.jar" ;;
|
||||
*) echo "$sbt_launch_dir/$sbt_release_version/sbt-launch.jar" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
download_url () {
|
||||
local url="$1"
|
||||
local jar="$2"
|
||||
|
||||
echo "Downloading sbt launcher $(sbt_version):"
|
||||
echo " From $url"
|
||||
echo " To $jar"
|
||||
|
||||
mkdir -p $(dirname "$jar") && {
|
||||
if which curl >/dev/null; then
|
||||
curl --fail --silent "$url" --output "$jar"
|
||||
elif which wget >/dev/null; then
|
||||
wget --quiet -O "$jar" "$url"
|
||||
fi
|
||||
} && [[ -r "$jar" ]]
|
||||
}
|
||||
|
||||
acquire_sbt_jar () {
|
||||
sbt_url="$(jar_url)"
|
||||
sbt_jar="$(jar_file $(sbt_version))"
|
||||
|
||||
[[ -r "$sbt_jar" ]] || download_url "$sbt_url" "$sbt_jar"
|
||||
}
|
||||
|
||||
usage () {
|
||||
cat <<EOM
|
||||
Usage: $script_name [options]
|
||||
|
||||
-h | -help print this message
|
||||
-v | -verbose this runner is chattier
|
||||
-d | -debug set sbt log level to Debug
|
||||
-q | -quiet set sbt log level to Error
|
||||
-trace <level> display stack traces with a max of <level> frames (default: -1, traces suppressed)
|
||||
-no-colors disable ANSI color codes
|
||||
-sbt-create start sbt even if current directory contains no sbt project
|
||||
-sbt-dir <path> path to global settings/plugins directory (default: ~/.sbt/<version>)
|
||||
-sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11+)
|
||||
-ivy <path> path to local Ivy repository (default: ~/.ivy2)
|
||||
-no-share use all local caches; no sharing
|
||||
-offline put sbt in offline mode
|
||||
-jvm-debug <port> Turn on JVM debugging, open at the given port.
|
||||
-batch Disable interactive mode
|
||||
-prompt <expr> Set the sbt prompt; in expr, 's' is the State and 'e' is Extracted
|
||||
|
||||
# sbt version (default: from project/build.properties if present, else latest release)
|
||||
!!! The only way to accomplish this pre-0.12.0 if there is a build.properties file which
|
||||
!!! contains an sbt.version property is to update the file on disk. That's what this does.
|
||||
-sbt-version <version> use the specified version of sbt (default: $sbt_release_version)
|
||||
-sbt-jar <path> use the specified jar as the sbt launcher
|
||||
-sbt-beta use a beta version of sbt (currently: $sbt_beta_version)
|
||||
-sbt-snapshot use a snapshot version of sbt (currently: $sbt_snapshot_version)
|
||||
-sbt-launch-dir <path> directory to hold sbt launchers (default: $sbt_launch_dir)
|
||||
|
||||
# scala version (default: as chosen by sbt)
|
||||
-28 use $latest_28
|
||||
-29 use $latest_29
|
||||
-210 use $latest_210
|
||||
-scala-home <path> use the scala build at the specified directory
|
||||
-scala-version <version> use the specified version of scala
|
||||
-binary-version <version> use the specified scala version when searching for dependencies
|
||||
|
||||
# java version (default: java from PATH, currently $(java -version 2>&1 | grep version))
|
||||
-java-home <path> alternate JAVA_HOME
|
||||
|
||||
# passing options to the jvm - note it does NOT use JAVA_OPTS due to pollution
|
||||
# The default set is used if JVM_OPTS is unset and no -jvm-opts file is found
|
||||
<default> $default_jvm_opts
|
||||
JVM_OPTS environment variable holding either the jvm args directly, or
|
||||
the reference to a file containing jvm args if given path is prepended by '@' (e.g. '@/etc/jvmopts')
|
||||
Note: "@"-file is overridden by local '.jvmopts' or '-jvm-opts' argument.
|
||||
-jvm-opts <path> file containing jvm args (if not given, .jvmopts in project root is used if present)
|
||||
-Dkey=val pass -Dkey=val directly to the jvm
|
||||
-J-X pass option -X directly to the jvm (-J is stripped)
|
||||
|
||||
# passing options to sbt, OR to this runner
|
||||
SBT_OPTS environment variable holding either the sbt args directly, or
|
||||
the reference to a file containing sbt args if given path is prepended by '@' (e.g. '@/etc/sbtopts')
|
||||
Note: "@"-file is overridden by local '.sbtopts' or '-sbt-opts' argument.
|
||||
-sbt-opts <path> file containing sbt args (if not given, .sbtopts in project root is used if present)
|
||||
-S-X add -X to sbt's scalacOptions (-S is stripped)
|
||||
EOM
|
||||
}
|
||||
|
||||
addJava () {
|
||||
dlog "[addJava] arg = '$1'"
|
||||
java_args=( "${java_args[@]}" "$1" )
|
||||
}
|
||||
addSbt () {
|
||||
dlog "[addSbt] arg = '$1'"
|
||||
sbt_commands=( "${sbt_commands[@]}" "$1" )
|
||||
}
|
||||
addScalac () {
|
||||
dlog "[addScalac] arg = '$1'"
|
||||
scalac_args=( "${scalac_args[@]}" "$1" )
|
||||
}
|
||||
addResidual () {
|
||||
dlog "[residual] arg = '$1'"
|
||||
residual_args=( "${residual_args[@]}" "$1" )
|
||||
}
|
||||
addResolver () {
|
||||
addSbt "set resolvers in ThisBuild += $1"
|
||||
}
|
||||
addDebugger () {
|
||||
addJava "-Xdebug"
|
||||
addJava "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=$1"
|
||||
}
|
||||
setScalaVersion () {
|
||||
addSbt "set scalaVersion in ThisBuild := \"$1\""
|
||||
if [[ "$1" == *SNAPSHOT* ]]; then
|
||||
addResolver Opts.resolver.sonatypeSnapshots
|
||||
fi
|
||||
}
|
||||
|
||||
process_args ()
|
||||
{
|
||||
require_arg () {
|
||||
local type="$1"
|
||||
local opt="$2"
|
||||
local arg="$3"
|
||||
|
||||
if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
|
||||
die "$opt requires <$type> argument"
|
||||
fi
|
||||
}
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h|-help) usage; exit 1 ;;
|
||||
-v|-verbose) verbose=true && log_level=Info && shift ;;
|
||||
-d|-debug) debug=true && log_level=Debug && shift ;;
|
||||
-q|-quiet) quiet=true && log_level=Error && shift ;;
|
||||
|
||||
-trace) require_arg integer "$1" "$2" && trace_level=$2 && shift 2 ;;
|
||||
-ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;
|
||||
-no-colors) addJava "-Dsbt.log.noformat=true" && shift ;;
|
||||
-no-share) noshare=true && shift ;;
|
||||
-sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;
|
||||
-sbt-dir) require_arg path "$1" "$2" && sbt_dir="$2" && shift 2 ;;
|
||||
-debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;;
|
||||
-offline) addSbt "set offline := true" && shift ;;
|
||||
-jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;;
|
||||
-batch) batch=true && shift ;;
|
||||
-prompt) require_arg "expr" "$1" "$2" && addSbt "set shellPrompt in ThisBuild := (s => { val e = Project.extract(s) ; $2 })" && shift 2 ;;
|
||||
|
||||
-sbt-create) sbt_create=true && shift ;;
|
||||
-sbt-snapshot) sbt_explicit_version=$sbt_snapshot_version && shift ;;
|
||||
-sbt-beta) sbt_explicit_version=$sbt_beta_version && shift ;;
|
||||
-sbt-jar) require_arg path "$1" "$2" && sbt_jar="$2" && shift 2 ;;
|
||||
-sbt-version) require_arg version "$1" "$2" && sbt_explicit_version="$2" && shift 2 ;;
|
||||
-sbt-launch-dir) require_arg path "$1" "$2" && sbt_launch_dir="$2" && shift 2 ;;
|
||||
-scala-version) require_arg version "$1" "$2" && setScalaVersion "$2" && shift 2 ;;
|
||||
-binary-version) require_arg version "$1" "$2" && addSbt "set scalaBinaryVersion in ThisBuild := \"$2\"" && shift 2 ;;
|
||||
-scala-home) require_arg path "$1" "$2" && addSbt "set every scalaHome := Some(file(\"$2\"))" && shift 2 ;;
|
||||
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
|
||||
-sbt-opts) require_arg path "$1" "$2" && sbt_opts_file="$2" && shift 2 ;;
|
||||
-jvm-opts) require_arg path "$1" "$2" && jvm_opts_file="$2" && shift 2 ;;
|
||||
|
||||
-D*) addJava "$1" && shift ;;
|
||||
-J*) addJava "${1:2}" && shift ;;
|
||||
-S*) addScalac "${1:2}" && shift ;;
|
||||
-28) addSbt "++ $latest_28" && shift ;;
|
||||
-29) addSbt "++ $latest_29" && shift ;;
|
||||
-210) addSbt "++ $latest_210" && shift ;;
|
||||
|
||||
*) addResidual "$1" && shift ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# process the direct command line arguments
|
||||
process_args "$@"
|
||||
|
||||
# skip #-styled comments
|
||||
readConfigFile() {
|
||||
while read line; do echo ${line/\#*/} | grep -vE '^\s*$'; done < $1
|
||||
}
|
||||
|
||||
# if there are file/environment sbt_opts, process again so we
|
||||
# can supply args to this runner
|
||||
if [[ -r "$sbt_opts_file" ]]; then
|
||||
vlog "Using sbt options defined in file $sbt_opts_file"
|
||||
readarr extra_sbt_opts < <(readConfigFile "$sbt_opts_file")
|
||||
elif [[ -n "$SBT_OPTS" && !($SBT_OPTS =~ ^@.*) ]]; then
|
||||
vlog "Using sbt options defined in variable \$SBT_OPTS"
|
||||
extra_sbt_opts=( $SBT_OPTS )
|
||||
else
|
||||
vlog "No extra sbt options have been defined"
|
||||
fi
|
||||
|
||||
[[ -n $extra_sbt_opts ]] && process_args "${extra_sbt_opts[@]}"
|
||||
|
||||
# reset "$@" to the residual args
|
||||
set -- "${residual_args[@]}"
|
||||
argumentCount=$#
|
||||
|
||||
# only exists in 0.12+
|
||||
setTraceLevel() {
|
||||
case $(sbt_version) in
|
||||
0.{7,10,11}.*) echoerr "Cannot set trace level in sbt version $(sbt_version)" ;;
|
||||
*) addSbt "set every traceLevel := $trace_level" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# set scalacOptions if we were given any -S opts
|
||||
[[ ${#scalac_args[@]} -eq 0 ]] || addSbt "set scalacOptions in ThisBuild += \"${scalac_args[@]}\""
|
||||
|
||||
# Update build.properties no disk to set explicit version - sbt gives us no choice
|
||||
[[ -n "$sbt_explicit_version" ]] && update_build_props_sbt "$sbt_explicit_version"
|
||||
vlog "Detected sbt version $(sbt_version)"
|
||||
|
||||
[[ -n "$scala_version" ]] && echoerr "Overriding scala version to $scala_version"
|
||||
|
||||
# no args - alert them there's stuff in here
|
||||
(( $argumentCount > 0 )) || vlog "Starting $script_name: invoke with -help for other options"
|
||||
|
||||
# verify this is an sbt dir or -create was given
|
||||
[[ -r ./build.sbt || -d ./project || -n "$sbt_create" ]] || {
|
||||
cat <<EOM
|
||||
$(pwd) doesn't appear to be an sbt project.
|
||||
If you want to start sbt anyway, run:
|
||||
$0 -sbt-create
|
||||
|
||||
EOM
|
||||
exit 1
|
||||
}
|
||||
|
||||
# pick up completion if present; todo
|
||||
[[ -r .sbt_completion.sh ]] && source .sbt_completion.sh
|
||||
|
||||
# no jar? download it.
|
||||
[[ -r "$sbt_jar" ]] || acquire_sbt_jar || {
|
||||
# still no jar? uh-oh.
|
||||
echo "Download failed. Obtain the jar manually and place it at $sbt_jar"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ -n $noshare ]]; then
|
||||
addJava "$noshare_opts"
|
||||
else
|
||||
[[ -n "$sbt_dir" ]] || {
|
||||
sbt_dir=~/.sbt/$(sbt_version)
|
||||
vlog "Using $sbt_dir as sbt dir, -sbt-dir to override."
|
||||
}
|
||||
addJava "-Dsbt.global.base=$sbt_dir"
|
||||
fi
|
||||
|
||||
if [[ -r "$jvm_opts_file" ]]; then
|
||||
vlog "Using jvm options defined in file $jvm_opts_file"
|
||||
readarr extra_jvm_opts < <(readConfigFile "$jvm_opts_file")
|
||||
elif [[ -n "$JVM_OPTS" && !($JVM_OPTS =~ ^@.*) ]]; then
|
||||
vlog "Using jvm options defined in \$JVM_OPTS variable"
|
||||
extra_jvm_opts=( $JVM_OPTS )
|
||||
else
|
||||
vlog "Using default jvm options"
|
||||
extra_jvm_opts=( $default_jvm_opts )
|
||||
fi
|
||||
|
||||
# since sbt 0.7 doesn't understand iflast
|
||||
[[ ${#residual_args[@]} -eq 0 ]] && [[ -z "$batch" ]] && residual_args=( "shell" )
|
||||
|
||||
# traceLevel is 0.12+
|
||||
[[ -n $trace_level ]] && setTraceLevel
|
||||
|
||||
[[ -n $log_level ]] && [[ $log_level != Info ]] && logLevalArg="set logLevel in Global := Level.$log_level"
|
||||
|
||||
# run sbt
|
||||
execRunner "$java_cmd" \
|
||||
"${extra_jvm_opts[@]}" \
|
||||
"${java_args[@]}" \
|
||||
-jar "$sbt_jar" \
|
||||
"$logLevalArg" \
|
||||
"${sbt_commands[@]}" \
|
||||
"${residual_args[@]}"
|
100
specs/admin.json
100
specs/admin.json
@ -1,100 +0,0 @@
|
||||
{
|
||||
"apiVersion": "0.5",
|
||||
"swaggerVersion": "1.1",
|
||||
"basePath": "http://localhost:8000",
|
||||
"resourcePath": "/admin",
|
||||
"apis": [
|
||||
{
|
||||
"path": "/admin.{format}/health",
|
||||
"description": "Administrative operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Returns health report on this JVM",
|
||||
"responseClass": "Health",
|
||||
"nickname": "getHealth"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/admin.{format}/ping",
|
||||
"description": "Administrative operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Pings service",
|
||||
"responseClass": "string",
|
||||
"nickname": "ping"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"models": {
|
||||
"Memory": {
|
||||
"required": false,
|
||||
"id": "Memory",
|
||||
"properties": {
|
||||
"free": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "long"
|
||||
},
|
||||
"max": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "long"
|
||||
},
|
||||
"allocated": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "long"
|
||||
},
|
||||
"used": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "long"
|
||||
},
|
||||
"percentUsed": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "double"
|
||||
}
|
||||
},
|
||||
"uniqueItems": false,
|
||||
"type": "any"
|
||||
},
|
||||
"Health": {
|
||||
"required": false,
|
||||
"id": "Health",
|
||||
"properties": {
|
||||
"peakThreadCount": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "int"
|
||||
},
|
||||
"memory": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "Memory"
|
||||
},
|
||||
"startedThreadCount": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "long"
|
||||
},
|
||||
"liveThreadCount": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "int"
|
||||
},
|
||||
"daemonThreadCount": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "int"
|
||||
}
|
||||
},
|
||||
"uniqueItems": false,
|
||||
"type": "any"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,337 +0,0 @@
|
||||
{
|
||||
"apiVersion": "0.5",
|
||||
"swaggerVersion": "1.1",
|
||||
"basePath": "http://localhost:8000",
|
||||
"resourcePath": "/discovery",
|
||||
"apis": [
|
||||
{
|
||||
"path": "/discovery.{format}/commission",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Perpare for a service to boot up and make contact",
|
||||
"responseClass": "string",
|
||||
"nickname": "commissionInstance",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service from which to anticipate contact",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "serviceName",
|
||||
"description": "Name of service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "buildNumber",
|
||||
"description": "Build Number of service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "cluster",
|
||||
"description": "Name of cluster to launch this into",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/de-commission",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Decomission an instance and remove it",
|
||||
"responseClass": "string",
|
||||
"nickname": "decommissionInstance",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service to be decommissioned",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/register",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Register an instance and return its configuration",
|
||||
"responseClass": "RegistrationResponse",
|
||||
"nickname": "registerInstance",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service to be registered",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/config",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Returns configuration of an instance",
|
||||
"responseClass": "ConfigurationResponse",
|
||||
"nickname": "getInstanceConfiguration",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service for which configuration is required",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/status",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Marks an instance's status",
|
||||
"responseClass": "string",
|
||||
"nickname": "updateInstanceStatus",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service which is to be marked as available",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"description": "The new status",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/{targetServiceName}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return base urls for a given service",
|
||||
"responseClass": "List[string]",
|
||||
"nickname": "getServiceInstances",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sourceInstanceId",
|
||||
"description": "InstanceId of the service which wants to call the target service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetServiceName",
|
||||
"description": "Name of service whose instances are needed",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Source Instance not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown service name specified"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/services/{status}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return instances running in the zone managed by this Discovery Service",
|
||||
"responseClass": "List[Instance]",
|
||||
"nickname": "getServiceInstancesByStatus",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "status",
|
||||
"description": "The status for which services need to be returned",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instances not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown status specified"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"models": {
|
||||
"Instance": {
|
||||
"required": false,
|
||||
"id": "Instance",
|
||||
"properties": {
|
||||
"baseUrl": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "long"
|
||||
},
|
||||
"privateIp": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
},
|
||||
"buildNumber": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
},
|
||||
"lastPingedOn": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "Date"
|
||||
},
|
||||
"status": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
},
|
||||
"createdAt": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "Date"
|
||||
},
|
||||
"awsInstanceId": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
},
|
||||
"cluster": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
},
|
||||
"zone": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
},
|
||||
"serviceName": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"uniqueItems": false,
|
||||
"type": "any"
|
||||
},
|
||||
"ConfigurationResponse": {
|
||||
"required": false,
|
||||
"id": "ConfigurationResponse",
|
||||
"properties": {
|
||||
"config": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"uniqueItems": false,
|
||||
"type": "any"
|
||||
},
|
||||
"RegistrationResponse": {
|
||||
"required": false,
|
||||
"id": "RegistrationResponse",
|
||||
"properties": {
|
||||
"config": {
|
||||
"required": true,
|
||||
"uniqueItems": false,
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"uniqueItems": false,
|
||||
"type": "any"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,403 +0,0 @@
|
||||
{
|
||||
"apiVersion": "0.5",
|
||||
"swaggerVersion": "1.1",
|
||||
"basePath": "http://localhost:9000/",
|
||||
"resourcePath": "/discovery.{format}",
|
||||
"models": {
|
||||
"Instance": {
|
||||
"id": "Instance",
|
||||
"properties": {
|
||||
"baseUrl": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "long"
|
||||
},
|
||||
"privateIp": {
|
||||
"type": "string"
|
||||
},
|
||||
"buildNumber": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastPingedOn": {
|
||||
"type": "Date"
|
||||
},
|
||||
"status": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "Date"
|
||||
},
|
||||
"awsInstanceId": {
|
||||
"type": "string"
|
||||
},
|
||||
"cluster": {
|
||||
"type": "string"
|
||||
},
|
||||
"publicIp": {
|
||||
"type": "string"
|
||||
},
|
||||
"zone": {
|
||||
"type": "string"
|
||||
},
|
||||
"serviceName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ConfigurationResponse": {
|
||||
"id": "ConfigurationResponse",
|
||||
"properties": {
|
||||
"config": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"RegistrationResponse": {
|
||||
"id": "RegistrationResponse",
|
||||
"properties": {
|
||||
"config": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"apis": [
|
||||
{
|
||||
"path": "/discovery.{format}/commission",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Perpare for a service to boot up and make contact",
|
||||
"responseClass": "string",
|
||||
"nickname": "commissionInstance",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service from which to anticipate contact",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "serviceName",
|
||||
"description": "Name of service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "buildNumber",
|
||||
"description": "Build Number of service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "cluster",
|
||||
"description": "Name of cluster to launch this into",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/de-commission",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Decomission an instance and remove it",
|
||||
"responseClass": "string",
|
||||
"nickname": "decommissionInstance",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service to be decommissioned",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/register",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Register an instance and return its configuration",
|
||||
"responseClass": "RegistrationResponse",
|
||||
"nickname": "registerInstance",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service to be registered",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/instances/{targetServiceName}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return instances accessible to a target service",
|
||||
"responseClass": "List[Instance]",
|
||||
"nickname": "getServiceInstances",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sourceInstanceId",
|
||||
"description": "InstanceId of the service which wants to call the target service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetZone",
|
||||
"description": "The zone in which the target service instances should be located. Valid values are all - (all zones in the same region), same - (same zone a the source service), [zone-name] - (the name of zone for example us-west-1a, us-west-1b, us-west-1c)",
|
||||
"paramType": "query",
|
||||
"defaultValue": "all",
|
||||
"required": false,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetServiceName",
|
||||
"description": "Name of service whose instances are needed",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Source Instance not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown service name specified"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/services/{status}/{targetServiceName}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return instances in the zone managed by this Discovery Service for a given status and and service",
|
||||
"responseClass": "List[Instance]",
|
||||
"nickname": "getServiceInstancesByStatusAndName",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "status",
|
||||
"description": "The status for which services need to be returned",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetServiceName",
|
||||
"description": "Name of service whose instances are needed",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instances not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown status specified"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/config",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Returns configuration of an instance",
|
||||
"responseClass": "ConfigurationResponse",
|
||||
"nickname": "getInstanceConfiguration",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service for which configuration is required",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/status",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Marks an instance's status",
|
||||
"responseClass": "string",
|
||||
"nickname": "updateInstanceStatus",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service which is to be marked as available",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"description": "The new status",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/{targetServiceName}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return base urls accessible to a target service",
|
||||
"responseClass": "List[String]",
|
||||
"nickname": "getServiceInstancesUrls",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sourceInstanceId",
|
||||
"description": "InstanceId of the service which wants to call the target service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetZone",
|
||||
"description": "The zone in which the target service instances should be located. Valid values are all - (all zones in the same region), same - (same zone a the source service), [zone-name] - (the name of zone for example us-west-1a, us-west-1b, us-west-1c)",
|
||||
"paramType": "query",
|
||||
"defaultValue": "all",
|
||||
"required": false,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetServiceName",
|
||||
"description": "Name of service whose instances are needed",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Source Instance not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown service name specified"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/services/{status}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return instances running in the zone managed by this Discovery Service",
|
||||
"responseClass": "List[Instance]",
|
||||
"nickname": "getServiceInstancesByStatus",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "status",
|
||||
"description": "The status for which services need to be returned",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
],
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instances not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown status specified"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -1,403 +0,0 @@
|
||||
{
|
||||
"apiVersion": "0.5",
|
||||
"swaggerVersion": "1.1",
|
||||
"basePath": "http://localhost:9000/",
|
||||
"resourcePath": "/discovery.{format}",
|
||||
"apis": [
|
||||
{
|
||||
"path": "/discovery.{format}/config",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Returns configuration of an instance",
|
||||
"responseClass": "ConfigurationResponse",
|
||||
"nickname": "getInstanceConfiguration",
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service for which configuration is required",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/status",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Marks an instance's status",
|
||||
"responseClass": "string",
|
||||
"nickname": "updateInstanceStatus",
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service which is to be marked as available",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "status",
|
||||
"description": "The new status",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/{targetServiceName}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return base urls accessible to a target service",
|
||||
"responseClass": "List[String]",
|
||||
"nickname": "getServiceInstancesUrls",
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Source Instance not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown service name specified"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sourceInstanceId",
|
||||
"description": "InstanceId of the service which wants to call the target service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetZone",
|
||||
"description": "The zone in which the target service instances should be located. Valid values are all - (all zones in the same region), same - (same zone a the source service), [zone-name] - (the name of zone for example us-west-1a, us-west-1b, us-west-1c)",
|
||||
"paramType": "query",
|
||||
"defaultValue": "all",
|
||||
"required": false,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetServiceName",
|
||||
"description": "Name of service whose instances are needed",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/commission",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Perpare for a service to boot up and make contact",
|
||||
"responseClass": "string",
|
||||
"nickname": "commissionInstance",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service from which to anticipate contact",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "serviceName",
|
||||
"description": "Name of service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "buildNumber",
|
||||
"description": "Build Number of service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "cluster",
|
||||
"description": "Name of cluster to launch this into",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/de-commission",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Decomission an instance and remove it",
|
||||
"responseClass": "string",
|
||||
"nickname": "decommissionInstance",
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service to be decommissioned",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/register",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "POST",
|
||||
"summary": "Register an instance and return its configuration",
|
||||
"responseClass": "RegistrationResponse",
|
||||
"nickname": "registerInstance",
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instance not found"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "instanceId",
|
||||
"description": "InstanceId of the service to be registered",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/instances/{targetServiceName}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return instances accessible to a target service",
|
||||
"responseClass": "List[Instance]",
|
||||
"nickname": "getServiceInstances",
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Source Instance not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown service name specified"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "sourceInstanceId",
|
||||
"description": "InstanceId of the service which wants to call the target service",
|
||||
"paramType": "query",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetZone",
|
||||
"description": "The zone in which the target service instances should be located. Valid values are all - (all zones in the same region), same - (same zone a the source service), [zone-name] - (the name of zone for example us-west-1a, us-west-1b, us-west-1c)",
|
||||
"paramType": "query",
|
||||
"defaultValue": "all",
|
||||
"required": false,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetServiceName",
|
||||
"description": "Name of service whose instances are needed",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/services/{status}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return instances running in the zone managed by this Discovery Service",
|
||||
"responseClass": "List[Instance]",
|
||||
"nickname": "getServiceInstancesByStatus",
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instances not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown status specified"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "status",
|
||||
"description": "The status for which services need to be returned",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}/services/{status}/{targetServiceName}",
|
||||
"description": "Discovery Service's Core Operations",
|
||||
"operations": [
|
||||
{
|
||||
"httpMethod": "GET",
|
||||
"summary": "Return instances in the zone managed by this Discovery Service for a given status and and service",
|
||||
"responseClass": "List[Instance]",
|
||||
"nickname": "getServiceInstancesByStatusAndName",
|
||||
"errorResponses": [
|
||||
{
|
||||
"code": 404,
|
||||
"reason": "Instances not found"
|
||||
},
|
||||
{
|
||||
"code": 400,
|
||||
"reason": "Unknown status specified"
|
||||
}
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "status",
|
||||
"description": "The status for which services need to be returned",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
},
|
||||
{
|
||||
"name": "targetServiceName",
|
||||
"description": "Name of service whose instances are needed",
|
||||
"paramType": "path",
|
||||
"required": true,
|
||||
"allowMultiple": false,
|
||||
"dataType": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"models": {
|
||||
"Instance": {
|
||||
"id": "Instance",
|
||||
"properties": {
|
||||
"baseUrl": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "long"
|
||||
},
|
||||
"privateIp": {
|
||||
"type": "string"
|
||||
},
|
||||
"buildNumber": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastPingedOn": {
|
||||
"type": "Date"
|
||||
},
|
||||
"status": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "Date"
|
||||
},
|
||||
"awsInstanceId": {
|
||||
"type": "string"
|
||||
},
|
||||
"cluster": {
|
||||
"type": "string"
|
||||
},
|
||||
"publicIp": {
|
||||
"type": "string"
|
||||
},
|
||||
"zone": {
|
||||
"type": "string"
|
||||
},
|
||||
"serviceName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ConfigurationResponse": {
|
||||
"id": "ConfigurationResponse",
|
||||
"properties": {
|
||||
"config": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"RegistrationResponse": {
|
||||
"id": "RegistrationResponse",
|
||||
"properties": {
|
||||
"config": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"apiVersion": "0.5",
|
||||
"swaggerVersion": "1.1",
|
||||
"basePath": "http://localhost:8000",
|
||||
"apis": [
|
||||
{
|
||||
"path": "/admin.{format}",
|
||||
"description": "Administrative operations"
|
||||
},
|
||||
{
|
||||
"path": "/discovery.{format}",
|
||||
"description": "Discovery Service's Core Operations"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright 2014 Reverb, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.codegen.ClientOpts;
|
||||
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
|
||||
public class ClientOptInput {
|
||||
private ClientOpts opts;
|
||||
private Swagger swagger;
|
||||
protected CodegenConfig config;
|
||||
|
||||
public ClientOptInput swagger(Swagger swagger) {
|
||||
this.setSwagger(swagger);
|
||||
return this;
|
||||
}
|
||||
public ClientOptInput opts(ClientOpts opts) {
|
||||
this.setOpts(opts);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CodegenConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
public void setConfig(CodegenConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void setOpts(ClientOpts opts) {
|
||||
this.opts = opts;
|
||||
}
|
||||
|
||||
public ClientOpts getOpts() {
|
||||
return opts;
|
||||
}
|
||||
|
||||
public void setSwagger(Swagger swagger) {
|
||||
this.swagger = swagger;
|
||||
}
|
||||
|
||||
public Swagger getSwagger() {
|
||||
return swagger;
|
||||
}
|
||||
}
|
52
src/main/java/com/wordnik/swagger/codegen/ClientOpts.java
Normal file
52
src/main/java/com/wordnik/swagger/codegen/ClientOpts.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.codegen.auth.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ClientOpts {
|
||||
protected String uri;
|
||||
protected String target;
|
||||
protected AuthMethod auth;
|
||||
protected Map<String, String> properties = new HashMap<String, String>();
|
||||
protected String outputDirectory;
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
public void setProperties(Map<String, String> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public String getOutputDirectory() {
|
||||
return outputDirectory;
|
||||
}
|
||||
public void setOutputDirectory(String outputDirectory) {
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("ClientOpts: {\n");
|
||||
sb.append(" uri: ").append(uri).append(",");
|
||||
sb.append(" auth: ").append(auth).append(",");
|
||||
sb.append(properties);
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
61
src/main/java/com/wordnik/swagger/codegen/Codegen.java
Normal file
61
src/main/java/com/wordnik/swagger/codegen/Codegen.java
Normal file
@ -0,0 +1,61 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.codegen.languages.*;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import com.wordnik.swagger.util.*;
|
||||
|
||||
import org.apache.commons.cli.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Codegen extends DefaultGenerator {
|
||||
public static void main(String[] args) {
|
||||
Options options = new Options();
|
||||
options.addOption("l", "lang", true, "client language to generate");
|
||||
options.addOption("o", "output", true, "where to write the generated files");
|
||||
options.addOption("i", "input-spec", true, "location of the swagger spec, as URL or file");
|
||||
|
||||
ClientOptInput codegenInput = new ClientOptInput();
|
||||
ClientOpts clientArgs = new ClientOpts();
|
||||
Swagger swagger = null;
|
||||
|
||||
CommandLine cmd = null;
|
||||
try {
|
||||
CommandLineParser parser = new BasicParser();
|
||||
cmd = parser.parse(options, args);
|
||||
if (cmd.hasOption("l"))
|
||||
codegenInput.setConfig(getConfig(cmd.getOptionValue("l")));
|
||||
if (cmd.hasOption("o"))
|
||||
codegenInput.getConfig().setOutputDir(cmd.getOptionValue("o"));
|
||||
if (cmd.hasOption("i"))
|
||||
swagger = new SwaggerLoader().read(cmd.getOptionValue("i"));
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
codegenInput
|
||||
.opts(clientArgs)
|
||||
.swagger(swagger);
|
||||
|
||||
new Codegen().opts(codegenInput).generate();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static CodegenConfig getConfig(String name) {
|
||||
if("objc".equals(name))
|
||||
return new ObjcClientCodegen();
|
||||
else if("java".equals(name))
|
||||
return new JavaClientCodegen();
|
||||
else if("jaxrs".equals(name))
|
||||
return new JaxRSServerCodegen();
|
||||
else
|
||||
throw new RuntimeException("unsupported client type");
|
||||
}
|
||||
}
|
46
src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java
Normal file
46
src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface CodegenConfig {
|
||||
Map<String, Object> additionalProperties();
|
||||
String apiPackage();
|
||||
String apiFileFolder();
|
||||
String fileSuffix();
|
||||
String outputFolder();
|
||||
String templateDir();
|
||||
String modelFileFolder();
|
||||
String modelPackage();
|
||||
String toApiName(String name);
|
||||
String toModelName(String name);
|
||||
String toParamName(String name);
|
||||
String escapeReservedWord(String name);
|
||||
String getTypeDeclaration(Property p);
|
||||
String getTypeDeclaration(String name);
|
||||
|
||||
Set<String> reservedWords();
|
||||
|
||||
List<SupportingFile> supportingFiles();
|
||||
|
||||
void setOutputDir(String dir);
|
||||
String getOutputDir();
|
||||
|
||||
CodegenModel fromModel(String name, Model model);
|
||||
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation);
|
||||
Set<String> defaultIncludes();
|
||||
Map<String, String> typeMapping();
|
||||
Map<String, String> importMapping();
|
||||
Map<String, String> apiTemplateFiles();
|
||||
Map<String, String> modelTemplateFiles();
|
||||
|
||||
String toApiFilename(String name);
|
||||
String toModelFilename(String name);
|
||||
String toModelImport(String name);
|
||||
String toApiImport(String name);
|
||||
void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations);
|
||||
Map<String, Object> postProcessModels(Map<String, Object> objs);
|
||||
Map<String, Object> postProcessOperations(Map<String, Object> objs);
|
||||
}
|
13
src/main/java/com/wordnik/swagger/codegen/CodegenModel.java
Normal file
13
src/main/java/com/wordnik/swagger/codegen/CodegenModel.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class CodegenModel {
|
||||
public String name, classname, description;
|
||||
public String defaultValue;
|
||||
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
|
||||
public Set<String> imports = new HashSet<String>();
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class CodegenOperation {
|
||||
public Boolean hasParams, returnTypeIsPrimitive, returnSimpleType;
|
||||
public String path, operationId, returnType, httpMethod, returnBaseType,
|
||||
returnContainer, summary, notes, baseName;
|
||||
|
||||
public List<Map<String, String>> consumes, produces;
|
||||
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> bodyParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> pathParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> queryParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> headerParams = new ArrayList<CodegenParameter>();
|
||||
public List<CodegenParameter> formParams = new ArrayList<CodegenParameter>();
|
||||
public List<String> tags;
|
||||
public List<CodegenResponse> responses = new ArrayList<CodegenResponse>();
|
||||
|
||||
public Set<String> imports = new HashSet<String>();
|
||||
|
||||
// legacy support
|
||||
public String nickname;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
public class CodegenParameter {
|
||||
public Boolean hasMore = null, isContainer = null, secondaryParam = null;
|
||||
public String baseName, paramName, dataType, collectionFormat, description;
|
||||
public Boolean isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenProperty {
|
||||
public String baseName, complexType, getter, setter, description, datatype,
|
||||
name, min, max, defaultValue, baseType;
|
||||
public Double minimum, maximum, exclusiveMinimum, exclusiveMaximum;
|
||||
public Boolean hasMore = null, required = null, secondaryParam = null;
|
||||
public Boolean isPrimitiveType, isContainer, isNotContainer;
|
||||
public List<String> _enum;
|
||||
public Map<String, Object> allowableValues;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
|
||||
public class CodegenResponse {
|
||||
public String code, message;
|
||||
public Boolean hasMore;
|
||||
Object schema;
|
||||
}
|
678
src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java
Normal file
678
src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java
Normal file
@ -0,0 +1,678 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.util.Json;
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.parameters.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class DefaultCodegen {
|
||||
protected String outputFolder = "";
|
||||
protected Set<String> defaultIncludes = new HashSet<String>();
|
||||
protected Map<String, String> typeMapping = new HashMap<String, String>();
|
||||
protected Set<String> reservedWords = new HashSet<String>();
|
||||
protected Set<String> languageSpecificPrimitives = new HashSet<String>();
|
||||
protected Map<String, String> importMapping = new HashMap<String, String>();
|
||||
protected String modelPackage = "", apiPackage = "", fileSuffix;
|
||||
protected Map<String, String> apiTemplateFiles = new HashMap<String, String>();
|
||||
protected Map<String, String> modelTemplateFiles = new HashMap<String, String>();
|
||||
protected String templateDir;
|
||||
protected Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
||||
protected List<SupportingFile> supportingFiles = new ArrayList<SupportingFile>();
|
||||
|
||||
// override with any special post-processing
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
return objs;
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
return objs;
|
||||
}
|
||||
|
||||
public Set<String> defaultIncludes() {
|
||||
return defaultIncludes;
|
||||
}
|
||||
public Map<String, String> typeMapping() {
|
||||
return typeMapping;
|
||||
}
|
||||
public Set<String> reservedWords() {
|
||||
return reservedWords;
|
||||
}
|
||||
public Set<String> languageSpecificPrimitives() {
|
||||
return languageSpecificPrimitives;
|
||||
}
|
||||
public Map<String, String> importMapping() {
|
||||
return importMapping;
|
||||
}
|
||||
public String modelPackage() {
|
||||
return modelPackage;
|
||||
}
|
||||
public String apiPackage() {
|
||||
return apiPackage;
|
||||
}
|
||||
public String fileSuffix() {
|
||||
return fileSuffix;
|
||||
}
|
||||
public String templateDir() {
|
||||
return templateDir;
|
||||
}
|
||||
public Map<String, String> apiTemplateFiles() {
|
||||
return apiTemplateFiles;
|
||||
}
|
||||
public Map<String, String> modelTemplateFiles() {
|
||||
return modelTemplateFiles;
|
||||
}
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage().replaceAll("\\.", File.separator);
|
||||
}
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + modelPackage().replaceAll("\\.", File.separator);
|
||||
}
|
||||
public Map<String, Object> additionalProperties() {
|
||||
return additionalProperties;
|
||||
}
|
||||
public List<SupportingFile> supportingFiles() {
|
||||
return supportingFiles;
|
||||
}
|
||||
public String outputFolder() {
|
||||
return outputFolder;
|
||||
}
|
||||
|
||||
public void setOutputDir(String dir) {
|
||||
this.outputFolder = dir;
|
||||
}
|
||||
public String getOutputDir() {
|
||||
return outputFolder();
|
||||
}
|
||||
|
||||
public void setTemplateDir(String templateDir) {
|
||||
this.templateDir = templateDir;
|
||||
}
|
||||
|
||||
public String toApiFilename(String name) {
|
||||
return initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
public String toModelFilename(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toVarName(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toParamName(String name) {
|
||||
if(reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public String escapeReservedWord(String name) {
|
||||
throw new RuntimeException("reserved word " + name + " not allowed");
|
||||
}
|
||||
|
||||
public String toModelImport(String name) {
|
||||
if("".equals(modelPackage()))
|
||||
return name;
|
||||
else
|
||||
return modelPackage() + "." + name;
|
||||
}
|
||||
|
||||
public String toApiImport(String name) {
|
||||
return apiPackage() + "." + name;
|
||||
}
|
||||
|
||||
public DefaultCodegen() {
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList("double",
|
||||
"int",
|
||||
"long",
|
||||
"short",
|
||||
"char",
|
||||
"float",
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
);
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("Array", "List");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("List", "List");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("int", "Integer");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("number", "BigDecimal");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
typeMapping.put("long", "Long");
|
||||
typeMapping.put("short", "Short");
|
||||
typeMapping.put("char", "String");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("integer", "Integer");
|
||||
|
||||
reservedWords = new HashSet<String> (
|
||||
Arrays.asList(
|
||||
"abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
|
||||
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
|
||||
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
|
||||
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
|
||||
"native", "super", "while")
|
||||
);
|
||||
|
||||
importMapping = new HashMap<String, String> ();
|
||||
importMapping.put("BigDecimal", "java.math.BigDecimal");
|
||||
importMapping.put("UUID", "java.util.UUID");
|
||||
importMapping.put("File", "java.io.File");
|
||||
importMapping.put("Date", "java.util.Date");
|
||||
importMapping.put("Timestamp", "java.sql.Timestamp");
|
||||
importMapping.put("Array", "java.util.*");
|
||||
importMapping.put("ArrayList", "java.util.*");
|
||||
importMapping.put("List", "java.util.*");
|
||||
importMapping.put("Set", "java.util.*");
|
||||
importMapping.put("DateTime", "org.joda.time.*");
|
||||
importMapping.put("LocalDateTime", "org.joda.time.*");
|
||||
importMapping.put("LocalDate", "org.joda.time.*");
|
||||
importMapping.put("LocalTime", "org.joda.time.*");
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
if(p instanceof StringProperty)
|
||||
return "null";
|
||||
else if (p instanceof BooleanProperty)
|
||||
return "null";
|
||||
else if(p instanceof DateProperty)
|
||||
return "null";
|
||||
else if(p instanceof DateTimeProperty)
|
||||
return "null";
|
||||
else if (p instanceof DoubleProperty)
|
||||
return "null";
|
||||
else if (p instanceof FloatProperty)
|
||||
return "null";
|
||||
else if (p instanceof IntegerProperty)
|
||||
return "null";
|
||||
else if (p instanceof LongProperty)
|
||||
return "null";
|
||||
else if (p instanceof MapProperty)
|
||||
return "null";
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new ArrayList<" + inner + ">() ";
|
||||
}
|
||||
else {
|
||||
// System.out.println("unhandled property default value");
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the swagger type for the property
|
||||
**/
|
||||
public String getSwaggerType(Property p) {
|
||||
String datatype = null;
|
||||
if(p instanceof StringProperty)
|
||||
datatype = "string";
|
||||
else if (p instanceof BooleanProperty)
|
||||
datatype = "boolean";
|
||||
else if(p instanceof DateProperty)
|
||||
datatype = "date";
|
||||
else if(p instanceof DateTimeProperty)
|
||||
datatype = "DateTime";
|
||||
else if (p instanceof DoubleProperty)
|
||||
datatype = "double";
|
||||
else if (p instanceof FloatProperty)
|
||||
datatype = "float";
|
||||
else if (p instanceof IntegerProperty)
|
||||
datatype = "integer";
|
||||
else if (p instanceof LongProperty)
|
||||
datatype = "long";
|
||||
else if (p instanceof MapProperty)
|
||||
datatype = "map";
|
||||
else if (p instanceof DecimalProperty)
|
||||
datatype = "number";
|
||||
else if (p instanceof RefProperty) {
|
||||
RefProperty r = (RefProperty)p;
|
||||
datatype = r.get$ref();
|
||||
if(datatype.indexOf("#/definitions/") == 0)
|
||||
datatype = datatype.substring("#/definitions/".length());
|
||||
}
|
||||
else {
|
||||
if(p != null)
|
||||
datatype = p.getType();
|
||||
}
|
||||
return datatype;
|
||||
}
|
||||
|
||||
public String initialCaps(String name) {
|
||||
return Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
||||
}
|
||||
|
||||
public String getTypeDeclaration(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getTypeDeclaration(Property p) {
|
||||
String swaggerType = getSwaggerType(p);
|
||||
if(typeMapping.containsKey(swaggerType))
|
||||
return typeMapping.get(swaggerType);
|
||||
return swaggerType;
|
||||
}
|
||||
|
||||
public String toApiName(String name) {
|
||||
return initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
public String toModelName(String name) {
|
||||
return initialCaps(name);
|
||||
}
|
||||
|
||||
public CodegenModel fromModel(String name, Model model) {
|
||||
CodegenModel m = new CodegenModel();
|
||||
m.name = name;
|
||||
m.description = model.getDescription();
|
||||
m.classname = toModelName(name);
|
||||
|
||||
int count = 0;
|
||||
if(model instanceof ArrayModel) {
|
||||
ArrayModel am = (ArrayModel) model;
|
||||
ArrayProperty arrayProperty = new ArrayProperty(am.getItems());
|
||||
CodegenProperty cp = fromProperty(name, arrayProperty);
|
||||
m.vars.add(cp);
|
||||
}
|
||||
else if (model instanceof RefModel) {
|
||||
|
||||
}
|
||||
else {
|
||||
ModelImpl impl = (ModelImpl) model;
|
||||
for(String key: impl.getProperties().keySet()) {
|
||||
Property prop = impl.getProperties().get(key);
|
||||
if(prop == null) {
|
||||
System.out.println("null property for " + key);
|
||||
}
|
||||
else {
|
||||
CodegenProperty cp = fromProperty(key, prop);
|
||||
if(cp.complexType != null && !defaultIncludes.contains(cp.complexType)) {
|
||||
m.imports.add(cp.complexType);
|
||||
}
|
||||
m.vars.add(cp);
|
||||
count += 1;
|
||||
if(count != impl.getProperties().keySet().size())
|
||||
cp.hasMore = new Boolean(true);
|
||||
if(cp.isContainer != null) {
|
||||
String arrayImport = typeMapping.get("array");
|
||||
if(arrayImport != null &&
|
||||
!languageSpecificPrimitives.contains(arrayImport) &&
|
||||
!defaultIncludes.contains(arrayImport))
|
||||
m.imports.add(arrayImport);
|
||||
}
|
||||
|
||||
if(cp.complexType != null &&
|
||||
!languageSpecificPrimitives.contains(cp.complexType) &&
|
||||
!defaultIncludes.contains(cp.complexType))
|
||||
m.imports.add(cp.complexType);
|
||||
|
||||
if(cp.baseType != null &&
|
||||
!languageSpecificPrimitives.contains(cp.baseType) &&
|
||||
!defaultIncludes.contains(cp.baseType))
|
||||
m.imports.add(cp.baseType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
public CodegenProperty fromProperty(String name, Property p) {
|
||||
CodegenProperty property = new CodegenProperty();
|
||||
|
||||
property.name = toVarName(name);
|
||||
property.baseName = name;
|
||||
property.description = p.getDescription();
|
||||
property.getter = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
property.setter = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
|
||||
property.defaultValue = toDefaultValue(p);
|
||||
property.required = p.getRequired();
|
||||
|
||||
String type = getSwaggerType(p);
|
||||
|
||||
if(p instanceof AbstractNumericProperty) {
|
||||
AbstractNumericProperty np = (AbstractNumericProperty) p;
|
||||
property.minimum = np.getMinimum();
|
||||
property.maximum = np.getMaximum();
|
||||
property.exclusiveMinimum = np.getExclusiveMinimum();
|
||||
property.exclusiveMaximum = np.getExclusiveMaximum();
|
||||
|
||||
// legacy support
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
if(np.getMinimum() != null)
|
||||
allowableValues.put("min", np.getMinimum());
|
||||
if(np.getMaximum() != null)
|
||||
allowableValues.put("max", np.getMaximum());
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
|
||||
if(p instanceof StringProperty) {
|
||||
StringProperty sp = (StringProperty) p;
|
||||
if(sp.getEnum() != null) {
|
||||
List<String> _enum = sp.getEnum();
|
||||
property._enum = _enum;
|
||||
|
||||
// legacy support
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
allowableValues.put("values", _enum);
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
property.datatype = getTypeDeclaration(p);
|
||||
property.baseType = getSwaggerType(p);
|
||||
|
||||
if(p instanceof ArrayProperty) {
|
||||
property.isContainer = true;
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
CodegenProperty cp = fromProperty("inner", ap.getItems());
|
||||
property.baseType = cp.baseType;
|
||||
if(!languageSpecificPrimitives.contains(cp.baseType))
|
||||
property.complexType = cp.baseType;
|
||||
}
|
||||
else {
|
||||
property.isNotContainer = true;
|
||||
if(languageSpecificPrimitives().contains(type))
|
||||
property.isPrimitiveType = true;
|
||||
}
|
||||
return property;
|
||||
}
|
||||
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation){
|
||||
CodegenOperation op = new CodegenOperation();
|
||||
Set<String> imports = new HashSet<String>();
|
||||
|
||||
String operationId = operation.getOperationId();
|
||||
if(operationId == null) {
|
||||
operationId = path.replaceAll("/", "") + "_" + httpMethod;
|
||||
String[] parts = (path + "/" + httpMethod).split("/");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(int i = 0; i < parts.length; i++) {
|
||||
String part = parts[i];
|
||||
if(part.length() > 0) {
|
||||
if(builder.toString().length() == 0)
|
||||
part = Character.toLowerCase(part.charAt(0)) + part.substring(1);
|
||||
else
|
||||
part = Character.toUpperCase(part.charAt(0)) + part.substring(1);
|
||||
builder.append(part);
|
||||
}
|
||||
}
|
||||
operationId = builder.toString();
|
||||
System.out.println("generated operationId " + operationId);
|
||||
}
|
||||
op.path = path;
|
||||
op.operationId = operationId;
|
||||
op.summary = operation.getSummary();
|
||||
op.notes = operation.getDescription();
|
||||
op.tags = operation.getTags();
|
||||
|
||||
Response methodResponse = null;
|
||||
|
||||
if(operation.getConsumes() != null && operation.getConsumes().size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
int count = 0;
|
||||
for(String key: operation.getConsumes()) {
|
||||
Map<String, String> mediaType = new HashMap<String, String>();
|
||||
mediaType.put("mediaType", key);
|
||||
count += 1;
|
||||
if (count < operation.getConsumes().size())
|
||||
mediaType.put("hasMore", "true");
|
||||
c.add(mediaType);
|
||||
}
|
||||
op.consumes = c;
|
||||
}
|
||||
|
||||
if(operation.getProduces() != null && operation.getProduces().size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
int count = 0;
|
||||
for(String key: operation.getProduces()) {
|
||||
Map<String, String> mediaType = new HashMap<String, String>();
|
||||
mediaType.put("mediaType", key);
|
||||
count += 1;
|
||||
if (count < operation.getProduces().size())
|
||||
mediaType.put("hasMore", "true");
|
||||
c.add(mediaType);
|
||||
}
|
||||
op.produces = c;
|
||||
}
|
||||
|
||||
if(operation.getResponses() != null) {
|
||||
for(String responseCode: operation.getResponses().keySet()) {
|
||||
Response response = operation.getResponses().get(responseCode);
|
||||
if("200".equals(responseCode)) {
|
||||
methodResponse = response;
|
||||
}
|
||||
}
|
||||
if(methodResponse == null && operation.getResponses().keySet().contains("default")) {
|
||||
methodResponse = operation.getResponses().get("default");
|
||||
}
|
||||
for(String responseCode: operation.getResponses().keySet()) {
|
||||
Response response = operation.getResponses().get(responseCode);
|
||||
if(response != methodResponse) {
|
||||
CodegenResponse r = new CodegenResponse();
|
||||
if("default".equals(responseCode))
|
||||
r.code = "0";
|
||||
else
|
||||
r.code = responseCode;
|
||||
r.message = response.getDescription();
|
||||
r.schema = response.getSchema();
|
||||
op.responses.add(r);
|
||||
}
|
||||
for(int i = 0; i < op.responses.size() - 1; i++) {
|
||||
CodegenResponse r = op.responses.get(i);
|
||||
r.hasMore = new Boolean(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(methodResponse != null && methodResponse.getSchema() != null) {
|
||||
CodegenProperty cm = fromProperty("response", methodResponse.getSchema());
|
||||
|
||||
Property responseProperty = methodResponse.getSchema();
|
||||
|
||||
if(responseProperty instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) responseProperty;
|
||||
CodegenProperty innerProperty = fromProperty("response", ap.getItems());
|
||||
op.returnBaseType = innerProperty.baseType;
|
||||
}
|
||||
else {
|
||||
if(cm.complexType != null)
|
||||
op.returnBaseType = cm.complexType;
|
||||
else
|
||||
op.returnBaseType = cm.baseType;
|
||||
}
|
||||
|
||||
op.returnType = cm.datatype;
|
||||
if(cm.isContainer != null) {
|
||||
op.returnContainer = cm.complexType;
|
||||
}
|
||||
else
|
||||
op.returnSimpleType = true;
|
||||
if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null)
|
||||
op.returnTypeIsPrimitive = true;
|
||||
}
|
||||
|
||||
if(op.returnBaseType == null) {
|
||||
op.returnTypeIsPrimitive = true;
|
||||
op.returnSimpleType = true;
|
||||
}
|
||||
|
||||
if(op.returnBaseType != null &&
|
||||
!defaultIncludes.contains(op.returnBaseType) &&
|
||||
!languageSpecificPrimitives.contains(op.returnBaseType))
|
||||
imports.add(op.returnBaseType);
|
||||
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> bodyParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> pathParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> queryParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> headerParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> cookieParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> formParams = new ArrayList<CodegenParameter>();
|
||||
|
||||
if(parameters != null) {
|
||||
for(Parameter param : parameters) {
|
||||
CodegenParameter p = new CodegenParameter();
|
||||
p.baseName = param.getName();
|
||||
p.description = param.getDescription();
|
||||
|
||||
if(param instanceof SerializableParameter) {
|
||||
SerializableParameter qp = (SerializableParameter) param;
|
||||
Property property = null;
|
||||
String collectionFormat = null;
|
||||
if("array".equals(qp.getType())) {
|
||||
Property inner = qp.getItems();
|
||||
property = new ArrayProperty(inner);
|
||||
collectionFormat = qp.getCollectionFormat();
|
||||
}
|
||||
else
|
||||
property = PropertyBuilder.build(qp.getType(), qp.getFormat(), null);
|
||||
CodegenProperty model = fromProperty(qp.getName(), property);
|
||||
p.collectionFormat = collectionFormat;
|
||||
p.dataType = model.datatype;
|
||||
p.paramName = toParamName(qp.getName());
|
||||
|
||||
if(model.complexType != null)
|
||||
imports.add(model.complexType);
|
||||
}
|
||||
else {
|
||||
BodyParameter bp = (BodyParameter) param;
|
||||
Model model = bp.getSchema();
|
||||
|
||||
if(model instanceof ModelImpl) {
|
||||
ModelImpl impl = (ModelImpl) model;
|
||||
CodegenModel cm = fromModel(bp.getName(), impl);
|
||||
p.dataType = getTypeDeclaration(cm.classname);
|
||||
// imports.add(p.dataType);
|
||||
}
|
||||
else if(model instanceof ArrayModel) {
|
||||
// to use the built-in model parsing, we unwrap the ArrayModel
|
||||
// and get a single property from it
|
||||
ArrayModel impl = (ArrayModel) model;
|
||||
CodegenModel cm = fromModel(bp.getName(), impl);
|
||||
// get the single property
|
||||
CodegenProperty cp = fromProperty("inner", impl.getItems());
|
||||
|
||||
imports.add(cp.baseType);
|
||||
p.dataType = getTypeDeclaration(typeMapping.get(impl.getType()));
|
||||
p.isContainer = true;
|
||||
}
|
||||
else{
|
||||
Model sub = bp.getSchema();
|
||||
if(sub instanceof RefModel) {
|
||||
String name = ((RefModel)sub).getSimpleRef();
|
||||
if(typeMapping.containsKey(name))
|
||||
name = typeMapping.get(name);
|
||||
else {
|
||||
name = toModelName(name);
|
||||
if(defaultIncludes.contains(name))
|
||||
imports.add(name);
|
||||
name = getTypeDeclaration(name);
|
||||
}
|
||||
p.dataType = name;
|
||||
|
||||
}
|
||||
}
|
||||
p.paramName = toParamName(bp.getName());
|
||||
}
|
||||
allParams.add(p);
|
||||
if(param instanceof QueryParameter) {
|
||||
queryParams.add(p);
|
||||
p.isQueryParam = new Boolean(true);
|
||||
}
|
||||
else if(param instanceof PathParameter) {
|
||||
pathParams.add(p);
|
||||
p.isPathParam = new Boolean(true);
|
||||
}
|
||||
else if(param instanceof HeaderParameter) {
|
||||
headerParams.add(p);
|
||||
p.isHeaderParam = new Boolean(true);
|
||||
}
|
||||
else if(param instanceof CookieParameter) {
|
||||
cookieParams.add(p);
|
||||
p.isCookieParam = new Boolean(true);
|
||||
}
|
||||
else if(param instanceof BodyParameter) {
|
||||
bodyParams.add(p);
|
||||
p.isBodyParam = new Boolean(true);
|
||||
}
|
||||
// else if(param instanceof FormParameter)
|
||||
// formParams.add(p);
|
||||
}
|
||||
}
|
||||
for(String i: imports) {
|
||||
if(!defaultIncludes.contains(i) && !languageSpecificPrimitives.contains(i)){
|
||||
op.imports.add(i);
|
||||
}
|
||||
}
|
||||
op.httpMethod = httpMethod.toUpperCase();
|
||||
op.allParams = addHasMore(allParams);
|
||||
op.bodyParams = addHasMore(bodyParams);
|
||||
op.pathParams = addHasMore(pathParams);
|
||||
op.queryParams = addHasMore(queryParams);
|
||||
op.headerParams = addHasMore(headerParams);
|
||||
// op.cookieParams = cookieParams;
|
||||
op.formParams = addHasMore(formParams);
|
||||
// legacy support
|
||||
op.nickname = operationId;
|
||||
|
||||
if(op.allParams.size() > 0)
|
||||
op.hasParams = true;
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
private List<CodegenParameter> addHasMore(List<CodegenParameter> objs) {
|
||||
if(objs != null) {
|
||||
for(int i = 0; i < objs.size(); i++) {
|
||||
if(i > 0)
|
||||
objs.get(i).secondaryParam = new Boolean(true);
|
||||
if(i < objs.size() - 1)
|
||||
objs.get(i).hasMore = new Boolean(true);
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
private Map<String, Object> addHasMore(Map<String, Object> objs) {
|
||||
if(objs != null) {
|
||||
for(int i = 0; i < objs.size() - 1; i++) {
|
||||
if(i > 0)
|
||||
objs.put("secondaryParam", new Boolean(true));
|
||||
if(i < objs.size() - 1)
|
||||
objs.put("hasMore", true);
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
List<CodegenOperation> opList = operations.get(tag);
|
||||
if(opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
operations.put(tag, opList);
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = tag;
|
||||
}
|
||||
}
|
275
src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java
Normal file
275
src/main/java/com/wordnik/swagger/codegen/DefaultGenerator.java
Normal file
@ -0,0 +1,275 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
import com.wordnik.swagger.util.*;
|
||||
|
||||
import com.wordnik.swagger.codegen.languages.*;
|
||||
import com.samskivert.mustache.*;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class DefaultGenerator implements Generator {
|
||||
private CodegenConfig config;
|
||||
private ClientOptInput opts = null;
|
||||
private Swagger swagger = null;
|
||||
|
||||
public Generator opts(ClientOptInput opts) {
|
||||
this.opts = opts;
|
||||
|
||||
this.swagger = opts.getSwagger();
|
||||
ClientOpts clientOpts = opts.getOpts();
|
||||
this.config = opts.getConfig();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
if(swagger == null || config == null) {
|
||||
throw new RuntimeException("missing swagger input or config!");
|
||||
}
|
||||
try {
|
||||
Map<String, Object> models = null;
|
||||
Map<String, Object> operations = null;
|
||||
|
||||
// models
|
||||
Map<String, Model> definitions = swagger.getDefinitions();
|
||||
for(String name: definitions.keySet()) {
|
||||
Model model = definitions.get(name);
|
||||
Map<String, Model> modelMap = new HashMap<String, Model>();
|
||||
modelMap.put(name, model);
|
||||
models = processModels(config, modelMap);
|
||||
models.putAll(config.additionalProperties());
|
||||
for(String templateName : config.modelTemplateFiles().keySet()) {
|
||||
String suffix = config.modelTemplateFiles().get(templateName);
|
||||
String filename = config.modelFileFolder() + File.separator + config.toModelFilename(name) + suffix;
|
||||
|
||||
String template = readTemplate(config.templateDir() + File.separator + templateName);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
public Reader getTemplate (String name) {
|
||||
return getTemplateReader(config.templateDir() + File.separator + name + ".mustache");
|
||||
};
|
||||
})
|
||||
.defaultValue("")
|
||||
.compile(template);
|
||||
|
||||
writeToFile(filename, tmpl.execute(models));
|
||||
}
|
||||
}
|
||||
// apis
|
||||
Map<String, List<CodegenOperation>> paths = processPaths(swagger.getPaths());
|
||||
for(String tag : paths.keySet()) {
|
||||
List<CodegenOperation> ops = paths.get(tag);
|
||||
|
||||
operations = processOperations(config, tag, ops);
|
||||
operations.putAll(config.additionalProperties());
|
||||
operations.put("baseName", tag);
|
||||
for(String templateName : config.apiTemplateFiles().keySet()) {
|
||||
String suffix = config.apiTemplateFiles().get(templateName);
|
||||
String filename = config.apiFileFolder() +
|
||||
File.separator +
|
||||
config.toApiFilename(tag) +
|
||||
suffix;
|
||||
|
||||
String template = readTemplate(config.templateDir() + File.separator + templateName);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
public Reader getTemplate (String name) {
|
||||
return getTemplateReader(config.templateDir() + File.separator + name + ".mustache");
|
||||
};
|
||||
})
|
||||
.defaultValue("")
|
||||
.compile(template);
|
||||
|
||||
writeToFile(filename, tmpl.execute(operations));
|
||||
}
|
||||
}
|
||||
|
||||
// supporting files
|
||||
Map<String, Object> bundle = new HashMap<String, Object>();
|
||||
bundle.putAll(config.additionalProperties());
|
||||
bundle.put("apiPackage", config.apiPackage());
|
||||
for(SupportingFile support : config.supportingFiles()) {
|
||||
String outputFolder = config.outputFolder();
|
||||
if(support.folder != null && !"".equals(support.folder))
|
||||
outputFolder += File.separator + support.folder;
|
||||
File of = new File(outputFolder);
|
||||
if(!of.isDirectory())
|
||||
of.mkdirs();
|
||||
String outputFilename = outputFolder + File.separator + support.destinationFilename;
|
||||
|
||||
if(support.templateFile.endsWith("mustache")) {
|
||||
String template = readTemplate(config.templateDir() + File.separator + support.templateFile);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
public Reader getTemplate (String name) {
|
||||
return getTemplateReader(config.templateDir() + File.separator + name + ".mustache");
|
||||
};
|
||||
})
|
||||
.defaultValue("")
|
||||
.compile(template);
|
||||
|
||||
writeToFile(outputFilename, tmpl.execute(bundle));
|
||||
}
|
||||
else {
|
||||
String template = readTemplate(config.templateDir() + File.separator + support.templateFile);
|
||||
FileUtils.writeStringToFile(new File(outputFilename), template);
|
||||
System.out.println("copying file to " + outputFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, List<CodegenOperation>> processPaths(Map<String, Path> paths) {
|
||||
// group by tag, create a Default grouping if none
|
||||
Map<String, List<CodegenOperation>> ops = new HashMap<String, List<CodegenOperation>>();
|
||||
List<String> tags = null;
|
||||
|
||||
for(String resourcePath : paths.keySet()) {
|
||||
Path path = paths.get(resourcePath);
|
||||
processOperation(resourcePath, "get", path.getGet(), ops);
|
||||
processOperation(resourcePath, "put", path.getPut(), ops);
|
||||
processOperation(resourcePath, "post", path.getPost(), ops);
|
||||
processOperation(resourcePath, "delete", path.getDelete(), ops);
|
||||
processOperation(resourcePath, "patch", path.getPatch(), ops);
|
||||
processOperation(resourcePath, "options", path.getOptions(), ops);
|
||||
}
|
||||
return ops;
|
||||
}
|
||||
|
||||
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations) {
|
||||
if(operation != null) {
|
||||
List<String> tags = operation.getTags();
|
||||
if(tags == null) {
|
||||
tags = new ArrayList<String>();
|
||||
tags.add("default");
|
||||
}
|
||||
|
||||
for(String tag : tags) {
|
||||
CodegenOperation co = config.fromOperation(resourcePath, httpMethod, operation);
|
||||
co.tags = new ArrayList<String>();
|
||||
co.tags.add(tag);
|
||||
|
||||
config.addOperationToGroup(tag, resourcePath, operation, co, operations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public File writeToFile(String filename, String contents) throws IOException {
|
||||
System.out.println("writing file " + filename);
|
||||
File output = new File(filename);
|
||||
|
||||
if(output.getParent() != null && !new File(output.getParent()).exists()) {
|
||||
File parent = new File(output.getParent());
|
||||
parent.mkdirs();
|
||||
}
|
||||
Writer out = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(output), "UTF-8"));
|
||||
|
||||
out.write(contents);
|
||||
out.close();
|
||||
return output;
|
||||
}
|
||||
|
||||
public String readTemplate(String name) {
|
||||
try{
|
||||
Reader reader = getTemplateReader(name);
|
||||
if(reader == null)
|
||||
throw new RuntimeException("no file found");
|
||||
java.util.Scanner s = new java.util.Scanner(reader).useDelimiter("\\A");
|
||||
return s.hasNext() ? s.next() : "";
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new RuntimeException("can't load template " + name);
|
||||
}
|
||||
|
||||
public Reader getTemplateReader(String name) {
|
||||
try{
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(name);
|
||||
if(is == null)
|
||||
is = new FileInputStream(new File(name));
|
||||
if(is == null)
|
||||
throw new RuntimeException("no file found");
|
||||
return new InputStreamReader(is);
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new RuntimeException("can't load template " + name);
|
||||
}
|
||||
|
||||
public Map<String, Object> processOperations(CodegenConfig config, String tag, List<CodegenOperation> ops) {
|
||||
Map<String, Object> operations = new HashMap<String, Object>();
|
||||
Map<String, Object> objs = new HashMap<String, Object>();
|
||||
objs.put("classname", config.toApiName(tag));
|
||||
objs.put("operation", ops);
|
||||
operations.put("operations", objs);
|
||||
operations.put("package", config.apiPackage());
|
||||
|
||||
Set<String> allImports = new HashSet<String>();
|
||||
for(CodegenOperation op: ops) {
|
||||
allImports.addAll(op.imports);
|
||||
}
|
||||
|
||||
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
|
||||
for(String i: allImports) {
|
||||
Map<String, String> im = new HashMap<String, String>();
|
||||
String m = config.importMapping().get(i);
|
||||
if(m == null)
|
||||
m = config.toModelImport(i);
|
||||
if(m != null) {
|
||||
im.put("import", m);
|
||||
imports.add(im);
|
||||
}
|
||||
}
|
||||
|
||||
operations.put("imports", imports);
|
||||
config.postProcessOperations(operations);
|
||||
return operations;
|
||||
}
|
||||
|
||||
public Map<String, Object> processModels(CodegenConfig config, Map<String, Model> definitions) {
|
||||
Map<String, Object> objs = new HashMap<String, Object>();
|
||||
objs.put("package", config.modelPackage());
|
||||
List<Object> models = new ArrayList<Object>();
|
||||
List<Object> model = new ArrayList<Object>();
|
||||
Set<String> allImports = new HashSet<String>();
|
||||
for(String key: definitions.keySet()) {
|
||||
Model mm = definitions.get(key);
|
||||
if(mm instanceof ModelImpl) {
|
||||
CodegenModel cm = config.fromModel(key, (ModelImpl) mm);
|
||||
Map<String, Object> mo = new HashMap<String, Object>();
|
||||
mo.put("model", cm);
|
||||
models.add(mo);
|
||||
allImports.addAll(cm.imports);
|
||||
}
|
||||
}
|
||||
objs.put("models", models);
|
||||
|
||||
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
|
||||
for(String i: allImports) {
|
||||
Map<String, String> im = new HashMap<String, String>();
|
||||
String m = config.importMapping().get(i);
|
||||
if(m == null)
|
||||
m = config.toModelImport(i);
|
||||
if(m != null) {
|
||||
im.put("import", m);
|
||||
imports.add(im);
|
||||
}
|
||||
}
|
||||
|
||||
objs.put("imports", imports);
|
||||
config.postProcessModels(objs);
|
||||
|
||||
return objs;
|
||||
}
|
||||
}
|
8
src/main/java/com/wordnik/swagger/codegen/Generator.java
Normal file
8
src/main/java/com/wordnik/swagger/codegen/Generator.java
Normal file
@ -0,0 +1,8 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
|
||||
public interface Generator {
|
||||
Generator opts(ClientOptInput opts);
|
||||
void generate();
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
public class SupportingFile {
|
||||
public String templateFile;
|
||||
public String folder;
|
||||
public String destinationFilename;
|
||||
|
||||
public SupportingFile(String templateFile, String folder, String destinationFilename) {
|
||||
this.templateFile = templateFile;
|
||||
this.folder = folder;
|
||||
this.destinationFilename = destinationFilename;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.wordnik.swagger.codegen.auth;
|
||||
|
||||
public interface AuthMethod {
|
||||
String getType();
|
||||
void setType(String type);
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "com.wordnik.api";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/java";
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/java";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
templateDir = "Java";
|
||||
apiPackage = "com.wordnik.api";
|
||||
modelPackage = "com.wordnik.model";
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("apiInvoker.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiInvoker.java"));
|
||||
supportingFiles.add(new SupportingFile("JsonUtil.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "JsonUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replaceAll("\\.", File.separator);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replaceAll("\\.", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if(p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
else if (p instanceof MapProperty) {
|
||||
throw new RuntimeException("not supported yet");
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type = null;
|
||||
if(typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if(languageSpecificPrimitives.contains(type))
|
||||
return toModelName(type);
|
||||
}
|
||||
else
|
||||
type = swaggerType;
|
||||
return toModelName(type);
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.models.Operation;
|
||||
import com.wordnik.swagger.models.Path;
|
||||
import com.wordnik.swagger.util.Json;
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "com.wordnik.api";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-server";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/java";
|
||||
protected String title = "Swagger Server";
|
||||
|
||||
public JaxRSServerCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/javaJaxRS";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
templateDir = "JavaJaxRS";
|
||||
apiPackage = "com.wordnik.api";
|
||||
modelPackage = "com.wordnik.model";
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiOriginFilter.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("NotFoundException.mustache",
|
||||
(sourceFolder + File.separator + apiPackage).replace(".", java.io.File.separator), "NotFoundException.java"));
|
||||
supportingFiles.add(new SupportingFile("web.mustache",
|
||||
("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
String basePath = resourcePath;
|
||||
if(basePath.startsWith("/"))
|
||||
basePath = basePath.substring(1);
|
||||
int pos = basePath.indexOf("/");
|
||||
if(pos > 0)
|
||||
basePath = basePath.substring(0, pos);
|
||||
|
||||
if(basePath == "")
|
||||
basePath = "default";
|
||||
else {
|
||||
if(co.path.startsWith("/" + basePath))
|
||||
co.path = co.path.substring(("/" + basePath).length());
|
||||
}
|
||||
List<CodegenOperation> opList = operations.get(basePath);
|
||||
if(opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
operations.put(basePath, opList);
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>)objs.get("operations");
|
||||
if(operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for(CodegenOperation operation : ops) {
|
||||
if(operation.returnType == null)
|
||||
operation.returnType = "Void";
|
||||
else if(operation.returnType.startsWith("List")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if(end > 0) {
|
||||
operation.returnType = rt.substring("List<".length(), end);
|
||||
operation.returnContainer = "List";
|
||||
}
|
||||
}
|
||||
else if(operation.returnType.startsWith("Map")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if(end > 0) {
|
||||
operation.returnType = rt.substring("Map<".length(), end);
|
||||
operation.returnContainer = "Map";
|
||||
}
|
||||
}
|
||||
else if(operation.returnType.startsWith("Set")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if(end > 0) {
|
||||
operation.returnType = rt.substring("Set<".length(), end);
|
||||
operation.returnContainer = "Set";
|
||||
}
|
||||
}
|
||||
// Json.prettyPrint(operation);
|
||||
// if(return)
|
||||
}
|
||||
}
|
||||
// Json.prettyPrint(objs);
|
||||
return objs;
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.util.Json;
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
protected String sourceFolder = "client";
|
||||
|
||||
public ObjcClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/objc";
|
||||
modelTemplateFiles.put("model-header.mustache", ".h");
|
||||
modelTemplateFiles.put("model-body.mustache", ".m");
|
||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-body.mustache", ".m");
|
||||
templateDir = "objc";
|
||||
modelPackage = "";
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList("bool",
|
||||
"int",
|
||||
"NSString",
|
||||
"NSObject",
|
||||
"NSArray",
|
||||
"NSNumber")
|
||||
);
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"NSNumber",
|
||||
"NSString",
|
||||
"NSObject",
|
||||
"bool")
|
||||
);
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"void", "char", "short", "int", "void", "char", "short", "int",
|
||||
"long", "float", "double", "signed", "unsigned", "id", "const",
|
||||
"volatile", "in", "out", "inout", "bycopy", "byref", "oneway",
|
||||
"self", "super"
|
||||
));
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("enum", "NSString");
|
||||
typeMapping.put("Date", "SWGDate");
|
||||
typeMapping.put("DateTime", "SWGDate");
|
||||
// typeMapping.put("Date", "SWGDate");
|
||||
typeMapping.put("boolean", "NSNumber");
|
||||
typeMapping.put("string", "NSString");
|
||||
typeMapping.put("integer", "NSNumber");
|
||||
typeMapping.put("int", "NSNumber");
|
||||
typeMapping.put("float", "NSNumber");
|
||||
typeMapping.put("long", "NSNumber");
|
||||
typeMapping.put("double", "NSNumber");
|
||||
typeMapping.put("array", "NSArray");
|
||||
typeMapping.put("number", "NSNumber");
|
||||
typeMapping.put("List", "NSArray");
|
||||
typeMapping.put("object", "NSObject");
|
||||
|
||||
importMapping = new HashMap<String, String> ();
|
||||
importMapping.put("Date", "SWGDate");
|
||||
|
||||
foundationClasses = new HashSet<String> (
|
||||
Arrays.asList(
|
||||
"NSNumber",
|
||||
"NSObject",
|
||||
"NSString")
|
||||
);
|
||||
|
||||
supportingFiles.add(new SupportingFile("SWGObject.h", sourceFolder, "SWGObject.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGObject.m", sourceFolder, "SWGObject.m"));
|
||||
supportingFiles.add(new SupportingFile("SWGApiClient.h", sourceFolder, "SWGApiClient.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGApiClient.m", sourceFolder, "SWGApiClient.m"));
|
||||
supportingFiles.add(new SupportingFile("SWGFile.h", sourceFolder, "SWGFile.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGFile.m", sourceFolder, "SWGFile.m"));
|
||||
supportingFiles.add(new SupportingFile("SWGDate.h", sourceFolder, "SWGDate.h"));
|
||||
supportingFiles.add(new SupportingFile("SWGDate.m", sourceFolder, "SWGDate.m"));
|
||||
supportingFiles.add(new SupportingFile("Podfile.mustache", "", "Podfile"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(String name) {
|
||||
if(languageSpecificPrimitives.contains(name) && !foundationClasses.contains(name))
|
||||
return name;
|
||||
else
|
||||
return name + "*";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type = null;
|
||||
if(typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if(languageSpecificPrimitives.contains(type) && !foundationClasses.contains(type))
|
||||
return toModelName(type);
|
||||
}
|
||||
else
|
||||
type = swaggerType;
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
String swaggerType = getSwaggerType(p);
|
||||
if(languageSpecificPrimitives.contains(swaggerType) && !foundationClasses.contains(swaggerType))
|
||||
return toModelName(swaggerType);
|
||||
else
|
||||
return swaggerType + "*";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if(typeMapping.keySet().contains(type) ||
|
||||
foundationClasses.contains(type) ||
|
||||
importMapping.values().contains(type) ||
|
||||
defaultIncludes.contains(type) ||
|
||||
languageSpecificPrimitives.contains(type)) {
|
||||
return Character.toUpperCase(type.charAt(0)) + type.substring(1);
|
||||
}
|
||||
else {
|
||||
return "SWG" + Character.toUpperCase(type.charAt(0)) + type.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
// name = name + ".h";
|
||||
if("".equals(modelPackage()))
|
||||
return name;
|
||||
else
|
||||
return modelPackage() + "." + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return "SWG" + initialCaps(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return "SWG" + initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
public String toApiFilename(String name) {
|
||||
return "SWG" + initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
String paramName = name.replaceAll("[^a-zA-Z0-9_]","");
|
||||
if(paramName.startsWith("new") || reservedWords.contains(paramName)) {
|
||||
return escapeReservedWord(paramName);
|
||||
}
|
||||
else
|
||||
return paramName;
|
||||
}
|
||||
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
}
|
@ -21,11 +21,11 @@ public class {{classname}} {
|
||||
public ApiInvoker getInvoker() {
|
||||
return apiInvoker;
|
||||
}
|
||||
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
@ -35,7 +35,7 @@ public class {{classname}} {
|
||||
{{/responseModel}}{{^responseModel}}<none>
|
||||
{{/responseModel}}
|
||||
{{/errorList}}
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{bodyParam}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
{{#requiredParamCount}}
|
||||
// verify required params are set
|
||||
@ -45,7 +45,8 @@ public class {{classname}} {
|
||||
{{/requiredParamCount}}
|
||||
|
||||
// create path and map variables
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
|
||||
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
|
@ -3,24 +3,24 @@ package {{package}};
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
public class {{classname}} {
|
||||
{{#vars}}
|
||||
|
||||
{{#description}}/* {{{description}}} */
|
||||
{{/description}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};
|
||||
{{#allowableValues}}{{#min}} // range from {{min}} to {{max}}
|
||||
{{/min}}
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
public class {{classname}} { {{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}
|
||||
* required: {{required}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{#allowableValues}}
|
||||
|
||||
//{{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };
|
||||
{{/min}}
|
||||
{{/allowableValues}}
|
||||
{{/min}}{{/allowableValues}}{{/vars}}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
|
||||
public {{{datatype}}} {{getter}}() {
|
||||
{{#vars}}public {{{datatype}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatype}}} {{name}}) {
|
||||
@ -33,10 +33,8 @@ public class {{classname}} {
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#vars}}
|
||||
sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}
|
||||
sb.append("}\n");
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
9
src/main/resources/JavaJaxRS/ApiException.mustache
Normal file
9
src/main/resources/JavaJaxRS/ApiException.mustache
Normal file
@ -0,0 +1,9 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
26
src/main/resources/JavaJaxRS/ApiOriginFilter.mustache
Normal file
26
src/main/resources/JavaJaxRS/ApiOriginFilter.mustache
Normal file
@ -0,0 +1,26 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
68
src/main/resources/JavaJaxRS/ApiResponseMessage.mustache
Normal file
68
src/main/resources/JavaJaxRS/ApiResponseMessage.mustache
Normal file
@ -0,0 +1,68 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
9
src/main/resources/JavaJaxRS/NotFoundException.mustache
Normal file
9
src/main/resources/JavaJaxRS/NotFoundException.mustache
Normal file
@ -0,0 +1,9 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
10
src/main/resources/JavaJaxRS/README.mustache
Normal file
10
src/main/resources/JavaJaxRS/README.mustache
Normal file
@ -0,0 +1,10 @@
|
||||
# Swagger generated server
|
||||
|
||||
## Overview
|
||||
This server was generated by the [swagger-codegen](https://github.com/wordnik/swagger-codegen) project. By using the
|
||||
[swagger-spec](https://github.com/wordnik/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
|
||||
is an example of building a swagger-enabled scalatra server.
|
||||
|
||||
This example uses the [scalatra](http://scalatra.org/) framework. To see how to make this your own, look here:
|
||||
|
||||
[README](https://github.com/wordnik/swagger-codegen/tree/master/samples/server-generator/scalatra)
|
36
src/main/resources/JavaJaxRS/api.mustache
Normal file
36
src/main/resources/JavaJaxRS/api.mustache
Normal file
@ -0,0 +1,36 @@
|
||||
package {{package}};
|
||||
|
||||
import com.wordnik.swagger.annotations.*;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import java.util.List;
|
||||
import {{package}}.NotFoundException;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.*;
|
||||
|
||||
@Path("/{{baseName}}")
|
||||
@Api(value = "/{{baseName}}", description = "the {{baseName}} API")
|
||||
@Produces({"application/json"})
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
{{#operation}}
|
||||
@{{httpMethod}}
|
||||
@Path("{{path}}")
|
||||
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}})
|
||||
@ApiResponses(value = { {{#responses}}
|
||||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},
|
||||
{{/hasMore}}{{/responses}} })
|
||||
|
||||
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{#hasMore}},
|
||||
{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
// do some magic!
|
||||
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
1
src/main/resources/JavaJaxRS/bodyParams.mustache
Normal file
1
src/main/resources/JavaJaxRS/bodyParams.mustache
Normal file
@ -0,0 +1 @@
|
||||
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isBodyParam}}
|
1
src/main/resources/JavaJaxRS/headerParams.mustache
Normal file
1
src/main/resources/JavaJaxRS/headerParams.mustache
Normal file
@ -0,0 +1 @@
|
||||
{{#isHeaderParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}}
|
42
src/main/resources/JavaJaxRS/model.mustache
Normal file
42
src/main/resources/JavaJaxRS/model.mustache
Normal file
@ -0,0 +1,42 @@
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
public class {{classname}} { {{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}
|
||||
* required: {{required}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{#allowableValues}}
|
||||
|
||||
//{{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };
|
||||
{{/min}}{{/allowableValues}}{{/vars}}
|
||||
|
||||
{{#vars}}public {{{datatype}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatype}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
1
src/main/resources/JavaJaxRS/pathParams.mustache
Normal file
1
src/main/resources/JavaJaxRS/pathParams.mustache
Normal file
@ -0,0 +1 @@
|
||||
{{#isPathParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
|
132
src/main/resources/JavaJaxRS/pom.mustache
Normal file
132
src/main/resources/JavaJaxRS/pom.mustache
Normal file
@ -0,0 +1,132 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webAppConfig>
|
||||
<contextPath>/</contextPath>
|
||||
</webAppConfig>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<connectors>
|
||||
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
|
||||
<port>8002</port>
|
||||
<maxIdleTime>60000</maxIdleTime>
|
||||
<confidentialPort>8443</confidentialPort>
|
||||
</connector>
|
||||
</connectors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-jaxrs</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-core</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-json</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-servlet</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.9.1</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-core-version>1.5.0-SNAPSHOT</swagger-core-version>
|
||||
<jetty-version>8.1.11.v20130520</jetty-version>
|
||||
<jersey-version>1.13</jersey-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
</properties>
|
||||
</project>
|
1
src/main/resources/JavaJaxRS/project/build.properties
Normal file
1
src/main/resources/JavaJaxRS/project/build.properties
Normal file
@ -0,0 +1 @@
|
||||
sbt.version=0.12.0
|
9
src/main/resources/JavaJaxRS/project/plugins.sbt
Normal file
9
src/main/resources/JavaJaxRS/project/plugins.sbt
Normal file
@ -0,0 +1,9 @@
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.4")
|
||||
|
||||
libraryDependencies <+= sbtVersion(v => v match {
|
||||
case "0.11.0" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.0-0.2.8"
|
||||
case "0.11.1" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.1-0.2.10"
|
||||
case "0.11.2" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.2-0.2.11"
|
||||
case "0.11.3" => "com.github.siasia" %% "xsbt-web-plugin" % "0.11.3-0.2.11.1"
|
||||
case x if (x.startsWith("0.12")) => "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1"
|
||||
})
|
1
src/main/resources/JavaJaxRS/queryParams.mustache
Normal file
1
src/main/resources/JavaJaxRS/queryParams.mustache
Normal file
@ -0,0 +1 @@
|
||||
{{#isQueryParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @QueryParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}}
|
54
src/main/resources/JavaJaxRS/web.mustache
Normal file
54
src/main/resources/JavaJaxRS/web.mustache
Normal file
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
|
||||
|
||||
<servlet>
|
||||
<servlet-name>jersey</servlet-name>
|
||||
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.config.property.packages</param-name>
|
||||
<param-value>com.wordnik.swagger.jaxrs.json;com.wordnik.swagger.jaxrs.listing;{{apiPackage}}</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
|
||||
<param-value>com.sun.jersey.api.container.filter.PostReplaceFilter</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>DefaultJaxrsConfig</servlet-name>
|
||||
<servlet-class>com.wordnik.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
|
||||
<init-param>
|
||||
<param-name>api.version</param-name>
|
||||
<param-value>1.0.0</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>swagger.api.title</param-name>
|
||||
<param-value>{{{title}}}</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>swagger.api.basepath</param-name>
|
||||
<param-value>http://localhost:8002</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>jersey</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>ApiOriginFilter</filter-name>
|
||||
<filter-class>com.wordnik.api.ApiOriginFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>ApiOriginFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
@ -53,7 +53,8 @@ static NSString * basePath = @"{{basePath}}";
|
||||
|
||||
|
||||
{{#operation}}
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}}{{newline}} {{/allParams}}
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}}
|
||||
{{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}}{{newline}} {{/allParams}}
|
||||
{{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{returnType}} output, NSError* error))completionBlock{{/returnBaseType}}
|
||||
{{^returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock{{/returnBaseType}} {
|
||||
|
||||
@ -69,17 +70,15 @@ static NSString * basePath = @"{{basePath}}";
|
||||
NSString* requestContentType = @"application/json";
|
||||
NSString* responseContentType = @"application/json";
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
{{#queryParams}}if({{paramName}} != nil)
|
||||
queryParams[@"{{baseName}}"] = {{paramName}};
|
||||
{{/queryParams}}
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
queryParams[@"{{baseName}}"] = {{paramName}};{{/queryParams}}
|
||||
NSMutableDictionary* headerParams = [[NSMutableDictionary alloc] init];
|
||||
{{#headerParams}}if({{paramName}} != nil)
|
||||
headerParams[@"{{baseName}}"] = {{paramName}};
|
||||
{{/headerParams}}
|
||||
headerParams[@"{{baseName}}"] = {{paramName}};{{/headerParams}}
|
||||
|
||||
id bodyDictionary = nil;
|
||||
{{#bodyParam}}
|
||||
{{#bodyParam}}
|
||||
if(body != nil && [body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)body) {
|
||||
@ -170,22 +169,21 @@ static NSString * basePath = @"{{basePath}}";
|
||||
{{#returnSimpleType}}
|
||||
{{#returnTypeIsPrimitive}}
|
||||
{{#returnBaseType}}
|
||||
return [client stringWithCompletionBlock:requestUrl
|
||||
method:@"{{httpMethod}}"
|
||||
queryParams:queryParams
|
||||
body:bodyDictionary
|
||||
headerParams:headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock:^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);
|
||||
return;
|
||||
}
|
||||
{{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil;
|
||||
completionBlock(result, nil);
|
||||
}];
|
||||
{{/returnBaseType}}
|
||||
return [client stringWithCompletionBlock: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);
|
||||
return;
|
||||
}
|
||||
{{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil;
|
||||
completionBlock(result, nil);
|
||||
}];{{/returnBaseType}}
|
||||
{{^returnBaseType}}
|
||||
return [client stringWithCompletionBlock:requestUrl
|
||||
method:@"{{httpMethod}}"
|
||||
@ -201,10 +199,8 @@ static NSString * basePath = @"{{basePath}}";
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
{{/returnBaseType}}
|
||||
{{/returnTypeIsPrimitive}}
|
||||
{{#returnBaseType}}
|
||||
{{^returnTypeIsPrimitive}}
|
||||
{{/returnBaseType}}{{/returnTypeIsPrimitive}}
|
||||
{{#returnBaseType}}{{^returnTypeIsPrimitive}}
|
||||
return [client dictionary:requestUrl
|
||||
method:@"{{httpMethod}}"
|
||||
queryParams:queryParams
|
||||
@ -226,9 +222,7 @@ static NSString * basePath = @"{{basePath}}";
|
||||
{{#returnBaseType}}completionBlock(result , nil);{{/returnBaseType}}
|
||||
{{/returnBaseType}}
|
||||
}];
|
||||
{{/returnTypeIsPrimitive}}
|
||||
{{/returnBaseType}}
|
||||
{{/returnSimpleType}}
|
||||
{{/returnTypeIsPrimitive}}{{/returnBaseType}}{{/returnSimpleType}}
|
||||
{{newline}}
|
||||
}
|
||||
|
||||
|
@ -14,22 +14,16 @@
|
||||
{{#operation}}
|
||||
/**
|
||||
|
||||
{{{summary}}}
|
||||
{{#notes}}
|
||||
{{{notes}}}
|
||||
{{/notes}}
|
||||
{{#summary}}{{{summary}}}{{/summary}}
|
||||
{{#notes}}{{{notes}}}{{/notes}}
|
||||
|
||||
{{#allParams}}
|
||||
@param {{paramName}} {{description}}
|
||||
{{#allParams}}@param {{paramName}} {{description}}
|
||||
{{/allParams}}
|
||||
|
||||
*/
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}{{newline}} {{/hasMore}}{{/allParams}}
|
||||
{{#returnBaseType}}{{#hasParams}}{{newline}} completionHandler: {{/hasParams}}(void (^)({{returnType}} output, NSError* error))completionBlock;{{/returnBaseType}}
|
||||
{{^returnBaseType}}{{#hasParams}}{{newline}} completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
|
||||
|
||||
{{newline}}
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}}
|
||||
{{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}{{/allParams}}
|
||||
{{#returnBaseType}}{{#hasParams}} completionHandler: {{/hasParams}}(void (^)({{returnType}} output, NSError* error))completionBlock;{{/returnBaseType}}
|
||||
{{^returnBaseType}}{{#hasParams}} completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
|
||||
{{/operation}}
|
||||
|
||||
{{/operations}}
|
||||
@end
|
@ -5,10 +5,10 @@
|
||||
|
||||
@implementation {{classname}}
|
||||
|
||||
-(id){{#vars}}{{name}}: ({{datatype}}) {{name}}{{#hasMore}}{{newline}} {{/hasMore}}{{/vars}}{{newline}}{
|
||||
{{#vars}}_{{name}} = {{name}};
|
||||
{{/vars}}
|
||||
|
||||
-(id){{#vars}}{{name}}: ({{datatype}}) {{name}}{{^hasMore}} { {{/hasMore}}
|
||||
{{/vars}}
|
||||
{{#vars}}_{{name}} = {{name}};
|
||||
{{/vars}}
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -16,16 +16,9 @@
|
||||
{
|
||||
self = [super init];
|
||||
if(self) {
|
||||
{{#vars}}
|
||||
|
||||
{{#isPrimitiveType}}
|
||||
_{{name}} = dict[@"{{baseName}}"];
|
||||
{{/isPrimitiveType}}
|
||||
{{#complexType}}
|
||||
id {{name}}_dict = dict[@"{{baseName}}"];
|
||||
{{#isContainer}}
|
||||
{{#vars}}{{#isPrimitiveType}}_{{name}} = dict[@"{{baseName}}"];{{/isPrimitiveType}}{{#complexType}}
|
||||
id {{name}}_dict = dict[@"{{baseName}}"];{{#isContainer}}
|
||||
if([{{name}}_dict isKindOfClass:[NSArray class]]) {
|
||||
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[(NSArray*){{name}}_dict count]];
|
||||
|
||||
if([(NSArray*){{name}}_dict count] > 0) {
|
||||
@ -44,21 +37,16 @@
|
||||
_{{name}} = [[NSArray alloc] init];
|
||||
}
|
||||
{{/isContainer}}
|
||||
{{#isNotContainer}}
|
||||
if({{name}}_dict != nil)
|
||||
{{#isNotContainer}}if({{name}}_dict != nil)
|
||||
_{{name}} = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{complexType}}} {{/instantiationType}} alloc]initWithValues:{{name}}_dict];
|
||||
{{/isNotContainer}}
|
||||
{{/complexType}}
|
||||
{{/vars}}{{newline}}
|
||||
{{/isNotContainer}}{{/complexType}}{{/vars}}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(NSDictionary*) asDictionary {
|
||||
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
|
||||
{{#vars}}
|
||||
{{#complexType}}
|
||||
if(_{{name}} != nil){
|
||||
{{#vars}}{{#complexType}}if(_{{name}} != nil){
|
||||
if([_{{name}} isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * array = [[NSMutableArray alloc] init];
|
||||
for( {{complexType}} *{{name}} in (NSArray*)_{{name}}) {
|
||||
@ -73,14 +61,12 @@
|
||||
}
|
||||
}
|
||||
else {
|
||||
{{/complexType}}
|
||||
if(_{{name}} != nil) dict[@"{{baseName}}"] = {{#complexType}}[(SWGObject*){{/complexType}}_{{name}} {{#complexType}}asDictionary]{{/complexType}};
|
||||
{{#complexType}}
|
||||
if(_{{name}} != nil) dict[@"{{baseName}}"] = [(SWGObject*)_{{name}} asDictionary];
|
||||
}
|
||||
}
|
||||
{{/complexType}}
|
||||
{{/vars}}
|
||||
|
||||
{{/complexType}}{{#isPrimitiveType}}if(_{{name}} != nil)
|
||||
dict[@"{{baseName}}"] = [(SWGObject*)_{{name}} asDictionary];
|
||||
{{/isPrimitiveType}}{{/vars}}
|
||||
NSDictionary* output = [dict copy];
|
||||
return output;
|
||||
}
|
||||
|
@ -11,7 +11,8 @@
|
||||
{{#vars}}
|
||||
@property(nonatomic) {{datatype}} {{name}}; {{#description}}/* {{{description}}} {{#isNotRequired}}[optional]{{/isNotRequired}} */{{/description}}{{newline}}
|
||||
{{/vars}}
|
||||
- (id) {{#vars}}{{name}}: ({{datatype}}) {{name}}{{#hasMore}}{{newline}} {{/hasMore}}{{^hasMore}};{{/hasMore}}
|
||||
- (id) {{#vars}}{{name}}: ({{datatype}}) {{name}}{{#hasMore}}
|
||||
{{/hasMore}}{{^hasMore}};{{/hasMore}}
|
||||
{{/vars}}
|
||||
{{newline}}
|
||||
- (id) initWithValues: (NSDictionary*)dict;
|
||||
|
@ -1,76 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
object BasicAndroidJavaClient extends BasicAndroidJavaGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicAndroidJavaGenerator extends BasicJavaGenerator {
|
||||
override def typeMapping = super.typeMapping ++ Map(
|
||||
"file" -> "File")
|
||||
|
||||
override def importMapping = super.importMapping ++ Map(
|
||||
"Set" -> "java.util.Set")
|
||||
|
||||
override def defaultIncludes = Set(
|
||||
"Integer",
|
||||
"String",
|
||||
"Long",
|
||||
"Short",
|
||||
"Char",
|
||||
"Byte",
|
||||
"Float",
|
||||
"Double",
|
||||
"Boolean",
|
||||
"AnyRef",
|
||||
"Any")
|
||||
|
||||
// package for api invoker, error files
|
||||
override def invokerPackage:Option[String] = Some("com.wordnik.client")
|
||||
|
||||
override def templateDir = "android-java"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/android-java/src/main/java"
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("com.wordnik.client.model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage: Option[String] = Some("com.wordnik.client.api")
|
||||
|
||||
/**
|
||||
* you should override these params for generating the pom.xml and processing
|
||||
* additional params
|
||||
**/
|
||||
additionalParams ++= Map(
|
||||
"artifactId" -> "android-client",
|
||||
"artifactVersion" -> "1.0.0",
|
||||
"groupId" -> "com.wordnik")
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("httpPatch.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "HttpPatch.java"),
|
||||
("apiInvoker.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiInvoker.java"),
|
||||
("jsonUtil.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "JsonUtil.java"),
|
||||
("apiException.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiException.java"),
|
||||
("pom.mustache", destinationDir, "pom.xml")
|
||||
)
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
object BasicCSharpGenerator extends BasicCSharpGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicCSharpGenerator extends BasicGenerator {
|
||||
override def defaultIncludes = Set(
|
||||
"char",
|
||||
"double",
|
||||
"int",
|
||||
"long",
|
||||
"float",
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
|
||||
/**
|
||||
* We are using csharp objects instead of primitives to avoid showing default
|
||||
* primitive values when the API returns missing data. For instance, having a
|
||||
* {"count":0} != count is unknown. You can change this to use primitives if you
|
||||
* desire, but update the default values as well or they'll be set to null in
|
||||
* variable declarations.
|
||||
*/
|
||||
override def typeMapping = Map(
|
||||
"array" -> "List",
|
||||
"boolean" -> "bool?",
|
||||
"string" -> "string",
|
||||
"int" -> "int?",
|
||||
"float" -> "float?",
|
||||
"long" -> "long?",
|
||||
"double" -> "double?",
|
||||
"object" -> "object",
|
||||
"Date" -> "DateTime?",
|
||||
"date" -> "DateTime?",
|
||||
"File" -> "byte[]",
|
||||
"file" -> "byte[]")
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "csharp"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/csharp/src"
|
||||
|
||||
override def invokerPackage: Option[String] = Some("Swagger.Client.Common")
|
||||
|
||||
// template used for models
|
||||
modelTemplateFiles += "model.mustache" -> ".cs"
|
||||
|
||||
// template used for models
|
||||
apiTemplateFiles += "api.mustache" -> ".cs"
|
||||
|
||||
override def reservedWords = Set("abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "do", "goto", "private", "this", "break",
|
||||
"implements", "protected", "throw", "else", "import", "public", "throws", "case",
|
||||
"enum", "instanceof", "return", "transient", "catch", "extends", "try", "final",
|
||||
"interface", "static", "void", "class", "finally", "strictfp", "volatile", "const",
|
||||
"native", "super", "while")
|
||||
|
||||
// import/require statements for specific datatypes
|
||||
override def importMapping = Map()
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("Swagger.Client.Model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage: Option[String] = Some("Swagger.Client.Api")
|
||||
|
||||
// file suffix
|
||||
override def fileSuffix = ".cs"
|
||||
|
||||
// response classes
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => Some(typeMapping.getOrElse(e, e.replaceAll("\\[", "<").replaceAll("\\]", ">")))
|
||||
}
|
||||
}
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
val ComplexTypeMatcher = "(.*)\\[(.*)\\].*".r
|
||||
val t = e match {
|
||||
case ComplexTypeMatcher(container, inner) => {
|
||||
e.replaceAll(container, typeMapping.getOrElse(container.toLowerCase, container))
|
||||
}
|
||||
case _ => e
|
||||
}
|
||||
Some(typeMapping.getOrElse(t, t.replaceAll("\\[", "<").replaceAll("\\]", ">")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = dt.indexOf("[") match {
|
||||
case -1 => dt
|
||||
case n: Int => {
|
||||
if (dt.substring(0, n) == "Array")
|
||||
"List" + dt.substring(n).replaceAll("\\[", "<").replaceAll("\\]", ">")
|
||||
else dt.replaceAll("\\[", "<").replaceAll("\\]", ">")
|
||||
}
|
||||
}
|
||||
typeMapping.getOrElse(declaredType, declaredType)
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty) = {
|
||||
var declaredType = toDeclaredType(obj.`type`)
|
||||
|
||||
declaredType.toLowerCase match {
|
||||
case "array" => declaredType = "List"
|
||||
case e: String => e
|
||||
}
|
||||
|
||||
val defaultValue = toDefaultValue(declaredType, obj)
|
||||
declaredType match {
|
||||
case "List" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
declaredType += "<" + toDeclaredType(inner) + ">"
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
(declaredType, defaultValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* we are defaulting to null values since the codegen uses csharp objects instead of primitives
|
||||
* If you change to primitives, you can put in the appropriate values (0.0f, etc).
|
||||
*/
|
||||
override def toDefaultValue(dataType: String, obj: ModelProperty) = {
|
||||
dataType match {
|
||||
case "Boolean" => "null"
|
||||
case "Integer" => "null"
|
||||
case "Long" => "null"
|
||||
case "Float" => "null"
|
||||
case "Double" => "null"
|
||||
case "List" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + dataType + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
"new ArrayList<" + toDeclaredType(inner) + ">" + "()"
|
||||
}
|
||||
case _ => "null"
|
||||
}
|
||||
}
|
||||
|
||||
override def escapeReservedWord(word: String) = {
|
||||
if (reservedWords.contains(word))
|
||||
throw new Exception("reserved word " + "\"" + word + "\" not allowed")
|
||||
else word
|
||||
}
|
||||
|
||||
/*override def toVarName(name: String): String = {
|
||||
name match {
|
||||
case _ if (reservedWords.contains(name)) => escapeReservedWord(name)
|
||||
case _ => typeMapping.getOrElse(name, name)
|
||||
}
|
||||
capitalize(name)
|
||||
}
|
||||
|
||||
def capitalize(s: String) = {
|
||||
s(0).toUpper + s.substring(1, s.length).toLowerCase
|
||||
}*/
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles =
|
||||
List(
|
||||
("apiInvoker.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiInvoker.cs"),
|
||||
("apiException.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiException.cs"),
|
||||
("Newtonsoft.Json.dll", "generated-code/csharp/bin", "Newtonsoft.Json.dll"),
|
||||
("compile.mustache", "generated-code/csharp", "compile.bat"))
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
abstract class BasicFlashCodegen extends BasicGenerator {
|
||||
override def defaultIncludes = Set(
|
||||
"Date",
|
||||
"String",
|
||||
"Boolean",
|
||||
"Number")
|
||||
|
||||
override def typeMapping = Map(
|
||||
"boolean" -> "Boolean",
|
||||
"string" -> "String",
|
||||
"int" -> "Number",
|
||||
"float" -> "Number",
|
||||
"long" -> "Number",
|
||||
"double" -> "Number")
|
||||
|
||||
override def packageName = "com.wordnik.client"
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "flash"
|
||||
|
||||
// template used for models
|
||||
modelTemplateFiles += "model.mustache" -> ".as"
|
||||
modelTemplateFiles += "modelList.mustache" -> "List.as"
|
||||
|
||||
// template used for models
|
||||
apiTemplateFiles += "api.mustache" -> ".as"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "src/test/flash"
|
||||
|
||||
// import/require statements for specific datatypes
|
||||
override def importMapping = Map()
|
||||
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("com.wordnik.client.model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage: Option[String] = Some("com.wordnik.client.api")
|
||||
|
||||
// file suffix
|
||||
override def fileSuffix = ".as"
|
||||
|
||||
override def toVarName(name: String): String = {
|
||||
name.substring(0, 1).toLowerCase + name.substring(1, name.length)
|
||||
}
|
||||
|
||||
// response classes
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => Some(e)
|
||||
}
|
||||
}
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
responseClass.startsWith("List") match {
|
||||
case true => {
|
||||
val responseSubClass = responseClass.dropRight(1).substring(5)
|
||||
typeMapping.contains(responseSubClass) match {
|
||||
case true => Some("Array")
|
||||
case false => Some(packageName + ".model." +
|
||||
responseSubClass + "List")
|
||||
}
|
||||
}
|
||||
case false => Some(responseClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = dt.indexOf("[") match {
|
||||
case -1 => dt
|
||||
case n: Int => {
|
||||
if (dt.substring(0, n) == "Array") {
|
||||
"Array"
|
||||
} else if (dt.substring(0, n) == "List") {
|
||||
"Array"
|
||||
} else dt
|
||||
}
|
||||
}
|
||||
typeMapping.getOrElse(declaredType, declaredType)
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty) = {
|
||||
var declaredType = toDeclaredType(obj.`type`)
|
||||
|
||||
declaredType match {
|
||||
case "Array" => {
|
||||
declaredType = "Array"
|
||||
}
|
||||
case "List" => {
|
||||
declaredType = "Array"
|
||||
}
|
||||
case e: String => e
|
||||
}
|
||||
|
||||
val defaultValue = toDefaultValue(declaredType, obj)
|
||||
declaredType match {
|
||||
case "List" => "Array"
|
||||
case _ =>
|
||||
}
|
||||
(declaredType, defaultValue)
|
||||
}
|
||||
|
||||
override def toDefaultValue(dataType: String, obj: ModelProperty) = {
|
||||
dataType match {
|
||||
case "Boolean" => "false"
|
||||
case "Number" => "0.0"
|
||||
case "List" => "new Array()"
|
||||
case "Array" => "new Array()"
|
||||
case _ => "null"
|
||||
}
|
||||
}
|
||||
|
||||
def destinationRoot: String
|
||||
|
||||
// supporting classes
|
||||
def baseSupportingFiles = List(
|
||||
("ApiInvoker.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/common", "ApiInvoker.as"),
|
||||
("ApiUrlHelper.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/common", "ApiUrlHelper.as"),
|
||||
("ApiUserCredentials.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/common", "ApiUserCredentials.as"),
|
||||
("ListWrapper.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/common", "ListWrapper.as"),
|
||||
("SwaggerApi.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/common", "SwaggerApi.as"),
|
||||
("XMLWriter.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/common", "XMLWriter.as"),
|
||||
|
||||
("ApiError.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/exception", "ApiError.as"),
|
||||
("ApiErrorCodes.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/exception", "ApiErrorCodes.as"),
|
||||
|
||||
("ApiClientEvent.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/event", "ApiClientEvent.as"),
|
||||
("Response.as", destinationRoot + "/src/main/flex/com/wordnik/swagger/event", "Response.as"),
|
||||
|
||||
("build.properties", destinationRoot, "build.properties"),
|
||||
("build.xml", destinationRoot, "build.xml"),
|
||||
("AirExecutorApp-app.xml", destinationRoot + "/bin", "AirExecutorApp-app.xml"),
|
||||
|
||||
("ASAXB-0.1.1.swc", destinationRoot + "/lib", "ASAXB-0.1.1.swc"),
|
||||
("as3corelib.swc", destinationRoot + "/lib/ext", "as3corelib.swc"),
|
||||
("flexunit-4.1.0_RC2-28-flex_3.5.0.12683.swc", destinationRoot + "/lib/ext", "flexunit-4.1.0_RC2-28-flex_3.5.0.12683.swc"),
|
||||
("flexunit-aircilistener-4.1.0_RC2-28-3.5.0.12683.swc", destinationRoot + "/lib/ext", "flexunit-aircilistener-4.1.0_RC2-28-3.5.0.12683.swc"),
|
||||
("flexunit-cilistener-4.1.0_RC2-28-3.5.0.12683.swc", destinationRoot + "/lib/ext", "flexunit-cilistener-4.1.0_RC2-28-3.5.0.12683.swc"),
|
||||
("flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc", destinationRoot + "/lib/ext", "flexunit-core-flex-4.0.0.2-sdk3.5.0.12683.swc")
|
||||
)
|
||||
}
|
@ -1,394 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen._
|
||||
import com.wordnik.swagger.codegen.util._
|
||||
import com.wordnik.swagger.codegen.language.CodegenConfig
|
||||
import com.wordnik.swagger.codegen.spec.SwaggerSpecValidator
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
import com.wordnik.swagger.codegen.model.SwaggerSerializers
|
||||
import com.wordnik.swagger.codegen.spec.ValidationMessage
|
||||
import com.wordnik.swagger.codegen.spec.SwaggerSpec._
|
||||
import com.wordnik.swagger.util.ValidationException
|
||||
|
||||
import java.io.{ File, FileWriter }
|
||||
|
||||
import org.json4s.jackson.JsonMethods._
|
||||
import org.json4s.jackson.Serialization.write
|
||||
|
||||
import scala.io._
|
||||
import scala.collection.JavaConversions._
|
||||
import scala.collection.mutable.{ ListBuffer, HashMap, HashSet }
|
||||
import scala.io.Source
|
||||
|
||||
abstract class BasicGenerator extends CodegenConfig with PathUtil {
|
||||
implicit val formats = SwaggerSerializers.formats("1.2")
|
||||
|
||||
def packageName = "com.wordnik.client"
|
||||
def templateDir = "src/main/resources/scala"
|
||||
def destinationDir = "generated-code/src/main/scala"
|
||||
def fileSuffix = ".scala"
|
||||
|
||||
override def invokerPackage: Option[String] = Some("com.wordnik.client.common")
|
||||
override def modelPackage: Option[String] = Some("com.wordnik.client.model")
|
||||
override def apiPackage: Option[String] = Some("com.wordnik.client.api")
|
||||
|
||||
var codegen = new Codegen(this)
|
||||
var fileMap: Option[String] = None
|
||||
|
||||
@deprecated(message = "please use the generate function", since = "2.0.16")
|
||||
def generateClient(args: Array[String]): Unit = {
|
||||
generateClientWithoutExit(args)
|
||||
System.exit(0)
|
||||
}
|
||||
|
||||
@deprecated(message = "please use the generate function", since = "2.0.16")
|
||||
def generateClientWithoutExit(args: Array[String]): Seq[File] = {
|
||||
if (args.length == 0) {
|
||||
throw new RuntimeException("Need url to resource listing as argument. You can also specify VM Argument -DfileMap=/path/to/folder/containing.resources.json/")
|
||||
}
|
||||
val host = args(0)
|
||||
val apiKey = if(args.length > 1) Some(args(1)) else None
|
||||
val authorization = authenticate(apiKey)
|
||||
|
||||
val opts = new ClientOpts()
|
||||
opts.uri = host
|
||||
opts.auth = authorization
|
||||
opts.properties = Map("fileMap" -> sys.props("fileMap"))
|
||||
|
||||
generate(opts)
|
||||
}
|
||||
|
||||
def generate(opts: ClientOpts) = {
|
||||
if (opts == null) {
|
||||
throw new RuntimeException("Need url to resource listing as argument. You can also specify VM Argument -DfileMap=/path/to/folder/containing.resources.json/")
|
||||
}
|
||||
val host = opts.uri
|
||||
val authorization = opts.auth
|
||||
|
||||
fileMap = Option(opts.properties.getOrElse("fileMap", null))
|
||||
val doc = ResourceExtractor.fetchListing(getResourcePath(host, fileMap), authorization)
|
||||
|
||||
additionalParams ++= opts.properties
|
||||
val apis: List[ApiListing] = getApis(host, doc, authorization)
|
||||
|
||||
val errors = new ListBuffer[ValidationError] ++ SwaggerValidator.validate(doc)
|
||||
for(api <- apis)
|
||||
SwaggerValidator.validate(api, errors)
|
||||
|
||||
errors.filter(_.severity == SwaggerValidator.ERROR).size match {
|
||||
case i: Int if i > 0 => {
|
||||
println("********* Failed to read swagger json!")
|
||||
errors.foreach(msg => {
|
||||
println(msg)
|
||||
})
|
||||
Option(System.getProperty("skipErrors")) match {
|
||||
case Some(str) => println("**** ignoring errors and continuing")
|
||||
case None => {
|
||||
val out = new StringBuilder
|
||||
errors.foreach(m => out.append(m).append("\n"))
|
||||
println(errors)
|
||||
throw new ValidationException(400, "Failed validation", errors.toList)
|
||||
}
|
||||
}
|
||||
}
|
||||
case 0 =>
|
||||
}
|
||||
|
||||
implicit val basePath = getBasePath(host, doc.basePath, fileMap)
|
||||
|
||||
new SwaggerSpecValidator(doc, apis).validate()
|
||||
|
||||
val allModels = new HashMap[String, Model]
|
||||
val operations = extractApiOperations(apis, allModels)
|
||||
val operationMap: Map[(String, String), List[(String, Operation)]] =
|
||||
groupOperationsToFiles(operations)
|
||||
|
||||
val modelMap = prepareModelMap(allModels.toMap)
|
||||
val modelFileContents = writeFiles(modelMap, modelTemplateFiles.toMap)
|
||||
val modelFiles = new ListBuffer[File]()
|
||||
|
||||
for((filename, contents) <- modelFileContents) {
|
||||
val file = new java.io.File(filename)
|
||||
modelFiles += file
|
||||
file.getParentFile().mkdirs
|
||||
val fw = new FileWriter(filename, false)
|
||||
fw.write(contents + "\n")
|
||||
fw.close()
|
||||
}
|
||||
|
||||
val apiBundle = prepareApiBundle(operationMap.toMap)
|
||||
val apiInfo = writeFiles(apiBundle, apiTemplateFiles.toMap)
|
||||
val apiFiles = new ListBuffer[File]()
|
||||
|
||||
apiInfo.map(m => {
|
||||
val filename = m._1
|
||||
val file = new java.io.File(filename)
|
||||
apiFiles += file
|
||||
file.getParentFile().mkdirs
|
||||
|
||||
val fw = new FileWriter(filename, false)
|
||||
fw.write(m._2 + "\n")
|
||||
fw.close()
|
||||
println("wrote api " + filename)
|
||||
})
|
||||
|
||||
codegen.writeSupportingClasses2(apiBundle, modelMap, doc.apiVersion) ++
|
||||
modelFiles ++ apiFiles
|
||||
}
|
||||
|
||||
/**
|
||||
* applies a template to each of the models
|
||||
*/
|
||||
def writeFiles(models: List[Map[String, AnyRef]], templates: Map[String, String]): List[(String, String)] = {
|
||||
val output = new ListBuffer[Tuple2[String, String]]
|
||||
models.foreach(m => {
|
||||
for ((templateFile, suffix) <- templates) {
|
||||
val imports = m.getOrElse("imports", None)
|
||||
val filename = m("outputDirectory").toString + File.separator + m("filename").toString + suffix
|
||||
output += Tuple2(filename, generateSource(m, templateFile))
|
||||
}
|
||||
})
|
||||
output.toList
|
||||
}
|
||||
|
||||
def generateSource(bundle: Map[String, AnyRef], templateFile: String): String = {
|
||||
val rootDir = new java.io.File(".")
|
||||
val (resourcePath, (engine, template)) = Codegen.templates.getOrElseUpdate(templateFile, codegen.compileTemplate(templateFile, Some(rootDir)))
|
||||
var output = engine.layout(resourcePath, template, bundle)
|
||||
|
||||
engine.compiler.shutdown
|
||||
output
|
||||
}
|
||||
|
||||
def getApis(host: String, doc: ResourceListing, authorization: Option[ApiKeyValue]): List[ApiListing] = {
|
||||
implicit val basePath = getBasePath(host, doc.basePath, fileMap)
|
||||
println("base path is " + basePath)
|
||||
|
||||
val apiReferences = doc.apis
|
||||
if (apiReferences == null)
|
||||
throw new Exception("No APIs specified by resource")
|
||||
ApiExtractor.fetchApiListings(doc.swaggerVersion, basePath, apiReferences, authorization)
|
||||
}
|
||||
|
||||
def authenticate(apiKey: Option[String]): Option[ApiKeyValue] = {
|
||||
Option(System.getProperty("header")) match {
|
||||
case Some(e) => {
|
||||
// this is ugly and will be replaced with proper arg parsing like in ScalaAsyncClientGenerator soon
|
||||
val authInfo = e.split(":")
|
||||
Some(ApiKeyValue(authInfo(0), "header", authInfo(1)))
|
||||
}
|
||||
case _ => {
|
||||
apiKey.map{ key =>
|
||||
Some(ApiKeyValue("api_key", "query", key))
|
||||
}.getOrElse(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def extractApiOperations(apiListings: List[ApiListing], allModels: HashMap[String, Model] )(implicit basePath:String) = {
|
||||
val output = new ListBuffer[(String, String, Operation)]
|
||||
apiListings.foreach(apiDescription => {
|
||||
val basePath = apiDescription.basePath
|
||||
val resourcePath = apiDescription.resourcePath
|
||||
if(apiDescription.apis != null) {
|
||||
apiDescription.apis.foreach(api => {
|
||||
for ((apiPath, operation) <- ApiExtractor.extractApiOperations(basePath, api)) {
|
||||
output += Tuple3(basePath, apiPath, operation)
|
||||
}
|
||||
})
|
||||
}
|
||||
output.map(op => processApiOperation(op._2, op._3))
|
||||
allModels ++= CoreUtils.extractApiModels(apiDescription)
|
||||
})
|
||||
|
||||
output.toList
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a map of models and properties needed to write source
|
||||
*/
|
||||
def prepareModelMap(models: Map[String, Model]): List[Map[String, AnyRef]] = {
|
||||
val allImports = new HashSet[String]
|
||||
val outputDirectory = (destinationDir + File.separator + modelPackage.getOrElse("").replace(".", File.separator))
|
||||
(for ((name, schema) <- models) yield {
|
||||
if (!defaultIncludes.contains(name)) {
|
||||
val modelMap: Map[String, AnyRef] = codegen.modelToMap(name, schema)
|
||||
|
||||
val imports = modelMap("imports").asInstanceOf[Set[Map[String, AnyRef]]]
|
||||
|
||||
val models: List[Map[String, Map[String, AnyRef]]] = List(Map("model" -> modelMap))
|
||||
val m = new HashMap[String, AnyRef]
|
||||
m += "imports" -> processImports(imports)
|
||||
m += "name" -> toModelName(name)
|
||||
m += "className" -> name
|
||||
m += "filename" -> toModelFilename(name)
|
||||
m += "apis" -> None
|
||||
m += "models" -> models
|
||||
m += "package" -> modelPackage
|
||||
m += "invokerPackage" -> invokerPackage
|
||||
m += "outputDirectory" -> outputDirectory
|
||||
m += "newline" -> "\n"
|
||||
m += "modelPackage" -> modelPackage
|
||||
m += "modelJson" -> codegen.writeJson(schema)
|
||||
m ++= additionalParams
|
||||
Some(m.toMap)
|
||||
}
|
||||
else None
|
||||
}).flatten.toList
|
||||
}
|
||||
|
||||
def processImports(ii: Set[Map[String, AnyRef]]) = {
|
||||
val allImports = new HashSet[String]()
|
||||
|
||||
ii.foreach(_.map(m => allImports += m._2.asInstanceOf[String]))
|
||||
|
||||
val imports = new ListBuffer[Map[String, String]]
|
||||
val includedModels = new HashSet[String]
|
||||
val importScope = modelPackage match {
|
||||
case Some(s) => s + "."
|
||||
case _ => ""
|
||||
}
|
||||
// do the mapping before removing primitives!
|
||||
allImports.foreach(value => {
|
||||
val model = toModelName(value.asInstanceOf[String])
|
||||
includedModels.contains(model) match {
|
||||
case false => {
|
||||
importMapping.containsKey(model) match {
|
||||
case true => {
|
||||
if(!imports.flatten.map(m => m._2).toSet.contains(importMapping(model))) {
|
||||
imports += Map("import" -> importMapping(model))
|
||||
}
|
||||
}
|
||||
case false =>
|
||||
}
|
||||
}
|
||||
case true =>
|
||||
}
|
||||
})
|
||||
|
||||
allImports --= defaultIncludes
|
||||
allImports --= primitives
|
||||
allImports --= containers
|
||||
allImports.foreach(i => {
|
||||
val model = toModelName(i)
|
||||
includedModels.contains(model) match {
|
||||
case false => {
|
||||
importMapping.containsKey(model) match {
|
||||
case true =>
|
||||
case false => {
|
||||
if(!imports.flatten.map(m => m._2).toSet.contains(importScope + model)){
|
||||
imports += Map("import" -> (importScope + model))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case true => // no need to add the model
|
||||
}
|
||||
})
|
||||
imports
|
||||
}
|
||||
|
||||
def prepareApiBundle(apiMap: Map[(String, String), List[(String, Operation)]] ): List[Map[String, AnyRef]] = {
|
||||
(for ((identifier, operationList) <- apiMap) yield {
|
||||
val basePath = identifier._1
|
||||
val name = identifier._2
|
||||
val className = toApiName(name)
|
||||
val allImports = new HashSet[String]
|
||||
val operations = new ListBuffer[AnyRef]
|
||||
val o = new ListBuffer[AnyRef]
|
||||
|
||||
val classNameToOperationList = new HashMap[String, ListBuffer[AnyRef]]
|
||||
for ((apiPath, operation) <- operationList) {
|
||||
CoreUtils.extractModelNames(operation).foreach(i => allImports += i)
|
||||
}
|
||||
val imports = new ListBuffer[Map[String, String]]
|
||||
val includedModels = new HashSet[String]
|
||||
val modelList = new ListBuffer[Map[String, AnyRef]]
|
||||
val importScope = modelPackage match {
|
||||
case Some(s) => s + "."
|
||||
case None => ""
|
||||
}
|
||||
|
||||
allImports --= defaultIncludes
|
||||
allImports --= primitives
|
||||
allImports --= containers
|
||||
allImports.foreach(i => {
|
||||
val model = toModelName(i)
|
||||
if(!includedModels.contains(model) && !importMapping.containsKey(model)) {
|
||||
if(!imports.flatten.map(m => m._2).toSet.contains(importScope + model)){
|
||||
imports += Map("import" -> (importScope + model))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
val names = new HashSet[String]
|
||||
for((path, operation) <- operationList) {
|
||||
val op = codegen.apiToMap(path, operation)
|
||||
val nickname = op.getOrElse("nickname", op("httpMethod")).asInstanceOf[String]
|
||||
var updatedNickname = nickname
|
||||
if(names.contains(nickname)) {
|
||||
var counter = 0
|
||||
var done = false
|
||||
while(!done) {
|
||||
updatedNickname = nickname + "_" + className + "_" + counter
|
||||
if(!names.contains(updatedNickname)) done = true
|
||||
counter += 1
|
||||
}
|
||||
}
|
||||
names += updatedNickname
|
||||
o += (Map("path" -> path) ++ op ++ Map("nickname" -> updatedNickname))
|
||||
}
|
||||
operations += Map("operation" -> o)
|
||||
|
||||
val m = new HashMap[String, AnyRef]
|
||||
m += "imports" -> imports
|
||||
m += "baseName" -> name
|
||||
m += "filename" -> toApiFilename(name)
|
||||
m += "name" -> toApiName(name)
|
||||
m += "classname" -> className
|
||||
m += "className" -> className
|
||||
m += "basePath" -> basePath
|
||||
m += "package" -> apiPackage
|
||||
m += "invokerPackage" -> invokerPackage
|
||||
m += "operations" -> operations
|
||||
m += "models" -> None
|
||||
m += "outputDirectory" -> (destinationDir + File.separator + apiPackage.getOrElse("").replace(".", File.separator))
|
||||
m += "newline" -> "\n"
|
||||
m += "modelPackage" -> modelPackage
|
||||
|
||||
m ++= additionalParams
|
||||
|
||||
Some(m.toMap)
|
||||
}).flatten.toList
|
||||
}
|
||||
|
||||
def groupOperationsToFiles(operations: List[(String, String, Operation)]): Map[(String, String), List[(String, Operation)]] = {
|
||||
val opMap = new HashMap[(String, String), ListBuffer[(String, Operation)]]
|
||||
for ((basePath, apiPath, operation) <- operations) {
|
||||
val className = resourceNameFromFullPath(apiPath)
|
||||
val listToAddTo = opMap.getOrElse((basePath, className), {
|
||||
val l = new ListBuffer[(String, Operation)]
|
||||
opMap += (basePath, className) -> l
|
||||
l
|
||||
})
|
||||
listToAddTo += Tuple2(apiPath, operation)
|
||||
}
|
||||
opMap.map(m => (m._1, m._2.toList)).toMap
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
object BasicGroovyGenerator extends BasicGroovyGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicGroovyGenerator extends BasicJavaGenerator {
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "Groovy"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/groovy/src/main/groovy"
|
||||
|
||||
// template used for models
|
||||
modelTemplateFiles += "model.mustache" -> ".groovy"
|
||||
|
||||
// template used for models
|
||||
apiTemplateFiles += "api.mustache" -> ".groovy"
|
||||
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("com.wordnik.client.model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage: Option[String] = Some("com.wordnik.client.api")
|
||||
|
||||
// file suffix
|
||||
override def fileSuffix = ".groovy"
|
||||
|
||||
|
||||
override def supportingFiles =
|
||||
List(
|
||||
("ApiUtils.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiUtils.groovy"),
|
||||
("build.gradle.mustache", "generated-code/groovy", "build.gradle"))
|
||||
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
object BasicJavaGenerator extends BasicJavaGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicJavaGenerator extends BasicGenerator {
|
||||
override def defaultIncludes = Set(
|
||||
"double",
|
||||
"int",
|
||||
"long",
|
||||
"short",
|
||||
"char",
|
||||
"float",
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
|
||||
/**
|
||||
* We are using java objects instead of primitives to avoid showing default
|
||||
* primitive values when the API returns missing data. For instance, having a
|
||||
* {"count":0} != count is unknown. You can change this to use primitives if you
|
||||
* desire, but update the default values as well or they'll be set to null in
|
||||
* variable declarations.
|
||||
*/
|
||||
override def typeMapping = Map(
|
||||
"Array" -> "List",
|
||||
"array" -> "List",
|
||||
"List" -> "List",
|
||||
"boolean" -> "Boolean",
|
||||
"string" -> "String",
|
||||
"int" -> "Integer",
|
||||
"float" -> "Float",
|
||||
"number" -> "BigDecimal",
|
||||
"long" -> "Long",
|
||||
"short" -> "Short",
|
||||
"char" -> "String",
|
||||
"double" -> "Double",
|
||||
"object" -> "Object",
|
||||
"integer" -> "Integer")
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "Java"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/java/src/main/java"
|
||||
|
||||
// template used for models
|
||||
modelTemplateFiles += "model.mustache" -> ".java"
|
||||
|
||||
// template used for models
|
||||
apiTemplateFiles += "api.mustache" -> ".java"
|
||||
|
||||
override def reservedWords = Set("abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
|
||||
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
|
||||
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
|
||||
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
|
||||
"native", "super", "while")
|
||||
|
||||
// import/require statements for specific datatypes
|
||||
override def importMapping = Map(
|
||||
"BigDecimal" -> "java.math.BigDecimal",
|
||||
"UUID" -> "java.util.UUID",
|
||||
"File" -> "java.io.File",
|
||||
"Date" -> "java.util.Date",
|
||||
"Timestamp" -> "java.sql.Timestamp",
|
||||
"Array" -> "java.util.*",
|
||||
"ArrayList" -> "java.util.*",
|
||||
"List" -> "java.util.*",
|
||||
"Set" -> "java.util.*",
|
||||
"DateTime" -> "org.joda.time.*",
|
||||
"LocalDateTime" -> "org.joda.time.*",
|
||||
"LocalDate" -> "org.joda.time.*",
|
||||
"LocalTime" -> "org.joda.time.*"
|
||||
)
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("com.wordnik.client.model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage: Option[String] = Some("com.wordnik.client.api")
|
||||
|
||||
// file suffix
|
||||
override def fileSuffix = ".java"
|
||||
|
||||
override def toVarName(name: String): String = {
|
||||
val paramName = name.replaceAll("[^a-zA-Z0-9_]","")
|
||||
super.toVarName(paramName)
|
||||
}
|
||||
|
||||
override def toApiFilename(name: String): String = {
|
||||
val paramName = name.replaceAll("[^a-zA-Z0-9_]","")
|
||||
super.toApiFilename(paramName)
|
||||
}
|
||||
|
||||
override def toApiName(name: String): String = {
|
||||
val paramName = name.replaceAll("[^a-zA-Z0-9_]","")
|
||||
super.toApiName(paramName)
|
||||
}
|
||||
|
||||
// response classes
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => Some(typeMapping.getOrElse(e, e.replaceAll("\\[", "<").replaceAll("\\]", ">")))
|
||||
}
|
||||
}
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
val ComplexTypeMatcher = "(.*)\\[(.*)\\].*".r
|
||||
val t = e match {
|
||||
case ComplexTypeMatcher(container, inner) => {
|
||||
e.replaceAll(container, typeMapping.getOrElse(container, container))
|
||||
}
|
||||
case _ => e
|
||||
}
|
||||
Some(typeMapping.getOrElse(t, t.replaceAll("\\[", "<").replaceAll("\\]", ">")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = dt.indexOf("[") match {
|
||||
case -1 => dt
|
||||
case n: Int => {
|
||||
if (dt.substring(0, n) == "Array")
|
||||
"List" + dt.substring(n).replaceAll("\\[", "<").replaceAll("\\]", ">")
|
||||
else if (dt.substring(0, n) == "Set")
|
||||
"Set" + dt.substring(n).replaceAll("\\[", "<").replaceAll("\\]", ">")
|
||||
else dt.replaceAll("\\[", "<").replaceAll("\\]", ">")
|
||||
}
|
||||
}
|
||||
typeMapping.getOrElse(declaredType, declaredType)
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty) = {
|
||||
var declaredType = toDeclaredType(obj.`type`)
|
||||
declaredType match {
|
||||
case "Array" => declaredType = "List"
|
||||
case e: String => e
|
||||
}
|
||||
|
||||
val defaultValue = toDefaultValue(declaredType, obj)
|
||||
declaredType match {
|
||||
case "List" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + declaredType + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
declaredType += "<" + toDeclaredType(inner) + ">"
|
||||
}
|
||||
case "Set" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + declaredType + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
declaredType += "<" + toDeclaredType(inner) + ">"
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
(declaredType, defaultValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* you should override these params for generating the pom.xml and processing
|
||||
* additional params
|
||||
**/
|
||||
additionalParams ++= Map(
|
||||
"artifactId" -> "java-client",
|
||||
"artifactVersion" -> "1.0.0",
|
||||
"groupId" -> "com.wordnik")
|
||||
|
||||
/**
|
||||
* we are defaulting to null values since the codegen uses java objects instead of primitives
|
||||
* If you change to primitives, you can put in the appropriate values (0.0f, etc).
|
||||
*/
|
||||
override def toDefaultValue(dataType: String, obj: ModelProperty) = {
|
||||
dataType match {
|
||||
case "Boolean" => "null"
|
||||
case "Integer" => "null"
|
||||
case "Long" => "null"
|
||||
case "Short" => "null"
|
||||
case "Float" => "null"
|
||||
case "Double" => "null"
|
||||
case "List" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + dataType + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
"new ArrayList<" + toDeclaredType(inner) + ">" + "()"
|
||||
}
|
||||
case _ => "null"
|
||||
}
|
||||
}
|
||||
|
||||
override def escapeReservedWord(word: String) = {
|
||||
if (reservedWords.contains(word))
|
||||
throw new Exception("reserved word " + "\"" + word + "\" not allowed")
|
||||
else word
|
||||
}
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles =
|
||||
List(
|
||||
("apiInvoker.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiInvoker.java"),
|
||||
("JsonUtil.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "JsonUtil.java"),
|
||||
("apiException.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiException.java"),
|
||||
("pom.mustache", "generated-code/java", "pom.xml"))
|
||||
}
|
@ -1,247 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
object BasicObjcGenerator extends BasicObjcGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicObjcGenerator extends BasicGenerator {
|
||||
override def defaultIncludes = Set(
|
||||
"bool",
|
||||
"int",
|
||||
"NSString",
|
||||
"NSObject",
|
||||
"NSArray",
|
||||
"NSNumber")
|
||||
|
||||
override def languageSpecificPrimitives = Set(
|
||||
"NSNumber",
|
||||
"NSString",
|
||||
"NSObject",
|
||||
"bool")
|
||||
|
||||
override def reservedWords = Set("void", "char", "short", "int", "void", "char", "short", "int", "long", "float", "double", "signed", "unsigned", "id", "const", "volatile", "in", "out", "inout", "bycopy", "byref", "oneway", "self", "super")
|
||||
|
||||
def foundationClasses = Set(
|
||||
"NSNumber",
|
||||
"NSObject",
|
||||
"NSString")
|
||||
|
||||
override def typeMapping = Map(
|
||||
"enum" -> "NSString",
|
||||
"date" -> "SWGDate",
|
||||
"Date" -> "SWGDate",
|
||||
"boolean" -> "NSNumber",
|
||||
"string" -> "NSString",
|
||||
"integer" -> "NSNumber",
|
||||
"int" -> "NSNumber",
|
||||
"float" -> "NSNumber",
|
||||
"long" -> "NSNumber",
|
||||
"double" -> "NSNumber",
|
||||
"Array" -> "NSArray",
|
||||
"array" -> "NSArray",
|
||||
"List" -> "NSArray",
|
||||
"object" -> "NSObject")
|
||||
|
||||
override def importMapping = Map(
|
||||
"Date" -> "SWGDate")
|
||||
|
||||
override def toModelFilename(name: String) = "SWG" + name
|
||||
|
||||
// naming for the models
|
||||
override def toModelName(name: String) = {
|
||||
(typeMapping.keys ++
|
||||
foundationClasses ++
|
||||
importMapping.values ++
|
||||
defaultIncludes ++
|
||||
languageSpecificPrimitives
|
||||
).toSet.contains(name) match {
|
||||
case true => name(0).toUpper + name.substring(1)
|
||||
case _ => {
|
||||
"SWG" + name(0).toUpper + name.substring(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// objective c doesn't like variables starting with "new"
|
||||
override def toVarName(name: String): String = {
|
||||
val paramName = name.replaceAll("[^a-zA-Z0-9_]","")
|
||||
if(paramName.startsWith("new") || reservedWords.contains(paramName)) {
|
||||
escapeReservedWord(paramName)
|
||||
}
|
||||
else paramName
|
||||
}
|
||||
|
||||
// naming for the apis
|
||||
override def toApiName(name: String) = "SWG" + name(0).toUpper + name.substring(1) + "Api"
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "objc"
|
||||
|
||||
// template used for models
|
||||
modelTemplateFiles += "model-header.mustache" -> ".h"
|
||||
modelTemplateFiles += "model-body.mustache" -> ".m"
|
||||
|
||||
// template used for apis
|
||||
apiTemplateFiles += "api-header.mustache" -> ".h"
|
||||
apiTemplateFiles += "api-body.mustache" -> ".m"
|
||||
|
||||
// package for models
|
||||
override def invokerPackage: Option[String] = None
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = None
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage: Option[String] = None
|
||||
|
||||
// response classes
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
typeMapping.contains(responseClass) match {
|
||||
case true => Some(typeMapping(responseClass))
|
||||
case false => {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
if(responseClass.toLowerCase.startsWith("array") || responseClass.toLowerCase.startsWith("list"))
|
||||
Some("NSArray")
|
||||
else
|
||||
Some(toModelName(responseClass))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def processApiMap(m: Map[String, AnyRef]): Map[String, AnyRef] = {
|
||||
val mutable = scala.collection.mutable.Map() ++ m
|
||||
mutable += "newline" -> "\n"
|
||||
|
||||
mutable.map(k => {
|
||||
k._1 match {
|
||||
case e: String if (e == "allParams") => {
|
||||
val sp = (mutable(e)).asInstanceOf[List[_]]
|
||||
sp.size match {
|
||||
case i: Int if(i > 0) => mutable += "hasParams" -> "true"
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
})
|
||||
mutable.toMap
|
||||
}
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
processResponseClass(responseClass) match {
|
||||
case Some("void") => Some("void")
|
||||
case Some(e) => Some(e + "*")
|
||||
case _ => Some(responseClass)
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = dt.indexOf("[") match {
|
||||
case -1 => dt
|
||||
case n: Int => "NSArray"
|
||||
}
|
||||
val t = typeMapping.getOrElse(declaredType, declaredType)
|
||||
|
||||
(languageSpecificPrimitives.contains(t) && !foundationClasses.contains(t)) match {
|
||||
case true => toModelName(t)
|
||||
case _ => toModelName(t) + "*" // needs pointer
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty) = {
|
||||
var declaredType = toDeclaredType(obj.`type`)
|
||||
declaredType.toLowerCase match {
|
||||
case "list" => {
|
||||
declaredType = "array"
|
||||
}
|
||||
case e: String => e
|
||||
}
|
||||
|
||||
val defaultValue = toDefaultValue(declaredType, obj)
|
||||
declaredType match {
|
||||
case "array" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => {
|
||||
if(items.ref != null)
|
||||
items.ref
|
||||
else
|
||||
items.`type`
|
||||
}
|
||||
case _ => {
|
||||
println("failed on " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
"NSArray"
|
||||
}
|
||||
case "set" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
"NSArray"
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
(declaredType, defaultValue)
|
||||
}
|
||||
|
||||
override def escapeReservedWord(word: String) = "_" + word
|
||||
|
||||
override def toDefaultValue(properCase: String, obj: ModelProperty) = {
|
||||
properCase match {
|
||||
case "boolean" => "false"
|
||||
case "int" => "0"
|
||||
case "long" => "0L"
|
||||
case "float" => "0.0f"
|
||||
case "double" => "0.0"
|
||||
case "List" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => {
|
||||
if(items.ref != null)
|
||||
items.ref
|
||||
else
|
||||
items.`type`
|
||||
}
|
||||
case _ => {
|
||||
println("failed on " + properCase + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
"new ArrayList<" + inner + ">" + "()"
|
||||
}
|
||||
case _ => "null"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
import java.io.File
|
||||
|
||||
object BasicPHPGenerator extends BasicPHPGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicPHPGenerator extends BasicGenerator {
|
||||
// template used for models
|
||||
modelTemplateFiles += "model.mustache" -> ".php"
|
||||
|
||||
// template used for models
|
||||
apiTemplateFiles += "api.mustache" -> ".php"
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "php"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/php"
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("models")
|
||||
|
||||
// package for apis
|
||||
override def apiPackage: Option[String] = Some("")
|
||||
|
||||
// file suffix
|
||||
override def fileSuffix = ".php"
|
||||
|
||||
// reserved words which need special quoting
|
||||
// These will all be object properties, in which context we don't need
|
||||
// to worry about escaping them for PHP.
|
||||
override def reservedWords = Set()
|
||||
|
||||
// import/require statements for specific datatypes
|
||||
override def importMapping = Map()
|
||||
|
||||
|
||||
// response classes
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
typeMapping.contains(responseClass) match {
|
||||
case true => Some(typeMapping(responseClass))
|
||||
case false => {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
responseClass.startsWith("List") match {
|
||||
case true => Some("array")
|
||||
case false => Some(responseClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
typeMapping.contains(responseClass) match {
|
||||
case true => Some(typeMapping(responseClass))
|
||||
case false => {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
responseClass.startsWith("List") match {
|
||||
case true => {
|
||||
val responseSubClass = responseClass.dropRight(1).substring(5)
|
||||
typeMapping.contains(responseSubClass) match {
|
||||
case true => Some("array[" + typeMapping(responseSubClass) + "]")
|
||||
case false => Some("array[" + responseSubClass + "]")
|
||||
}
|
||||
}
|
||||
case false => Some(responseClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
override def typeMapping = Map(
|
||||
"string" -> "string",
|
||||
"str" -> "string",
|
||||
"int" -> "int",
|
||||
"float" -> "float",
|
||||
"long" -> "int",
|
||||
"double" -> "float",
|
||||
"Array" -> "array",
|
||||
"boolean" -> "bool",
|
||||
"Date" -> "DateTime"
|
||||
)
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = typeMapping.getOrElse(dt, dt)
|
||||
declaredType.startsWith("Array") match {
|
||||
case true => {
|
||||
val innerType = dt.dropRight(1).substring(6)
|
||||
typeMapping.contains(innerType) match {
|
||||
case true => "array[" + typeMapping(innerType) + "]"
|
||||
case false => "array[" + innerType + "]"
|
||||
}
|
||||
}
|
||||
case _ => declaredType
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty) = {
|
||||
var declaredType = toDeclaredType(obj.`type`)
|
||||
|
||||
declaredType match {
|
||||
case "Array" => declaredType = "array"
|
||||
case e: String => {
|
||||
e
|
||||
}
|
||||
}
|
||||
|
||||
val defaultValue = toDefaultValue(declaredType, obj)
|
||||
declaredType match {
|
||||
case "array" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + declaredType + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
declaredType += "[" + toDeclaredType(inner) + "]"
|
||||
"array"
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
(declaredType, defaultValue)
|
||||
}
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("Swagger.mustache", destinationDir + File.separator + apiPackage.get,
|
||||
"Swagger.php")
|
||||
)
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import java.io.File
|
||||
|
||||
object BasicPython3Generator extends BasicPython3Generator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicPython3Generator extends BasicPythonGenerator {
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "python3"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/python3"
|
||||
|
||||
// Python3 erases int/long distinction
|
||||
override def typeMapping = Map(
|
||||
"string" -> "str",
|
||||
"int" -> "int",
|
||||
"float" -> "float",
|
||||
"long" -> "int",
|
||||
"double" -> "float",
|
||||
"Array" -> "list",
|
||||
"array" -> "list",
|
||||
"boolean" -> "bool",
|
||||
"Date" -> "datetime"
|
||||
)
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
import java.io.File
|
||||
|
||||
object BasicPythonGenerator extends BasicPythonGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicPythonGenerator extends BasicGenerator {
|
||||
// template used for models
|
||||
modelTemplateFiles += "model.mustache" -> ".py"
|
||||
|
||||
// template used for models
|
||||
apiTemplateFiles += "api.mustache" -> ".py"
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "python"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/python"
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("models")
|
||||
|
||||
// package for apis
|
||||
override def apiPackage = None
|
||||
|
||||
// file suffix
|
||||
override def fileSuffix = ".py"
|
||||
|
||||
// reserved words which need special quoting
|
||||
// These will all be object properties, in which context we don't need
|
||||
// to worry about escaping them for Python.
|
||||
override def reservedWords = Set()
|
||||
|
||||
// import/require statements for specific datatypes
|
||||
override def importMapping = Map()
|
||||
|
||||
|
||||
// response classes
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
typeMapping.contains(responseClass) match {
|
||||
case true => Some(typeMapping(responseClass))
|
||||
case false => {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
responseClass.startsWith("List") match {
|
||||
case true => Some("list")
|
||||
case false => Some(responseClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
typeMapping.contains(responseClass) match {
|
||||
case true => Some(typeMapping(responseClass))
|
||||
case false => {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
responseClass.startsWith("List") match {
|
||||
case true => {
|
||||
val responseSubClass = responseClass.dropRight(1).substring(5)
|
||||
typeMapping.contains(responseSubClass) match {
|
||||
case true => Some("list[" + typeMapping(responseSubClass) + "]")
|
||||
case false => Some("list[" + responseSubClass + "]")
|
||||
}
|
||||
}
|
||||
case false => Some(responseClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
override def typeMapping = Map(
|
||||
"float" -> "float",
|
||||
"long" -> "long",
|
||||
"double" -> "float",
|
||||
"Array" -> "list",
|
||||
"boolean" -> "bool",
|
||||
"string" -> "str",
|
||||
"Date" -> "datetime"
|
||||
)
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = typeMapping.getOrElse(dt, dt)
|
||||
declaredType.startsWith("Array") match {
|
||||
case true => {
|
||||
val innerType = dt.dropRight(1).substring(6)
|
||||
typeMapping.contains(innerType) match {
|
||||
case true => "list[" + typeMapping(innerType) + "]"
|
||||
case false => "list[" + innerType + "]"
|
||||
}
|
||||
}
|
||||
case _ => {
|
||||
declaredType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty) = {
|
||||
var declaredType = toDeclaredType(obj.`type`)
|
||||
|
||||
declaredType match {
|
||||
case "Array" => declaredType = "list"
|
||||
case e: String => {
|
||||
e
|
||||
}
|
||||
}
|
||||
|
||||
val defaultValue = toDefaultValue(declaredType, obj)
|
||||
declaredType match {
|
||||
case "list" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + declaredType + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
declaredType += "[" + toDeclaredType(inner) + "]"
|
||||
"list"
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
(declaredType, defaultValue)
|
||||
}
|
||||
|
||||
// escape keywords
|
||||
override def escapeReservedWord(word: String) = "`" + word + "`"
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("__init__.mustache", destinationDir, "__init__.py"),
|
||||
("swagger.mustache", destinationDir + File.separator + apiPackage.getOrElse(""),
|
||||
"swagger.py"),
|
||||
("__init__.mustache", destinationDir + File.separator +
|
||||
modelPackage.getOrElse(""), "__init__.py"))
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
import java.io.File
|
||||
|
||||
object BasicRubyGenerator extends BasicRubyGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicRubyGenerator extends BasicGenerator {
|
||||
|
||||
override def apiPackage: Option[String] = Some("lib")
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "ruby"
|
||||
|
||||
// template used for models
|
||||
modelTemplateFiles += "model.mustache" -> ".rb"
|
||||
|
||||
// template used for models
|
||||
apiTemplateFiles += "api.mustache" -> ".rb"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/ruby"
|
||||
|
||||
// file suffix
|
||||
override def fileSuffix = ".rb"
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("models")
|
||||
|
||||
// response classes
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => Some(e)
|
||||
}
|
||||
}
|
||||
|
||||
override def toApiName(name: String) = {
|
||||
var fixedName = name.replaceAll("(\\{|\\})","")
|
||||
fixedName(0).toUpper + fixedName.substring(1) + "_api"
|
||||
}
|
||||
|
||||
override def toModelFilename(name: String) = name.toLowerCase.replaceAll("(\\{|\\})","")
|
||||
override def toApiFilename(name: String) = name.toLowerCase.replaceAll("(\\{|\\})","") + "_api"
|
||||
override def toVarName(name: String): String = toUnderscore(name)
|
||||
|
||||
override def toMethodName(name: String): String = toUnderscore(name)
|
||||
|
||||
def toUnderscore(name: String): String = {
|
||||
val sb = new StringBuilder
|
||||
for ((char) <- super.toVarName(name)) {
|
||||
if (char.isUpper) sb.append("_").append(char.toLower)
|
||||
else sb.append(char)
|
||||
}
|
||||
sb.toString
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty) = {
|
||||
var dataType = obj.`type`(0).toUpper + obj.`type`.substring(1)
|
||||
|
||||
dataType match {
|
||||
case "Array" => dataType = "List"
|
||||
case e: String => e
|
||||
}
|
||||
|
||||
val defaultValue = toDefaultValue(dataType, obj)
|
||||
dataType match {
|
||||
case "List" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => {
|
||||
if(items.ref != null)
|
||||
items.ref
|
||||
else
|
||||
items.`type`
|
||||
}
|
||||
case _ => {
|
||||
println("failed on " + dataType + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
dataType = "java.util.List[" + inner + "]"
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
(dataType, defaultValue)
|
||||
}
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("monkey.mustache", destinationDir + File.separator + apiPackage.get, "monkey.rb"),
|
||||
("swagger.mustache", destinationDir + File.separator + apiPackage.get, "swagger.rb"),
|
||||
("swagger" + File.separator + "configuration.mustache", destinationDir + File.separator + apiPackage.get, "swagger" + File.separator + "configuration.rb"),
|
||||
("swagger" + File.separator + "response.mustache", destinationDir + File.separator + apiPackage.get, "swagger" + File.separator + "response.rb"),
|
||||
("swagger" + File.separator + "version.mustache", destinationDir + File.separator + apiPackage.get, "swagger" + File.separator + "version.rb"),
|
||||
("swagger" + File.separator + "request.mustache", destinationDir + File.separator + apiPackage.get, "swagger" + File.separator + "request.rb"))
|
||||
}
|
@ -1,221 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
object BasicScalaGenerator extends BasicScalaGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class BasicScalaGenerator extends BasicGenerator {
|
||||
override def defaultIncludes = Set(
|
||||
"Int",
|
||||
"String",
|
||||
"Long",
|
||||
"Short",
|
||||
"Char",
|
||||
"Byte",
|
||||
"Float",
|
||||
"Double",
|
||||
"Boolean",
|
||||
"AnyRef",
|
||||
"Any")
|
||||
|
||||
override def typeMapping = Map(
|
||||
"array" -> "List",
|
||||
"set" -> "Set",
|
||||
"boolean" -> "Boolean",
|
||||
"string" -> "String",
|
||||
"int" -> "Int",
|
||||
"long" -> "Long",
|
||||
"float" -> "Float",
|
||||
"byte" -> "Byte",
|
||||
"short" -> "Short",
|
||||
"char" -> "Char",
|
||||
"long" -> "Long",
|
||||
"double" -> "Double",
|
||||
"object" -> "Any",
|
||||
"file" -> "File")
|
||||
|
||||
// template used for models
|
||||
modelTemplateFiles += "model.mustache" -> ".scala"
|
||||
|
||||
// template used for models
|
||||
apiTemplateFiles += "api.mustache" -> ".scala"
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "scala"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/scala/src/main/scala"
|
||||
|
||||
// reserved words which need special quoting
|
||||
override def reservedWords =
|
||||
Set(
|
||||
"abstract",
|
||||
"case",
|
||||
"catch",
|
||||
"class",
|
||||
"def",
|
||||
"do",
|
||||
"else",
|
||||
"extends",
|
||||
"false",
|
||||
"final",
|
||||
"finally",
|
||||
"for",
|
||||
"forSome",
|
||||
"if",
|
||||
"implicit",
|
||||
"import",
|
||||
"lazy",
|
||||
"match",
|
||||
"new",
|
||||
"null",
|
||||
"object",
|
||||
"override",
|
||||
"package",
|
||||
"private",
|
||||
"protected",
|
||||
"return",
|
||||
"sealed",
|
||||
"super",
|
||||
"this",
|
||||
"throw",
|
||||
"trait",
|
||||
"try",
|
||||
"true",
|
||||
"type",
|
||||
"val",
|
||||
"var",
|
||||
"while",
|
||||
"with",
|
||||
"yield")
|
||||
|
||||
// import/require statements for specific datatypes
|
||||
override def importMapping = Map(
|
||||
"Date" -> "java.util.Date",
|
||||
"File" -> "java.io.File"
|
||||
)
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("com.wordnik.client.model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage: Option[String] = Some("com.wordnik.client.api")
|
||||
|
||||
// response classes--if you don't want a response class, override and set to None
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => Some(typeMapping.getOrElse(e, e))
|
||||
}
|
||||
}
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => {
|
||||
val ComplexTypeMatcher = "(.*)\\[(.*)\\].*".r
|
||||
val t = e match {
|
||||
case ComplexTypeMatcher(container, inner) => {
|
||||
e.replaceAll(container, typeMapping.getOrElse(container.toLowerCase, container))
|
||||
}
|
||||
case _ => e
|
||||
}
|
||||
Some(typeMapping.getOrElse(t, t))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = dt.indexOf("[") match {
|
||||
case -1 => dt
|
||||
case n: Int => {
|
||||
if (dt.substring(0, n) == "Array")
|
||||
"List" + dt.substring(n)
|
||||
else if (dt.substring(0, n) == "Set")
|
||||
"Set" + dt.substring(n)
|
||||
else dt
|
||||
}
|
||||
}
|
||||
typeMapping.getOrElse(declaredType, declaredType)
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty): (String, String) = {
|
||||
obj.`type` match {
|
||||
case "Array" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
val e = "List[%s]".format(toDeclaredType(inner))
|
||||
(e, toDefaultValue(inner, obj))
|
||||
}
|
||||
case "List" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
val e = "List[%s]".format(toDeclaredType(inner))
|
||||
(e, toDefaultValue(inner, obj))
|
||||
}
|
||||
case "Set" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
val e = "Set[%s]".format(toDeclaredType(inner))
|
||||
(e, toDefaultValue(inner, obj))
|
||||
}
|
||||
case e: String => (toDeclaredType(e), toDefaultValue(e, obj))
|
||||
}
|
||||
}
|
||||
|
||||
// escape keywords
|
||||
override def escapeReservedWord(word: String) = "`" + word + "`"
|
||||
|
||||
/**
|
||||
* you should override these params for generating the pom.xml and processing
|
||||
* additional params
|
||||
**/
|
||||
additionalParams ++= Map(
|
||||
"artifactId" -> "scala-client",
|
||||
"artifactVersion" -> "1.0.0",
|
||||
"groupId" -> "com.wordnik")
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("apiInvoker.mustache", destinationDir + "/com/wordnik/client", "ApiInvoker.scala"),
|
||||
("pom.mustache", "generated-code/scala", "pom.xml"))
|
||||
}
|
@ -1,548 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
import com.wordnik.swagger.codegen.util.CoreUtils
|
||||
import com.wordnik.swagger.codegen.language.CodegenConfig
|
||||
import com.wordnik.swagger.codegen.spec.SwaggerSpec._
|
||||
|
||||
import org.json4s.jackson.JsonMethods._
|
||||
import org.json4s.jackson.Serialization.write
|
||||
|
||||
import org.fusesource.scalate._
|
||||
import org.fusesource.scalate.layout.DefaultLayoutStrategy
|
||||
import org.fusesource.scalate.mustache._
|
||||
import org.fusesource.scalate.support.ScalaCompiler
|
||||
|
||||
import java.io.{ File, FileWriter, InputStream }
|
||||
|
||||
import org.apache.commons.io.FileUtils
|
||||
|
||||
import scala.io.Source
|
||||
import scala.collection.mutable.{ HashMap, ListBuffer, HashSet }
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
object Codegen {
|
||||
val templates = new HashMap[String, (String, (TemplateEngine, Template))]
|
||||
}
|
||||
|
||||
class Codegen(config: CodegenConfig) {
|
||||
implicit val formats = SwaggerSerializers.formats("1.2")
|
||||
|
||||
def compileTemplate(templateFile: String, rootDir: Option[File] = None, engine: Option[TemplateEngine] = None): (String, (TemplateEngine, Template)) = {
|
||||
val engine = new TemplateEngine(rootDir orElse Some(new File(".")))
|
||||
val srcName = config.templateDir + "/" + templateFile
|
||||
val srcStream = {
|
||||
getClass.getClassLoader.getResourceAsStream(srcName) match {
|
||||
case is: java.io.InputStream => is
|
||||
case _ => {
|
||||
val f = new java.io.File(srcName)
|
||||
if (!f.exists) throw new Exception("Missing template: " + srcName)
|
||||
else new java.io.FileInputStream(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
val template = engine.compile(
|
||||
TemplateSource.fromText(config.templateDir + File.separator + templateFile,
|
||||
Source.fromInputStream(srcStream).mkString))
|
||||
(srcName, engine -> template)
|
||||
}
|
||||
|
||||
def rawAllowableValuesToString(v: AllowableValues) = {
|
||||
v match {
|
||||
case av: AllowableListValues => {
|
||||
av
|
||||
}
|
||||
case av: AllowableRangeValues => {
|
||||
av
|
||||
}
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def allowableValuesToString(v: AllowableValues) = {
|
||||
v match {
|
||||
case av: AllowableListValues => {
|
||||
Some(av.values.mkString("LIST[", ",", "]"))
|
||||
}
|
||||
case av: AllowableRangeValues => {
|
||||
Some("RANGE[" + av.min + "," + av.max + "]")
|
||||
}
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
|
||||
def apiToMap(path: String, operation: Operation): Map[String, AnyRef] = {
|
||||
var bodyParam: Option[String] = None
|
||||
var queryParams = new ListBuffer[AnyRef]
|
||||
val pathParams = new ListBuffer[AnyRef]
|
||||
val headerParams = new ListBuffer[AnyRef]
|
||||
val bodyParams = new ListBuffer[AnyRef]
|
||||
val formParams = new ListBuffer[AnyRef]
|
||||
var paramList = new ListBuffer[HashMap[String, AnyRef]]
|
||||
var errorList = new ListBuffer[HashMap[String, AnyRef]]
|
||||
var bodyParamRequired: Option[String] = Some("true")
|
||||
|
||||
if (operation.responseMessages != null) {
|
||||
operation.responseMessages.foreach(param => {
|
||||
val params = new HashMap[String, AnyRef]
|
||||
params += "code" -> param.code.toString()
|
||||
params += "reason" -> param.message
|
||||
if (!param.responseModel.isEmpty)
|
||||
params += "responseModel" -> param.responseModel
|
||||
params += "hasMore" -> "true"
|
||||
errorList += params
|
||||
})
|
||||
}
|
||||
|
||||
if (operation.parameters != null) {
|
||||
operation.parameters.foreach(param => {
|
||||
val params = new HashMap[String, AnyRef]
|
||||
params += (param.paramType + "Parameter") -> "true"
|
||||
params += "type" -> param.paramType
|
||||
params += "defaultValue" -> config.toDefaultValue(param.dataType, param.defaultValue.getOrElse(""))
|
||||
params += "swaggerDataType" -> param.dataType
|
||||
params += "description" -> param.description
|
||||
params += "hasMore" -> "true"
|
||||
params += "allowMultiple" -> param.allowMultiple.toString
|
||||
|
||||
if(param.dataType == "File") params += "isFile" -> "true"
|
||||
else params += "notFile" -> "true"
|
||||
|
||||
val u = param.dataType.indexOf("[") match {
|
||||
case -1 => config.toDeclaredType(param.dataType)
|
||||
case n: Int => {
|
||||
val ComplexTypeMatcher = "(.*)\\[(.*)\\].*".r
|
||||
val ComplexTypeMatcher(container, basePart) = param.dataType
|
||||
config.toDeclaredType(container + "[" + config.toDeclaredType(basePart) + "]")
|
||||
}
|
||||
}
|
||||
|
||||
params += "dataType" -> u
|
||||
params += "getter" -> config.toGetter(param.name, u)
|
||||
params += "setter" -> config.toSetter(param.name, u)
|
||||
|
||||
param.allowableValues match {
|
||||
case a: AllowableValues => params += "allowableValues" -> allowableValuesToString(a)
|
||||
case _ =>
|
||||
}
|
||||
|
||||
if (param.required) {
|
||||
params += "required" -> "true"
|
||||
} else {
|
||||
params += "optional" -> "true"
|
||||
}
|
||||
param.paramType match {
|
||||
case "body" => {
|
||||
params += "paramName" -> "body"
|
||||
params += "baseName" -> "body"
|
||||
if (!param.required) {
|
||||
bodyParamRequired = None
|
||||
}
|
||||
|
||||
bodyParam = Some("body")
|
||||
bodyParams += params.clone
|
||||
}
|
||||
case "path" => {
|
||||
params += "paramName" -> config.toVarName(param.name)
|
||||
params += "baseName" -> param.name
|
||||
params += "required" -> "true"
|
||||
params -= "optional"
|
||||
pathParams += params.clone
|
||||
}
|
||||
case "query" => {
|
||||
params += "paramName" -> config.toVarName(param.name)
|
||||
params += "baseName" -> param.name
|
||||
queryParams += params.clone
|
||||
}
|
||||
case "header" => {
|
||||
params += "paramName" -> config.toVarName(param.name)
|
||||
params += "baseName" -> param.name
|
||||
headerParams += params.clone
|
||||
}
|
||||
case "form" => {
|
||||
params += "paramName" -> config.toVarName(param.name)
|
||||
params += "baseName" -> param.name
|
||||
formParams += params.clone
|
||||
}
|
||||
case x @ _ => throw new Exception("Unknown parameter type: " + x)
|
||||
}
|
||||
paramList += params
|
||||
})
|
||||
}
|
||||
|
||||
val requiredParams = new ListBuffer[HashMap[String, AnyRef]]
|
||||
paramList.filter(p => p.contains("required") && p("required") == "true").foreach(param => {
|
||||
requiredParams += (param.clone += "hasMore" -> "true")
|
||||
})
|
||||
requiredParams.size match {
|
||||
case 0 =>
|
||||
case _ => requiredParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
|
||||
}
|
||||
|
||||
headerParams.size match {
|
||||
case 0 =>
|
||||
case _ => headerParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
|
||||
}
|
||||
|
||||
queryParams.size match {
|
||||
case 0 =>
|
||||
case _ => queryParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
|
||||
}
|
||||
|
||||
pathParams.size match {
|
||||
case 0 =>
|
||||
case _ => pathParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
|
||||
}
|
||||
errorList.size match{
|
||||
case 0 =>
|
||||
case _ => errorList.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
|
||||
}
|
||||
|
||||
val sp = {
|
||||
val lb = new ListBuffer[AnyRef]
|
||||
paramList.foreach(i => {
|
||||
i += "secondaryParam" -> "true"
|
||||
i("defaultValue") match {
|
||||
case Some(e) =>
|
||||
case None => lb += i
|
||||
}
|
||||
})
|
||||
paramList.foreach(i => {
|
||||
i("defaultValue") match {
|
||||
case Some(e) => lb += i
|
||||
case None =>
|
||||
}
|
||||
})
|
||||
lb.toList
|
||||
}
|
||||
|
||||
paramList.size match {
|
||||
case 0 =>
|
||||
case _ => {
|
||||
sp.head.asInstanceOf[HashMap[String, String]] -= "secondaryParam"
|
||||
sp.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
|
||||
}
|
||||
}
|
||||
|
||||
val writeMethods = Set("POST", "PUT", "PATCH")
|
||||
val properties =
|
||||
HashMap[String, AnyRef](
|
||||
"path" -> path,
|
||||
"nickname" -> config.toMethodName(operation.nickname),
|
||||
"summary" -> operation.summary,
|
||||
"notes" -> operation.notes,
|
||||
"deprecated" -> operation.`deprecated`,
|
||||
"bodyParam" -> bodyParam,
|
||||
"bodyParamRequired" -> bodyParamRequired,
|
||||
"emptyBodyParam" -> (if (writeMethods contains operation.method.toUpperCase) "{}" else ""),
|
||||
"allParams" -> sp,
|
||||
"bodyParams" -> bodyParams.toList,
|
||||
"pathParams" -> pathParams.toList,
|
||||
"queryParams" -> queryParams.toList,
|
||||
"headerParams" -> headerParams.toList,
|
||||
"formParams" -> formParams.toList,
|
||||
"requiredParams" -> requiredParams.toList,
|
||||
"errorList" -> errorList,
|
||||
"httpMethod" -> operation.method.toUpperCase,
|
||||
"httpMethodLowerCase" -> operation.method.toLowerCase,
|
||||
operation.method.toLowerCase -> "true")
|
||||
if (0 < operation.consumes.length) {
|
||||
val o = new ListBuffer[Map[String, String]]
|
||||
for(i <- 0 until operation.consumes.length) {
|
||||
val m = new HashMap[String, String]
|
||||
if(i < (operation.consumes.length - 1))
|
||||
m += "hasMore" -> "true"
|
||||
m += "mediaType" -> operation.consumes(i)
|
||||
o += m.toMap
|
||||
}
|
||||
properties += "consumes" -> o.toList
|
||||
} else {
|
||||
properties += "consumes" -> List(Map("mediaType" -> "application/json"))
|
||||
}
|
||||
if (0 < operation.produces.length) {
|
||||
val o = new ListBuffer[Map[String, String]]
|
||||
for(i <- 0 until operation.produces.length) {
|
||||
val m = new HashMap[String, String]
|
||||
if((i + 1) < operation.produces.length)
|
||||
m += "hasMore" -> "true"
|
||||
m += "mediaType" -> operation.produces(i)
|
||||
o += m.toMap
|
||||
}
|
||||
properties += "produces" -> o.toList
|
||||
} else {
|
||||
properties += "produces" -> List(Map("mediaType" -> "application/json"))
|
||||
}
|
||||
if (requiredParams.size > 0) properties += "requiredParamCount" -> requiredParams.size.toString
|
||||
operation.responseClass.indexOf("[") match {
|
||||
case -1 => {
|
||||
val baseType = operation.responseClass
|
||||
properties += "returnType" -> config.processResponseDeclaration(baseType)
|
||||
properties += "returnBaseType" -> config.processResponseClass(baseType)
|
||||
properties += "returnSimpleType" -> "true"
|
||||
properties += "returnTypeIsPrimitive" -> {
|
||||
(config.languageSpecificPrimitives.contains(baseType) || primitives.contains(baseType)) match {
|
||||
case true => Some("true")
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
case n: Int => {
|
||||
val ComplexTypeMatcher = ".*\\[(.*)\\].*".r
|
||||
val ComplexTypeMatcher(basePart) = operation.responseClass
|
||||
|
||||
properties += "returnType" -> config.processResponseDeclaration(operation.responseClass.replaceAll(basePart, config.processResponseClass(basePart).get))
|
||||
properties += "returnContainer" -> config.processResponseClass(operation.responseClass.substring(0, n))
|
||||
properties += "returnBaseType" -> config.processResponseClass(basePart)
|
||||
properties += "returnTypeIsPrimitive" -> {
|
||||
(config.languageSpecificPrimitives.contains(basePart) || primitives.contains(basePart)) match {
|
||||
case true => Some("true")
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
config.processApiMap(properties.toMap)
|
||||
}
|
||||
|
||||
def modelToMap(className: String, model: Model): Map[String, AnyRef] = {
|
||||
val data: HashMap[String, AnyRef] =
|
||||
HashMap(
|
||||
"classname" -> config.toModelName(className),
|
||||
"className" -> config.toModelName(className),
|
||||
"classVarName" -> config.toVarName(className), // suggested name of object created from this class
|
||||
"modelPackage" -> config.modelPackage,
|
||||
"description" -> model.description,
|
||||
"modelJson" -> writeJson(model),
|
||||
"newline" -> "\n")
|
||||
|
||||
val l = new ListBuffer[AnyRef]
|
||||
|
||||
val imports = new HashSet[AnyRef]
|
||||
model.properties.map(prop => {
|
||||
val propertyDocSchema = prop._2
|
||||
val dt = propertyDocSchema.`type`
|
||||
|
||||
var baseType = dt
|
||||
// import the object inside the container
|
||||
if (propertyDocSchema.items != null && !config.typeMapping.contains(dt)) {
|
||||
// import the container
|
||||
imports += Map("import" -> dt)
|
||||
propertyDocSchema.items match {
|
||||
case Some(items) => baseType = items.ref.getOrElse(items.`type`)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
baseType = config.typeMapping.contains(baseType) match {
|
||||
case true => config.typeMapping(baseType)
|
||||
case false => {
|
||||
// imports += Map("import" -> config.toDeclaredType(baseType))
|
||||
baseType
|
||||
}
|
||||
}
|
||||
(config.defaultIncludes ++ config.languageSpecificPrimitives).toSet.contains(baseType) match {
|
||||
case true =>
|
||||
case _ => {
|
||||
imports += Map("import" -> baseType)
|
||||
}
|
||||
}
|
||||
|
||||
val isList = (if (isListType(propertyDocSchema.`type`)) true else None)
|
||||
val isMap = (if (isMapType(propertyDocSchema.`type`)) true else None)
|
||||
val isNotContainer = if (!isListType(propertyDocSchema.`type`) && !isMapType(propertyDocSchema.`type`)) true else None
|
||||
val isContainer = if (isListType(propertyDocSchema.`type`) || isMapType(propertyDocSchema.`type`)) true else None
|
||||
|
||||
val properties =
|
||||
HashMap(
|
||||
"name" -> config.toVarName(prop._1),
|
||||
"nameSingular" -> {
|
||||
val name = config.toVarName(prop._1)
|
||||
if (name.endsWith("s") && name.length > 1) name.substring(0, name.length - 1) else name
|
||||
},
|
||||
"baseType" -> {
|
||||
if (primitives.contains(baseType))
|
||||
baseType
|
||||
else
|
||||
config.modelPackage match {
|
||||
case Some(p) => p + "." + baseType
|
||||
case _ => baseType
|
||||
}
|
||||
},
|
||||
"baseTypeVarName" -> config.toVarName(baseType),
|
||||
"baseName" -> prop._1,
|
||||
"datatype" -> config.toDeclaration(propertyDocSchema)._1,
|
||||
"defaultValue" -> config.toDeclaration(propertyDocSchema)._2,
|
||||
"description" -> propertyDocSchema.description,
|
||||
"notes" -> propertyDocSchema.description,
|
||||
"allowableValues" -> rawAllowableValuesToString(propertyDocSchema.allowableValues),
|
||||
(if(propertyDocSchema.required) "required" else "isNotRequired") -> "true",
|
||||
"getter" -> config.toGetter(prop._1, config.toDeclaration(propertyDocSchema)._1),
|
||||
"setter" -> config.toSetter(prop._1, config.toDeclaration(propertyDocSchema)._1),
|
||||
"isList" -> isList,
|
||||
"isMap" -> isMap,
|
||||
"isContainer" -> isContainer,
|
||||
"isNotContainer" -> isNotContainer,
|
||||
"hasMore" -> "true")
|
||||
(config.languageSpecificPrimitives.contains(baseType) || primitives.contains(baseType)) match {
|
||||
case true => properties += "isPrimitiveType" -> "true"
|
||||
case _ => properties += "complexType" -> config.toModelName(baseType)
|
||||
}
|
||||
l += properties
|
||||
})
|
||||
if(l.size > 0) {
|
||||
val last = l.last.asInstanceOf[HashMap[String, String]]
|
||||
last.remove("hasMore")
|
||||
}
|
||||
data += "vars" -> l
|
||||
data += "imports" -> imports.toSet
|
||||
config.processModelMap(data.toMap)
|
||||
}
|
||||
|
||||
/**
|
||||
* gets an input stream from resource or file
|
||||
*/
|
||||
def getInputStream(path: String): InputStream = {
|
||||
getClass.getClassLoader.getResourceAsStream(path) match {
|
||||
case is: InputStream => is
|
||||
case _ => new java.io.FileInputStream(path)
|
||||
}
|
||||
}
|
||||
|
||||
def writeJson(m: AnyRef): String = {
|
||||
Option(System.getProperty("modelFormat")) match {
|
||||
case Some(e) if e =="1.1" => write1_1(m)
|
||||
case _ => pretty(render(parse(write(m))))
|
||||
}
|
||||
}
|
||||
|
||||
def write1_1(m: AnyRef): String = {
|
||||
implicit val formats = SwaggerSerializers.formats("1.1")
|
||||
write(m)
|
||||
}
|
||||
|
||||
def writeSupportingClasses2(
|
||||
apiBundle: List[Map[String, AnyRef]],
|
||||
modelsMap: List[Map[String, AnyRef]],
|
||||
apiVersion: String): Seq[File] = {
|
||||
|
||||
|
||||
|
||||
val b = new HashMap[String, HashMap[String, AnyRef]]
|
||||
modelsMap.foreach(m => {
|
||||
if(m.contains("models")) {
|
||||
val f = m("models").asInstanceOf[List[Map[String, AnyRef]]]
|
||||
|
||||
f.foreach(g => {
|
||||
val e = new HashMap[String, AnyRef]
|
||||
val model = g("model").asInstanceOf[Map[String, AnyRef]]
|
||||
e ++= model
|
||||
e += "hasMoreModels" -> "true"
|
||||
|
||||
b += model("classVarName").toString -> e
|
||||
})
|
||||
}
|
||||
})
|
||||
val models = new ListBuffer[HashMap[String, AnyRef]]
|
||||
|
||||
val keys = b.keys
|
||||
var count = 0
|
||||
b.values.foreach(v => {
|
||||
models += v
|
||||
count += 1
|
||||
if(count != keys.size) {
|
||||
v += "hasMoreModels" -> "true"
|
||||
}
|
||||
else {
|
||||
v.remove("hasMoreModels")
|
||||
}
|
||||
})
|
||||
|
||||
val f = Map("model" -> models)
|
||||
val rootDir: Option[File] = Some(new File("."))
|
||||
val engine = new TemplateEngine(rootDir orElse Some(new File(".")))
|
||||
|
||||
val data = Map(
|
||||
"invokerPackage" -> config.invokerPackage,
|
||||
"package" -> config.packageName,
|
||||
"modelPackage" -> config.modelPackage,
|
||||
"apiPackage" -> config.apiPackage,
|
||||
"apiInfo" -> Map("apis" -> apiBundle),
|
||||
"models" -> f,
|
||||
"apiVersion" -> apiVersion) ++ config.additionalParams
|
||||
|
||||
val outputFiles = config.supportingFiles map { file =>
|
||||
val supportingFile = file._1
|
||||
val outputDir = file._2
|
||||
val destFile = file._3
|
||||
|
||||
val outputFile = new File(outputDir + File.separator + destFile)
|
||||
val outputFolder = outputFile.getParent
|
||||
new File(outputFolder).mkdirs
|
||||
|
||||
if (supportingFile.endsWith(".mustache")) {
|
||||
val output = {
|
||||
val (resourceName, (_, template)) = compileTemplate(supportingFile, rootDir, Some(engine))
|
||||
engine.layout(resourceName, template, data.toMap)
|
||||
}
|
||||
val fw = new FileWriter(outputFile, false)
|
||||
fw.write(output + "\n")
|
||||
fw.close()
|
||||
println("wrote " + outputFile.getPath())
|
||||
} else {
|
||||
val file = new File(config.templateDir + File.separator + supportingFile)
|
||||
if (file.isDirectory()) {
|
||||
// copy the whole directory
|
||||
FileUtils.copyDirectory(file, new File(outputDir))
|
||||
println("copied directory " + supportingFile)
|
||||
} else {
|
||||
val is = getInputStream(config.templateDir + File.separator + supportingFile)
|
||||
val parentDir = outputFile.getParentFile()
|
||||
if (parentDir != null && !parentDir.exists) {
|
||||
println("making directory: " + parentDir.toString + ": " + parentDir.mkdirs)
|
||||
}
|
||||
FileUtils.copyInputStreamToFile(is, outputFile)
|
||||
println("copied " + outputFile.getPath())
|
||||
is.close
|
||||
}
|
||||
}
|
||||
outputFile
|
||||
}
|
||||
//a shutdown method will be added to scalate in an upcoming release
|
||||
engine.compiler.shutdown()
|
||||
outputFiles
|
||||
}
|
||||
|
||||
protected def isListType(dt: String) = isCollectionType(dt, "List") || isCollectionType(dt, "Array") || isCollectionType(dt, "Set")
|
||||
|
||||
protected def isMapType(dt: String) = isCollectionType(dt, "Map")
|
||||
|
||||
protected def isCollectionType(dt: String, str: String) = {
|
||||
if (dt.equals(str))
|
||||
true
|
||||
else
|
||||
dt.indexOf("[") match {
|
||||
case -1 => false
|
||||
case n: Int => {
|
||||
if (dt.substring(0, n) == str) {
|
||||
true
|
||||
} else false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
trait PathUtil {
|
||||
def getResourcePath(host: String, fileMap: Option[String] = None) = {
|
||||
fileMap match {
|
||||
case Some(s) => s
|
||||
case _ => host
|
||||
}
|
||||
}
|
||||
|
||||
def getBasePath(host: String, basePath: String, fileMap: Option[String] = None) = {
|
||||
fileMap match {
|
||||
case Some(s) => {
|
||||
// return the parent folder
|
||||
val f = new java.io.File(s)
|
||||
f.getParent
|
||||
}
|
||||
case _ => {
|
||||
if(basePath != "") basePath
|
||||
else host
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def toModelName(name: String) = {
|
||||
if(name.length > 0)
|
||||
name(0).toUpper + name.substring(1)
|
||||
else "MISSING MODEL NAME"
|
||||
}
|
||||
|
||||
def toApiName(name: String) = {
|
||||
name.replaceAll("\\{","").replaceAll("\\}", "") match {
|
||||
case s: String if(s.length > 0) => s(0).toUpper + s.substring(1) + "Api"
|
||||
case _ => "Api"
|
||||
}
|
||||
}
|
||||
|
||||
def nameFromPath(apiPath: String) = {
|
||||
apiPath.split("/")(1).split("\\.")(0).replaceAll("/", "")
|
||||
}
|
||||
|
||||
def apiNameFromPath(apiPath: String) = toApiName(nameFromPath(apiPath))
|
||||
|
||||
def resourceNameFromFullPath(apiPath: String) = {
|
||||
apiPath.split("/")(1).split("\\.")(0).replaceAll("/", "")
|
||||
}
|
||||
}
|
@ -1,508 +0,0 @@
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import scala.collection.mutable
|
||||
import java.io.{File, FileWriter}
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
import scala.collection.mutable.{HashMap, ListBuffer}
|
||||
import language.CodegenConfig
|
||||
import scala.io.Source
|
||||
import org.json4s.jackson.Serialization._
|
||||
import org.fusesource.scalate.{Template, TemplateSource, TemplateEngine}
|
||||
import org.apache.commons.io.FileUtils
|
||||
import com.wordnik.swagger.codegen.util.{CoreUtils, ApiExtractor, ResourceExtractor}
|
||||
import com.wordnik.swagger.codegen.spec.SwaggerSpecValidator
|
||||
import mojolly.inflector.InflectorImports._
|
||||
import org.rogach.scallop.{ScallopConf, Scallop}
|
||||
import scala.annotation.switch
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
case class SwaggerApi(
|
||||
clientName: String,
|
||||
resourceUrl: String,
|
||||
packageName: String,
|
||||
apiTemplates: Map[String, String] = Map("api.mustache" -> ".scala"),
|
||||
modelTemplates: Map[String, String] = Map("model.mustache" -> ".scala"),
|
||||
apiKey: Option[String] = None,
|
||||
baseUrl: Option[String] = None,
|
||||
excludedApis: Set[String] = Set.empty,
|
||||
excludedModels: Set[String] = Set.empty,
|
||||
excludedModelPackages: Set[String] = Set.empty,
|
||||
defaultImports: Map[String, String] = Map.empty)
|
||||
case class SwaggerGenConfig(
|
||||
api: SwaggerApi,
|
||||
templateDir: File,
|
||||
codeDir: File,
|
||||
projectRoot: File,
|
||||
defaultIncludes: Set[String] = Set.empty,
|
||||
typeMapping: Map[String, String] = Map.empty,
|
||||
defaultImports: Map[String, String] = Map.empty,
|
||||
excludedModelPackages: Set[String] = Set.empty)
|
||||
object AsycnClientGeneratorConf {
|
||||
val appBanner: String = """
|
||||
|
|
||||
|
|
||||
| .--.--.
|
||||
| / / '.
|
||||
|| : /`. / .---. __ ,-.
|
||||
|; | |--` /. ./| ,----._,. ,----._,. ,' ,'/ /|
|
||||
|| : ;_ .-'-. ' | ,--.--. / / ' // / ' / ,---. ' | |' |
|
||||
| \ \ `. /___/ \: |/ \| : | : | / \| | ,'
|
||||
| `----. \.-'.. ' ' .--. .-. | | .\ | | .\ ./ / ' : /
|
||||
| __ \ \ /___/ \: '\__\/: . . ; '; . ; '; . ' / | | '
|
||||
| / /`--' . \ ' .\ ," .--.; ' . . ' . . ' ; /; : |
|
||||
|'--'. / \ \ ' \ / / ,. |`---`-'| |`---`-'| ' | / | , ;
|
||||
| `--'---' \ \ |--; : .' .'__/\_: |.'__/\_: | : |---'
|
||||
| \ \ | | , .-.| : :| : :\ \ /
|
||||
| '---" `--`---' \ \ / \ \ / `----'
|
||||
| `--`-' `--`-'
|
||||
|
|
||||
| Swagger Codegen, Reverb Technologies Inc. (c) 2009-2013
|
||||
| For more info, visit: https://developers.helloreverb.com/swagger/
|
||||
""".stripMargin
|
||||
}
|
||||
class AsycnClientGeneratorConf(arguments: Seq[String]) extends ScallopConf(arguments) {
|
||||
|
||||
val name = opt[String](required = true, descr = "The name of the generated client.")
|
||||
val `package` = opt[String](default = Some("com.wordnik.swagger.client.async"), descr = "The package for the generated code.")
|
||||
val resourceUrl = trailArg[String](descr = "The url to use for fetching the swagger spec from. This can be a http(s) url or a file path.")
|
||||
val baseUrl = opt[String](descr = "The url to use when you want to override the base url provided by the resource url json.")
|
||||
val apiKey = opt[String](required = false, descr = "An optional api key to use when calling the swagger api")
|
||||
val templateDir = opt[String](descr = "The directory that contains the templates for use in this generator", default = Some("asyncscala"))
|
||||
val codeDir = opt[String](descr = "The directory to use as base for generating code files, this will contain the generated scala files.", default = Some("src/main/scala"), hidden = true)
|
||||
val projectRoot = opt[String](descr = "The directory to use as project dir, this will receive the build files (*.sbt, *.pom)", default = Some("."))
|
||||
|
||||
mainOptions = Seq(resourceUrl, name)
|
||||
|
||||
banner("""
|
||||
|Usage: scala-async.sh [OPTION] spec-url
|
||||
|
|
||||
|The scala-async tool generates a swagger api client, using async-http-client
|
||||
|and stdlib futures.
|
||||
|
|
||||
|Options:
|
||||
|
|
||||
""".stripMargin)
|
||||
|
||||
footer("\nFor more information, visit https://developers.helloreverb.com/swagger/")
|
||||
}
|
||||
|
||||
object ScalaAsyncClientGenerator extends App {
|
||||
val appBanner: String = AsycnClientGeneratorConf.appBanner
|
||||
|
||||
val opts = new AsycnClientGeneratorConf(if (args.nonEmpty) args else Array("--help"))
|
||||
val rootDir = new File(opts.projectRoot())
|
||||
val codeDir = {
|
||||
val cd = opts.codeDir()
|
||||
if (cd.startsWith("/")) new File(cd)
|
||||
else new File(rootDir, cd)
|
||||
}
|
||||
val resUrl = {
|
||||
val r = opts.resourceUrl()
|
||||
if (!r.startsWith("http") && !r.startsWith("file")) sys.props("fileMap") = r
|
||||
r
|
||||
}
|
||||
val baseUrl = opts.baseUrl.get
|
||||
val cfg = SwaggerGenConfig(
|
||||
api = SwaggerApi(opts.name(), resUrl, opts.`package`(), apiKey = opts.apiKey.get, baseUrl = baseUrl),
|
||||
templateDir = new File(opts.templateDir()),
|
||||
codeDir = new File(rootDir, opts.codeDir()),
|
||||
projectRoot = rootDir
|
||||
)
|
||||
|
||||
val generator = new ScalaAsyncClientGenerator(cfg)
|
||||
|
||||
val clientOpts = new ClientOpts()
|
||||
val props = new HashMap[String, String]
|
||||
if(resUrl.startsWith("http"))
|
||||
clientOpts.uri = resUrl
|
||||
else
|
||||
props += "fileMap" -> resUrl
|
||||
|
||||
props += "clientName" -> cfg.api.clientName.underscore.pascalize
|
||||
|
||||
clientOpts.properties = props.toMap.asJava
|
||||
|
||||
println(appBanner)
|
||||
generator.generate(clientOpts)
|
||||
}
|
||||
|
||||
class AsyncClientCodegen(clientName: String, config: CodegenConfig, rootDir: Option[File] = None) extends Codegen(config) {
|
||||
/*
|
||||
override def writeSupportingClasses(apis: Map[(String, String), List[(String, Operation)]],
|
||||
models: Map[String, Model], apiVersion: String): Seq[File] = {
|
||||
|
||||
def apiListF(apis: Map[(String, String), List[(String, Operation)]]): List[Map[String, AnyRef]] = {
|
||||
val apiList = new ListBuffer[Map[String, AnyRef]]
|
||||
apis.map(a => {
|
||||
apiList += Map(
|
||||
"name" -> a._1._2,
|
||||
"filename" -> config.toApiFilename(a._1._2),
|
||||
"className" -> config.toApiName(a._1._2),
|
||||
"basePath" -> a._1._1,
|
||||
"operations" -> {
|
||||
(for (t <- a._2) yield { Map("operation" -> t._2, "path" -> t._1) }).toList
|
||||
})
|
||||
})
|
||||
apiList.toList
|
||||
}
|
||||
|
||||
def modelListF(models: Map[String, Model]): List[Map[String, AnyRef]] = {
|
||||
val modelList = new ListBuffer[HashMap[String, AnyRef]]
|
||||
models.foreach(m => {
|
||||
val json = write(m._2)
|
||||
modelList += HashMap(
|
||||
"modelName" -> m._1,
|
||||
"model" -> m._2,
|
||||
"filename" -> config.toModelFilename(m._1),
|
||||
"modelJson" -> json,
|
||||
"hasMore" -> "true")
|
||||
})
|
||||
modelList.size match {
|
||||
case 0 =>
|
||||
case _ => modelList.last.asInstanceOf[HashMap[String, String]] -= "hasMore"
|
||||
}
|
||||
modelList.map(_.toMap).toList
|
||||
}
|
||||
|
||||
def dataF(apis: Map[(String, String), List[(String, Operation)]],
|
||||
models: Map[String, Model]): Map[String, AnyRef] =
|
||||
Map(
|
||||
"clientName" -> clientName.underscore.pascalize,
|
||||
"projectName" -> clientName.underscore.dasherize,
|
||||
"package" -> config.packageName,
|
||||
"modelPackage" -> config.modelPackage,
|
||||
"apiPackage" -> config.apiPackage,
|
||||
"apis" -> apiListF(apis),
|
||||
"models" -> modelListF(models))
|
||||
|
||||
writeSupportingClasses(apis, models, apiVersion, rootDir, dataF)
|
||||
}
|
||||
|
||||
override def compileTemplate(templateFile: String, rootDir: Option[File] = None, engine: Option[TemplateEngine] = None): (String, (TemplateEngine, Template)) = {
|
||||
val eng = engine getOrElse new TemplateEngine(rootDir orElse Some(new File(".")))
|
||||
val rn = config.templateDir + File.separator + templateFile
|
||||
val rrn = "asyncscala" + File.separator + templateFile
|
||||
val resourceName = if (new File(rn).exists) rn else rrn
|
||||
val is = getInputStream(resourceName)
|
||||
if (is == null)
|
||||
throw new Exception("Missing template: " + resourceName)
|
||||
|
||||
val template = eng.compile(TemplateSource.fromText(resourceName,Source.fromInputStream(is).mkString))
|
||||
(resourceName, eng -> template)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
||||
private[this] val pascalizedClientName = cfg.api.clientName.underscore.pascalize
|
||||
|
||||
override val packageName: String = cfg.api.packageName
|
||||
override val templateDir: String = cfg.templateDir.getPath
|
||||
override val destinationDir: String = cfg.codeDir.getPath
|
||||
override val fileSuffix: String = ".scala"
|
||||
override val modelPackage: Option[String] = Some(packageName + ".model")
|
||||
override val apiPackage: Option[String] = Some(packageName + ".apis")
|
||||
|
||||
|
||||
override val reservedWords: Set[String] =
|
||||
Set(
|
||||
"abstract",
|
||||
"case",
|
||||
"catch",
|
||||
"class",
|
||||
"def",
|
||||
"do",
|
||||
"else",
|
||||
"extends",
|
||||
"false",
|
||||
"final",
|
||||
"finally",
|
||||
"for",
|
||||
"forSome",
|
||||
"if",
|
||||
"implicit",
|
||||
"import",
|
||||
"lazy",
|
||||
"match",
|
||||
"new",
|
||||
"null",
|
||||
"object",
|
||||
"override",
|
||||
"package",
|
||||
"private",
|
||||
"protected",
|
||||
"return",
|
||||
"sealed",
|
||||
"super",
|
||||
"this",
|
||||
"throw",
|
||||
"trait",
|
||||
"try",
|
||||
"true",
|
||||
"type",
|
||||
"val",
|
||||
"var",
|
||||
"while",
|
||||
"with",
|
||||
"yield")
|
||||
override val importMapping = Map(
|
||||
"Date" -> "java.util.Date",
|
||||
"File" -> "java.io.File"
|
||||
) ++ cfg.defaultImports ++ cfg.api.defaultImports
|
||||
override val typeMapping = Map(
|
||||
"array" -> "List",
|
||||
"boolean" -> "Boolean",
|
||||
"string" -> "String",
|
||||
"int" -> "Int",
|
||||
"long" -> "Long",
|
||||
"float" -> "Float",
|
||||
"byte" -> "Byte",
|
||||
"short" -> "Short",
|
||||
"char" -> "Char",
|
||||
"long" -> "Long",
|
||||
"double" -> "Double",
|
||||
"object" -> "Any",
|
||||
"file" -> "File") ++ cfg.typeMapping
|
||||
|
||||
override val defaultIncludes = Set(
|
||||
"Int",
|
||||
"String",
|
||||
"Long",
|
||||
"Short",
|
||||
"Char",
|
||||
"Byte",
|
||||
"Float",
|
||||
"Double",
|
||||
"Boolean",
|
||||
"AnyRef",
|
||||
"Any") ++ cfg.defaultIncludes ++ cfg.api.excludedModels
|
||||
|
||||
override def supportingFiles = List(
|
||||
("client.mustache", destinationDir + "/" + cfg.api.packageName.replace('.', '/'), (pascalizedClientName +".scala")),
|
||||
("sbt.mustache", cfg.projectRoot.getPath, "swagger-client.sbt")
|
||||
)
|
||||
|
||||
modelTemplateFiles ++= cfg.api.modelTemplates
|
||||
apiTemplateFiles ++= cfg.api.apiTemplates
|
||||
|
||||
codegen = new AsyncClientCodegen(cfg.api.clientName, this, Some(cfg.projectRoot))
|
||||
|
||||
override def getBasePath(host: String, basePath: String, fileMap: Option[String]): String =
|
||||
cfg.api.baseUrl.getOrElse(super.getBasePath(host, basePath, fileMap))
|
||||
/*
|
||||
override def generateClient(args: Array[String]) = {
|
||||
val host = cfg.api.resourceUrl
|
||||
val authorization = {
|
||||
val apiKey = cfg.api.apiKey
|
||||
if(apiKey != None)
|
||||
Some(ApiKeyValue("api_key", "query", apiKey.get))
|
||||
else
|
||||
None
|
||||
}
|
||||
|
||||
val doc = {
|
||||
try {
|
||||
ResourceExtractor.fetchListing(getResourcePath(host, fileMap), authorization)
|
||||
} catch {
|
||||
case e: Exception => throw new Exception("unable to read from " + host, e)
|
||||
}
|
||||
}
|
||||
|
||||
implicit val basePath = getBasePath(host, doc.basePath, fileMap)
|
||||
|
||||
val apiReferences = doc.apis
|
||||
if (apiReferences == null)
|
||||
throw new Exception("No APIs specified by resource")
|
||||
val apis = ApiExtractor.fetchApiListings(doc.swaggerVersion, basePath, apiReferences, authorization)
|
||||
|
||||
new SwaggerSpecValidator(doc, apis).validate()
|
||||
|
||||
val allModels = new mutable.HashMap[String, Model]
|
||||
val operations = extractApiOperations(apis, allModels)
|
||||
val operationMap = groupOperationsToFiles(operations)
|
||||
|
||||
val modelMap = prepareModelMap(allModels.toMap)
|
||||
|
||||
val modelFileContents = writeFiles(modelMap, modelTemplateFiles.toMap)
|
||||
val modelFiles = new ListBuffer[File]()
|
||||
|
||||
for((filename, contents) <- modelFileContents) {
|
||||
val file = new java.io.File(filename)
|
||||
modelFiles += file
|
||||
file.getParentFile().mkdirs
|
||||
val fw = new FileWriter(filename, false)
|
||||
fw.write(contents + "\n")
|
||||
fw.close()
|
||||
}
|
||||
|
||||
val apiBundle = prepareApiBundle(operationMap.toMap)
|
||||
val apiInfo = writeFiles(apiBundle, apiTemplateFiles.toMap)
|
||||
val apiFiles = new ListBuffer[File]()
|
||||
|
||||
apiInfo.map(m => {
|
||||
val filename = m._1
|
||||
val file = new java.io.File(filename)
|
||||
apiFiles += file
|
||||
file.getParentFile().mkdirs
|
||||
|
||||
val fw = new FileWriter(filename, false)
|
||||
fw.write(m._2 + "\n")
|
||||
fw.close()
|
||||
println("wrote api " + filename)
|
||||
})
|
||||
|
||||
codegen.writeSupportingClasses2(apiBundle, allModels.toMap, doc.apiVersion) ++
|
||||
modelFiles ++ apiFiles
|
||||
}
|
||||
|
||||
|
||||
|
||||
override def extractApiOperations(apiListings: List[ApiListing], allModels: mutable.HashMap[String, Model] )(implicit basePath:String) = {
|
||||
val output = new mutable.ListBuffer[(String, String, Operation)]
|
||||
apiListings.foreach(apiDescription => {
|
||||
val basePath = apiDescription.basePath
|
||||
val resourcePath = apiDescription.resourcePath
|
||||
if(apiDescription.apis != null) {
|
||||
apiDescription.apis.foreach(api => {
|
||||
for ((apiPath, operation) <- ApiExtractor.extractApiOperations(basePath, api)) {
|
||||
output += ((basePath, apiPath, operation))
|
||||
}
|
||||
})
|
||||
}
|
||||
output.map(op => processApiOperation(op._2, op._3))
|
||||
allModels ++= CoreUtils.extractApiModels(apiDescription, defaultIncludes, typeMapping)
|
||||
})
|
||||
output.toList
|
||||
}
|
||||
|
||||
override def toModelName(name: String) = toDeclaredType(name.pascalize)
|
||||
*/
|
||||
override def toApiName(name: String) = {
|
||||
name.replaceAll("\\{","").replaceAll("\\}", "") match {
|
||||
case s: String if(s.length > 0) => s.underscore.pascalize + "Client"
|
||||
case _ => "Client"
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// override def nameFromPath(apiPath: String) = resourceNameFromFullPath(apiPath)
|
||||
//
|
||||
//
|
||||
// override def resourceNameFromFullPath(apiPath: String) =
|
||||
// apiPath.split('/').head.split('.').head
|
||||
|
||||
/**
|
||||
* creates a map of models and properties needed to write source
|
||||
*/
|
||||
/*
|
||||
override def prepareModelMap(models: Map[String, Model]): List[Map[String, AnyRef]] = {
|
||||
for {
|
||||
(name, schema) <- (models -- defaultIncludes).toList
|
||||
if !(cfg.excludedModelPackages ++ cfg.api.excludedModelPackages).exists(schema.qualifiedType.startsWith)
|
||||
} yield {
|
||||
Map(
|
||||
"name" -> toModelName(name),
|
||||
"className" -> name,
|
||||
"filename" -> toModelFilename(name),
|
||||
"apis" -> None,
|
||||
"models" -> List((name, schema)),
|
||||
"package" -> modelPackage,
|
||||
"invokerPackage" -> invokerPackage,
|
||||
"outputDirectory" -> (destinationDir + File.separator + modelPackage.getOrElse("").replaceAll("\\.", File.separator)),
|
||||
"newline" -> "\n")
|
||||
}
|
||||
}
|
||||
|
||||
override def prepareApiBundle(apiMap: Map[(String, String), List[(String, Operation)]] ): List[Map[String, AnyRef]] = {
|
||||
for {
|
||||
((basePath, name), operationList) <- apiMap.toList
|
||||
className = toApiName(name)
|
||||
} yield {
|
||||
Map(
|
||||
"baseName" -> name,
|
||||
"filename" -> toApiFilename(name),
|
||||
"name" -> toApiName(name),
|
||||
"className" -> className,
|
||||
"basePath" -> basePath,
|
||||
"package" -> apiPackage,
|
||||
"invokerPackage" -> invokerPackage,
|
||||
"apis" -> Map(className -> operationList.toList),
|
||||
"models" -> None,
|
||||
"outputDirectory" -> (destinationDir + File.separator + apiPackage.getOrElse("").replaceAll("\\.", File.separator)),
|
||||
"newline" -> "\n")
|
||||
}
|
||||
}
|
||||
|
||||
def bundleToSource(bundle:List[Map[String, AnyRef]], templates: Map[String, String]): List[(String, String)] = {
|
||||
bundle.foldLeft(List.empty[(String, String)]) { (acc, m) =>
|
||||
templates.foldLeft(acc) { (out, tem) =>
|
||||
val (file, suffix) = tem
|
||||
(m("outputDirectory").toString + File.separator + m("filename").toString + suffix) -> codegen.generateSource(m, file) :: acc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def generateAndWrite(bundle: Map[String, AnyRef], templateFile: String) = {
|
||||
val output = codegen.generateSource(bundle, templateFile)
|
||||
val outputDir = new File(bundle("outputDirectory").asInstanceOf[String])
|
||||
outputDir.mkdirs
|
||||
|
||||
val filename = outputDir + File.separator + bundle("filename")
|
||||
val fw = new FileWriter(filename, false)
|
||||
fw.write(output + "\n")
|
||||
fw.close()
|
||||
println("wrote " + filename)
|
||||
}
|
||||
*/
|
||||
|
||||
// response classes--if you don't want a response class, override and set to None
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None //Some("Unit")
|
||||
case e: String => Some(toDeclaredType(e))
|
||||
}
|
||||
}
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None //Some("Unit")
|
||||
case e: String => Some(toDeclaredType(e))
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = (dt.indexOf("[")) match {
|
||||
case -1 => dt
|
||||
case n: Int => {
|
||||
if (dt.substring(0, n).toLowerCase == "array") {
|
||||
val dtt = dt.substring(n + 1, dt.length - 1)
|
||||
"List[%s]".format(typeMapping.getOrElse(dtt, dtt))
|
||||
} else dt
|
||||
}
|
||||
}
|
||||
typeMapping.getOrElse(declaredType, declaredType)
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty): (String, String) = {
|
||||
obj.`type` match {
|
||||
case "Array" | "array" => makeContainerType(obj, "List")
|
||||
case "Set" | "set" => makeContainerType(obj, "Set")
|
||||
case e: String => (toDeclaredType(e), toDefaultValue(e, obj))
|
||||
}
|
||||
}
|
||||
|
||||
private def makeContainerType(obj: ModelProperty, container: String): (String, String) = {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
val e = "%s[%s]" format (container, toDeclaredType(inner))
|
||||
(e, toDefaultValue(inner, obj))
|
||||
}
|
||||
|
||||
// escape keywords
|
||||
override def escapeReservedWord(word: String) = "`" + word + "`"
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.util.{ ResourceExtractor, ApiExtractor }
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
import java.io.File
|
||||
|
||||
import org.json4s._
|
||||
import org.json4s.jackson.JsonMethods._
|
||||
import org.json4s.jackson.Serialization.{ read, write }
|
||||
|
||||
object SpecConverter {
|
||||
def main(args: Array[String]) = {
|
||||
implicit val formats = SwaggerSerializers.formats("1.2")
|
||||
|
||||
if(args == null || args.length < 2) {
|
||||
println("Usage: SpecConverter {host} {outputDir}\nIf no API key is required, use an empty string")
|
||||
sys.exit(0)
|
||||
}
|
||||
|
||||
val url = args(0)
|
||||
val key = None
|
||||
val outputDir = new File(args(1))
|
||||
|
||||
if(!outputDir.exists) outputDir.mkdir
|
||||
|
||||
val resourcePath = url.split("/").last
|
||||
val resourceListing = ResourceExtractor.fetchListing(url, key)
|
||||
|
||||
resourceListing.swaggerVersion match {
|
||||
case "1.1" =>
|
||||
case e: String => {
|
||||
println("unsupported swagger version %s".format(e))
|
||||
sys.exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
val updatedListing = {
|
||||
val apis = (for(api <- resourceListing.apis) yield {
|
||||
val path = if(api.path.startsWith("/" + resourcePath)) {
|
||||
api.path.substring(resourcePath.length + 1)
|
||||
}
|
||||
else api.path
|
||||
api.copy(path = path.replace(".{format}",""))
|
||||
}).toList
|
||||
resourceListing.copy(apis = apis, swaggerVersion = "1.2")
|
||||
}
|
||||
writeToFile(outputDir + File.separator + "api-docs", write(updatedListing))
|
||||
|
||||
val listings = ApiExtractor.fetchApiListings(resourceListing.swaggerVersion, resourceListing.basePath, resourceListing.apis, key)
|
||||
|
||||
listings.foreach(listing => {
|
||||
val apis = (for(api <- listing.apis) yield {
|
||||
api.copy(path = api.path.replace(".{format}", ""))
|
||||
})
|
||||
val filename = listing.resourcePath.replace("/","")
|
||||
val updatedApi = listing.copy(swaggerVersion = "1.2", apis = apis)
|
||||
writeToFile(outputDir + File.separator + filename, write(updatedApi))
|
||||
})
|
||||
}
|
||||
|
||||
def writeToFile(p: String, s: String) {
|
||||
val pw = new java.io.PrintWriter(new File(p))
|
||||
try {
|
||||
println("writing file %s".format(p))
|
||||
pw.write(s)
|
||||
} finally {
|
||||
pw.close()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen
|
||||
|
||||
import com.wordnik.swagger.codegen.spec.SwaggerSpec
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
import scala.collection.mutable.{ HashMap, ListBuffer }
|
||||
|
||||
object SwaggerDocGenerator extends SwaggerDocGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
}
|
||||
|
||||
class SwaggerDocGenerator extends BasicGenerator {
|
||||
override def templateDir = "src/main/resources/swagger-static"
|
||||
|
||||
val outputFolder = "samples/swagger-static-docs"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = outputFolder + "/docs"
|
||||
|
||||
// template used for apis
|
||||
apiTemplateFiles += "operation.mustache" -> ".html"
|
||||
|
||||
modelTemplateFiles += "model.mustache" -> ".html"
|
||||
|
||||
override def toDeclaration(obj: ModelProperty): (String, String) = {
|
||||
obj.`type` match {
|
||||
case "Array" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
case _ => {
|
||||
println("failed on " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
}
|
||||
}
|
||||
}
|
||||
val e = "List[%s]" format toDeclaredType(inner)
|
||||
(e, toDefaultValue(inner, obj))
|
||||
}
|
||||
case e: String => (toDeclaredType(e), toDefaultValue(e, obj))
|
||||
}
|
||||
}
|
||||
|
||||
override def processApiMap(m: Map[String, AnyRef]): Map[String, AnyRef] = {
|
||||
val mutable = scala.collection.mutable.Map() ++ m
|
||||
mutable.map(k => {
|
||||
k._1 match {
|
||||
case "allParams" => {
|
||||
val paramList = k._2.asInstanceOf[List[_]]
|
||||
paramList.foreach(param => {
|
||||
val map = param.asInstanceOf[scala.collection.mutable.HashMap[String, AnyRef]]
|
||||
if(map.contains("dataType")){
|
||||
val ComplexTypeMatcher = ".*\\[(.*)\\].*".r
|
||||
val v = map("dataType") match {
|
||||
case ComplexTypeMatcher(v) => v
|
||||
case _ => map("dataType").asInstanceOf[String]
|
||||
}
|
||||
if(SwaggerSpec.primitives.contains(v)) {
|
||||
map += "simpleType" -> v
|
||||
}
|
||||
else {
|
||||
map += "complexType" -> v
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
})
|
||||
mutable.toMap
|
||||
}
|
||||
|
||||
// package for models
|
||||
override def modelPackage: Option[String] = Some("models")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage: Option[String] = Some("operations")
|
||||
|
||||
override def supportingFiles = List(
|
||||
("package.mustache", outputFolder, "package.json"),
|
||||
("main.mustache", outputFolder, "main.js"),
|
||||
("assets/css/bootstrap-responsive.css", destinationDir + "/assets/css", "bootstrap-responsive.css"),
|
||||
("assets/css/bootstrap.css", destinationDir + "/assets/css", "bootstrap.css"),
|
||||
("assets/css/style.css", destinationDir + "/assets/css", "style.css"),
|
||||
("assets/images/logo.png", destinationDir + "/assets/images", "logo.png"),
|
||||
("assets/js/bootstrap.js", destinationDir + "/assets/js", "bootstrap.js"),
|
||||
("assets/js/jquery-1.8.3.min.js", destinationDir + "/assets/js", "jquery-1.8.3.min.js"),
|
||||
("assets/js/main.js", destinationDir + "/assets/js", "main.js"),
|
||||
("index.mustache", destinationDir, "index.html")
|
||||
)
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen.language
|
||||
|
||||
import com.wordnik.swagger.codegen.model._
|
||||
|
||||
import scala.collection.mutable.{ HashMap, HashSet }
|
||||
|
||||
abstract class CodegenConfig {
|
||||
/*
|
||||
* abstract methods
|
||||
*/
|
||||
def packageName: String
|
||||
def templateDir: String
|
||||
def destinationDir: String
|
||||
def toModelName(name: String): String
|
||||
def toApiName(name: String): String
|
||||
|
||||
def toModelFilename(name: String) = name
|
||||
def toApiFilename(name: String) = toApiName(name)
|
||||
def apiNameFromPath(apiPath: String): String
|
||||
def processApiMap(m: Map[String, AnyRef]): Map[String, AnyRef] = m
|
||||
def processModelMap(m: Map[String, AnyRef]): Map[String, AnyRef] = m
|
||||
|
||||
val apiTemplateFiles = new HashMap[String, String]()
|
||||
val modelTemplateFiles = new HashMap[String, String]()
|
||||
val additionalParams = new HashMap[String, String]
|
||||
|
||||
def defaultIncludes = Set[String]()
|
||||
def languageSpecificPrimitives = Set[String]()
|
||||
def typeMapping = Map[String, String]()
|
||||
|
||||
// optional configs
|
||||
def invokerPackage: Option[String] = None
|
||||
def apiPackage: Option[String] = None
|
||||
def modelPackage: Option[String] = None
|
||||
|
||||
def reservedWords: Set[String] = Set()
|
||||
|
||||
// swagger primitive types
|
||||
def importMapping: Map[String, String] = Map()
|
||||
def escapeReservedWord(word: String) = word
|
||||
|
||||
// only process these apis (by name)
|
||||
val apisToProcess = new HashSet[String]
|
||||
|
||||
// only process these models
|
||||
val modelsToProcess = new HashSet[String]
|
||||
|
||||
// method name from operation.nickname
|
||||
def toMethodName(name: String): String = name
|
||||
|
||||
// override if you want to do something special on processing
|
||||
// def processOperation(apiPath: String, op: DocumentationOperation) = {}
|
||||
def processOperation(apiPath: String, op: Operation) = {}
|
||||
|
||||
def processResponseClass(responseClass: String): Option[String] = Some(responseClass)
|
||||
|
||||
def processApiOperation(apiPath: String, op: Operation) = {}
|
||||
def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => Some(toDeclaredType(e))
|
||||
}
|
||||
}
|
||||
|
||||
def supportingFiles = List(): List[(String, String, String)]
|
||||
|
||||
// mapping for datatypes
|
||||
def toDeclaration(property: ModelProperty) = {
|
||||
var declaredType = toDeclaredType(property.`type`)
|
||||
val defaultValue = toDefaultValue(declaredType, property)
|
||||
(declaredType, defaultValue)
|
||||
}
|
||||
|
||||
def toDeclaredType(dataType: String): String = {
|
||||
typeMapping.getOrElse(dataType, dataType)
|
||||
}
|
||||
|
||||
def toGetter(name: String, datatype: String) = {
|
||||
val base = datatype match {
|
||||
case "boolean" => "is"
|
||||
case _ => "get"
|
||||
}
|
||||
base + {
|
||||
if (name.length > 0) name(0).toUpper + name.substring(1)
|
||||
else ""
|
||||
}
|
||||
}
|
||||
|
||||
def toSetter(name: String, datatype: String) = {
|
||||
val base = datatype match {
|
||||
case _ => "set"
|
||||
}
|
||||
base + {
|
||||
if (name.length > 0) name(0).toUpper + name.substring(1)
|
||||
else ""
|
||||
}
|
||||
}
|
||||
|
||||
def toVarName(name: String): String = {
|
||||
name match {
|
||||
case _ if (reservedWords.contains(name)) => escapeReservedWord(name)
|
||||
case _ => name
|
||||
}
|
||||
}
|
||||
|
||||
def toDefaultValue(datatype: String, v: String): Option[String] = {
|
||||
if (v != "" && v != null) {
|
||||
datatype match {
|
||||
case "int" => Some(v)
|
||||
case "long" => Some(v)
|
||||
case "double" => Some(v)
|
||||
case x if x == "string" || x == "String" => {
|
||||
v match {
|
||||
case e: String => Some("\"" + v + "\"")
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
case _ => None
|
||||
}
|
||||
} else None
|
||||
}
|
||||
|
||||
def toDefaultValue(dataType: String, obj: ModelProperty) = {
|
||||
dataType match {
|
||||
case "int" => "0"
|
||||
case "long" => "0L"
|
||||
case "float" => "0f"
|
||||
case "double" => "0.0"
|
||||
case e: String if (Set("List").contains(e)) => {
|
||||
val inner =
|
||||
obj.items.map(i => i.ref.getOrElse(i.`type`)).getOrElse({
|
||||
println("failed on " + dataType + ", " + obj)
|
||||
throw new Exception("no inner type defined")
|
||||
})
|
||||
"List.empty[" + toDeclaredType(inner) + "]"
|
||||
}
|
||||
case _ => "_"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright 2014 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wordnik.swagger.codegen.model
|
||||
|
||||
trait AuthorizationType {
|
||||
def `type`: String
|
||||
}
|
||||
case class OAuth(
|
||||
scopes: List[String],
|
||||
grantTypes: List[GrantType]) extends AuthorizationType {
|
||||
override def `type` = "oauth2"
|
||||
}
|
||||
case class ApiKey(keyname: String, passAs: String = "header") extends AuthorizationType {
|
||||
override def `type` = "apiKey"
|
||||
}
|
||||
|
||||
trait GrantType {
|
||||
def `type`: String
|
||||
}
|
||||
case class ImplicitGrant(
|
||||
loginEndpoint: LoginEndpoint,
|
||||
tokenName: String) extends GrantType {
|
||||
def `type` = "implicit"
|
||||
}
|
||||
case class AuthorizationCodeGrant(
|
||||
tokenRequestEndpoint: TokenRequestEndpoint,
|
||||
tokenEndpoint: TokenEndpoint) extends GrantType {
|
||||
def `type` = "authorization_code"
|
||||
}
|
||||
|
||||
trait AuthorizationValue
|
||||
case class ApiKeyValue(keyName: String, passAs: String, value: String) extends AuthorizationValue
|
@ -1,23 +0,0 @@
|
||||
package com.wordnik.swagger.codegen.model
|
||||
|
||||
import scala.beans.BeanProperty
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
class ClientOpts(
|
||||
@BeanProperty var uri: String,
|
||||
@BeanProperty var auth: Option[ApiKeyValue],
|
||||
@BeanProperty var properties: java.util.Map[String, String]) {
|
||||
def this() = this(null, None, new java.util.HashMap[String, String]())
|
||||
|
||||
@BeanProperty var outputDirectory: String = _
|
||||
|
||||
override def toString() = {
|
||||
val sb = new StringBuilder()
|
||||
sb.append("ClientOpts: {\n")
|
||||
sb.append(" uri: ").append(uri).append(",")
|
||||
sb.append(" auth: ").append(auth).append(",")
|
||||
sb.append(properties.asScala.mkString(" ", ",", "\n"))
|
||||
sb.append("}")
|
||||
sb.toString
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user