mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
Merge remote branch 'upstream/master'
This commit is contained in:
commit
f20522a586
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,4 +28,3 @@ target
|
||||
.lib
|
||||
atlassian-ide-plugin.xml
|
||||
.DS_Store
|
||||
*~
|
||||
|
@ -1,3 +1,4 @@
|
||||
language: scala
|
||||
scala:
|
||||
- 2.10.0
|
||||
language: java
|
||||
script: mvn verify
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
|
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.
|
282
README.md
282
README.md
@ -3,8 +3,7 @@
|
||||
[![Build Status](https://travis-ci.org/swagger-api/swagger-codegen.png)](https://travis-ci.org/swagger-api/swagger-codegen)
|
||||
|
||||
## Overview
|
||||
This is the swagger codegen project, which allows generation of client libraries automatically from a
|
||||
Swagger-compliant server.
|
||||
This is the swagger codegen project, which allows generation of client libraries automatically from a Swagger-compliant server.
|
||||
|
||||
## What's Swagger?
|
||||
|
||||
@ -15,127 +14,84 @@ Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additi
|
||||
|
||||
|
||||
## Compatibility
|
||||
The Swagger Specification has undergone 3 revisions since initial creation in 2010. Compatibility between swagger-codegen and the Swagger specification is as follows:
|
||||
The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilities with the swagger specification:
|
||||
|
||||
Swagger Codegen Version | Release Date | Swagger Spec compatibility | Notes
|
||||
Swagger Codegen Version | Release Date | Swagger Spec compatability | Notes
|
||||
----------------------- | ------------ | -------------------------- | -----
|
||||
2.1.0 (in development) | n/a | 1.0, 1.1, 1.2, 2.0 | [branch develop_2.0](https://github.com/swagger-api/swagger-codegen/tree/develop_2.0)
|
||||
2.0.17 | 2014-08-22 | 1.1, 1.2 | [tag v2.0.17](https://github.com/swagger-api/swagger-codegen/tree/2.0.17)
|
||||
2.1.2-M1 (master) | 2015-02-23 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.0-M1](https://github.com/swagger-api/swagger-codegen)
|
||||
2.0.17 | 2014-08-22 | 1.1, 1.2 | [tag v2.0.17](https://github.com/swagger-api/swagger-codegen/tree/v2.0.17)
|
||||
1.0.4 | 2012-04-12 | 1.0, 1.1 | [tag v1.0.4](https://github.com/swagger-api/swagger-codegen/tree/swagger-codegen_2.9.1-1.1)
|
||||
|
||||
|
||||
### 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!
|
||||
* [Java 7](http://java.oracle.com)
|
||||
|
||||
* [Apache maven 3.0.3 or greater](http://maven.apache.org/)
|
||||
|
||||
* [Scala 2.10.4](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:
|
||||
After cloning the project, you can build it from source with this command:
|
||||
|
||||
```
|
||||
./sbt assembly
|
||||
mvn package
|
||||
```
|
||||
|
||||
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:
|
||||
You can build a client against the swagger sample [petstore](http://petstore.swagger.io) API as follows:
|
||||
|
||||
```
|
||||
./bin/scala-petstore.sh
|
||||
./bin/java-petstore.sh
|
||||
```
|
||||
|
||||
This will run the script in [samples/client/petstore/ScalaPetstoreCodegen.scala](https://github.com/swagger-api/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:
|
||||
This will run the generator with this command:
|
||||
|
||||
```
|
||||
cd samples/client/petstore/scala
|
||||
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l java \
|
||||
-o samples/client/petstore/java
|
||||
```
|
||||
|
||||
With a number of options. You can get the options with the -h flag:
|
||||
```
|
||||
usage: Codegen
|
||||
-a,--auth addes authorization headers when fetching the
|
||||
swagger definitions remotely. Pass in a
|
||||
URL-encoded string of name:header with a comma
|
||||
separating multiple values
|
||||
-d,--debug-info prints additional info for debugging
|
||||
-h,--help shows this message
|
||||
-i,--input-spec <arg> location of the swagger spec, as URL or file
|
||||
-l,--lang <arg> client language to generate.
|
||||
Available languages include:
|
||||
[android, java, jaxrs, nodejs, objc, scalatra,
|
||||
scala, dynamic-html, html, swagger, tizen, php,
|
||||
python]
|
||||
-o,--output <arg> where to write the generated files
|
||||
-t,--template-dir <arg> folder containing the template files
|
||||
```
|
||||
|
||||
You can then compile and run the client, as well as unit tests against it:
|
||||
|
||||
```
|
||||
cd samples/client/petstore/java
|
||||
mvn package
|
||||
```
|
||||
|
||||
Other languages have petstore samples, too:
|
||||
```
|
||||
./bin/flash-petstore.sh
|
||||
./bin/android-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/swagger-api/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.
|
||||
It's just as easy--just use the `-i` flag to point to either a server or file.
|
||||
|
||||
### 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.
|
||||
Don't like the default swagger client syntax? Want a different language supported? No problem! Swagger codegen processes mustache templates with the [jmustache](https://github.com/samskivert/jmustache) 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.
|
||||
You can look at `modules/swagger-codegen/src/main/resources/${your-language}` for examples. To make your own templates, create your own files and use the `-t` flag to specify your tempalte folder. It actually is that easy.
|
||||
|
||||
### Where is Javascript???
|
||||
See our [javascript library](http://github.com/swagger-api/swagger-js)--it's completely dynamic and doesn't require
|
||||
@ -148,102 +104,132 @@ If you don't want to call your server, you can save the swagger spec files into
|
||||
to the code generator like this:
|
||||
|
||||
```
|
||||
-DfileMap=/path/to/resource-listing
|
||||
-i ./modules/swagger-codegen/src/test/resources/2_0/petstore.json
|
||||
```
|
||||
|
||||
Or for example:
|
||||
Great for creating libraries on your ci server, from the [Swagger Editor](http://editor.swagger.io)... or while coding on an airplane.
|
||||
|
||||
### Customizing the generator
|
||||
|
||||
There are different aspects of customizing the code generator beyond just creating or modifying templates. Each language has a supporting configuration file to handle different type mappings, etc:
|
||||
|
||||
```
|
||||
./bin/java-petstore-filemap.sh
|
||||
$ ls -1 modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/
|
||||
AndroidClientCodegen.java
|
||||
JavaClientCodegen.java
|
||||
JaxRSServerCodegen.java
|
||||
NodeJSServerCodegen.java
|
||||
ObjcClientCodegen.java
|
||||
PhpClientCodegen.java
|
||||
PythonClientCodegen.java
|
||||
ScalaClientCodegen.java
|
||||
ScalatraServerCodegen.java
|
||||
StaticDocCodegen.java
|
||||
StaticHtmlGenerator.java
|
||||
SwaggerGenerator.java
|
||||
TizenClientCodegen.java
|
||||
```
|
||||
|
||||
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.
|
||||
Each of these files creates reasonable defaults so you can get running quickly. But if you want to configure package names, prefixes, model folders, etc., you may want to extend these.
|
||||
|
||||
To change, for example, the prefix for the Objective-C generated files, simply subclass the ObjcClientCodegen.java:
|
||||
|
||||
```
|
||||
package com.mycompany.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.codegen.languages.*;
|
||||
|
||||
public class MyObjcCodegen extends ObjcClientCodegen {
|
||||
static {
|
||||
PREFIX = "HELO";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
and specify the `classname` when running the generator:
|
||||
|
||||
```
|
||||
-i com.mycompany.swagger.codegen.MyObjcCodegen
|
||||
```
|
||||
|
||||
Your subclass will now be loaded and overrides the `PREFIX` value in the superclass.
|
||||
|
||||
### 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-spec](https://github.com/swagger-api/swagger-spec). 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:
|
||||
You have options. The easiest is to use our [online validator](https://github.com/swagger-api/validator-badge) which not only will let you validate your spec, but with the debug flag, you can see what's wrong with your spec. For example:
|
||||
|
||||
http://online.swagger.io/validator/debug?url=http://petstore.swagger.io/v2/swagger.json
|
||||
|
||||
### Generating dynamic html api documentation
|
||||
|
||||
To do so, just use the `-l dynamic-html` flag when reading a spec file. This creates HTML documentation that is available as a single-page application with AJAX. To view the documentation:
|
||||
|
||||
```
|
||||
./bin/validate.sh http://petstore.swagger.wordnik.com/api/api-docs "specia-key" ./swagger-errors.html
|
||||
cd samples/dynamic-html/
|
||||
npm install
|
||||
node .
|
||||
```
|
||||
|
||||
### 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.
|
||||
Which launches a node.js server so the AJAX calls have a place to go.
|
||||
|
||||
|
||||
### Generating static html api documentation
|
||||
|
||||
To do so, just use the `-l html` flag when reading a spec file. This creates a single, simple HTML file with embedded css so you can ship it as an email attachment, or load it from your filesystem:
|
||||
|
||||
```
|
||||
./bin/static-docs.sh
|
||||
cd samples/html/
|
||||
open index.html
|
||||
```
|
||||
|
||||
Will produce the output here:
|
||||
|
||||
```
|
||||
https://github.com/swagger-api/swagger-codegen/tree/master/samples/swagger-static-docs/docs
|
||||
```
|
||||
|
||||
which is based on these templates:
|
||||
|
||||
```
|
||||
https://github.com/swagger-api/swagger-codegen/tree/master/src/main/resources/swagger-static
|
||||
```
|
||||
|
||||
and looks like this
|
||||
|
||||
![Image](https://raw.github.com/swagger-api/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/swagger-api/swagger-codegen/tree/master/samples/server-generator/node)
|
||||
|
||||
* [ruby sinatra generator](https://github.com/swagger-api/swagger-codegen/tree/master/samples/server-generator/sinatra)
|
||||
|
||||
* [scala scalatra generator](https://github.com/swagger-api/swagger-codegen/tree/master/samples/server-generator/scalatra)
|
||||
|
||||
* [java jax-rs generator](https://github.com/swagger-api/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/swagger-api/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
|
||||
### node.js
|
||||
```
|
||||
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l nodejs \
|
||||
-o samples/server/petstore/nodejs
|
||||
```
|
||||
|
||||
Will read the 1.1 spec from wordnik developer and write it into the folder called `wordnik-developer`.
|
||||
### rails-grape
|
||||
#### Not yet migrated to this branch
|
||||
|
||||
|
||||
### scala scalatra
|
||||
```
|
||||
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l scalatra \
|
||||
-o samples/server/petstore/scalatra
|
||||
```
|
||||
|
||||
### java jax-rs
|
||||
|
||||
```
|
||||
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l jaxrs \
|
||||
-o samples/server/petstore/jaxrs
|
||||
```
|
||||
|
||||
### To build the codegen library
|
||||
|
||||
This will create the swagger-codegen library from source.
|
||||
|
||||
```
|
||||
./sbt assembly
|
||||
mvn package
|
||||
```
|
||||
|
||||
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!
|
||||
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 specify a path to your scripts
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Copyright 2014 Reverb Technologies, Inc.
|
||||
Copyright 2015 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.
|
||||
|
@ -1,6 +0,0 @@
|
||||
val version = scala.util.Properties.scalaPropOrElse("version.number", "unknown").toString match {
|
||||
case s if s startsWith "2.10" => "2.10"
|
||||
case s if s startsWith "2.11" => "2.11"
|
||||
case e: String => e
|
||||
}
|
||||
println(version)
|
@ -18,20 +18,14 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
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/dynamic-html.sh
|
||||
./bin/html.sh
|
||||
./bin/jaxrs-petstore-server.sh
|
||||
./bin/java-petstore-filemap.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/objc-petstore.sh
|
||||
./bin/scala-petstore.sh
|
||||
./bin/tizen-petstore.sh
|
||||
|
24
bin/all-wordnik.sh
Executable file
24
bin/all-wordnik.sh
Executable file
@ -0,0 +1,24 @@
|
||||
#!/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/android-java-wordnik-api.sh
|
||||
./bin/java-wordnik-api.sh
|
||||
./bin/objc-wordnik-api.sh
|
||||
./bin/scala-wordnik-api.sh
|
@ -17,16 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l android -o samples/client/petstore/android-java"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -18,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/wordnik.json -l android -o samples/client/wordnik/android-java"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -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
|
36
bin/dynamic-html.sh
Executable file
36
bin/dynamic-html.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
|
||||
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l dynamic-html -o samples/dynamic-html"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -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
|
36
bin/html-petstore.sh
Executable file
36
bin/html-petstore.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
|
||||
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l html -o samples/html"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -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,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -18,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l java -o samples/client/petstore/java"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -18,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/wordnik.json -l java -o samples/client/wordnik/java"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
36
bin/jaxrs-petstore-server.sh
Executable file
36
bin/jaxrs-petstore-server.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
|
||||
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l jaxrs -o samples/server/petstore/jaxrs"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
36
bin/nodejs-petstore-server.sh
Executable file
36
bin/nodejs-petstore-server.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
|
||||
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l nodejs -o samples/server/petstore/nodejs"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -1,9 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
version="$(scala ./bin/Version.scala)"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -20,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l objc -o samples/client/petstore/objc"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -18,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/wordnik.json -l objc -o samples/client/wordnik/objc"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -18,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l php -o samples/client/petstore/php"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -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,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -18,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l python -o samples/client/petstore/python"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -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
|
36
bin/scala-async-petstore.sh
Executable file
36
bin/scala-async-petstore.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
|
||||
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l async-scala -o samples/client/petstore/async-scala"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -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,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -18,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l scala -o samples/client/petstore/scala"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
@ -1,7 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
@ -18,15 +17,20 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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"
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ -i modules/swagger-codegen/src/test/resources/2_0/wordnik.json -l scala -o samples/client/wordnik/scala"
|
||||
|
||||
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
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
36
bin/scalatra-petstore-server.sh
Executable file
36
bin/scalatra-petstore-server.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
|
||||
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l scalatra -o samples/server/petstore/scalatra"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -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
|
36
bin/tizen-petstore.sh
Executable file
36
bin/tizen-petstore.sh
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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
|
||||
|
||||
root=./modules/swagger-codegen-distribution/pom.xml
|
||||
|
||||
# gets version of swagger-codegen
|
||||
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||
|
||||
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# 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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l tizen -o samples/client/petstore/tizen"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
137
build.sbt
137
build.sbt
@ -1,137 +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",
|
||||
"net.iharder" % "base64" % "2.3.8",
|
||||
"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>
|
80
modules/swagger-codegen-distribution/pom.xml
Normal file
80
modules/swagger-codegen-distribution/pom.xml
Normal file
@ -0,0 +1,80 @@
|
||||
<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>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen-project</artifactId>
|
||||
<version>2.1.2-M1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen-distribution</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>swagger-codegen (executable)</name>
|
||||
<version>2.1.2-M1</version>
|
||||
<build>
|
||||
<testSourceDirectory>src/test/scala</testSourceDirectory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<directory>target</directory>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>com.wordnik.swagger.codegen.Codegen</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
<createDependencyReducedPom>true</createDependencyReducedPom>
|
||||
<dependencyReducedPomLocation>
|
||||
${java.io.tmpdir}/dependency-reduced-pom.xml
|
||||
</dependencyReducedPomLocation>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,7 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
public class Readme {
|
||||
public String getInfo() {
|
||||
return "See the documentation for swagger-codegen";
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
<logger name="com.wordnik" level="debug"/>
|
||||
<root level="error">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
341
modules/swagger-codegen/pom.xml
Normal file
341
modules/swagger-codegen/pom.xml
Normal file
@ -0,0 +1,341 @@
|
||||
<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>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen-project</artifactId>
|
||||
<version>2.1.2-M1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>swagger-codegen (core library)</name>
|
||||
<version>2.1.2-M1</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<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>
|
||||
<directory>target</directory>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>com.wordnik.swagger.codegen.Codegen</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<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>
|
||||
<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>
|
||||
</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>io.swagger</groupId>
|
||||
<artifactId>swagger-parser</artifactId>
|
||||
<version>${swagger-parser-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-compat-spec-parser</artifactId>
|
||||
<version>${swagger-parser-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>swagger-core</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.samskivert</groupId>
|
||||
<artifactId>jmustache</artifactId>
|
||||
<version>${jmustache-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io-version}</version>
|
||||
</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>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>${commons-lang-version}</version>
|
||||
</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>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright 2015 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.annotations.*;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import com.wordnik.swagger.models.auth.AuthorizationValue;
|
||||
|
||||
import java.util.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public class ClientOptInput {
|
||||
private ClientOpts opts;
|
||||
private Swagger swagger;
|
||||
private List<AuthorizationValue> auths;
|
||||
protected CodegenConfig config;
|
||||
|
||||
public ClientOptInput swagger(Swagger swagger) {
|
||||
this.setSwagger(swagger);
|
||||
return this;
|
||||
}
|
||||
public ClientOptInput opts(ClientOpts opts) {
|
||||
this.setOpts(opts);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAuth(String urlEncodedAuthString) {
|
||||
List<AuthorizationValue> auths = new ArrayList<AuthorizationValue>();
|
||||
if(urlEncodedAuthString != null && !"".equals(urlEncodedAuthString)) {
|
||||
String[] parts = urlEncodedAuthString.split(",");
|
||||
for(String part : parts) {
|
||||
String[] kvPair = part.split(":");
|
||||
if(kvPair.length == 2) {
|
||||
auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0]), URLDecoder.decode(kvPair[1]), "header"));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.auths = auths;
|
||||
}
|
||||
public String getAuth() {
|
||||
if(auths != null) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(AuthorizationValue v : auths) {
|
||||
try {
|
||||
if(b.toString().length() > 0)
|
||||
b.append(",");
|
||||
b.append(URLEncoder.encode(v.getKeyName(), "UTF-8"))
|
||||
.append(":")
|
||||
.append(URLEncoder.encode(v.getValue(), "UTF-8"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// continue
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
public List<AuthorizationValue> getAuthorizationValues() {
|
||||
return auths;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ApiModelProperty(dataType="Object")
|
||||
public Swagger getSwagger() {
|
||||
return swagger;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.codegen.languages.*;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
import com.wordnik.swagger.models.auth.AuthorizationValue;
|
||||
import com.wordnik.swagger.util.*;
|
||||
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
|
||||
import org.apache.commons.cli.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class Codegen extends DefaultGenerator {
|
||||
static Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
|
||||
static String configString;
|
||||
static {
|
||||
List<CodegenConfig> extensions = getExtensions();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(CodegenConfig config : extensions) {
|
||||
if(sb.toString().length() != 0)
|
||||
sb.append(", ");
|
||||
sb.append(config.getName());
|
||||
configs.put(config.getName(), config);
|
||||
configString = sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
static String debugInfoOptions = "\nThe following additional debug options are available for all codegen targets:" +
|
||||
"\n -DdebugSwagger prints the swagger specification as interpreted by the codegen" +
|
||||
"\n -DdebugModels prints models passed to the template engine" +
|
||||
"\n -DdebugOperations prints operations passed to the template engine" +
|
||||
"\n -DdebugSupportingFiles prints additional data passed to the template engine";
|
||||
public static void main(String[] args) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Options options = new Options();
|
||||
options.addOption("h", "help", false, "shows this message");
|
||||
options.addOption("l", "lang", true, "client language to generate.\nAvailable languages include:\n\t[" + configString + "]");
|
||||
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");
|
||||
options.addOption("t", "template-dir", true, "folder containing the template files");
|
||||
options.addOption("d", "debug-info", false, "prints additional info for debugging");
|
||||
options.addOption("a", "auth", true, "adds authorization headers when fetching the swagger definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values");
|
||||
|
||||
ClientOptInput clientOptInput = new ClientOptInput();
|
||||
ClientOpts clientOpts = new ClientOpts();
|
||||
Swagger swagger = null;
|
||||
|
||||
CommandLine cmd = null;
|
||||
try {
|
||||
CommandLineParser parser = new BasicParser();
|
||||
CodegenConfig config = null;
|
||||
|
||||
cmd = parser.parse(options, args);
|
||||
if (cmd.hasOption("d")) {
|
||||
usage(options);
|
||||
System.out.println(debugInfoOptions);
|
||||
return;
|
||||
}
|
||||
if (cmd.hasOption("a"))
|
||||
clientOptInput.setAuth(cmd.getOptionValue("a"));
|
||||
if (cmd.hasOption("l"))
|
||||
clientOptInput.setConfig(getConfig(cmd.getOptionValue("l")));
|
||||
else {
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
if (cmd.hasOption("o"))
|
||||
clientOptInput.getConfig().setOutputDir(cmd.getOptionValue("o"));
|
||||
if (cmd.hasOption("h")) {
|
||||
if(cmd.hasOption("l")) {
|
||||
config = getConfig(String.valueOf(cmd.getOptionValue("l")));
|
||||
if(config != null) {
|
||||
options.addOption("h", "help", true, config.getHelp());
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
}
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
if (cmd.hasOption("i"))
|
||||
swagger = new SwaggerParser().read(cmd.getOptionValue("i"), clientOptInput.getAuthorizationValues(), true);
|
||||
if (cmd.hasOption("t"))
|
||||
clientOpts.getProperties().put("templateDir", String.valueOf(cmd.getOptionValue("t")));
|
||||
}
|
||||
catch (Exception e) {
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
try{
|
||||
clientOptInput
|
||||
.opts(clientOpts)
|
||||
.swagger(swagger);
|
||||
new Codegen().opts(clientOptInput).generate();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<CodegenConfig> getExtensions() {
|
||||
ServiceLoader<CodegenConfig> loader = ServiceLoader.load(CodegenConfig.class);
|
||||
List<CodegenConfig> output = new ArrayList<CodegenConfig>();
|
||||
Iterator<CodegenConfig> itr = loader.iterator();
|
||||
while(itr.hasNext()) {
|
||||
output.add(itr.next());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
static void usage(Options options) {
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
formatter.printHelp( "Codegen", options );
|
||||
}
|
||||
|
||||
public static CodegenConfig getConfig(String name) {
|
||||
if(configs.containsKey(name)) {
|
||||
return configs.get(name);
|
||||
}
|
||||
else {
|
||||
// see if it's a class
|
||||
try {
|
||||
System.out.println("loading class " + name);
|
||||
Class customClass = Class.forName(name);
|
||||
System.out.println("loaded");
|
||||
return (CodegenConfig)customClass.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("can't load class " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface CodegenConfig {
|
||||
CodegenType getTag();
|
||||
String getName();
|
||||
String getHelp();
|
||||
Map<String, Object> additionalProperties();
|
||||
String apiPackage();
|
||||
String apiFileFolder();
|
||||
String fileSuffix();
|
||||
String outputFolder();
|
||||
String templateDir();
|
||||
String modelFileFolder();
|
||||
String modelPackage();
|
||||
String toApiName(String name);
|
||||
String toApiVarName(String name);
|
||||
String toModelName(String name);
|
||||
String toParamName(String name);
|
||||
String escapeReservedWord(String name);
|
||||
String getTypeDeclaration(Property p);
|
||||
String getTypeDeclaration(String name);
|
||||
void processOpts();
|
||||
|
||||
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> instantiationTypes();
|
||||
Map<String, String> importMapping();
|
||||
Map<String, String> apiTemplateFiles();
|
||||
Map<String, String> modelTemplateFiles();
|
||||
void processSwagger(Swagger swagger);
|
||||
|
||||
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);
|
||||
Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs);
|
||||
}
|
@ -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 CodegenModel {
|
||||
public String parent;
|
||||
public String name, classname, description, classVarName, modelJson;
|
||||
public String defaultValue;
|
||||
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
|
||||
public Set<String> imports = new HashSet<String>();
|
||||
public Boolean hasVars, emptyVars, hasMoreModels;
|
||||
public ExternalDocs externalDocs;
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CodegenModelFactory {
|
||||
|
||||
private static final Map<CodegenModelType, Class<?>> typeMapping = new HashMap<CodegenModelType, Class<?>>();
|
||||
|
||||
/**
|
||||
* Configure a different implementation class.
|
||||
* @param type the type that shall be replaced
|
||||
* @param implementation the implementation class must extend the default class and must provide a public no-arg constructor
|
||||
*/
|
||||
public static void setTypeMapping(CodegenModelType type, Class<?> implementation) {
|
||||
if (!type.getDefaultImplementation().isAssignableFrom(implementation)) {
|
||||
throw new IllegalArgumentException(implementation.getSimpleName() + " doesn't extend " + type.getDefaultImplementation().getSimpleName());
|
||||
}
|
||||
try {
|
||||
implementation.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
typeMapping.put(type, implementation);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T newInstance(CodegenModelType type) {
|
||||
Class<?> classType = typeMapping.get(type);
|
||||
try {
|
||||
return (T) (classType != null ? classType : type.getDefaultImplementation()).newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
public enum CodegenModelType {
|
||||
|
||||
MODEL(CodegenModel.class),
|
||||
OPERATION(CodegenOperation.class),
|
||||
PARAMETER(CodegenParameter.class),
|
||||
PROPERTY(CodegenProperty.class),
|
||||
RESPONSE(CodegenResponse.class);
|
||||
|
||||
private final Class<?> defaultImplementation;
|
||||
|
||||
private CodegenModelType(Class<?> defaultImplementation) {
|
||||
this.defaultImplementation = defaultImplementation;
|
||||
}
|
||||
|
||||
public Class<?> getDefaultImplementation() {
|
||||
return defaultImplementation;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenOperation {
|
||||
public Boolean hasConsumes, hasProduces, hasParams, returnTypeIsPrimitive,
|
||||
returnSimpleType, subresourceOperation, isMapContainer, isListContainer;
|
||||
public String path, operationId, returnType, httpMethod, returnBaseType,
|
||||
returnContainer, summary, notes, baseName, defaultResponse;
|
||||
|
||||
public List<Map<String, String>> consumes, produces;
|
||||
public CodegenParameter bodyParam;
|
||||
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 final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
|
||||
public Set<String> imports = new HashSet<String>();
|
||||
public List<Map<String, String>> examples;
|
||||
public ExternalDocs externalDocs;
|
||||
|
||||
// legacy support
|
||||
public String nickname;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
public class CodegenParameter {
|
||||
public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
|
||||
isCookieParam, isBodyParam, isFile, notFile, hasMore, isContainer, secondaryParam;
|
||||
public String baseName, paramName, dataType, collectionFormat, description, baseType;
|
||||
/**
|
||||
* Determines whether this parameter is mandatory. If the parameter is in "path",
|
||||
* this property is required and its value MUST be true. Otherwise, the property
|
||||
* MAY be included and its default value is false.
|
||||
*/
|
||||
public Boolean required;
|
||||
|
||||
public CodegenParameter copy() {
|
||||
CodegenParameter output = new CodegenParameter();
|
||||
output.isFile = this.isFile;
|
||||
output.notFile = this.notFile;
|
||||
output.hasMore = this.hasMore;
|
||||
output.isContainer = this.isContainer;
|
||||
output.secondaryParam = this.secondaryParam;
|
||||
output.baseName = this.baseName;
|
||||
output.paramName = this.paramName;
|
||||
output.dataType = this.dataType;
|
||||
output.collectionFormat = this.collectionFormat;
|
||||
output.description = this.description;
|
||||
output.baseType = this.baseType;
|
||||
output.isFormParam = this.isFormParam;
|
||||
output.isQueryParam = this.isQueryParam;
|
||||
output.isPathParam = this.isPathParam;
|
||||
output.isHeaderParam = this.isHeaderParam;
|
||||
output.isCookieParam = this.isCookieParam;
|
||||
output.isBodyParam = this.isBodyParam;
|
||||
output.required = this.required;
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenProperty {
|
||||
public String baseName, complexType, getter, setter, description, datatype, datatypeWithEnum,
|
||||
name, min, max, defaultValue, baseType, containerType;
|
||||
|
||||
/** maxLength validation for strings, see http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.1 */
|
||||
public Integer maxLength;
|
||||
/** minLength validation for strings, see http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.2 */
|
||||
public Integer minLength;
|
||||
/** pattern validation for strings, see http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.3 */
|
||||
public String pattern;
|
||||
/** A free-form property to include an example of an instance for this schema. */
|
||||
public String example;
|
||||
|
||||
public Double minimum, maximum, exclusiveMinimum, exclusiveMaximum;
|
||||
public Boolean hasMore = null, required = null, secondaryParam = null;
|
||||
public Boolean isPrimitiveType, isContainer, isNotContainer;
|
||||
public boolean isEnum;
|
||||
public List<String> _enum;
|
||||
public Map<String, Object> allowableValues;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenResponse {
|
||||
public String code, message;
|
||||
public Boolean hasMore;
|
||||
public List<Map<String, String>> examples;
|
||||
Object schema;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public enum CodegenType {
|
||||
CLIENT, SERVER, DOCUMENTATION, OTHER;
|
||||
|
||||
private static Map<String, CodegenType> names = new HashMap<String, CodegenType>();
|
||||
|
||||
static {
|
||||
names.put("client", CLIENT);
|
||||
names.put("server", SERVER);
|
||||
names.put("documentation", DOCUMENTATION);
|
||||
names.put("other", OTHER);
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static CodegenType forValue(String value) {
|
||||
return names.get(value.toLowerCase());
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String toValue() {
|
||||
for (Map.Entry<String, CodegenType> entry : names.entrySet()) {
|
||||
if (entry.getValue() == this)
|
||||
return entry.getKey();
|
||||
}
|
||||
|
||||
return null; // or fail
|
||||
}
|
||||
}
|
@ -0,0 +1,910 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.parameters.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
import com.wordnik.swagger.util.Json;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class DefaultCodegen {
|
||||
Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||
|
||||
protected String outputFolder = "";
|
||||
protected Set<String> defaultIncludes = new HashSet<String>();
|
||||
protected Map<String, String> typeMapping = new HashMap<String, String>();
|
||||
protected Map<String, String> instantiationTypes = 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>();
|
||||
|
||||
public void processOpts(){
|
||||
if(additionalProperties.containsKey("templateDir")) {
|
||||
this.setTemplateDir((String)additionalProperties.get("templateDir"));
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
return objs;
|
||||
}
|
||||
|
||||
// override with any special handling of the entire swagger spec
|
||||
public void processSwagger(Swagger swagger) {}
|
||||
|
||||
// override with any special text escaping logic
|
||||
public String escapeText(String input) {
|
||||
if(input != null) {
|
||||
String output = input.replaceAll("\n", " ");
|
||||
output = output.replace("\"", "\\\"");
|
||||
return output;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public Set<String> defaultIncludes() {
|
||||
return defaultIncludes;
|
||||
}
|
||||
public Map<String, String> typeMapping() {
|
||||
return typeMapping;
|
||||
}
|
||||
public Map<String, String> instantiationTypes() {
|
||||
return instantiationTypes;
|
||||
}
|
||||
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 + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
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 toApiVarName(String name) {
|
||||
return snakeCase(name);
|
||||
}
|
||||
|
||||
public String toModelFilename(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toVarName(String name) {
|
||||
if(reservedWords.contains(name))
|
||||
return escapeReservedWord(name);
|
||||
else
|
||||
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",
|
||||
"Void",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
);
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("map", "Map");
|
||||
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");
|
||||
|
||||
instantiationTypes = new HashMap<String, String>();
|
||||
|
||||
reservedWords = new HashSet<String>();
|
||||
|
||||
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("Map", "java.util.Map");
|
||||
importMapping.put("HashMap", "java.util.HashMap");
|
||||
importMapping.put("Array", "java.util.List");
|
||||
importMapping.put("ArrayList", "java.util.ArrayList");
|
||||
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 toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return instantiationTypes.get("map") + "<String, " + inner + ">";
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return instantiationTypes.get("array") + "<" + inner + ">";
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "new HashMap<String, " + inner + ">() ";
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new ArrayList<" + inner + ">() ";
|
||||
}
|
||||
else
|
||||
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 snakeCase(String name) {
|
||||
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
|
||||
}
|
||||
|
||||
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) {
|
||||
if(name.length() == 0)
|
||||
return "DefaultApi";
|
||||
return initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
public String toModelName(String name) {
|
||||
return initialCaps(name);
|
||||
}
|
||||
|
||||
public CodegenModel fromModel(String name, Model model) {
|
||||
CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
|
||||
if(reservedWords.contains(name))
|
||||
m.name = escapeReservedWord(name);
|
||||
else
|
||||
m.name = name;
|
||||
m.description = model.getDescription();
|
||||
m.classname = toModelName(name);
|
||||
m.classVarName = toVarName(name);
|
||||
m.modelJson = Json.pretty(model);
|
||||
m.externalDocs = model.getExternalDocs();
|
||||
int count = 0;
|
||||
if(model instanceof ArrayModel) {
|
||||
ArrayModel am = (ArrayModel) model;
|
||||
ArrayProperty arrayProperty = new ArrayProperty(am.getItems());
|
||||
CodegenProperty cp = fromProperty(name, arrayProperty);
|
||||
if(cp.complexType != null && !defaultIncludes.contains(cp.complexType))
|
||||
m.imports.add(cp.complexType);
|
||||
m.parent = toInstantiationType(arrayProperty);
|
||||
String containerType = cp.containerType;
|
||||
if(instantiationTypes.containsKey(containerType))
|
||||
m.imports.add(instantiationTypes.get(containerType));
|
||||
if(typeMapping.containsKey(containerType)) {
|
||||
containerType = typeMapping.get(containerType);
|
||||
cp.containerType = containerType;
|
||||
m.imports.add(containerType);
|
||||
}
|
||||
}
|
||||
else if (model instanceof RefModel) {
|
||||
// TODO
|
||||
}
|
||||
else {
|
||||
ModelImpl impl = (ModelImpl) model;
|
||||
if(impl.getAdditionalProperties() != null) {
|
||||
MapProperty mapProperty = new MapProperty(impl.getAdditionalProperties());
|
||||
CodegenProperty cp = fromProperty(name, mapProperty);
|
||||
if(cp.complexType != null && !defaultIncludes.contains(cp.complexType))
|
||||
m.imports.add(cp.complexType);
|
||||
m.parent = toInstantiationType(mapProperty);
|
||||
String containerType = cp.containerType;
|
||||
if(instantiationTypes.containsKey(containerType))
|
||||
m.imports.add(instantiationTypes.get(containerType));
|
||||
if(typeMapping.containsKey(containerType)) {
|
||||
containerType = typeMapping.get(containerType);
|
||||
cp.containerType = containerType;
|
||||
m.imports.add(containerType);
|
||||
}
|
||||
}
|
||||
if(impl.getProperties() != null && impl.getProperties().size() > 0) {
|
||||
m.hasVars = true;
|
||||
for(String key: impl.getProperties().keySet()) {
|
||||
Property prop = impl.getProperties().get(key);
|
||||
|
||||
if(prop == null) {
|
||||
LOGGER.warn("null property for " + key);
|
||||
}
|
||||
else {
|
||||
CodegenProperty cp = fromProperty(key, prop);
|
||||
cp.required = false;
|
||||
if(impl.getRequired() != null) {
|
||||
for(String req : impl.getRequired()) {
|
||||
if(key.equals(req))
|
||||
cp.required = true;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
m.emptyVars = true;
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
public CodegenProperty fromProperty(String name, Property p) {
|
||||
if(p == null) {
|
||||
LOGGER.error("unexpected missing property for name " + null);
|
||||
return null;
|
||||
}
|
||||
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
|
||||
|
||||
property.name = toVarName(name);
|
||||
property.baseName = name;
|
||||
property.description = escapeText(p.getDescription());
|
||||
property.getter = "get" + initialCaps(name);
|
||||
property.setter = "set" + initialCaps(name);
|
||||
property.example = p.getExample();
|
||||
property.defaultValue = toDefaultValue(p);
|
||||
|
||||
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;
|
||||
property.maxLength = sp.getMaxLength();
|
||||
property.minLength = sp.getMinLength();
|
||||
property.pattern = sp.getPattern();
|
||||
if(sp.getEnum() != null) {
|
||||
List<String> _enum = sp.getEnum();
|
||||
property._enum = _enum;
|
||||
property.isEnum = true;
|
||||
|
||||
// legacy support
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
allowableValues.put("values", _enum);
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
property.datatype = getTypeDeclaration(p);
|
||||
|
||||
// this can cause issues for clients which don't support enums
|
||||
if(property.isEnum)
|
||||
property.datatypeWithEnum = StringUtils.capitalize(property.name) + "Enum";
|
||||
else
|
||||
property.datatypeWithEnum = property.datatype;
|
||||
|
||||
property.baseType = getSwaggerType(p);
|
||||
|
||||
if(p instanceof ArrayProperty) {
|
||||
property.isContainer = true;
|
||||
property.containerType = "array";
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
CodegenProperty cp = fromProperty("inner", ap.getItems());
|
||||
if(cp == null) {
|
||||
LOGGER.warn("skipping invalid property " + Json.pretty(p));
|
||||
}
|
||||
else {
|
||||
property.baseType = getSwaggerType(p);
|
||||
if(!languageSpecificPrimitives.contains(cp.baseType))
|
||||
property.complexType = cp.baseType;
|
||||
else
|
||||
property.isPrimitiveType = true;
|
||||
}
|
||||
}
|
||||
else if(p instanceof MapProperty) {
|
||||
property.isContainer = true;
|
||||
property.containerType = "map";
|
||||
MapProperty ap = (MapProperty) p;
|
||||
CodegenProperty cp = fromProperty("inner", ap.getAdditionalProperties());
|
||||
|
||||
property.baseType = getSwaggerType(p);
|
||||
if(!languageSpecificPrimitives.contains(cp.baseType))
|
||||
property.complexType = cp.baseType;
|
||||
else
|
||||
property.isPrimitiveType = true;
|
||||
}
|
||||
else {
|
||||
property.isNotContainer = true;
|
||||
if(languageSpecificPrimitives().contains(type))
|
||||
property.isPrimitiveType = true;
|
||||
else
|
||||
property.complexType = property.baseType;
|
||||
}
|
||||
return property;
|
||||
}
|
||||
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation){
|
||||
CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION);
|
||||
Set<String> imports = new HashSet<String>();
|
||||
|
||||
String operationId = operation.getOperationId();
|
||||
if(operationId == null) {
|
||||
String tmpPath = path;
|
||||
tmpPath = tmpPath.replaceAll("\\{", "");
|
||||
tmpPath = tmpPath.replaceAll("\\}", "");
|
||||
String[] parts = (tmpPath + "/" + httpMethod).split("/");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if("/".equals(tmpPath)) {
|
||||
// must be root tmpPath
|
||||
builder.append("root");
|
||||
}
|
||||
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 = initialCaps(part);
|
||||
builder.append(part);
|
||||
}
|
||||
}
|
||||
operationId = builder.toString();
|
||||
LOGGER.warn("generated operationId " + operationId);
|
||||
}
|
||||
op.path = path;
|
||||
op.operationId = operationId;
|
||||
op.summary = escapeText(operation.getSummary());
|
||||
op.notes = escapeText(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;
|
||||
op.hasConsumes = true;
|
||||
}
|
||||
|
||||
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;
|
||||
op.hasProduces = true;
|
||||
}
|
||||
|
||||
if(operation.getResponses() != null) {
|
||||
for(String responseCode: new TreeSet<String>(operation.getResponses().keySet())) {
|
||||
Response response = operation.getResponses().get(responseCode);
|
||||
if (responseCode.startsWith("2")) {
|
||||
// use the first, i.e. the smallest 2xx response status as methodResponse
|
||||
methodResponse = response;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 = fromResponse(responseCode, response);
|
||||
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) {
|
||||
if (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.examples = toExamples(methodResponse.getExamples());
|
||||
op.defaultResponse = toDefaultValue(responseProperty);
|
||||
op.returnType = cm.datatype;
|
||||
if(cm.isContainer != null) {
|
||||
op.returnContainer = cm.containerType;
|
||||
if("map".equals(cm.containerType))
|
||||
op.isMapContainer = Boolean.TRUE;
|
||||
else if ("list".equalsIgnoreCase(cm.containerType))
|
||||
op.isListContainer = Boolean.TRUE;
|
||||
}
|
||||
else
|
||||
op.returnSimpleType = true;
|
||||
if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null)
|
||||
op.returnTypeIsPrimitive = true;
|
||||
}
|
||||
addHeaders(methodResponse, op.responseHeaders);
|
||||
}
|
||||
|
||||
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();
|
||||
CodegenParameter bodyParam = null;
|
||||
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 = fromParameter(param, imports);
|
||||
allParams.add(p);
|
||||
if(param instanceof QueryParameter) {
|
||||
p.isQueryParam = new Boolean(true);
|
||||
queryParams.add(p.copy());
|
||||
}
|
||||
else if(param instanceof PathParameter) {
|
||||
p.required = true;
|
||||
p.isPathParam = new Boolean(true);
|
||||
pathParams.add(p.copy());
|
||||
}
|
||||
else if(param instanceof HeaderParameter) {
|
||||
p.isHeaderParam = new Boolean(true);
|
||||
headerParams.add(p.copy());
|
||||
}
|
||||
else if(param instanceof CookieParameter) {
|
||||
p.isCookieParam = new Boolean(true);
|
||||
cookieParams.add(p.copy());
|
||||
}
|
||||
else if(param instanceof BodyParameter) {
|
||||
p.isBodyParam = new Boolean(true);
|
||||
bodyParam = p;
|
||||
bodyParams.add(p.copy());
|
||||
}
|
||||
else if(param instanceof FormParameter) {
|
||||
if("file".equalsIgnoreCase(((FormParameter)param).getType()))
|
||||
p.isFile = true;
|
||||
else
|
||||
p.notFile = true;
|
||||
p.isFormParam = new Boolean(true);
|
||||
formParams.add(p.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
for(String i: imports) {
|
||||
if(!defaultIncludes.contains(i) && !languageSpecificPrimitives.contains(i)){
|
||||
op.imports.add(i);
|
||||
}
|
||||
}
|
||||
op.bodyParam = bodyParam;
|
||||
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;
|
||||
op.externalDocs = operation.getExternalDocs();
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
public CodegenResponse fromResponse(String responseCode, Response response) {
|
||||
CodegenResponse r = CodegenModelFactory.newInstance(CodegenModelType.RESPONSE);
|
||||
if("default".equals(responseCode))
|
||||
r.code = "0";
|
||||
else
|
||||
r.code = responseCode;
|
||||
r.message = response.getDescription();
|
||||
r.schema = response.getSchema();
|
||||
r.examples = toExamples(response.getExamples());
|
||||
return r;
|
||||
}
|
||||
|
||||
public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
|
||||
CodegenParameter p = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
|
||||
p.baseName = param.getName();
|
||||
p.description = param.getDescription();
|
||||
p.required = param.getRequired();
|
||||
|
||||
if(param instanceof SerializableParameter) {
|
||||
SerializableParameter qp = (SerializableParameter) param;
|
||||
Property property = null;
|
||||
String collectionFormat = null;
|
||||
if("array".equals(qp.getType())) {
|
||||
Property inner = qp.getItems();
|
||||
if(inner == null) {
|
||||
LOGGER.warn("warning! No inner type supplied for array parameter \"" + qp.getName() + "\", using String");
|
||||
inner = new StringProperty().description("//TODO automatically added by swagger-codegen");
|
||||
}
|
||||
property = new ArrayProperty(inner);
|
||||
collectionFormat = qp.getCollectionFormat();
|
||||
CodegenProperty pr = fromProperty("inner", inner);
|
||||
p.baseType = pr.datatype;
|
||||
imports.add(pr.baseType);
|
||||
}
|
||||
else
|
||||
property = PropertyBuilder.build(qp.getType(), qp.getFormat(), null);
|
||||
if(property == null) {
|
||||
LOGGER.warn("warning! Property type \"" + qp.getType() + "\" not found for parameter \"" + param.getName() + "\", using String");
|
||||
property = new StringProperty().description("//TODO automatically added by swagger-codegen. Type was " + qp.getType() + " but not supported");
|
||||
}
|
||||
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);
|
||||
if(cm.emptyVars != null && cm.emptyVars == false) {
|
||||
p.dataType = getTypeDeclaration(cm.classname);
|
||||
imports.add(p.dataType);
|
||||
}
|
||||
else {
|
||||
// TODO: missing format, so this will not always work
|
||||
Property prop = PropertyBuilder.build(impl.getType(), null, null);
|
||||
CodegenProperty cp = fromProperty("property", prop);
|
||||
if(cp != null) {
|
||||
p.dataType = cp.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
|
||||
ArrayProperty ap = new ArrayProperty().items(impl.getItems());
|
||||
CodegenProperty cp = fromProperty("inner", ap);
|
||||
if(cp.complexType != null) {
|
||||
imports.add(cp.complexType);
|
||||
}
|
||||
imports.add(cp.baseType);
|
||||
p.dataType = cp.datatype;
|
||||
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);
|
||||
}
|
||||
imports.add(name);
|
||||
name = getTypeDeclaration(name);
|
||||
}
|
||||
p.dataType = name;
|
||||
}
|
||||
}
|
||||
p.paramName = toParamName(bp.getName());
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
protected List<Map<String, String>> toExamples(Map<String, String> examples) {
|
||||
if(examples == null)
|
||||
return null;
|
||||
|
||||
List<Map<String, String>> output = new ArrayList<Map<String, String>>();
|
||||
for(String key: examples.keySet()) {
|
||||
String value = examples.get(key);
|
||||
|
||||
Map<String, String> kv = new HashMap<String, String>();
|
||||
kv.put("contentType", key);
|
||||
kv.put("example", value);
|
||||
output.add(kv);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private void addHeaders(Response response, List<CodegenProperty> target) {
|
||||
if (response.getHeaders() != null) {
|
||||
for (Map.Entry<String, Property> headers : response.getHeaders().entrySet()) {
|
||||
target.add(fromProperty(headers.getKey(), headers.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,382 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.util.*;
|
||||
import com.samskivert.mustache.*;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.*;
|
||||
import java.io.*;
|
||||
|
||||
public class DefaultGenerator implements Generator {
|
||||
protected CodegenConfig config;
|
||||
protected ClientOptInput opts = null;
|
||||
protected Swagger swagger = null;
|
||||
|
||||
public Generator opts(ClientOptInput opts) {
|
||||
this.opts = opts;
|
||||
|
||||
this.swagger = opts.getSwagger();
|
||||
ClientOpts clientOpts = opts.getOpts();
|
||||
this.config = opts.getConfig();
|
||||
this.config.additionalProperties().putAll(clientOpts.getProperties());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<File> generate() {
|
||||
if(swagger == null || config == null) {
|
||||
throw new RuntimeException("missing swagger input or config!");
|
||||
}
|
||||
if(System.getProperty("debugSwagger") != null) {
|
||||
Json.prettyPrint(swagger);
|
||||
}
|
||||
List<File> files = new ArrayList<File>();
|
||||
try {
|
||||
config.processOpts();
|
||||
if(swagger.getInfo() != null) {
|
||||
Info info = swagger.getInfo();
|
||||
if(info.getTitle() != null)
|
||||
config.additionalProperties().put("appName", info.getTitle());
|
||||
if(info.getDescription() != null)
|
||||
config.additionalProperties().put("appDescription", info.getDescription());
|
||||
if(info.getContact() != null) {
|
||||
Contact contact = info.getContact();
|
||||
config.additionalProperties().put("infoUrl", contact.getUrl());
|
||||
if(contact.getEmail() != null)
|
||||
config.additionalProperties().put("infoEmail", contact.getEmail());
|
||||
}
|
||||
if(info.getLicense() != null) {
|
||||
License license = info.getLicense();
|
||||
if(license.getName() != null)
|
||||
config.additionalProperties().put("licenseInfo", license.getName());
|
||||
if(license.getUrl() != null)
|
||||
config.additionalProperties().put("licenseUrl", license.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder hostBuilder = new StringBuilder();
|
||||
if(swagger.getSchemes() != null && swagger.getSchemes().size() > 0) {
|
||||
hostBuilder.append(swagger.getSchemes().get(0).toValue());
|
||||
hostBuilder.append("://");
|
||||
}
|
||||
else
|
||||
hostBuilder.append("https://");
|
||||
hostBuilder.append(swagger.getHost()).append(swagger.getBasePath());
|
||||
String basePath = hostBuilder.toString();
|
||||
|
||||
List<Object> allOperations = new ArrayList<Object>();
|
||||
List<Object> allModels = new ArrayList<Object>();
|
||||
|
||||
// models
|
||||
Map<String, Model> definitions = swagger.getDefinitions();
|
||||
if(definitions != null) {
|
||||
for(String name: definitions.keySet()) {
|
||||
Model model = definitions.get(name);
|
||||
Map<String, Model> modelMap = new HashMap<String, Model>();
|
||||
modelMap.put(name, model);
|
||||
Map<String, Object> models = processModels(config, modelMap);
|
||||
models.putAll(config.additionalProperties());
|
||||
|
||||
allModels.add(((List<Object>)models.get("models")).get(0));
|
||||
|
||||
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));
|
||||
files.add(new File(filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(System.getProperty("debugModels") != null) {
|
||||
System.out.println("############ Model info ############");
|
||||
Json.prettyPrint(allModels);
|
||||
}
|
||||
|
||||
// apis
|
||||
Map<String, List<CodegenOperation>> paths = processPaths(swagger.getPaths());
|
||||
for(String tag : paths.keySet()) {
|
||||
List<CodegenOperation> ops = paths.get(tag);
|
||||
Map<String, Object> operation = processOperations(config, tag, ops);
|
||||
operation.put("basePath", basePath);
|
||||
operation.put("baseName", tag);
|
||||
operation.put("modelPackage", config.modelPackage());
|
||||
operation.putAll(config.additionalProperties());
|
||||
operation.put("classname", config.toApiName(tag));
|
||||
operation.put("classVarName", config.toApiVarName(tag));
|
||||
allOperations.add(operation);
|
||||
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(operation));
|
||||
files.add(new File(filename));
|
||||
}
|
||||
}
|
||||
if(System.getProperty("debugOperations") != null) {
|
||||
System.out.println("############ Operation info ############");
|
||||
Json.prettyPrint(allOperations);
|
||||
}
|
||||
|
||||
// supporting files
|
||||
Map<String, Object> bundle = new HashMap<String, Object>();
|
||||
bundle.putAll(config.additionalProperties());
|
||||
bundle.put("apiPackage", config.apiPackage());
|
||||
|
||||
Map<String, Object> apis = new HashMap<String, Object>();
|
||||
apis.put("apis", allOperations);
|
||||
if(swagger.getBasePath() != null) {
|
||||
bundle.put("basePath", swagger.getBasePath());
|
||||
}
|
||||
bundle.put("apiInfo", apis);
|
||||
bundle.put("models", allModels);
|
||||
bundle.put("apiFolder", config.apiPackage().replace('.', File.separatorChar));
|
||||
bundle.put("modelPackage", config.modelPackage());
|
||||
if (swagger.getExternalDocs() != null) {
|
||||
bundle.put("externalDocs", swagger.getExternalDocs());
|
||||
}
|
||||
for(int i = 0; i < allModels.size() - 1; i++) {
|
||||
HashMap<String, CodegenModel> cm = (HashMap<String, CodegenModel>) allModels.get(i);
|
||||
CodegenModel m = cm.get("model");
|
||||
m.hasMoreModels = true;
|
||||
}
|
||||
|
||||
config.postProcessSupportingFileData(bundle);
|
||||
|
||||
if(System.getProperty("debugSupportingFiles") != null) {
|
||||
System.out.println("############ Supporting file info ############");
|
||||
Json.prettyPrint(bundle);
|
||||
}
|
||||
|
||||
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));
|
||||
files.add(new File(outputFilename));
|
||||
}
|
||||
else {
|
||||
String template = readTemplate(config.templateDir() + File.separator + support.templateFile);
|
||||
FileUtils.writeStringToFile(new File(outputFilename), template);
|
||||
System.out.println("copying file to " + outputFilename);
|
||||
files.add(new File(outputFilename));
|
||||
}
|
||||
}
|
||||
|
||||
config.processSwagger(swagger);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
public Map<String, List<CodegenOperation>> processPaths(Map<String, Path> paths) {
|
||||
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(sanitizeTag(tag));
|
||||
|
||||
config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String sanitizeTag(String tag) {
|
||||
// remove spaces and make strong case
|
||||
String [] parts = tag.split(" ");
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for(String part: parts) {
|
||||
if(!"".equals(part)) {
|
||||
buf.append(Character.toUpperCase(part.charAt(0)));
|
||||
if(part.length() > 1)
|
||||
buf.append(part.substring(1));
|
||||
}
|
||||
}
|
||||
return buf.toString().replaceAll("[^a-zA-Z ]", "");
|
||||
}
|
||||
|
||||
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(getCPResourcePath(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);
|
||||
}
|
||||
|
||||
private String getCPResourcePath(String name) {
|
||||
if (!"/".equals(File.separator))
|
||||
return name.replaceAll(Pattern.quote(File.separator), "/");
|
||||
return 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 LinkedHashSet<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 LinkedHashMap<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 LinkedHashSet<String>();
|
||||
for(String key: definitions.keySet()) {
|
||||
Model mm = definitions.get(key);
|
||||
CodegenModel cm = config.fromModel(key, 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 LinkedHashMap<String, String>();
|
||||
String m = config.importMapping().get(i);
|
||||
if(m == null)
|
||||
m = config.toModelImport(i);
|
||||
if(m != null && !config.defaultIncludes().contains(m)) {
|
||||
im.put("import", m);
|
||||
imports.add(im);
|
||||
}
|
||||
// add instantiation types
|
||||
m = config.instantiationTypes().get(i);
|
||||
if(m != null && !config.defaultIncludes().contains(m)) {
|
||||
im.put("import", m);
|
||||
imports.add(im);
|
||||
}
|
||||
}
|
||||
|
||||
objs.put("imports", imports);
|
||||
config.postProcessModels(objs);
|
||||
|
||||
return objs;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.wordnik.swagger.codegen;
|
||||
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public interface Generator {
|
||||
Generator opts(ClientOptInput opts);
|
||||
List<File> 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,86 @@
|
||||
#---------------------------------------------------------------------
|
||||
# Global settings
|
||||
#---------------------------------------------------------------------
|
||||
global
|
||||
log 127.0.0.1 local2
|
||||
chroot /var/lib/haproxy
|
||||
pidfile /var/run/haproxy.pid
|
||||
maxconn 4000
|
||||
user haproxy
|
||||
group haproxy
|
||||
daemon
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# common defaults that all the 'listen' and 'backend' sections will
|
||||
# use if not designated in their block
|
||||
#---------------------------------------------------------------------
|
||||
defaults
|
||||
mode http
|
||||
log global
|
||||
option dontlognull
|
||||
option httpclose
|
||||
option httplog
|
||||
option forwardfor
|
||||
option redispatch
|
||||
timeout connect 10000 # default 10 second time out if a backend is not found
|
||||
timeout client 300000
|
||||
timeout server 300000
|
||||
maxconn 60000
|
||||
retries 3
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# main frontend which proxys to the backends
|
||||
#---------------------------------------------------------------------
|
||||
frontend main *:80
|
||||
default_backend app
|
||||
|
||||
acl is_swagger_online hdr_beg(host) -i online.swagger.io
|
||||
acl is_swagger_io hdr_beg(host) -i swagger.io
|
||||
acl is_old hdr_beg(host) -i swagger.wordnik.com
|
||||
acl is_old_editor hdr_beg(host) -i editor.swagger.wordnik.com
|
||||
acl is_validator_swagger path_beg /swagger.json
|
||||
|
||||
# online spec validator
|
||||
reqrep ([^\ ]*)\ /validator/(.*) \1\ /validator/validator/\2 if is_swagger_online
|
||||
|
||||
# something that didn't work
|
||||
reqrep ([^\ ]*)\ /swagger.json(.*) \1\ /validator/swagger.json if is_validator_swagger
|
||||
|
||||
# swagger schema
|
||||
reqrep ^([^\ :]*)\ /v2/schema.json(.*) \1\ /swagger-api/swagger-spec/master/schemas/v2.0/schema.json\2
|
||||
acl is_swagger_spec path_beg /swagger-api/swagger-spec
|
||||
|
||||
# swagger docs
|
||||
reqrep ^([^\ :]*)\ /swagger-core/documentation/annotations/apidocs/current(.*) \1\ /swagger-core/apidocs/\2
|
||||
acl is_swagger_docs path_beg /swagger-core/apidocs
|
||||
|
||||
use_backend github_swagger_io if is_swagger_docs
|
||||
use_backend validator if is_swagger_online
|
||||
use_backend validator if is_validator_swagger
|
||||
use_backend github_swagger_io if is_swagger_io !is_swagger_spec
|
||||
use_backend github_swagger_spec if is_swagger_spec
|
||||
|
||||
redirect location http://editor.swagger.io if is_old_editor
|
||||
redirect location http://swagger.io if is_old
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# round robin balancing between the various backends
|
||||
#---------------------------------------------------------------------
|
||||
backend github_swagger_io
|
||||
balance roundrobin
|
||||
server gh1 swagger-api.github.io:80 check
|
||||
|
||||
backend github_swagger_spec
|
||||
http-request set-header Host raw.githubusercontent.com
|
||||
rspirep ^Content-type:(.*) Content-Type:\ application/json
|
||||
rspirep ^Access-Control-Allow-Origin:(.*) Access-Control-Allow-Origin:*
|
||||
balance roundrobin
|
||||
server gh2 raw.githubusercontent.com:443 check ssl verify none
|
||||
|
||||
backend validator
|
||||
balance roundrobin
|
||||
server app1 127.0.0.1:8000 check
|
||||
|
||||
backend app
|
||||
balance roundrobin
|
||||
server app1 127.0.0.1:8000 check
|
@ -0,0 +1,110 @@
|
||||
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 AndroidClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/java";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "android";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates an Android client library.";
|
||||
}
|
||||
|
||||
public AndroidClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/android";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
templateDir = "android-java";
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.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("httpPatch.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "HttpPatch.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",
|
||||
"Object")
|
||||
);
|
||||
instantiationTypes.put("array", "ArrayList");
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
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,194 @@
|
||||
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 AsyncScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/scala";
|
||||
protected String clientName = "SwaggerClient";
|
||||
protected String authScheme = "";
|
||||
protected boolean authPreemptive = false;
|
||||
protected boolean asyncHttpClient = !authScheme.isEmpty();
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "async-scala";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates an Asynchronous Scala client library.";
|
||||
}
|
||||
|
||||
public AsyncScalaClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/async-scala";
|
||||
modelTemplateFiles.put("model.mustache", ".scala");
|
||||
apiTemplateFiles.put("api.mustache", ".scala");
|
||||
templateDir = "asyncscala";
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String> (
|
||||
Arrays.asList(
|
||||
"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")
|
||||
);
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
additionalProperties.put("asyncHttpClient", asyncHttpClient);
|
||||
additionalProperties.put("authScheme", authScheme);
|
||||
additionalProperties.put("authPreemptive", authPreemptive);
|
||||
additionalProperties.put("clientName", clientName);
|
||||
|
||||
supportingFiles.add(new SupportingFile("sbt.mustache", "", "build.sbt"));
|
||||
supportingFiles.add(new SupportingFile("client.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), clientName + ".scala"));
|
||||
|
||||
importMapping.remove("List");
|
||||
importMapping.remove("Set");
|
||||
importMapping.remove("Map");
|
||||
|
||||
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||
importMapping.put("ListBuffer", "scala.collections.mutable.ListBuffer");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("enum", "NSString");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("set", "Set");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Long");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("byte", "Byte");
|
||||
typeMapping.put("short", "Short");
|
||||
typeMapping.put("char", "Char");
|
||||
typeMapping.put("long", "Long");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("object", "Any");
|
||||
typeMapping.put("file", "File");
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Int",
|
||||
"Long",
|
||||
"Float",
|
||||
"Object",
|
||||
"List",
|
||||
"Map")
|
||||
);
|
||||
instantiationTypes.put("array", "ListBuffer");
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return instantiationTypes.get("array") + "[" + inner + "]";
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "new HashMap[String, " + inner + "]() ";
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new ListBuffer[" + inner + "]() ";
|
||||
}
|
||||
else
|
||||
return "null";
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
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 = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/java";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "java";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Java client library.";
|
||||
}
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/java";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
templateDir = "Java";
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
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")
|
||||
);
|
||||
|
||||
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",
|
||||
"Object")
|
||||
);
|
||||
instantiationTypes.put("array", "ArrayList");
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
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,149 @@
|
||||
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 = "io.swagger.api";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-server";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/java";
|
||||
protected String title = "Swagger Server";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "jaxrs";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Java JAXRS Server application.";
|
||||
}
|
||||
|
||||
public JaxRSServerCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/javaJaxRS";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
templateDir = "JavaJaxRS";
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.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 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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getTypeDeclaration(inner);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@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());
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.models.Model;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
import com.wordnik.swagger.util.Json;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "com.wordnik.client";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "nodejs";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a node.js server application compatible with the 1.2 swagger specification.";
|
||||
}
|
||||
|
||||
public NodeJSServerCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/nodejs";
|
||||
apiTemplateFiles.put("api.mustache", ".js");
|
||||
templateDir = "nodejs";
|
||||
apiPackage = "app.apis";
|
||||
modelPackage = "app";
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("models.mustache", modelPackage, "models.js"));
|
||||
supportingFiles.add(new SupportingFile("main.mustache", "", "main.js"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
);
|
||||
typeMapping.put("array", "array");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
List<Map<String, Object>> o = (List<Map<String, Object>>)objs.get("models");
|
||||
|
||||
for(Map<String, Object> modelMap : o) {
|
||||
try {
|
||||
CodegenModel m = (CodegenModel) modelMap.get("model");
|
||||
ObjectNode on = (ObjectNode) Json.mapper().readTree(m.modelJson);
|
||||
// inject the id field
|
||||
on.put("id", m.name);
|
||||
|
||||
// remove the definitions qualifier with this nasty hack
|
||||
m.modelJson = Json.pretty(on).replaceAll("\"#/definitions/", "\"");
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// skip conversion
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type = null;
|
||||
if(typeMapping.containsKey(swaggerType)) {
|
||||
return typeMapping.get(swaggerType);
|
||||
}
|
||||
else
|
||||
type = swaggerType;
|
||||
return toModelName(type);
|
||||
}
|
||||
}
|
@ -0,0 +1,221 @@
|
||||
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";
|
||||
protected static String PREFIX = "SWG";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "objc";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates an Objective-C client library.";
|
||||
}
|
||||
|
||||
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 = "";
|
||||
|
||||
additionalProperties.put("projectName", "swaggerClient");
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"bool",
|
||||
"int",
|
||||
"NSString",
|
||||
"NSObject",
|
||||
"NSArray",
|
||||
"NSNumber",
|
||||
"NSDictionary",
|
||||
"NSMutableArray",
|
||||
"NSMutableDictionary")
|
||||
);
|
||||
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", "description"
|
||||
));
|
||||
|
||||
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("map", "NSDictionary");
|
||||
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",
|
||||
"NSDictionary")
|
||||
);
|
||||
|
||||
instantiationTypes.put("array", "NSMutableArray");
|
||||
instantiationTypes.put("map", "NSMutableDictionary");
|
||||
|
||||
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 toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return instantiationTypes.get("map");
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return instantiationTypes.get("array");
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@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 PREFIX + Character.toUpperCase(type.charAt(0)) + type.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if("".equals(modelPackage()))
|
||||
return name;
|
||||
else
|
||||
return modelPackage() + "." + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@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 PREFIX + initialCaps(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return PREFIX + initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
public String toApiFilename(String name) {
|
||||
return PREFIX + 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.util.Json;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "com.wordnik.client";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "php";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a PHP client library.";
|
||||
}
|
||||
|
||||
public PhpClientCodegen() {
|
||||
super();
|
||||
modelPackage = "models";
|
||||
outputFolder = "generated-code/php";
|
||||
modelTemplateFiles.put("model.mustache", ".php");
|
||||
apiTemplateFiles.put("api.mustache", ".php");
|
||||
templateDir = "php";
|
||||
|
||||
typeMapping.clear();
|
||||
languageSpecificPrimitives.clear();
|
||||
|
||||
reservedWords = new HashSet<String> (
|
||||
Arrays.asList(
|
||||
"int")
|
||||
);
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
|
||||
languageSpecificPrimitives.add("int");
|
||||
languageSpecificPrimitives.add("array");
|
||||
languageSpecificPrimitives.add("map");
|
||||
languageSpecificPrimitives.add("string");
|
||||
languageSpecificPrimitives.add("DateTime");
|
||||
|
||||
typeMapping.put("long", "int");
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("Array", "array");
|
||||
typeMapping.put("String", "string");
|
||||
typeMapping.put("List", "array");
|
||||
typeMapping.put("map", "map");
|
||||
|
||||
supportingFiles.add(new SupportingFile("Swagger.mustache", "", "Swagger.php"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return getSwaggerType(p) + "[string," + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
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 type;
|
||||
}
|
||||
}
|
||||
else
|
||||
type = swaggerType;
|
||||
if(type == null)
|
||||
return null;
|
||||
return type;
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
String module = "client";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "python";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Python client library.";
|
||||
}
|
||||
|
||||
public PythonClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/python";
|
||||
modelTemplateFiles.put("model.mustache", ".py");
|
||||
apiTemplateFiles.put("api.mustache", ".py");
|
||||
templateDir = "python";
|
||||
|
||||
apiPackage = module;
|
||||
modelPackage = module + ".models";
|
||||
|
||||
languageSpecificPrimitives.clear();
|
||||
languageSpecificPrimitives.add("int");
|
||||
languageSpecificPrimitives.add("float");
|
||||
languageSpecificPrimitives.add("long");
|
||||
languageSpecificPrimitives.add("list");
|
||||
languageSpecificPrimitives.add("bool");
|
||||
languageSpecificPrimitives.add("str");
|
||||
languageSpecificPrimitives.add("datetime");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("float", "float");
|
||||
typeMapping.put("long", "long");
|
||||
typeMapping.put("double", "float");
|
||||
typeMapping.put("array", "list");
|
||||
typeMapping.put("map", "map");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("string", "str");
|
||||
typeMapping.put("date", "datetime");
|
||||
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("swagger.mustache", module, "swagger.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__.mustache", module, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__.mustache", modelPackage.replace('.', File.separatorChar), "__init__.py"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "(String, " + getTypeDeclaration(inner) + ")";
|
||||
}
|
||||
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 type;
|
||||
}
|
||||
}
|
||||
else
|
||||
type = swaggerType;
|
||||
return type;
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
// TODO: Support Python def value
|
||||
return "null";
|
||||
}
|
||||
}
|
@ -0,0 +1,192 @@
|
||||
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 ScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/java";
|
||||
protected String authScheme = "";
|
||||
protected boolean authPreemptive = false;
|
||||
protected boolean asyncHttpClient = !authScheme.isEmpty();
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "scala";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Scala client library.";
|
||||
}
|
||||
|
||||
public ScalaClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/scala";
|
||||
modelTemplateFiles.put("model.mustache", ".scala");
|
||||
apiTemplateFiles.put("api.mustache", ".scala");
|
||||
templateDir = "scala";
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String> (
|
||||
Arrays.asList(
|
||||
"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")
|
||||
);
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
additionalProperties.put("asyncHttpClient", asyncHttpClient);
|
||||
additionalProperties.put("authScheme", authScheme);
|
||||
additionalProperties.put("authPreemptive", authPreemptive);
|
||||
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("apiInvoker.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiInvoker.scala"));
|
||||
|
||||
importMapping.remove("List");
|
||||
importMapping.remove("Set");
|
||||
importMapping.remove("Map");
|
||||
|
||||
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||
importMapping.put("ListBuffer", "scala.collections.mutable.ListBuffer");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("enum", "NSString");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("set", "Set");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Long");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("byte", "Byte");
|
||||
typeMapping.put("short", "Short");
|
||||
typeMapping.put("char", "Char");
|
||||
typeMapping.put("long", "Long");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("object", "Any");
|
||||
typeMapping.put("file", "File");
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Int",
|
||||
"Long",
|
||||
"Float",
|
||||
"Object",
|
||||
"List",
|
||||
"Map")
|
||||
);
|
||||
instantiationTypes.put("array", "ListBuffer");
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return instantiationTypes.get("array") + "[" + inner + "]";
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "new HashMap[String, " + inner + "]() ";
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new ListBuffer[" + inner + "]() ";
|
||||
}
|
||||
else
|
||||
return "null";
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
import com.wordnik.swagger.util.Json;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "com.wordnik.client";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/scala";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "scalatra";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Scala server application with Scalatra.";
|
||||
}
|
||||
|
||||
public ScalatraServerCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/scalatra";
|
||||
modelTemplateFiles.put("model.mustache", ".scala");
|
||||
apiTemplateFiles.put("api.mustache", ".scala");
|
||||
templateDir = "scalatra";
|
||||
apiPackage = "com.wordnik.client.api";
|
||||
modelPackage = "com.wordnik.client.model";
|
||||
|
||||
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")
|
||||
);
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList("double",
|
||||
"Int",
|
||||
"Long",
|
||||
"Float",
|
||||
"Double",
|
||||
"char",
|
||||
"float",
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"List",
|
||||
"Set",
|
||||
"Map")
|
||||
);
|
||||
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("long", "Long");
|
||||
|
||||
additionalProperties.put("appName", "Swagger Sample");
|
||||
additionalProperties.put("appName", "Swagger Sample");
|
||||
additionalProperties.put("appDescription", "A sample swagger server");
|
||||
additionalProperties.put("infoUrl", "http://developers.helloreverb.com");
|
||||
additionalProperties.put("infoEmail", "hello@helloreverb.com");
|
||||
additionalProperties.put("licenseInfo", "All rights reserved");
|
||||
additionalProperties.put("licenseUrl", "http://apache.org/licenses/LICENSE-2.0.html");
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("build.sbt", "", "build.sbt"));
|
||||
supportingFiles.add(new SupportingFile("web.xml", "/src/main/webapp/WEB-INF", "web.xml"));
|
||||
supportingFiles.add(new SupportingFile("JettyMain.scala", sourceFolder, "JettyMain.scala"));
|
||||
supportingFiles.add(new SupportingFile("Bootstrap.mustache", sourceFolder, "ScalatraBootstrap.scala"));
|
||||
supportingFiles.add(new SupportingFile("ServletApp.mustache", sourceFolder, "ServletApp.scala"));
|
||||
supportingFiles.add(new SupportingFile("project/build.properties", "project", "build.properties"));
|
||||
supportingFiles.add(new SupportingFile("project/plugins.sbt", "project", "plugins.sbt"));
|
||||
supportingFiles.add(new SupportingFile("sbt", "", "sbt"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Object")
|
||||
);
|
||||
instantiationTypes.put("array", "ArrayList");
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
|
||||
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("Map", "java.util.Map");
|
||||
importMapping.put("HashMap", "java.util.HashMap");
|
||||
importMapping.put("Array", "java.util.List");
|
||||
importMapping.put("ArrayList", "java.util.ArrayList");
|
||||
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||
importMapping.put("LocalDateTime", "org.joda.time.LocalDateTime");
|
||||
importMapping.put("LocalDate", "org.joda.time.LocalDate");
|
||||
importMapping.put("LocalTime", "org.joda.time.LocalTime");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||
for(CodegenOperation op: operationList) {
|
||||
op.httpMethod = op.httpMethod.toLowerCase();
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
@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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
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,76 @@
|
||||
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 StaticDocCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "com.wordnik.client";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "docs";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.DOCUMENTATION;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "dynamic-html";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a dynamic HTML site.";
|
||||
}
|
||||
|
||||
public StaticDocCodegen() {
|
||||
super();
|
||||
outputFolder = "docs";
|
||||
modelTemplateFiles.put("model.mustache", ".html");
|
||||
apiTemplateFiles.put("operation.mustache", ".html");
|
||||
templateDir = "swagger-static";
|
||||
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("main.mustache", "", "main.js"));
|
||||
supportingFiles.add(new SupportingFile("assets/css/bootstrap-responsive.css",
|
||||
outputFolder + "/assets/css", "bootstrap-responsive.css"));
|
||||
supportingFiles.add(new SupportingFile("assets/css/bootstrap.css",
|
||||
outputFolder + "/assets/css", "bootstrap.css"));
|
||||
supportingFiles.add(new SupportingFile("assets/css/style.css",
|
||||
outputFolder + "/assets/css", "style.css"));
|
||||
supportingFiles.add(new SupportingFile("assets/images/logo.png",
|
||||
outputFolder + "/assets/images", "logo.png"));
|
||||
supportingFiles.add(new SupportingFile("assets/js/bootstrap.js",
|
||||
outputFolder + "/assets/js", "bootstrap.js"));
|
||||
supportingFiles.add(new SupportingFile("assets/js/jquery-1.8.3.min.js",
|
||||
outputFolder + "/assets/js", "jquery-1.8.3.min.js"));
|
||||
supportingFiles.add(new SupportingFile("assets/js/main.js",
|
||||
outputFolder + "/assets/js", "main.js"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache",
|
||||
outputFolder, "index.html"));
|
||||
|
||||
instantiationTypes.put("array", "ArrayList");
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + "operations";
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + "models";
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
import com.wordnik.swagger.util.Json;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class StaticHtmlGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "com.wordnik.client";
|
||||
protected String groupId = "com.wordnik";
|
||||
protected String artifactId = "swagger-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/scala";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.DOCUMENTATION;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "html";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a static HTML file.";
|
||||
}
|
||||
|
||||
public StaticHtmlGenerator() {
|
||||
super();
|
||||
outputFolder = "docs";
|
||||
templateDir = "htmlDocs";
|
||||
|
||||
defaultIncludes = new HashSet<String>();
|
||||
|
||||
String partner = "our Partner";
|
||||
|
||||
if(System.getProperty("partner") != null)
|
||||
partner = System.getProperty("partner");
|
||||
|
||||
additionalProperties.put("partner", partner);
|
||||
additionalProperties.put("appName", "Swagger Sample");
|
||||
additionalProperties.put("appDescription", "A sample swagger server");
|
||||
additionalProperties.put("infoUrl", "https://helloreverb.com");
|
||||
additionalProperties.put("infoEmail", "hello@helloreverb.com");
|
||||
additionalProperties.put("licenseInfo", "All rights reserved");
|
||||
additionalProperties.put("licenseUrl", "http://apache.org/licenses/LICENSE-2.0.html");
|
||||
additionalProperties.put("invokerPackage", invokerPackage);
|
||||
additionalProperties.put("groupId", groupId);
|
||||
additionalProperties.put("artifactId", artifactId);
|
||||
additionalProperties.put("artifactVersion", artifactVersion);
|
||||
|
||||
supportingFiles.add(new SupportingFile("index.mustache", "", "index.html"));
|
||||
reservedWords = new HashSet<String>();
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>();
|
||||
importMapping = new HashMap<String, String> ();
|
||||
}
|
||||
|
||||
@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) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||
for(CodegenOperation op: operationList) {
|
||||
op.httpMethod = op.httpMethod.toLowerCase();
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.wordnik.swagger.codegen.languages;
|
||||
|
||||
import com.wordnik.swagger.codegen.*;
|
||||
import com.wordnik.swagger.util.*;
|
||||
import com.wordnik.swagger.models.Swagger;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SwaggerGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.DOCUMENTATION;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "swagger";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Creates a static swagger.json file.";
|
||||
}
|
||||
|
||||
public SwaggerGenerator() {
|
||||
super();
|
||||
outputFolder = "generated-code/swagger";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processSwagger(Swagger swagger) {
|
||||
String swaggerString = Json.pretty(swagger);
|
||||
|
||||
try{
|
||||
String outputFile = outputFolder + File.separator + "swagger.json";
|
||||
FileUtils.writeStringToFile(new File(outputFile), swaggerString);
|
||||
System.out.println("wrote file to " + outputFile);
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,247 @@
|
||||
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 TizenClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected Set<String> foundationClasses = new HashSet<String>();
|
||||
protected String sourceFolder = "client";
|
||||
protected static String PREFIX = "Sami";
|
||||
protected Map<String, String> namespaces = new HashMap<String, String>();
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "tizen";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Samsung Tizen C++ client library.";
|
||||
}
|
||||
|
||||
public TizenClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/tizen";
|
||||
modelTemplateFiles.put("model-header.mustache", ".h");
|
||||
modelTemplateFiles.put("model-body.mustache", ".cpp");
|
||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-body.mustache", ".cpp");
|
||||
templateDir = "tizen";
|
||||
modelPackage = "";
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"bool",
|
||||
"int",
|
||||
"long")
|
||||
);
|
||||
languageSpecificPrimitives = new HashSet<String>();
|
||||
|
||||
additionalProperties().put("prefix", PREFIX);
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
// VERIFY
|
||||
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"
|
||||
));
|
||||
|
||||
super.typeMapping = new HashMap<String, String>();
|
||||
|
||||
typeMapping.put("Date", "DateTime");
|
||||
typeMapping.put("DateTime", "DateTime");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("integer", "Integer");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("long", "Long");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("array", "IList");
|
||||
typeMapping.put("map", "HashMap");
|
||||
typeMapping.put("number", "Long");
|
||||
typeMapping.put("object", PREFIX + "Object");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
|
||||
namespaces = new HashMap<String, String> ();
|
||||
namespaces.put("DateTime", "Tizen::Base::DateTime");
|
||||
namespaces.put("Integer", "Tizen::Base::Integer");
|
||||
namespaces.put("Long", "Tizen::Base::Long");
|
||||
namespaces.put("Boolean", "Tizen::Base::Boolean");
|
||||
namespaces.put("Float", "Tizen::Base::Float");
|
||||
namespaces.put("String", "Tizen::Base::String");
|
||||
namespaces.put("Double", "Tizen::Base::Double");
|
||||
namespaces.put("IList", "Tizen::Base::Collection::IList");
|
||||
namespaces.put("HashMap", "Tizen::Base::Collection::HashMap");
|
||||
namespaces.put("ArrayList", "Tizen::Base::Collection::ArrayList");
|
||||
namespaces.put("JsonNumber", "Tizen::Web::Json");
|
||||
namespaces.put("JsonString", "Tizen::Web::Json");
|
||||
|
||||
foundationClasses = new HashSet<String> (
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"Integer",
|
||||
"Float")
|
||||
);
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("modelFactory.mustache", sourceFolder, PREFIX + "ModelFactory.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, PREFIX + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, PREFIX + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("apiclient-header.mustache", sourceFolder, PREFIX + "ApiClient.h"));
|
||||
supportingFiles.add(new SupportingFile("apiclient-body.mustache", sourceFolder, PREFIX + "ApiClient.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("error-header.mustache", sourceFolder, PREFIX + "Error.h"));
|
||||
supportingFiles.add(new SupportingFile("error-body.mustache", sourceFolder, PREFIX + "Error.cpp"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return instantiationTypes.get("map");
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return instantiationTypes.get("array");
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@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) ||
|
||||
typeMapping.values().contains(type) ||
|
||||
foundationClasses.contains(type) ||
|
||||
importMapping.values().contains(type) ||
|
||||
defaultIncludes.contains(type) ||
|
||||
languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
else {
|
||||
return PREFIX + Character.toUpperCase(type.charAt(0)) + type.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if(namespaces.containsKey(name)) {
|
||||
return "using " + namespaces.get(name) + ";";
|
||||
}
|
||||
return "#include \"" + name + ".h\"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if(p instanceof StringProperty)
|
||||
return "new String()";
|
||||
else if (p instanceof BooleanProperty)
|
||||
return "new Boolean(false)";
|
||||
else if(p instanceof DateProperty)
|
||||
return "new DateTime()";
|
||||
else if(p instanceof DateTimeProperty)
|
||||
return "new DateTime()";
|
||||
else if (p instanceof DoubleProperty)
|
||||
return "new Double()";
|
||||
else if (p instanceof FloatProperty)
|
||||
return "new Float()";
|
||||
else if (p instanceof IntegerProperty)
|
||||
return "new Integer()";
|
||||
else if (p instanceof LongProperty)
|
||||
return "new Long()";
|
||||
else if (p instanceof DecimalProperty)
|
||||
return "new Long()";
|
||||
else if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "new HashMap()";
|
||||
}
|
||||
else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new ArrayList()";
|
||||
}
|
||||
// else
|
||||
if(p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty) p;
|
||||
return "new " + toModelName(rp.getSimpleRef()) + "()";
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
@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 PREFIX + initialCaps(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
return PREFIX + initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
public String toApiFilename(String name) {
|
||||
return PREFIX + initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
String paramName = name.replaceAll("[^a-zA-Z0-9_]","");
|
||||
paramName = Character.toUpperCase(paramName.charAt(0)) + paramName.substring(1);
|
||||
return "p" + paramName;
|
||||
}
|
||||
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
}
|
@ -3,6 +3,10 @@ package {{package}};
|
||||
import {{invokerPackage}}.ApiException;
|
||||
import {{invokerPackage}}.ApiInvoker;
|
||||
|
||||
import {{modelPackage}}.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
@ -11,7 +15,8 @@ import com.sun.jersey.multipart.FormDataMultiPart;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
@ -21,25 +26,22 @@ public class {{classname}} {
|
||||
public ApiInvoker getInvoker() {
|
||||
return apiInvoker;
|
||||
}
|
||||
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
/*
|
||||
{{#errorList}}
|
||||
* error info- code: {{code}} reason: "{{reason}}" model: {{#responseModel}}{{responseModel}}
|
||||
{{#errorList}} //error info- code: {{code}} reason: "{{reason}}" model: {{#responseModel}}{{responseModel}}
|
||||
{{/responseModel}}{{^responseModel}}<none>
|
||||
{{/responseModel}}
|
||||
{{/errorList}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{bodyParam}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
{{#requiredParamCount}}
|
||||
// verify required params are set
|
||||
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
|
||||
@ -48,7 +50,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>();
|
||||
@ -58,10 +61,8 @@ public class {{classname}} {
|
||||
{{#queryParams}}if(!"null".equals(String.valueOf({{paramName}})))
|
||||
queryParams.put("{{baseName}}", String.valueOf({{paramName}}));
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams.put("{{baseName}}", {{paramName}});
|
||||
{{/headerParams}}
|
||||
|
||||
String[] contentTypes = {
|
||||
{{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}}
|
||||
};
|
||||
@ -71,24 +72,18 @@ public class {{classname}} {
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
boolean hasFields = false;
|
||||
FormDataMultiPart mp = new FormDataMultiPart();
|
||||
{{#formParams}}
|
||||
{{#notFile}}
|
||||
{{#formParams}}{{#notFile}}
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
{{/notFile}}
|
||||
{{#isFile}}
|
||||
{{/notFile}}{{#isFile}}
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{/isFile}}{{/formParams}}
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
{{#formParams}}
|
||||
{{#notFile}}
|
||||
formParams.put("{{baseName}}", String.valueOf({{paramName}}));
|
||||
{{/notFile}}
|
||||
{{#formParams}}{{#notFile}}formParams.put("{{baseName}}", {{paramName}});{{/notFile}}
|
||||
{{/formParams}}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.wordnik.client.common;
|
||||
package {{invokerPackage}};
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator.Feature;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
@ -11,6 +11,7 @@ import com.sun.jersey.api.client.config.ClientConfig;
|
||||
import com.sun.jersey.api.client.config.DefaultClientConfig;
|
||||
import com.sun.jersey.api.client.filter.LoggingFilter;
|
||||
import com.sun.jersey.api.client.WebResource.Builder;
|
||||
import com.sun.jersey.multipart.FormDataMultiPart;
|
||||
|
||||
import javax.ws.rs.core.Response.Status.Family;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
@ -50,8 +51,11 @@ public class ApiInvoker {
|
||||
}
|
||||
|
||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
if(null != containerType) {
|
||||
containerType = containerType.toLowerCase();
|
||||
}
|
||||
try{
|
||||
if("List".equals(containerType)) {
|
||||
if("list".equals(containerType) || "array".equals(containerType)) {
|
||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||
return response;
|
||||
@ -117,7 +121,10 @@ public class ApiInvoker {
|
||||
}
|
||||
else if ("POST".equals(method)) {
|
||||
if(body == null)
|
||||
response = builder.post(ClientResponse.class, serialize(body));
|
||||
response = builder.post(ClientResponse.class, null);
|
||||
else if(body instanceof FormDataMultiPart) {
|
||||
response = builder.type(contentType).post(ClientResponse.class, body);
|
||||
}
|
||||
else
|
||||
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
|
||||
}
|
||||
@ -181,4 +188,3 @@ public class ApiInvoker {
|
||||
return hostMap.get(host);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import com.wordnik.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty(required = {{required}}, value = "{{{description}}}")
|
||||
@JsonProperty("{{name}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -107,35 +107,35 @@
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
@ -146,7 +146,6 @@
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
@ -157,8 +156,8 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0-M1</swagger-annotations-version>
|
||||
<jersey-version>1.7</jersey-version>
|
||||
<jackson-version>2.1.4</jackson-version>
|
||||
<jodatime-version>2.3</jodatime-version>
|
@ -3,7 +3,7 @@ package {{apiPackage}};
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponse {
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
@ -14,9 +14,9 @@ public class ApiResponse {
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponse(){}
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponse(int code, String message){
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
@ -0,0 +1,46 @@
|
||||
package {{package}};
|
||||
|
||||
import {{modelPackage}}.*;
|
||||
|
||||
import com.wordnik.swagger.annotations.*;
|
||||
import com.sun.jersey.multipart.FormDataParam;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import java.util.List;
|
||||
import {{package}}.NotFoundException;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.sun.jersey.core.header.FormDataContentDisposition;
|
||||
import com.sun.jersey.multipart.FormDataParam;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.*;
|
||||
|
||||
@Path("/{{baseName}}")
|
||||
@Api(value = "/{{baseName}}", description = "the {{baseName}} API")
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
{{#operation}}
|
||||
@{{httpMethod}}
|
||||
{{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}}
|
||||
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
|
||||
{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
|
||||
// {{returnType}}
|
||||
@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}}{{>formParams}}{{#hasMore}},
|
||||
{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
// do some magic!
|
||||
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
@ -0,0 +1 @@
|
||||
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) {{{dataType}}} {{paramName}}{{/isBodyParam}}
|
@ -0,0 +1,2 @@
|
||||
{{#isFormParam}}{{#notFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@FormParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@ApiParam(value = "{{{description}}}") @FormDataParam("file") InputStream inputStream,
|
||||
@ApiParam(value = "file detail") @FormDataParam("file") FormDataContentDisposition fileDetail{{/isFile}}{{/isFormParam}}
|
@ -0,0 +1 @@
|
||||
{{#isHeaderParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@HeaderParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isHeaderParam}}
|
@ -0,0 +1,51 @@
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import com.wordnik.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty(required = {{required}}, value = "{{{description}}}")
|
||||
@JsonProperty("{{name}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
@ -0,0 +1 @@
|
||||
{{#isPathParam}}@ApiParam(value = "{{{description}}}"{{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}} {{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @PathParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
|
@ -1,10 +1,10 @@
|
||||
<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>com.wordnik</groupId>
|
||||
<artifactId>swagger-java-jaxrs-petstore</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>swagger-java-jaxrs-petstore</name>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
@ -31,7 +31,7 @@
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webAppConfig>
|
||||
<contextPath>/api</contextPath>
|
||||
<contextPath>{{^basePath}}/{{/basePath}}{{#basePath}}{{basePath}}{{/basePath}}</contextPath>
|
||||
</webAppConfig>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>
|
||||
@ -71,15 +71,40 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-jaxrs_2.9.1</artifactId>
|
||||
<artifactId>swagger-jersey-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>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-server</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.9.1</artifactId>
|
||||
@ -99,8 +124,9 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-core-version>1.2.1</swagger-core-version>
|
||||
<jetty-version>7.6.0.v20120127</jetty-version>
|
||||
<swagger-core-version>1.5.1-M1</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>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user