forked from loafle/openapi-generator-original
Merge remote-tracking branch 'main/master'
This commit is contained in:
@@ -30,7 +30,7 @@ samples/client/petstore/qt5cpp/build-*
|
||||
samples/client/petstore/qt5cpp/PetStore/PetStore
|
||||
samples/client/petstore/qt5cpp/PetStore/Makefile
|
||||
samples/client/petstore/java/hello.txt
|
||||
samples/client/petstore/android-java/hello.txt
|
||||
samples/client/petstore/android/default/hello.txt
|
||||
samples/client/petstore/objc/Build
|
||||
samples/client/petstore/objc/Pods
|
||||
samples/server/petstore/nodejs/node_modules
|
||||
|
||||
22
.gitignore
vendored
22
.gitignore
vendored
@@ -31,7 +31,7 @@ samples/client/petstore/qt5cpp/build-*
|
||||
samples/client/petstore/qt5cpp/PetStore/PetStore
|
||||
samples/client/petstore/qt5cpp/PetStore/Makefile
|
||||
samples/client/petstore/java/hello.txt
|
||||
samples/client/petstore/android-java/hello.txt
|
||||
samples/client/petstore/android/default/hello.txt
|
||||
samples/client/petstore/objc/SwaggerClientTests/Build
|
||||
samples/client/petstore/objc/SwaggerClientTests/Pods
|
||||
samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcworkspace
|
||||
@@ -48,6 +48,7 @@ atlassian-ide-plugin.xml
|
||||
packages/
|
||||
.pub
|
||||
.packages
|
||||
.vagrant/
|
||||
|
||||
samples/client/petstore/php/SwaggerClient-php/composer.lock
|
||||
samples/client/petstore/php/SwaggerClient-php/vendor/
|
||||
@@ -55,13 +56,30 @@ samples/client/petstore/php/SwaggerClient-php/vendor/
|
||||
samples/client/petstore/silex/SwaggerServer/composer.lock
|
||||
samples/client/petstore/silex/SwaggerServer/venodr/
|
||||
|
||||
samples/client/petstore/perl/deep_module_test/
|
||||
|
||||
samples/client/petstore/python/.projectile
|
||||
samples/client/petstore/python/.venv/
|
||||
samples/client/petstore/python/dev-requirements.txt.log
|
||||
|
||||
*/.settings
|
||||
samples/client/petstore/objc/SwaggerClientTests/SwaggerClient.xcodeproj/xcuserdata
|
||||
samples/client/petstore/swift/SwaggerClientTests/SwaggerClient.xcodeproj/xcuserdata
|
||||
samples/client/petstore/swift/SwaggerClientTests/SwaggerClient.xcworkspace/xcuserdata
|
||||
samples/client/petstore/swift/SwaggerClientTests/Pods/Pods.xcodeproj/xcuserdata
|
||||
samples/client/petstore/swift/SwaggerClientTests/Pods/Pods.xcodeproj/xcshareddata/xcschemes
|
||||
|
||||
.settings
|
||||
|
||||
*.mustache~
|
||||
*.java~
|
||||
*.pm~
|
||||
*.xml~
|
||||
*.t~
|
||||
|
||||
samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/
|
||||
samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/
|
||||
**/.gradle/
|
||||
|
||||
samples/client/petstore/python/dev-requirements.txt.log
|
||||
samples/client/petstore/python/swagger_client.egg-info/SOURCES.txt
|
||||
samples/client/petstore/python/.coverage
|
||||
|
||||
20
.travis.yml
20
.travis.yml
@@ -1,5 +1,21 @@
|
||||
sudo: false
|
||||
sudo: required
|
||||
language: java
|
||||
script: mvn verify -Psamples
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
- oraclejdk8
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_install:
|
||||
# required when sudo: required for the Ruby petstore tests
|
||||
- gem install bundler
|
||||
|
||||
install:
|
||||
|
||||
script:
|
||||
- mvn verify -Psamples
|
||||
- if [ $DOCKER_HUB_USERNAME ]; then docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD && docker build -t $DOCKER_IMAGE_NAME ./modules/swagger-generator && if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_IMAGE_NAME:latest $DOCKER_IMAGE_NAME:$TRAVIS_TAG; fi && docker push $DOCKER_IMAGE_NAME; fi
|
||||
|
||||
env:
|
||||
- DOCKER_IMAGE_NAME=swaggerapi/swagger-generator
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
## Before submitting an issue
|
||||
|
||||
- Before submitting an issue, search the [open issue](https://github.com/swagger-api/swagger-codegen/issues) and [closed issue](https://github.com/swagger-api/swagger-codegen/issues?q=is%3Aissue+is%3Aclosed) to ensure no one else has reported something similar before.
|
||||
- Search the [open issue](https://github.com/swagger-api/swagger-codegen/issues) and [closed issue](https://github.com/swagger-api/swagger-codegen/issues?q=is%3Aissue+is%3Aclosed) to ensure no one else has reported something similar before.
|
||||
- The issue should contain details on how to repeat the issue, e.g.
|
||||
- the Swagger spec for reproducing the issue (:bulb: use [Gist](https://gist.github.com) to share). If the Swagger spec cannot be shared publicly, it will be hard for the community to help
|
||||
- the OpenAPI Spec for reproducing the issue (:bulb: use [Gist](https://gist.github.com) to share). If the OpenAPI Spec cannot be shared publicly, it will be hard for the community to help
|
||||
- version of Swagger Codegen
|
||||
- language (`-l` in the command line, e.g. java, csharp, php)
|
||||
- You can also make a suggestion or ask a question by opening an "issue"
|
||||
@@ -31,10 +31,12 @@ For a list of variables available in the template, please refer to this [page](h
|
||||
Code change should conform to the programming style guide of the respective langauages:
|
||||
- C#: https://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx
|
||||
- Java: https://google.github.io/styleguide/javaguide.html
|
||||
- JavaScript - https://github.com/airbnb/javascript/tree/master/es5
|
||||
- ObjC: https://github.com/NYTimes/objective-c-style-guide
|
||||
- PHP: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
|
||||
- Python: https://www.python.org/dev/peps/pep-0008/
|
||||
- Ruby: https://github.com/bbatsov/ruby-style-guide
|
||||
- Swift: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html
|
||||
- TypeScript: https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines
|
||||
|
||||
|
||||
@@ -56,7 +58,7 @@ To start the CI tests, you can run `mvn verify -Psamples` (assuming you've all t
|
||||
|
||||
### Tips
|
||||
- Smaller changes are easier to review
|
||||
- [Optional] For bug fixes, provide a Swagger spec to repeat the issue so that the reviewer can use it to confirm the fix
|
||||
- [Optional] For bug fixes, provide a OpenAPI Spec to repeat the issue so that the reviewer can use it to confirm the fix
|
||||
- Add test case(s) to cover the change
|
||||
- Document the fix in the code to make the code more readable
|
||||
- Make sure test cases passed after the change (one way is to leverage https://travis-ci.org/ to run the CI tests)
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright 2015 SmartBear Software
|
||||
Copyright 2016 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
259
README.md
259
README.md
@@ -1,14 +1,15 @@
|
||||
# Swagger Code Generator
|
||||
|
||||
[](https://travis-ci.org/swagger-api/swagger-codegen)
|
||||
[](https://travis-ci.org/swagger-api/swagger-codegen)
|
||||
[](https://maven-badges.herokuapp.com/maven-central/io.swagger/swagger-codegen-project)
|
||||
[](http://issuestats.com/github/swagger-api/swagger-codegen) [](http://issuestats.com/github/swagger-api/swagger-codegen)
|
||||
|
||||
:star::star::star: If you would like to contribute, please refer to [guidelines](https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md) and a list of [open tasks](https://github.com/swagger-api/swagger-codegen/issues?q=is%3Aopen+is%3Aissue+label%3A%22Need+community+contribution%22).:star::star::star:
|
||||
|
||||
## Overview
|
||||
This is the swagger codegen project, which allows generation of client libraries automatically from a Swagger-compliant server.
|
||||
|
||||
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
||||
Check out [Swagger-Spec](https://github.com/OAI/OpenAPI-Specification) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
||||
|
||||
# Table of contents
|
||||
|
||||
@@ -22,7 +23,8 @@ Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additi
|
||||
- [Building](#building)
|
||||
- [Docker](#docker)
|
||||
- [Build and run](#build-and-run-using-docker)
|
||||
- [Build a Node.js server stub](#build-a-nodejs-server-stub)
|
||||
- [Run docker in Vagrant](#run-docker-in-vagrant)
|
||||
- [Public Docker image](#public-docker-image)
|
||||
- [Homebrew](#homebrew)
|
||||
- Generators
|
||||
- [To generate a sample client library](#to-generate-a-sample-client-library)
|
||||
@@ -32,47 +34,66 @@ Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additi
|
||||
- [Where is Javascript???](#where-is-javascript)
|
||||
- [Generating a client from local files](#generating-a-client-from-local-files)
|
||||
- [Customizing the generator](#customizing-the-generator)
|
||||
- [Validating your swagger spec](#validating-your-swagger-spec)
|
||||
- [Validating your OpenAPI Spec](#validating-your-openapi-spec)
|
||||
- [Generating dynamic html api documentation](#generating-dynamic-html-api-documentation)
|
||||
- [Generating static html api documentation](#generating-static-html-api-documentation)
|
||||
- [To build a server stub](#to-build-a-server-stub)
|
||||
- [Node.js](#nodejs)
|
||||
- [PHP Slim](#php-slim)
|
||||
- [PHP Silex](#php-silex)
|
||||
- [Python Flask (Connexion)](#python-flask-connexion)
|
||||
- [Ruby Sinatra](#ruby-sinatra)
|
||||
- [Scala Scalatra](#scala-scalatra)
|
||||
- [Java JAX-RS](#java-jax-rs)
|
||||
- [Java JAX-RS (Java JAX-RS (Jersey v1.18)](#java-jax-rs-jersey-v118)
|
||||
- [Java JAX-RS (Apache CXF 3)](#java-jax-rs-apache-cxf-3)
|
||||
- [Java Spring MVC](#java-spring-mvc)
|
||||
- [Haskell Servant](#haskell-servant)
|
||||
- [ASP.NET 5 Web API](#aspnet-5-web-api)
|
||||
- [To build the codegen library](#to-build-the-codegen-library)
|
||||
- [Workflow Integration](#workflow-integration)
|
||||
- [Online Generators](#online-generators)
|
||||
- [Guidelines for Contribution](https://github.com/swagger-api/swagger-codegen/wiki/Guidelines-for-Contribution)
|
||||
- [Companies/Projects using Swagger Codegen](#companiesprojects-using-swagger-codegen)
|
||||
- [License](#license)
|
||||
|
||||
|
||||
## Compatibility
|
||||
The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the swagger specification:
|
||||
The OpenAPI Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the OpenAPI Specification:
|
||||
|
||||
Swagger Codegen Version | Release Date | Swagger Spec compatibility | Notes
|
||||
Swagger Codegen Version | Release Date | OpenAPI Spec compatibility | Notes
|
||||
-------------------------- | ------------ | -------------------------- | -----
|
||||
2.1.5-SNAPSHOT | | 1.0, 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-codegen)
|
||||
2.1.4 (**current stable**) | 2015-10-25 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.4](https://github.com/swagger-api/swagger-codegen/tree/v2.1.4)
|
||||
2.1.6-SNAPSHOT | | 1.0, 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-codegen)
|
||||
2.1.5 (**current stable**) | 2015-01-06 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.5](https://github.com/swagger-api/swagger-codegen/tree/v2.1.5)
|
||||
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:
|
||||
If you're looking for the latest stable version, you can grab it directly from maven central (you'll need java 7 runtime at a minimum):
|
||||
|
||||
* [Java 7](http://java.oracle.com)
|
||||
```
|
||||
wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.1.5/swagger-codegen-cli-2.1.5.jar -o swagger-codegen-cli.jar
|
||||
|
||||
java -jar swagger-codegen-cli.jar help
|
||||
```
|
||||
|
||||
On a mac, it's even easier with `brew`:
|
||||
```
|
||||
brew install swagger-codegen
|
||||
```
|
||||
|
||||
To build from source, you need the following installed and available in your $PATH:
|
||||
|
||||
* [Java 7 or 8](http://java.oracle.com)
|
||||
|
||||
* [Apache maven 3.0.3 or greater](http://maven.apache.org/)
|
||||
|
||||
#### OS X Users
|
||||
Don't forget to install Java 7. You probably have 1.6 or 1.8.
|
||||
Don't forget to install Java 7 or 8. You probably have 1.6.
|
||||
|
||||
Export JAVA_HOME in order to use the supported Java version:
|
||||
```
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
|
||||
export PATH=${JAVA_HOME}/bin:$PATH
|
||||
```
|
||||
|
||||
@@ -88,21 +109,27 @@ mvn package
|
||||
|
||||
```
|
||||
git clone https://github.com/swagger-api/swagger-codegen
|
||||
|
||||
cd swagger-codegen
|
||||
|
||||
./run-in-docker.sh mvn package
|
||||
```
|
||||
|
||||
#### Build a Node.js server stub
|
||||
|
||||
|
||||
#### Run Docker in Vagrant
|
||||
Prerequisite: install [Vagrant](https://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
|
||||
```
|
||||
./run-in-docker.sh generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l nodejs \
|
||||
-o samples/server/petstore/nodejs
|
||||
git clone http://github.com/swagger-api/swagger-codegen.git
|
||||
cd swagger-codegen
|
||||
vagrant up
|
||||
vagrant ssh
|
||||
cd /vagrant
|
||||
./run-in-docker.sh mvn package
|
||||
```
|
||||
|
||||
#### Public Docker image
|
||||
|
||||
https://hub.docker.com/r/swaggerapi/swagger-generator/
|
||||
|
||||
### Homebrew
|
||||
To install, run `brew install swagger-codegen`
|
||||
|
||||
@@ -134,18 +161,27 @@ with a number of options. You can get the options with the `help generate` comm
|
||||
|
||||
```
|
||||
NAME
|
||||
swagger generate - Generate code with chosen lang
|
||||
swagger-codegen-cli generate - Generate code with chosen lang
|
||||
|
||||
SYNOPSIS
|
||||
swagger generate [(-a <authorization> | --auth <authorization>)]
|
||||
swagger-codegen-cli generate
|
||||
[(-a <authorization> | --auth <authorization>)]
|
||||
[--additional-properties <additional properties>]
|
||||
[--api-package <api package>] [--artifact-id <artifact id>]
|
||||
[--artifact-version <artifact version>]
|
||||
[(-c <configuration file> | --config <configuration file>)]
|
||||
[-D <system properties>]
|
||||
[-D <system properties>] [--group-id <group id>]
|
||||
(-i <spec file> | --input-spec <spec file>)
|
||||
[--import-mappings <import mappings>]
|
||||
[--instantiation-types <instantiation types>]
|
||||
[--invoker-package <invoker package>]
|
||||
(-l <language> | --lang <language>)
|
||||
[--language-specific-primitives <language specific primitives>]
|
||||
[--library <library>] [--model-package <model package>]
|
||||
[(-o <output directory> | --output <output directory>)]
|
||||
[(-t <template directory> | --template-dir <template directory>)]
|
||||
[(-v | --verbose)]
|
||||
[(-s | --skip-overwrite)]
|
||||
[(-t <template directory> | --template-dir <template directory>)]
|
||||
[--type-mappings <type mappings>] [(-v | --verbose)]
|
||||
|
||||
OPTIONS
|
||||
-a <authorization>, --auth <authorization>
|
||||
@@ -153,6 +189,19 @@ OPTIONS
|
||||
remotely. Pass in a URL-encoded string of name:header with a comma
|
||||
separating multiple values
|
||||
|
||||
--additional-properties <additional properties>
|
||||
sets additional properties that can be referenced by the mustache
|
||||
templates in the format of name=value,name=value
|
||||
|
||||
--api-package <api package>
|
||||
package for generated api classes
|
||||
|
||||
--artifact-id <artifact id>
|
||||
artifactId in generated pom.xml
|
||||
|
||||
--artifact-version <artifact version>
|
||||
artifact version in generated pom.xml
|
||||
|
||||
-c <configuration file>, --config <configuration file>
|
||||
Path to json configuration file. File content should be in a json
|
||||
format {"optionKey":"optionValue", "optionKey1":"optionValue1"...}
|
||||
@@ -163,25 +212,59 @@ OPTIONS
|
||||
sets specified system properties in the format of
|
||||
name=value,name=value
|
||||
|
||||
--group-id <group id>
|
||||
groupId in generated pom.xml
|
||||
|
||||
-i <spec file>, --input-spec <spec file>
|
||||
location of the swagger spec, as URL or file (required)
|
||||
|
||||
|
||||
--import-mappings <import mappings>
|
||||
specifies mappings between a given class and the import that should
|
||||
be used for that class in the format of type=import,type=import
|
||||
|
||||
--instantiation-types <instantiation types>
|
||||
sets instantiation type mappings in the format of
|
||||
type=instantiatedType,type=instantiatedType.For example (in Java):
|
||||
array=ArrayList,map=HashMap. In other words array types will get
|
||||
instantiated as ArrayList in generated code.
|
||||
|
||||
--invoker-package <invoker package>
|
||||
root package for generated code
|
||||
|
||||
-l <language>, --lang <language>
|
||||
client language to generate (maybe class name in classpath,
|
||||
required)
|
||||
|
||||
--language-specific-primitives <language specific primitives>
|
||||
specifies additional language specific primitive types in the format
|
||||
of type1,type2,type3,type3. For example:
|
||||
String,boolean,Boolean,Double
|
||||
|
||||
--library <library>
|
||||
library template (sub-template)
|
||||
|
||||
--model-package <model package>
|
||||
package for generated models
|
||||
|
||||
-o <output directory>, --output <output directory>
|
||||
where to write the generated files (current dir by default)
|
||||
|
||||
-s, --skip-overwrite
|
||||
specifies if the existing files should be overwritten during the
|
||||
generation.
|
||||
|
||||
-t <template directory>, --template-dir <template directory>
|
||||
folder containing the template files
|
||||
|
||||
--type-mappings <type mappings>
|
||||
sets mappings between swagger spec types and generated code types in
|
||||
the format of swaggerType=generatedType,swaggerType=generatedType.
|
||||
For example: array=List,map=Map,string=String
|
||||
|
||||
-v, --verbose
|
||||
verbose mode
|
||||
|
||||
-s , --skip-overwrite
|
||||
specifies if the existing files should be overwritten during
|
||||
the generation
|
||||
```
|
||||
|
||||
You can then compile and run the client, as well as unit tests against it:
|
||||
@@ -218,16 +301,15 @@ This will write, in the folder `output/myLibrary`, all the files you need to get
|
||||
|
||||
You would then compile your library in the `output/myLibrary` folder with `mvn package` and execute the codegen like such:
|
||||
|
||||
|
||||
```
|
||||
java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.Codegen
|
||||
java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen
|
||||
```
|
||||
|
||||
Note the `myClientCodegen` is an option now, and you can use the usual arguments for generating your library:
|
||||
|
||||
```
|
||||
java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
|
||||
io.swagger.codegen.Codegen generate -l myClientCodegen\
|
||||
io.swagger.codegen.SwaggerCodegen generate -l myClientCodegen\
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-o myClient
|
||||
```
|
||||
@@ -235,12 +317,12 @@ java -cp output/myLibrary/target/myClientCodegen-swagger-codegen-1.0.0.jar:modul
|
||||
### Where is Javascript???
|
||||
See our [javascript library](http://github.com/swagger-api/swagger-js)--it's completely dynamic and doesn't require
|
||||
static code generation.
|
||||
There is a third-party component called [swagger-js-codegen](https://github.com/wcandillon/swagger-js-codegen) that can generate angularjs or nodejs source code from a swagger specification.
|
||||
There is a third-party component called [swagger-js-codegen](https://github.com/wcandillon/swagger-js-codegen) that can generate angularjs or nodejs source code from a OpenAPI Specification.
|
||||
|
||||
:exclamation: On Dec 7th 2015, a Javascript API client generator has been added by @jfiala.
|
||||
|
||||
### Generating a client from local files
|
||||
If you don't want to call your server, you can save the swagger spec files into a directory and pass an argument
|
||||
If you don't want to call your server, you can save the OpenAPI Spec files into a directory and pass an argument
|
||||
to the code generator like this:
|
||||
|
||||
```
|
||||
@@ -285,9 +367,11 @@ There are different aspects of customizing the code generator beyond just creati
|
||||
|
||||
```
|
||||
$ ls -1 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/
|
||||
AbstractJavaJAXRSServerCodegen.java
|
||||
AbstractTypeScriptClientCodegen.java
|
||||
AkkaScalaClientCodegen.java
|
||||
AndroidClientCodegen.java
|
||||
AspNet5ServerCodegen.java
|
||||
AsyncScalaClientCodegen.java
|
||||
CSharpClientCodegen.java
|
||||
ClojureClientCodegen.java
|
||||
@@ -295,11 +379,14 @@ CsharpDotNet2ClientCodegen.java
|
||||
DartClientCodegen.java
|
||||
FlashClientCodegen.java
|
||||
FlaskConnexionCodegen.java
|
||||
GoClientCodegen.java
|
||||
HaskellServantCodegen.java
|
||||
JMeterCodegen.java
|
||||
JavaCXFServerCodegen.java
|
||||
JavaClientCodegen.java
|
||||
JavaInflectorServerCodegen.java
|
||||
JavaJerseyServerCodegen.java
|
||||
JavascriptClientCodegen.java
|
||||
JaxRSServerCodegen.java
|
||||
JMeterCodegen.java
|
||||
NodeJSServerCodegen.java
|
||||
ObjcClientCodegen.java
|
||||
PerlClientCodegen.java
|
||||
@@ -383,12 +470,12 @@ CONFIG OPTIONS
|
||||
retrofit2 - HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2)
|
||||
```
|
||||
|
||||
Your config file for java can look like
|
||||
Your config file for Java can look like
|
||||
|
||||
```
|
||||
```json
|
||||
{
|
||||
"groupId":"com.my.company",
|
||||
"artifactId":"MyClent",
|
||||
"artifactId":"MyClient",
|
||||
"artifactVersion":"1.2.0",
|
||||
"library":"feign"
|
||||
}
|
||||
@@ -399,7 +486,7 @@ For all the unspecified options default values will be used.
|
||||
Another way to override default options is to extend the config class for the specific language.
|
||||
To change, for example, the prefix for the Objective-C generated files, simply subclass the ObjcClientCodegen.java:
|
||||
|
||||
```
|
||||
```java
|
||||
package com.mycompany.swagger.codegen;
|
||||
|
||||
import io.swagger.codegen.languages.*;
|
||||
@@ -419,7 +506,25 @@ and specify the `classname` when running the generator:
|
||||
|
||||
Your subclass will now be loaded and overrides the `PREFIX` value in the superclass.
|
||||
|
||||
### Validating your swagger spec
|
||||
### Bringing your own models
|
||||
|
||||
Sometimes you don't want a model generated. In this case, you can simply specify an import mapping to tell
|
||||
the codegen what _not_ to create. When doing this, every location that references a specific model will
|
||||
refer back to your classes. Note, this may not apply to all languages...
|
||||
|
||||
To specify an import mapping, use the `--import-mappings` argument and specify the model-to-import logic as such:
|
||||
|
||||
```
|
||||
--import-mappings Pet=my.models.MyPet
|
||||
```
|
||||
|
||||
Or for multiple mappings:
|
||||
|
||||
```
|
||||
Pet=my.models.MyPet,Order=my.models.MyOrder
|
||||
```
|
||||
|
||||
### Validating your OpenAPI Spec
|
||||
|
||||
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:
|
||||
|
||||
@@ -461,6 +566,15 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-o samples/server/petstore/nodejs
|
||||
```
|
||||
|
||||
### PHP Slim
|
||||
|
||||
```
|
||||
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l slim \
|
||||
-o samples/server/petstore/slim
|
||||
```
|
||||
|
||||
### PHP Silex
|
||||
|
||||
```
|
||||
@@ -475,7 +589,7 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
```
|
||||
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l flaskConnexion \
|
||||
-l python-flask \
|
||||
-o samples/server/petstore/flaskConnexion
|
||||
```
|
||||
|
||||
@@ -496,13 +610,22 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-o samples/server/petstore/scalatra
|
||||
```
|
||||
|
||||
### Java JAX-RS
|
||||
### Java JAX-RS (Jersey v1.18)
|
||||
|
||||
```
|
||||
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l jaxrs \
|
||||
-o samples/server/petstore/jaxrs
|
||||
-o samples/server/petstore/jaxrs-jersey
|
||||
```
|
||||
|
||||
### Java JAX-RS (Apache CXF 3)
|
||||
|
||||
```
|
||||
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l jaxrs-cxf \
|
||||
-o samples/server/petstore/jaxrs-cxf
|
||||
```
|
||||
|
||||
### Java Spring MVC
|
||||
@@ -514,6 +637,24 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-o samples/server/petstore/spring-mvc
|
||||
```
|
||||
|
||||
### Haskell Servant
|
||||
|
||||
```
|
||||
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l haskell-servant \
|
||||
-o samples/server/petstore/haskell-servant
|
||||
```
|
||||
|
||||
### ASP.NET 5 Web API
|
||||
|
||||
```
|
||||
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
|
||||
-i http://petstore.swagger.io/v2/swagger.json \
|
||||
-l aspnet5 \
|
||||
-o samples/server/petstore/aspnet5
|
||||
```
|
||||
|
||||
### To build the codegen library
|
||||
|
||||
This will create the swagger-codegen library from source.
|
||||
@@ -524,6 +665,11 @@ 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 specify a path to your scripts
|
||||
|
||||
## Workflow integration
|
||||
|
||||
You can use the [swagger-codegen-maven-plugin](modules/swagger-codegen-maven-plugin/README.md) for integrating with your workflow, and generating any codegen target.
|
||||
|
||||
|
||||
## Online generators
|
||||
|
||||
One can also generate API client or server using the online generators (https://generator.swagger.io)
|
||||
@@ -539,10 +685,32 @@ Guidelines for Contribution
|
||||
|
||||
Please refer to this [page](https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md)
|
||||
|
||||
Companies/Projects using Swagger Codegen
|
||||
----------------------------------------
|
||||
Here are some companies/projects using Swagger Codegen in production. To add your company/project to the list, please visit [README.md](https://github.com/swagger-api/swagger-codegen/blob/master/README.md) and click on the icon to edit the page.
|
||||
- [Activehours](https://www.activehours.com/)
|
||||
- [Acunetix](https://www.acunetix.com/)
|
||||
- [Atlassian](https://www.atlassian.com/)
|
||||
- [Cupix](http://www.cupix.com)
|
||||
- [DocuSign](https://www.docusign.com)
|
||||
- [Ergon](http://www.ergon.ch/)
|
||||
- [everystory.us](http://everystory.us)
|
||||
- [Expected Behavior](http://www.expectedbehavior.com/)
|
||||
- [nViso](http://www.nviso.ch/)
|
||||
- [Okiok](https://www.okiok.com)
|
||||
- [OSDN](https://osdn.jp)
|
||||
- [Reload! A/S](https://reload.dk/)
|
||||
- [Royal Bank of Canada (RBC)](http://www.rbc.com/canada.html)
|
||||
- [SmartRecruiters](https://www.smartrecruiters.com/)
|
||||
- [StyleRecipe](http://stylerecipe.co.jp)
|
||||
- [ThoughtWorks](https://www.thoughtworks.com)
|
||||
- [uShip](https://www.uship.com/)
|
||||
- [ZEEF.com](https://zeef.com/)
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Copyright 2015 SmartBear Software
|
||||
Copyright 2016 SmartBear Software
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -553,3 +721,6 @@ 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.
|
||||
|
||||
---
|
||||
<img src="http://swagger.io/wp-content/uploads/2016/02/logo.jpg"/>
|
||||
|
||||
36
Vagrantfile
vendored
Normal file
36
Vagrantfile
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
||||
VAGRANTFILE_API_VERSION = "2"
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
config.vm.box = "ubuntu/trusty64"
|
||||
|
||||
config.vm.provider "virtualbox" do |v|
|
||||
v.name = "swagger-codegen"
|
||||
v.memory = 2048
|
||||
v.cpus = 2
|
||||
end
|
||||
|
||||
config.vm.box_check_update = true
|
||||
|
||||
#SSH
|
||||
config.ssh.forward_agent = true
|
||||
|
||||
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
|
||||
|
||||
#Provision
|
||||
config.vm.provision "shell", inline: <<-SHELL
|
||||
sudo touch /var/lib/cloud/instance/locale-check.skip
|
||||
sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
|
||||
sudo sh -c 'echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list'
|
||||
sudo apt-cache policy docker-engine
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade -y
|
||||
sudo apt-get install -y docker-engine
|
||||
sudo usermod -aG docker vagrant
|
||||
SHELL
|
||||
|
||||
end
|
||||
@@ -19,10 +19,11 @@ fi
|
||||
|
||||
cd $APP_DIR
|
||||
./bin/akka-scala-petstore.sh
|
||||
./bin/android-java-petstore.sh
|
||||
./bin/android-petstore.sh
|
||||
./bin/clojure-petstore.sh
|
||||
./bin/csharp-petstore.sh
|
||||
./bin/dynamic-html.sh
|
||||
./bin/haskell-petstore.sh
|
||||
./bin/html-petstore.sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/java-petstore-jersey2.sh
|
||||
@@ -43,6 +44,7 @@ cd $APP_DIR
|
||||
./bin/silex-petstore-server.sh
|
||||
./bin/slim-petstore-server.sh
|
||||
./bin/spring-mvc-petstore-server.sh
|
||||
./bin/spring-mvc-petstore-j8-async-server.sh
|
||||
./bin/swift-petstore.sh
|
||||
./bin/tizen-petstore.sh
|
||||
./bin/typescript-angular-petstore.sh
|
||||
|
||||
4
bin/android-petstore-volley.json
Normal file
4
bin/android-petstore-volley.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"library": "volley",
|
||||
"artifactId": "swagger-petstore-android-volley"
|
||||
}
|
||||
31
bin/android-petstore-volley.sh
Executable file
31
bin/android-petstore-volley.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l android -c bin/android-petstore-volley.json -o samples/client/petstore/android/volley"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -26,6 +26,6 @@ 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="$@ generate -t modules/swagger-codegen/src/main/resources/android-java -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l android -o samples/client/petstore/android-java"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/android -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l android -o samples/client/petstore/android/default"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
31
bin/aspnet5-petstore-server.sh
Executable file
31
bin/aspnet5-petstore-server.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -l aspnet5 -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -o samples/server/petstore/aspnet5"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
31
bin/go-petstore.sh
Executable file
31
bin/go-petstore.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -t modules/swagger-codegen/src/main/resources/go -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l go -o samples/client/petstore/go"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
31
bin/haskell-servant-petstore.sh
Executable file
31
bin/haskell-servant-petstore.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -t modules/swagger-codegen/src/main/resources/haskell-servant -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l haskell-servant -o samples/server/petstore/haskell-servant"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
9
bin/java-petstore-all.sh
Executable file
9
bin/java-petstore-all.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# update java petstore for all supported http libraries
|
||||
|
||||
./bin/java-petstore.sh
|
||||
./bin/java-petstore-jersey2.sh
|
||||
./bin/java-petstore-feign.sh
|
||||
./bin/java-petstore-okhttp-gson.sh
|
||||
./bin/java-petstore-retrofit.sh
|
||||
./bin/java-petstore-retrofit2.sh
|
||||
4
bin/java-petstore-retrofit2rx.json
Normal file
4
bin/java-petstore-retrofit2rx.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"library": "retrofit2",
|
||||
"artifactId": "swagger-petstore-retrofit2-rx"
|
||||
}
|
||||
31
bin/java-petstore-retrofit2rx.sh
Executable file
31
bin/java-petstore-retrofit2rx.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l java -c bin/java-petstore-retrofit2rx.json -o samples/client/petstore/java/retrofit2rx -DuseRxJava=true"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
31
bin/javascript-closure-angular.sh
Executable file
31
bin/javascript-closure-angular.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l javascript-closure-angular -o samples/client/petstore/javascript-closure-angular"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -26,6 +26,6 @@ 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="$@ generate -t modules/swagger-codegen/src/main/resources/javascript -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l javascript -o samples/client/petstore/javascript"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/Javascript -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l javascript -o samples/client/petstore/javascript"
|
||||
|
||||
java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
34
bin/javascript-promise-petstore.sh
Executable file
34
bin/javascript-promise-petstore.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -t modules/swagger-codegen/src/main/resources/Javascript \
|
||||
-i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l javascript \
|
||||
-o samples/client/petstore/javascript-promise \
|
||||
--additional-properties usePromises=true"
|
||||
|
||||
java -DappName=PetstoreClient $JAVA_OPTS -jar $executable $ags
|
||||
31
bin/jaxrs-cxf-petstore-server.sh
Executable file
31
bin/jaxrs-cxf-petstore-server.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l jaxrs-cxf -o samples/server/petstore/jaxrs-cxf"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -26,6 +26,6 @@ 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="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l jaxrs -o samples/server/petstore/jaxrs -Dswagger.codegen.jaxrs.impl.source=src/main/java"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l jaxrs -o samples/server/petstore/jaxrs"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
31
bin/jaxrs-resteasy-petstore-server.sh
Executable file
31
bin/jaxrs-resteasy-petstore-server.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -t modules/swagger-codegen/src/main/resources/JavaJaxRS -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l jaxrs-resteasy -o samples/server/petstore/jaxrs-resteasy"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -26,6 +26,9 @@ 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"
|
||||
# complex module name used for testing
|
||||
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l perl -o samples/client/petstore/perl"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags --additional-properties moduleName=Something::Deep -o samples/client/petstore/perl/deep_module_test
|
||||
|
||||
@@ -26,6 +26,6 @@ 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="$@ generate -t modules/swagger-codegen/src/main/resources/silex -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l silex -o samples/server/petstore/silex"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/silex -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l silex-PHP -o samples/server/petstore/silex"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
0
bin/slim-petstore-server.sh
Normal file → Executable file
0
bin/slim-petstore-server.sh
Normal file → Executable file
31
bin/spring-mvc-petstore-j8-async-server.sh
Executable file
31
bin/spring-mvc-petstore-j8-async-server.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
|
||||
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.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="$@ generate -t modules/swagger-codegen/src/main/resources/JavaSpringMVC -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l spring-mvc -o samples/server/petstore/spring-mvc-j8-async -c bin/spring-mvc-petstore-j8-async.json"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
3
bin/spring-mvc-petstore-j8-async.json
Normal file
3
bin/spring-mvc-petstore-j8-async.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"library": "j8-async"
|
||||
}
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\android-java -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l android -o samples\client\petstore\android-java
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\android -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l android -o samples\client\petstore\android\default
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
10
bin/windows/aspnet5-petstore-server.bat
Executable file
10
bin/windows/aspnet5-petstore-server.bat
Executable file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\aspnet5 -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l aspnet5 -o samples\server\petstore\aspnet5\
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
10
bin/windows/go-petstore.bat
Executable file
10
bin/windows/go-petstore.bat
Executable file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -t modules\swagger-codegen\src\main\resources\go -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l go -o samples\client\petstore\go
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -1 +0,0 @@
|
||||
{"library":"feign"}
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-project</artifactId>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
<version>2.1.6-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -89,13 +89,13 @@
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>${testng-version}</version>
|
||||
<!-- <version>${testng-version}</version> -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jmockit</groupId>
|
||||
<artifactId>jmockit</artifactId>
|
||||
<version>${jmockit-version}</version>
|
||||
<!-- <version>${jmockit-version}</version> -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -21,7 +21,8 @@ public class SwaggerCodegen {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("swagger")
|
||||
@SuppressWarnings("unchecked")
|
||||
Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("swagger-codegen-cli")
|
||||
.withDescription("Swagger code generator CLI. More info on swagger.io")
|
||||
.withDefaultCommand(Langs.class)
|
||||
.withCommands(
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.airlift.airline.Option;
|
||||
import io.swagger.codegen.ClientOptInput;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.DefaultGenerator;
|
||||
import io.swagger.codegen.cmd.utils.OptionUtils;
|
||||
import io.swagger.codegen.utils.OptionUtils;
|
||||
import io.swagger.codegen.config.CodegenConfigurator;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.slf4j.Logger;
|
||||
@@ -73,6 +73,12 @@ public class Generate implements Runnable {
|
||||
@Option(name = {"--model-package"}, title = "model package", description = CodegenConstants.MODEL_PACKAGE_DESC)
|
||||
private String modelPackage;
|
||||
|
||||
@Option(name = {"--model-name-prefix"}, title = "model name prefix", description = CodegenConstants.MODEL_NAME_PREFIX_DESC)
|
||||
private String modelNamePrefix;
|
||||
|
||||
@Option(name = {"--model-name-suffix"}, title = "model name suffix", description = CodegenConstants.MODEL_NAME_SUFFIX_DESC)
|
||||
private String modelNameSuffix;
|
||||
|
||||
@Option(name = {"--instantiation-types"}, title = "instantiation types", description = "sets instantiation type mappings in the format of type=instantiatedType,type=instantiatedType." +
|
||||
"For example (in Java): array=ArrayList,map=HashMap. In other words array types will get instantiated as ArrayList in generated code.")
|
||||
private String instantiationTypes;
|
||||
@@ -156,6 +162,14 @@ public class Generate implements Runnable {
|
||||
configurator.setModelPackage(modelPackage);
|
||||
}
|
||||
|
||||
if(isNotEmpty(modelNamePrefix)){
|
||||
configurator.setModelNamePrefix(modelNamePrefix);
|
||||
}
|
||||
|
||||
if(isNotEmpty(modelNameSuffix)){
|
||||
configurator.setModelNameSuffix(modelNameSuffix);
|
||||
}
|
||||
|
||||
if(isNotEmpty(invokerPackage)) {
|
||||
configurator.setInvokerPackage(invokerPackage);
|
||||
}
|
||||
@@ -230,15 +244,15 @@ public class Generate implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> createSetFromCsvList(String csvProperty) {
|
||||
private static Set<String> createSetFromCsvList(String csvProperty) {
|
||||
final List<String> values = OptionUtils.splitCommaSeparatedList(csvProperty);
|
||||
return new HashSet<String>(values);
|
||||
}
|
||||
|
||||
private Map createMapFromKeyValuePairs(String commaSeparatedKVPairs) {
|
||||
private static Map<String, String> createMapFromKeyValuePairs(String commaSeparatedKVPairs) {
|
||||
final List<Pair<String, String>> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs);
|
||||
|
||||
Map result = new HashMap();
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
|
||||
for (Pair<String, String> pair : pairs) {
|
||||
result.put(pair.getLeft(), pair.getRight());
|
||||
|
||||
@@ -33,7 +33,7 @@ import static com.google.common.base.Joiner.on;
|
||||
"specify, and includes default templates to include.")
|
||||
public class Meta implements Runnable {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Meta.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Meta.class);
|
||||
|
||||
private static final String TEMPLATE_DIR_CLASSPATH = "codegen";
|
||||
private static final String MUSTACHE_EXTENSION = ".mustache";
|
||||
@@ -53,7 +53,7 @@ public class Meta implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
final File targetDir = new File(outputFolder);
|
||||
LOG.info("writing to folder [{}]", targetDir.getAbsolutePath());
|
||||
LOGGER.info("writing to folder [{}]", targetDir.getAbsolutePath());
|
||||
|
||||
String mainClass = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name) + "Generator";
|
||||
|
||||
@@ -93,7 +93,7 @@ public class Meta implements Runnable {
|
||||
* @param data - map with additional params needed to process templates
|
||||
* @return converter object to pass to lambdaj
|
||||
*/
|
||||
private Converter<SupportingFile, File> processFiles(final File targetDir, final Map<String, Object> data) {
|
||||
private static Converter<SupportingFile, File> processFiles(final File targetDir, final Map<String, Object> data) {
|
||||
return new Converter<SupportingFile, File>() {
|
||||
private DefaultGenerator generator = new DefaultGenerator();
|
||||
|
||||
@@ -108,13 +108,13 @@ public class Meta implements Runnable {
|
||||
String formatted = template;
|
||||
|
||||
if (support.templateFile.endsWith(MUSTACHE_EXTENSION)) {
|
||||
LOG.info("writing file to {}", outputFile.getAbsolutePath());
|
||||
LOGGER.info("writing file to {}", outputFile.getAbsolutePath());
|
||||
formatted = Mustache.compiler().withLoader(loader(generator))
|
||||
.defaultValue("")
|
||||
.compile(template)
|
||||
.execute(data);
|
||||
} else {
|
||||
LOG.info("copying file to {}", outputFile.getAbsolutePath());
|
||||
LOGGER.info("copying file to {}", outputFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
FileUtils.writeStringToFile(outputFile, formatted);
|
||||
@@ -133,8 +133,9 @@ public class Meta implements Runnable {
|
||||
* @param generator - class with reader getter
|
||||
* @return loader for template
|
||||
*/
|
||||
private Mustache.TemplateLoader loader(final DefaultGenerator generator) {
|
||||
private static Mustache.TemplateLoader loader(final DefaultGenerator generator) {
|
||||
return new Mustache.TemplateLoader() {
|
||||
@Override
|
||||
public Reader getTemplate(String name) {
|
||||
return generator.getTemplateReader(TEMPLATE_DIR_CLASSPATH
|
||||
+ File.separator + name.concat(MUSTACHE_EXTENSION));
|
||||
@@ -148,7 +149,7 @@ public class Meta implements Runnable {
|
||||
* @param packageName - package name to convert
|
||||
* @return relative path
|
||||
*/
|
||||
private String asPath(String packageName) {
|
||||
private static String asPath(String packageName) {
|
||||
return packageName.replace(".", File.separator);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import mockit.Verifications;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class GenerateTest {
|
||||
|
||||
@Mocked
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.swagger.codegen.cmd.utils;
|
||||
|
||||
import io.swagger.codegen.utils.OptionUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -10,6 +11,7 @@ import java.util.List;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public class OptionUtilsTest {
|
||||
|
||||
@Test
|
||||
@@ -30,7 +32,7 @@ public class OptionUtilsTest {
|
||||
doTupleListTest(null, new ArrayList<Pair<String, String>>());
|
||||
}
|
||||
|
||||
private void doTupleListTest(String input, List<Pair<String, String>> expectedResults) {
|
||||
private static void doTupleListTest(String input, List<Pair<String, String>> expectedResults) {
|
||||
final List<Pair<String, String>> result = OptionUtils.parseCommaSeparatedTuples(input);
|
||||
assertNotNull(result);
|
||||
assertEquals(result.size(), expectedResults.size());
|
||||
@@ -41,7 +43,7 @@ public class OptionUtilsTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void doCommaSeparatedListTest(String csvStr, List<String> expectedResults) {
|
||||
private static void doCommaSeparatedListTest(String csvStr, List<String> expectedResults) {
|
||||
final List<String> result = OptionUtils.splitCommaSeparatedList(csvStr);
|
||||
assertNotNull(result);
|
||||
assertEquals(result.size(), expectedResults.size());
|
||||
|
||||
@@ -11,7 +11,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<plugin>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -37,7 +37,7 @@ mvn clean compile
|
||||
|
||||
### General Configuration parameters
|
||||
|
||||
- `inputSpec` - swagger spec file path
|
||||
- `inputSpec` - OpenAPI Spec file path
|
||||
- `language` - target generation language
|
||||
- `output` - target output path (default is `${project.build.directory}/generated-sources/swagger`)
|
||||
- `templateDirectory` - directory with mustache templates
|
||||
@@ -46,10 +46,8 @@ mvn clean compile
|
||||
- `apiPackage` - the package to use for generated api objects/classes
|
||||
- `invokerPackage` - the package to use for the generated invoker objects
|
||||
- `configOptions` - a map of language-specific parameters (see below)
|
||||
- `configHelp` - dumps the configuration help for the specified library (generates no sources)
|
||||
|
||||
### Java-specific parameters (under configOptions)
|
||||
### Sample configuration
|
||||
|
||||
- `sourceFolder` - the folder to use for generated sources under the output folder
|
||||
- `groupId` - groupId in generated pom.xml
|
||||
- `artifactId` - artifactId in generated pom.xml
|
||||
- `artifactVersion` - artifact version in generated pom.xml
|
||||
- Please see [an example configuration](examples) for using the plugin
|
||||
115
modules/swagger-codegen-maven-plugin/examples/java-client.xml
Normal file
115
modules/swagger-codegen-maven-plugin/examples/java-client.xml
Normal file
@@ -0,0 +1,115 @@
|
||||
<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>io.swagger</groupId>
|
||||
<artifactId>sample-project</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>sample-project</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- activate the plugin -->
|
||||
<plugin>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-maven-plugin</artifactId>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- specify the swagger yaml -->
|
||||
<inputSpec>swagger.yaml</inputSpec>
|
||||
|
||||
<!-- target to generate -->
|
||||
<language>java</language>
|
||||
|
||||
<!-- pass any necessary config options -->
|
||||
<configOptions>
|
||||
<dateLibrary>java8</dateLibrary>
|
||||
</configOptions>
|
||||
|
||||
<!-- override the default library to jersey2 -->
|
||||
<library>jersey2</library>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<!-- dependencies are needed for the client being generated -->
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- HTTP client: jersey-client -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON processing: jackson -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
<groupId>com.brsanthu</groupId>
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<jersey-version>2.12</jersey-version>
|
||||
<jackson-version>2.4.2</jackson-version>
|
||||
<jodatime-version>2.3</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
</properties>
|
||||
</project>
|
||||
702
modules/swagger-codegen-maven-plugin/examples/swagger.yaml
Normal file
702
modules/swagger-codegen-maven-plugin/examples/swagger.yaml
Normal file
@@ -0,0 +1,702 @@
|
||||
---
|
||||
swagger: "2.0"
|
||||
info:
|
||||
description: "This is a sample server Petstore server. You can find out more about\
|
||||
\ Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\
|
||||
\ For this sample, you can use the api key `special-key` to test the authorization\
|
||||
\ filters."
|
||||
version: "1.0.0"
|
||||
title: "Swagger Petstore"
|
||||
termsOfService: "http://swagger.io/terms/"
|
||||
contact:
|
||||
email: "apiteam@swagger.io"
|
||||
license:
|
||||
name: "Apache 2.0"
|
||||
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
host: "petstore.swagger.io"
|
||||
basePath: "/v2"
|
||||
tags:
|
||||
- name: "pet"
|
||||
description: "Everything about your Pets"
|
||||
externalDocs:
|
||||
description: "Find out more"
|
||||
url: "http://swagger.io"
|
||||
- name: "store"
|
||||
description: "Access to Petstore orders"
|
||||
- name: "user"
|
||||
description: "Operations about user"
|
||||
externalDocs:
|
||||
description: "Find out more about our store"
|
||||
url: "http://swagger.io"
|
||||
schemes:
|
||||
- "http"
|
||||
paths:
|
||||
/pet:
|
||||
post:
|
||||
tags:
|
||||
- "pet"
|
||||
summary: "Add a new pet to the store"
|
||||
description: ""
|
||||
operationId: "addPet"
|
||||
consumes:
|
||||
- "application/json"
|
||||
- "application/xml"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- in: "body"
|
||||
name: "body"
|
||||
description: "Pet object that needs to be added to the store"
|
||||
required: true
|
||||
schema:
|
||||
$ref: "#/definitions/Pet"
|
||||
responses:
|
||||
405:
|
||||
description: "Invalid input"
|
||||
security:
|
||||
- petstore_auth:
|
||||
- "write:pets"
|
||||
- "read:pets"
|
||||
put:
|
||||
tags:
|
||||
- "pet"
|
||||
summary: "Update an existing pet"
|
||||
description: ""
|
||||
operationId: "updatePet"
|
||||
consumes:
|
||||
- "application/json"
|
||||
- "application/xml"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- in: "body"
|
||||
name: "body"
|
||||
description: "Pet object that needs to be added to the store"
|
||||
required: true
|
||||
schema:
|
||||
$ref: "#/definitions/Pet"
|
||||
responses:
|
||||
400:
|
||||
description: "Invalid ID supplied"
|
||||
404:
|
||||
description: "Pet not found"
|
||||
405:
|
||||
description: "Validation exception"
|
||||
security:
|
||||
- petstore_auth:
|
||||
- "write:pets"
|
||||
- "read:pets"
|
||||
/pet/findByStatus:
|
||||
get:
|
||||
tags:
|
||||
- "pet"
|
||||
summary: "Finds Pets by status"
|
||||
description: "Multiple status values can be provided with comma seperated strings"
|
||||
operationId: "findPetsByStatus"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "status"
|
||||
in: "query"
|
||||
description: "Status values that need to be considered for filter"
|
||||
required: true
|
||||
type: "array"
|
||||
items:
|
||||
type: "string"
|
||||
enum:
|
||||
- "available"
|
||||
- "pending"
|
||||
- "sold"
|
||||
default: "available"
|
||||
collectionFormat: "csv"
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
type: "array"
|
||||
items:
|
||||
$ref: "#/definitions/Pet"
|
||||
400:
|
||||
description: "Invalid status value"
|
||||
security:
|
||||
- petstore_auth:
|
||||
- "write:pets"
|
||||
- "read:pets"
|
||||
/pet/findByTags:
|
||||
get:
|
||||
tags:
|
||||
- "pet"
|
||||
summary: "Finds Pets by tags"
|
||||
description: "Muliple tags can be provided with comma seperated strings. Use\
|
||||
\ tag1, tag2, tag3 for testing."
|
||||
operationId: "findPetsByTags"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "tags"
|
||||
in: "query"
|
||||
description: "Tags to filter by"
|
||||
required: true
|
||||
type: "array"
|
||||
items:
|
||||
type: "string"
|
||||
collectionFormat: "csv"
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
type: "array"
|
||||
items:
|
||||
$ref: "#/definitions/Pet"
|
||||
400:
|
||||
description: "Invalid tag value"
|
||||
security:
|
||||
- petstore_auth:
|
||||
- "write:pets"
|
||||
- "read:pets"
|
||||
/pet/{petId}:
|
||||
get:
|
||||
tags:
|
||||
- "pet"
|
||||
summary: "Find pet by ID"
|
||||
description: "Returns a single pet"
|
||||
operationId: "getPetById"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "petId"
|
||||
in: "path"
|
||||
description: "ID of pet to return"
|
||||
required: true
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
$ref: "#/definitions/Pet"
|
||||
400:
|
||||
description: "Invalid ID supplied"
|
||||
404:
|
||||
description: "Pet not found"
|
||||
security:
|
||||
- api_key: []
|
||||
post:
|
||||
tags:
|
||||
- "pet"
|
||||
summary: "Updates a pet in the store with form data"
|
||||
description: ""
|
||||
operationId: "updatePetWithForm"
|
||||
consumes:
|
||||
- "application/x-www-form-urlencoded"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "petId"
|
||||
in: "path"
|
||||
description: "ID of pet that needs to be updated"
|
||||
required: true
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
- name: "name"
|
||||
in: "formData"
|
||||
description: "Updated name of the pet"
|
||||
required: false
|
||||
type: "string"
|
||||
- name: "status"
|
||||
in: "formData"
|
||||
description: "Updated status of the pet"
|
||||
required: false
|
||||
type: "string"
|
||||
responses:
|
||||
405:
|
||||
description: "Invalid input"
|
||||
security:
|
||||
- petstore_auth:
|
||||
- "write:pets"
|
||||
- "read:pets"
|
||||
delete:
|
||||
tags:
|
||||
- "pet"
|
||||
summary: "Deletes a pet"
|
||||
description: ""
|
||||
operationId: "deletePet"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "api_key"
|
||||
in: "header"
|
||||
required: false
|
||||
type: "string"
|
||||
- name: "petId"
|
||||
in: "path"
|
||||
description: "Pet id to delete"
|
||||
required: true
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
responses:
|
||||
400:
|
||||
description: "Invalid pet value"
|
||||
security:
|
||||
- petstore_auth:
|
||||
- "write:pets"
|
||||
- "read:pets"
|
||||
/pet/{petId}/uploadImage:
|
||||
post:
|
||||
tags:
|
||||
- "pet"
|
||||
summary: "uploads an image"
|
||||
description: ""
|
||||
operationId: "uploadFile"
|
||||
consumes:
|
||||
- "multipart/form-data"
|
||||
produces:
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "petId"
|
||||
in: "path"
|
||||
description: "ID of pet to update"
|
||||
required: true
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
- name: "additionalMetadata"
|
||||
in: "formData"
|
||||
description: "Additional data to pass to server"
|
||||
required: false
|
||||
type: "string"
|
||||
- name: "file"
|
||||
in: "formData"
|
||||
description: "file to upload"
|
||||
required: false
|
||||
type: "file"
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
$ref: "#/definitions/ApiResponse"
|
||||
security:
|
||||
- petstore_auth:
|
||||
- "write:pets"
|
||||
- "read:pets"
|
||||
/store/inventory:
|
||||
get:
|
||||
tags:
|
||||
- "store"
|
||||
summary: "Returns pet inventories by status"
|
||||
description: "Returns a map of status codes to quantities"
|
||||
operationId: "getInventory"
|
||||
produces:
|
||||
- "application/json"
|
||||
parameters: []
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
type: "object"
|
||||
additionalProperties:
|
||||
type: "integer"
|
||||
format: "int32"
|
||||
security:
|
||||
- api_key: []
|
||||
/store/order:
|
||||
post:
|
||||
tags:
|
||||
- "store"
|
||||
summary: "Place an order for a pet"
|
||||
description: ""
|
||||
operationId: "placeOrder"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- in: "body"
|
||||
name: "body"
|
||||
description: "order placed for purchasing the pet"
|
||||
required: true
|
||||
schema:
|
||||
$ref: "#/definitions/Order"
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
$ref: "#/definitions/Order"
|
||||
400:
|
||||
description: "Invalid Order"
|
||||
/store/order/{orderId}:
|
||||
get:
|
||||
tags:
|
||||
- "store"
|
||||
summary: "Find purchase order by ID"
|
||||
description: "For valid response try integer IDs with value <= 5 or > 10. Other\
|
||||
\ values will generated exceptions"
|
||||
operationId: "getOrderById"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "orderId"
|
||||
in: "path"
|
||||
description: "ID of pet that needs to be fetched"
|
||||
required: true
|
||||
type: "integer"
|
||||
maximum: 5.0
|
||||
minimum: 1.0
|
||||
format: "int64"
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
$ref: "#/definitions/Order"
|
||||
400:
|
||||
description: "Invalid ID supplied"
|
||||
404:
|
||||
description: "Order not found"
|
||||
delete:
|
||||
tags:
|
||||
- "store"
|
||||
summary: "Delete purchase order by ID"
|
||||
description: "For valid response try integer IDs with value < 1000. Anything\
|
||||
\ above 1000 or nonintegers will generate API errors"
|
||||
operationId: "deleteOrder"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "orderId"
|
||||
in: "path"
|
||||
description: "ID of the order that needs to be deleted"
|
||||
required: true
|
||||
type: "string"
|
||||
minimum: 1.0
|
||||
responses:
|
||||
400:
|
||||
description: "Invalid ID supplied"
|
||||
404:
|
||||
description: "Order not found"
|
||||
/user:
|
||||
post:
|
||||
tags:
|
||||
- "user"
|
||||
summary: "Create user"
|
||||
description: "This can only be done by the logged in user."
|
||||
operationId: "createUser"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- in: "body"
|
||||
name: "body"
|
||||
description: "Created user object"
|
||||
required: true
|
||||
schema:
|
||||
$ref: "#/definitions/User"
|
||||
responses:
|
||||
default:
|
||||
description: "successful operation"
|
||||
/user/createWithArray:
|
||||
post:
|
||||
tags:
|
||||
- "user"
|
||||
summary: "Creates list of users with given input array"
|
||||
description: ""
|
||||
operationId: "createUsersWithArrayInput"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- in: "body"
|
||||
name: "body"
|
||||
description: "List of user object"
|
||||
required: true
|
||||
schema:
|
||||
type: "array"
|
||||
items:
|
||||
$ref: "#/definitions/User"
|
||||
responses:
|
||||
default:
|
||||
description: "successful operation"
|
||||
/user/createWithList:
|
||||
post:
|
||||
tags:
|
||||
- "user"
|
||||
summary: "Creates list of users with given input array"
|
||||
description: ""
|
||||
operationId: "createUsersWithListInput"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- in: "body"
|
||||
name: "body"
|
||||
description: "List of user object"
|
||||
required: true
|
||||
schema:
|
||||
type: "array"
|
||||
items:
|
||||
$ref: "#/definitions/User"
|
||||
responses:
|
||||
default:
|
||||
description: "successful operation"
|
||||
/user/login:
|
||||
get:
|
||||
tags:
|
||||
- "user"
|
||||
summary: "Logs user into the system"
|
||||
description: ""
|
||||
operationId: "loginUser"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "username"
|
||||
in: "query"
|
||||
description: "The user name for login"
|
||||
required: true
|
||||
type: "string"
|
||||
- name: "password"
|
||||
in: "query"
|
||||
description: "The password for login in clear text"
|
||||
required: true
|
||||
type: "string"
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
type: "string"
|
||||
headers:
|
||||
X-Rate-Limit:
|
||||
type: "integer"
|
||||
format: "int32"
|
||||
description: "calls per hour allowed by the user"
|
||||
X-Expires-After:
|
||||
type: "string"
|
||||
format: "date-time"
|
||||
description: "date in UTC when toekn expires"
|
||||
400:
|
||||
description: "Invalid username/password supplied"
|
||||
/user/logout:
|
||||
get:
|
||||
tags:
|
||||
- "user"
|
||||
summary: "Logs out current logged in user session"
|
||||
description: ""
|
||||
operationId: "logoutUser"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters: []
|
||||
responses:
|
||||
default:
|
||||
description: "successful operation"
|
||||
/user/{username}:
|
||||
get:
|
||||
tags:
|
||||
- "user"
|
||||
summary: "Get user by user name"
|
||||
description: ""
|
||||
operationId: "getUserByName"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "username"
|
||||
in: "path"
|
||||
description: "The name that needs to be fetched. Use user1 for testing. "
|
||||
required: true
|
||||
type: "string"
|
||||
responses:
|
||||
200:
|
||||
description: "successful operation"
|
||||
schema:
|
||||
$ref: "#/definitions/User"
|
||||
400:
|
||||
description: "Invalid username supplied"
|
||||
404:
|
||||
description: "User not found"
|
||||
put:
|
||||
tags:
|
||||
- "user"
|
||||
summary: "Updated user"
|
||||
description: "This can only be done by the logged in user."
|
||||
operationId: "updateUser"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "username"
|
||||
in: "path"
|
||||
description: "name that need to be deleted"
|
||||
required: true
|
||||
type: "string"
|
||||
- in: "body"
|
||||
name: "body"
|
||||
description: "Updated user object"
|
||||
required: true
|
||||
schema:
|
||||
$ref: "#/definitions/User"
|
||||
responses:
|
||||
400:
|
||||
description: "Invalid user supplied"
|
||||
404:
|
||||
description: "User not found"
|
||||
delete:
|
||||
tags:
|
||||
- "user"
|
||||
summary: "Delete user"
|
||||
description: "This can only be done by the logged in user."
|
||||
operationId: "deleteUser"
|
||||
produces:
|
||||
- "application/xml"
|
||||
- "application/json"
|
||||
parameters:
|
||||
- name: "username"
|
||||
in: "path"
|
||||
description: "The name that needs to be deleted"
|
||||
required: true
|
||||
type: "string"
|
||||
responses:
|
||||
400:
|
||||
description: "Invalid username supplied"
|
||||
404:
|
||||
description: "User not found"
|
||||
securityDefinitions:
|
||||
petstore_auth:
|
||||
type: "oauth2"
|
||||
authorizationUrl: "http://petstore.swagger.io/api/oauth/dialog"
|
||||
flow: "implicit"
|
||||
scopes:
|
||||
write:pets: "modify pets in your account"
|
||||
read:pets: "read your pets"
|
||||
api_key:
|
||||
type: "apiKey"
|
||||
name: "api_key"
|
||||
in: "header"
|
||||
definitions:
|
||||
Order:
|
||||
type: "object"
|
||||
properties:
|
||||
id:
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
petId:
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
quantity:
|
||||
type: "integer"
|
||||
format: "int32"
|
||||
shipDate:
|
||||
type: "string"
|
||||
format: "date-time"
|
||||
status:
|
||||
type: "string"
|
||||
description: "Order Status"
|
||||
enum:
|
||||
- "placed"
|
||||
- "approved"
|
||||
- "delivered"
|
||||
complete:
|
||||
type: "boolean"
|
||||
default: false
|
||||
xml:
|
||||
name: "Order"
|
||||
Category:
|
||||
type: "object"
|
||||
properties:
|
||||
id:
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
name:
|
||||
type: "string"
|
||||
xml:
|
||||
name: "Category"
|
||||
User:
|
||||
type: "object"
|
||||
properties:
|
||||
id:
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
username:
|
||||
type: "string"
|
||||
firstName:
|
||||
type: "string"
|
||||
lastName:
|
||||
type: "string"
|
||||
email:
|
||||
type: "string"
|
||||
password:
|
||||
type: "string"
|
||||
phone:
|
||||
type: "string"
|
||||
userStatus:
|
||||
type: "integer"
|
||||
format: "int32"
|
||||
description: "User Status"
|
||||
xml:
|
||||
name: "User"
|
||||
Tag:
|
||||
type: "object"
|
||||
properties:
|
||||
id:
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
name:
|
||||
type: "string"
|
||||
xml:
|
||||
name: "Tag"
|
||||
Pet:
|
||||
type: "object"
|
||||
required:
|
||||
- "name"
|
||||
- "photoUrls"
|
||||
properties:
|
||||
id:
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
category:
|
||||
$ref: "#/definitions/Category"
|
||||
name:
|
||||
type: "string"
|
||||
example: "doggie"
|
||||
photoUrls:
|
||||
type: "array"
|
||||
xml:
|
||||
name: "photoUrl"
|
||||
wrapped: true
|
||||
items:
|
||||
type: "string"
|
||||
tags:
|
||||
type: "array"
|
||||
xml:
|
||||
name: "tag"
|
||||
wrapped: true
|
||||
items:
|
||||
$ref: "#/definitions/Tag"
|
||||
status:
|
||||
type: "string"
|
||||
description: "pet status in the store"
|
||||
enum:
|
||||
- "available"
|
||||
- "pending"
|
||||
- "sold"
|
||||
xml:
|
||||
name: "Pet"
|
||||
ApiResponse:
|
||||
type: "object"
|
||||
properties:
|
||||
code:
|
||||
type: "integer"
|
||||
format: "int32"
|
||||
type:
|
||||
type: "string"
|
||||
message:
|
||||
type: "string"
|
||||
externalDocs:
|
||||
description: "Find out more about Swagger"
|
||||
url: "http://swagger.io"
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-project</artifactId>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
<version>2.1.6-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>swagger-codegen-maven-plugin</artifactId>
|
||||
@@ -51,7 +51,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<!-- <version>4.12</version> -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -10,7 +10,7 @@ public final class AdditionalParams {
|
||||
public static final String MODEL_PACKAGE_PARAM = "modelPackage";
|
||||
public static final String API_PACKAGE_PARAM = "apiPackage";
|
||||
public static final String INVOKER_PACKAGE_PARAM = "invokerPackage";
|
||||
public static final String LIBRARY_PARAM = "library";
|
||||
|
||||
private AdditionalParams() {
|
||||
}
|
||||
private AdditionalParams() {}
|
||||
}
|
||||
@@ -16,15 +16,13 @@ package io.swagger.codegen.plugin;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.ClientOptInput;
|
||||
import io.swagger.codegen.ClientOpts;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConfigLoader;
|
||||
import io.swagger.codegen.DefaultGenerator;
|
||||
import config.Config;
|
||||
import config.ConfigParser;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.codegen.utils.OptionUtils;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
@@ -32,18 +30,14 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import config.Config;
|
||||
import config.ConfigParser;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.swagger.codegen.plugin.AdditionalParams.API_PACKAGE_PARAM;
|
||||
import static io.swagger.codegen.plugin.AdditionalParams.INVOKER_PACKAGE_PARAM;
|
||||
import static io.swagger.codegen.plugin.AdditionalParams.MODEL_PACKAGE_PARAM;
|
||||
import static io.swagger.codegen.plugin.AdditionalParams.TEMPLATE_DIR_PARAM;
|
||||
import static io.swagger.codegen.plugin.AdditionalParams.*;
|
||||
|
||||
/**
|
||||
* Goal which generates client/server code from a swagger json/yaml definition.
|
||||
@@ -100,11 +94,17 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Parameter(name = "configurationFile", required = false)
|
||||
private String configurationFile;
|
||||
|
||||
/**
|
||||
* Sets the library
|
||||
*/
|
||||
@Parameter(name = "library", required = false)
|
||||
private String library;
|
||||
|
||||
/**
|
||||
* A map of language-specific parameters as passed with the -c option to the command line
|
||||
*/
|
||||
@Parameter(name = "configOptions")
|
||||
private Map configOptions;
|
||||
private Map<?, ?> configOptions;
|
||||
|
||||
/**
|
||||
* Add the output directory to the project as a source root, so that the
|
||||
@@ -116,6 +116,9 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
@Parameter
|
||||
protected Map<String, String> environmentVariables = new HashMap<String, String>();
|
||||
|
||||
@Parameter
|
||||
private boolean configHelp = false;
|
||||
|
||||
/**
|
||||
* The project being built.
|
||||
*/
|
||||
@@ -139,7 +142,9 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
System.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (null != library) {
|
||||
config.setLibrary(library);
|
||||
}
|
||||
if (null != templateDirectory) {
|
||||
config.additionalProperties().put(TEMPLATE_DIR_PARAM, templateDirectory.getAbsolutePath());
|
||||
}
|
||||
@@ -153,23 +158,33 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
config.additionalProperties().put(INVOKER_PACKAGE_PARAM, invokerPackage);
|
||||
}
|
||||
|
||||
if (configOptions != null) {
|
||||
Set<String> definedOptions = new HashSet<String>();
|
||||
for (CliOption langCliOption : config.cliOptions()) {
|
||||
if (configOptions.containsKey(langCliOption.getOpt())) {
|
||||
config.additionalProperties().put(langCliOption.getOpt(),
|
||||
configOptions.get(langCliOption.getOpt()));
|
||||
definedOptions.add(langCliOption.getOpt());
|
||||
}
|
||||
|
||||
if (configOptions != null) {
|
||||
if(configOptions.containsKey("import-mappings")) {
|
||||
Map<String, String> mappings = createMapFromKeyValuePairs(configOptions.remove("import-mappings").toString());
|
||||
config.importMapping().putAll(mappings);
|
||||
}
|
||||
|
||||
if(configOptions.containsKey("type-mappings")) {
|
||||
Map<String, String> mappings = createMapFromKeyValuePairs(configOptions.remove("type-mappings").toString());
|
||||
config.typeMapping().putAll(mappings);
|
||||
}
|
||||
|
||||
if(configOptions.containsKey("instantiation-types")) {
|
||||
Map<String, String> mappings = createMapFromKeyValuePairs(configOptions.remove("instantiation-types").toString());
|
||||
config.instantiationTypes().putAll(mappings);
|
||||
}
|
||||
addAdditionalProperties(config, definedOptions, configOptions);
|
||||
}
|
||||
|
||||
if (null != configurationFile) {
|
||||
Config genConfig = ConfigParser.read(configurationFile);
|
||||
if (null != genConfig) {
|
||||
for (CliOption langCliOption : config.cliOptions()) {
|
||||
if (genConfig.hasOption(langCliOption.getOpt())) {
|
||||
config.additionalProperties().put(langCliOption.getOpt(), genConfig.getOption(langCliOption.getOpt()));
|
||||
}
|
||||
}
|
||||
addAdditionalProperties(config, definedOptions, genConfig.getOptions());
|
||||
} else {
|
||||
throw new RuntimeException("Unable to read configuration file");
|
||||
}
|
||||
@@ -178,6 +193,14 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
ClientOptInput input = new ClientOptInput().opts(new ClientOpts()).swagger(swagger);
|
||||
input.setConfig(config);
|
||||
|
||||
if(configHelp) {
|
||||
for (CliOption langCliOption : config.cliOptions()) {
|
||||
System.out.println("\t" + langCliOption.getOpt());
|
||||
System.out.println("\t " + langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
|
||||
System.out.println();
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
new DefaultGenerator().opts(input).generate();
|
||||
} catch (Exception e) {
|
||||
@@ -192,4 +215,25 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
project.addCompileSourceRoot(output.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void addAdditionalProperties(CodegenConfig config, Set<String> definedOptions, Map<?,?> configOptions) {
|
||||
for(Map.Entry<?, ?> configEntry : configOptions.entrySet()) {
|
||||
config.additionalProperties().put(configEntry.getKey().toString(), configEntry.getValue());
|
||||
if(!definedOptions.contains(configEntry.getKey())) {
|
||||
getLog().warn("Additional property: " + configEntry.getKey() + " is not defined for this language.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> createMapFromKeyValuePairs(String commaSeparatedKVPairs) {
|
||||
final List<Pair<String, String>> pairs = OptionUtils.parseCommaSeparatedTuples(commaSeparatedKVPairs);
|
||||
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
|
||||
for (Pair<String, String> pair : pairs) {
|
||||
result.put(pair.getLeft(), pair.getRight());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen-project</artifactId>
|
||||
<version>2.1.5-SNAPSHOT</version>
|
||||
<version>2.1.6-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -101,7 +101,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
<!-- <version>2.1</version> -->
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -256,7 +256,7 @@
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>${testng-version}</version>
|
||||
<!-- <version>${testng-version}</version> -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -268,7 +268,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jmockit</groupId>
|
||||
<artifactId>jmockit</artifactId>
|
||||
<version>${jmockit-version}</version>
|
||||
<!-- <version>${jmockit-version}</version> -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -7,11 +7,16 @@ import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ConfigParser {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigParser.class);
|
||||
|
||||
public static Config read(String location) {
|
||||
|
||||
System.out.println("reading config from " + location);
|
||||
LOGGER.info("reading config from " + location);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@@ -27,11 +32,11 @@ public class ConfigParser {
|
||||
if (optionNode.getValue().isValueNode()) {
|
||||
config.setOption(optionNode.getKey(), optionNode.getValue().asText());
|
||||
} else {
|
||||
System.out.println("omitting non-value node " + optionNode.getKey());
|
||||
LOGGER.warn("omitting non-value node " + optionNode.getKey());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
LOGGER.error(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,18 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class AbstractGenerator {
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractGenerator {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGenerator.class);
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public File writeToFile(String filename, String contents) throws IOException {
|
||||
System.out.println("writing file " + filename);
|
||||
LOGGER.info("writing file " + filename);
|
||||
File output = new File(filename);
|
||||
|
||||
if (output.getParent() != null && !new File(output.getParent()).exists()) {
|
||||
@@ -36,10 +42,10 @@ public abstract class AbstractGenerator {
|
||||
if (reader == null) {
|
||||
throw new RuntimeException("no file found");
|
||||
}
|
||||
java.util.Scanner s = new java.util.Scanner(reader).useDelimiter("\\A");
|
||||
Scanner s = new Scanner(reader).useDelimiter("\\A");
|
||||
return s.hasNext() ? s.next() : "";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
throw new RuntimeException("can't load template " + name);
|
||||
}
|
||||
@@ -48,14 +54,11 @@ public abstract class AbstractGenerator {
|
||||
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");
|
||||
is = new FileInputStream(new File(name)); // May throw but never return a null value
|
||||
}
|
||||
return new InputStreamReader(is);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
throw new RuntimeException("can't load template " + name);
|
||||
}
|
||||
@@ -63,6 +66,9 @@ public abstract class AbstractGenerator {
|
||||
/**
|
||||
* Get the template file path with template dir prepended, and use the
|
||||
* library template if exists.
|
||||
*
|
||||
* @param config Codegen config
|
||||
* @param templateFile Template file
|
||||
*/
|
||||
public String getFullTemplateFile(CodegenConfig config, String templateFile) {
|
||||
String library = config.getLibrary();
|
||||
@@ -96,6 +102,7 @@ public abstract class AbstractGenerator {
|
||||
return this.getClass().getClassLoader().getResource(getCPResourcePath(name)) != null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public String getCPResourcePath(String name) {
|
||||
if (!"/".equals(File.separator)) {
|
||||
return name.replaceAll(Pattern.quote(File.separator), "/");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@@ -78,6 +79,14 @@ public class CliOption {
|
||||
this.enumValues = enumValues;
|
||||
}
|
||||
|
||||
public static CliOption newBoolean(String opt, String description) {
|
||||
return new CliOption(opt, description, BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString());
|
||||
}
|
||||
|
||||
public static CliOption newString(String opt, String description) {
|
||||
return new CliOption(opt, description, StringProperty.TYPE);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getOptionHelp() {
|
||||
StringBuilder sb = new StringBuilder(description);
|
||||
|
||||
@@ -5,13 +5,8 @@ import io.swagger.codegen.auth.AuthParser;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.auth.AuthorizationValue;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
public class ClientOptInput {
|
||||
private CodegenConfig config;
|
||||
private ClientOpts opts;
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import config.Config;
|
||||
import config.ConfigParser;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import org.apache.commons.cli.BasicParser;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.apache.commons.cli.BasicParser;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import config.Config;
|
||||
import config.ConfigParser;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
|
||||
/**
|
||||
* @deprecated use instead {@link io.swagger.codegen.DefaultGenerator}
|
||||
* or cli interface from https://github.com/swagger-api/swagger-codegen/pull/547
|
||||
*/
|
||||
@Deprecated
|
||||
public class Codegen extends DefaultGenerator {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Codegen.class);
|
||||
|
||||
static Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
|
||||
static String configString;
|
||||
static String debugInfoOptions = "\nThe following additional debug options are available for all codegen targets:" +
|
||||
@@ -32,10 +37,9 @@ public class Codegen extends DefaultGenerator {
|
||||
"\n -DdebugOperations prints operations passed to the template engine" +
|
||||
"\n -DdebugSupportingFiles prints additional data passed to the template engine";
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
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 + "]");
|
||||
@@ -113,7 +117,7 @@ public class Codegen extends DefaultGenerator {
|
||||
.swagger(swagger);
|
||||
new Codegen().opts(clientOptInput).generate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,9 +142,9 @@ public class Codegen extends DefaultGenerator {
|
||||
} else {
|
||||
// see if it's a class
|
||||
try {
|
||||
System.out.println("loading class " + name);
|
||||
Class customClass = Class.forName(name);
|
||||
System.out.println("loaded");
|
||||
LOGGER.debug("loading class " + name);
|
||||
Class<?> customClass = Class.forName(name);
|
||||
LOGGER.debug("loaded");
|
||||
return (CodegenConfig) customClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("can't load class " + name);
|
||||
|
||||
@@ -19,10 +19,16 @@ public interface CodegenConfig {
|
||||
|
||||
Map<String, Object> additionalProperties();
|
||||
|
||||
Map<String, Object> vendorExtensions();
|
||||
|
||||
String testPackage();
|
||||
|
||||
String apiPackage();
|
||||
|
||||
String apiFileFolder();
|
||||
|
||||
String apiTestFileFolder();
|
||||
|
||||
String fileSuffix();
|
||||
|
||||
String outputFolder();
|
||||
@@ -33,6 +39,8 @@ public interface CodegenConfig {
|
||||
|
||||
String modelFileFolder();
|
||||
|
||||
String modelTestFileFolder();
|
||||
|
||||
String modelPackage();
|
||||
|
||||
String toApiName(String name);
|
||||
@@ -87,6 +95,10 @@ public interface CodegenConfig {
|
||||
|
||||
Map<String, String> modelTemplateFiles();
|
||||
|
||||
Map<String, String> apiTestTemplateFiles();
|
||||
|
||||
Map<String, String> modelTestTemplateFiles();
|
||||
|
||||
Set<String> languageSpecificPrimitives();
|
||||
|
||||
void preprocessSwagger(Swagger swagger);
|
||||
@@ -97,20 +109,32 @@ public interface CodegenConfig {
|
||||
|
||||
String toModelFilename(String name);
|
||||
|
||||
String toApiTestFilename(String name);
|
||||
|
||||
String toModelTestFilename(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> postProcessAllModels(Map<String, Object> objs);
|
||||
|
||||
Map<String, Object> postProcessModels(Map<String, Object> objs);
|
||||
|
||||
Map<String, Object> postProcessOperations(Map<String, Object> objs);
|
||||
|
||||
Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs);
|
||||
|
||||
void postProcessModelProperty(CodegenModel model, CodegenProperty property);
|
||||
|
||||
void postProcessParameter(CodegenParameter parameter);
|
||||
|
||||
String apiFilename(String templateName, String tag);
|
||||
|
||||
String apiTestFilename(String templateName, String tag);
|
||||
|
||||
boolean shouldOverwrite(String filename);
|
||||
|
||||
boolean isSkipOverwrite();
|
||||
@@ -123,6 +147,8 @@ public interface CodegenConfig {
|
||||
|
||||
/**
|
||||
* Library template (sub-template).
|
||||
*
|
||||
* @return libray template
|
||||
*/
|
||||
String getLibrary();
|
||||
}
|
||||
|
||||
@@ -28,18 +28,27 @@ public class CodegenConstants {
|
||||
public static final String SOURCE_FOLDER = "sourceFolder";
|
||||
public static final String SOURCE_FOLDER_DESC = "source folder for generated code";
|
||||
|
||||
public static final String IMPL_FOLDER = "implFolder";
|
||||
public static final String IMPL_FOLDER_DESC = "folder for generated implementation code";
|
||||
|
||||
public static final String LOCAL_VARIABLE_PREFIX = "localVariablePrefix";
|
||||
public static final String LOCAL_VARIABLE_PREFIX_DESC = "prefix for generated code members and local variables";
|
||||
|
||||
public static final String SERIALIZABLE_MODEL = "serializableModel";
|
||||
public static final String SERIALIZABLE_MODEL_DESC = "boolean - toggle \"implements Serializable\" for generated models";
|
||||
|
||||
public static final String SERIALIZE_BIG_DECIMAL_AS_STRING = "bigDecimalAsString";
|
||||
public static final String SERIALIZE_BIG_DECIMAL_AS_STRING_DESC = "Treat BigDecimal values as Strings to avoid precision loss.";
|
||||
|
||||
public static final String LIBRARY = "library";
|
||||
public static final String LIBRARY_DESC = "library template (sub-template)";
|
||||
|
||||
public static final String SORT_PARAMS_BY_REQUIRED_FLAG = "sortParamsByRequiredFlag";
|
||||
public static final String SORT_PARAMS_BY_REQUIRED_FLAG_DESC = "Sort method arguments to place required parameters before optional parameters.";
|
||||
|
||||
public static final String USE_DATETIME_OFFSET = "useDateTimeOffset";
|
||||
public static final String USE_DATETIME_OFFSET_DESC = "Use DateTimeOffset to model date-time properties";
|
||||
|
||||
public static final String ENSURE_UNIQUE_PARAMS = "ensureUniqueParams";
|
||||
public static final String ENSURE_UNIQUE_PARAMS_DESC = "Whether to ensure parameter names are unique in an operation (rename parameters that are not).";
|
||||
|
||||
@@ -48,4 +57,34 @@ public class CodegenConstants {
|
||||
public static final String POD_VERSION = "podVersion";
|
||||
|
||||
public static final String OPTIONAL_METHOD_ARGUMENT = "optionalMethodArgument";
|
||||
public static final String OPTIONAL_METHOD_ARGUMENT_DESC = "Optional method argument, e.g. void square(int x=10) (.net 4.0+ only).";
|
||||
|
||||
public static final String OPTIONAL_ASSEMBLY_INFO = "optionalAssemblyInfo";
|
||||
public static final String OPTIONAL_ASSEMBLY_INFO_DESC = "Generate AssemblyInfo.cs.";
|
||||
|
||||
public static final String USE_COLLECTION = "useCollection";
|
||||
public static final String USE_COLLECTION_DESC = "Deserialize array types to Collection<T> instead of List<T>.";
|
||||
|
||||
public static final String RETURN_ICOLLECTION = "returnICollection";
|
||||
public static final String RETURN_ICOLLECTION_DESC = "Return ICollection<T> instead of the concrete type.";
|
||||
|
||||
public static final String OPTIONAL_PROJECT_FILE = "optionalProjectFile";
|
||||
public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate {PackageName}.csproj.";
|
||||
|
||||
public static final String OPTIONAL_PROJECT_GUID = "packageGuid";
|
||||
public static final String OPTIONAL_PROJECT_GUID_DESC = "The GUID that will be associated with the C# project";
|
||||
|
||||
public static final String MODEL_PROPERTY_NAMING = "modelPropertyNaming";
|
||||
public static final String MODEL_PROPERTY_NAMING_DESC = "Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name";
|
||||
|
||||
public static final String DOTNET_FRAMEWORK = "targetFramework";
|
||||
public static final String DOTNET_FRAMEWORK_DESC = "The target .NET framework version.";
|
||||
|
||||
public static enum MODEL_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case, original}
|
||||
|
||||
public static final String MODEL_NAME_PREFIX = "modelNamePrefix";
|
||||
public static final String MODEL_NAME_PREFIX_DESC = "Prefix that will be prepended to all model names. Default is the empty string.";
|
||||
|
||||
public static final String MODEL_NAME_SUFFIX = "modelNameSuffix";
|
||||
public static final String MODEL_NAME_SUFFIX_DESC = "Suffix that will be appended to all model names. Default is the empty string.";
|
||||
}
|
||||
|
||||
@@ -2,13 +2,10 @@ package io.swagger.codegen;
|
||||
|
||||
import io.swagger.models.ExternalDocs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenModel {
|
||||
public String parent;
|
||||
public String parent, parentSchema;
|
||||
public String name, classname, description, classVarName, modelJson, dataType;
|
||||
public String unescapedDescription;
|
||||
public String defaultValue;
|
||||
@@ -18,7 +15,9 @@ public class CodegenModel {
|
||||
// list of all required parameters
|
||||
public Set<String> mandatory = new HashSet<String>();
|
||||
|
||||
public Set<String> imports = new HashSet<String>();
|
||||
public Set<String> imports = new TreeSet<String>();
|
||||
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum;
|
||||
public ExternalDocs externalDocs;
|
||||
|
||||
public Map<String, Object> vendorExtensions;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CodegenOperation {
|
||||
*
|
||||
* @return true if parameter exists, false otherwise
|
||||
*/
|
||||
private boolean nonempty(List<CodegenParameter> params) {
|
||||
private static boolean nonempty(List<CodegenParameter> params) {
|
||||
return params != null && params.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,17 @@ import java.util.List;
|
||||
|
||||
public class CodegenParameter {
|
||||
public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
|
||||
isCookieParam, isBodyParam, isFile, notFile, hasMore, isContainer,
|
||||
secondaryParam, isBinary, isCollectionFormatMulti;
|
||||
public String baseName, paramName, dataType, collectionFormat, description, baseType, defaultValue;
|
||||
isCookieParam, isBodyParam, hasMore, isContainer,
|
||||
secondaryParam, isCollectionFormatMulti;
|
||||
public String baseName, paramName, dataType, datatypeWithEnum, collectionFormat, description, baseType, defaultValue;
|
||||
public String jsonSchema;
|
||||
public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime;
|
||||
public Boolean isListContainer, isMapContainer;
|
||||
public Boolean isFile, notFile;
|
||||
public boolean isEnum;
|
||||
public List<String> _enum;
|
||||
public Map<String, Object> allowableValues;
|
||||
public CodegenProperty items;
|
||||
public Map<String, Object> vendorExtensions;
|
||||
|
||||
/**
|
||||
@@ -78,6 +82,7 @@ public class CodegenParameter {
|
||||
output.baseName = this.baseName;
|
||||
output.paramName = this.paramName;
|
||||
output.dataType = this.dataType;
|
||||
output.datatypeWithEnum = this.datatypeWithEnum;
|
||||
output.collectionFormat = this.collectionFormat;
|
||||
output.isCollectionFormatMulti = this.isCollectionFormatMulti;
|
||||
output.description = this.description;
|
||||
@@ -109,7 +114,22 @@ public class CodegenParameter {
|
||||
if (this.allowableValues != null) {
|
||||
output.allowableValues = new HashMap<String, Object>(this.allowableValues);
|
||||
}
|
||||
if (this.items != null) {
|
||||
output.items = this.items;
|
||||
}
|
||||
output.vendorExtensions = this.vendorExtensions;
|
||||
output.isBinary = this.isBinary;
|
||||
output.isByteArray = this.isByteArray;
|
||||
output.isString = this.isString;
|
||||
output.isInteger = this.isInteger;
|
||||
output.isLong = this.isLong;
|
||||
output.isDouble = this.isDouble;
|
||||
output.isFloat = this.isFloat;
|
||||
output.isBoolean = this.isBoolean;
|
||||
output.isDate = this.isDate;
|
||||
output.isDateTime = this.isDateTime;
|
||||
output.isListContainer = this.isListContainer;
|
||||
output.isMapContainer = this.isMapContainer;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -31,13 +31,72 @@ public class CodegenProperty {
|
||||
public Double maximum;
|
||||
public Boolean exclusiveMinimum;
|
||||
public Boolean exclusiveMaximum;
|
||||
public Boolean hasMore = null, required = null, secondaryParam = null;
|
||||
public Boolean hasMore, required, secondaryParam;
|
||||
public Boolean isPrimitiveType, isContainer, isNotContainer;
|
||||
public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime;
|
||||
public Boolean isListContainer, isMapContainer;
|
||||
public boolean isEnum;
|
||||
public Boolean isReadOnly = false;
|
||||
public List<String> _enum;
|
||||
public Map<String, Object> allowableValues;
|
||||
public CodegenProperty items;
|
||||
public Map<String, Object> vendorExtensions;
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((_enum == null) ? 0 : _enum.hashCode());
|
||||
result = prime * result + ((allowableValues == null) ? 0 : allowableValues.hashCode());
|
||||
result = prime * result + ((baseName == null) ? 0 : baseName.hashCode());
|
||||
result = prime * result + ((baseType == null) ? 0 : baseType.hashCode());
|
||||
result = prime * result + ((complexType == null) ? 0 : complexType.hashCode());
|
||||
result = prime * result + ((containerType == null) ? 0 : containerType.hashCode());
|
||||
result = prime * result + ((datatype == null) ? 0 : datatype.hashCode());
|
||||
result = prime * result + ((datatypeWithEnum == null) ? 0 : datatypeWithEnum.hashCode());
|
||||
result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
|
||||
result = prime * result + ((defaultValueWithParam == null) ? 0 : defaultValueWithParam.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((example == null) ? 0 : example.hashCode());
|
||||
result = prime * result + ((exclusiveMaximum == null) ? 0 : exclusiveMaximum.hashCode());
|
||||
result = prime * result + ((exclusiveMinimum == null) ? 0 : exclusiveMinimum.hashCode());
|
||||
result = prime * result + ((getter == null) ? 0 : getter.hashCode());
|
||||
result = prime * result + ((hasMore == null) ? 0 : hasMore.hashCode());
|
||||
result = prime * result + ((isContainer == null) ? 0 : isContainer.hashCode());
|
||||
result = prime * result + (isEnum ? 1231 : 1237);
|
||||
result = prime * result + ((isNotContainer == null) ? 0 : isNotContainer.hashCode());
|
||||
result = prime * result + ((isPrimitiveType == null) ? 0 : isPrimitiveType.hashCode());
|
||||
result = prime * result + ((isReadOnly == null) ? 0 : isReadOnly.hashCode());
|
||||
result = prime * result + ((items == null) ? 0 : items.hashCode());
|
||||
result = prime * result + ((jsonSchema == null) ? 0 : jsonSchema.hashCode());
|
||||
result = prime * result + ((max == null) ? 0 : max.hashCode());
|
||||
result = prime * result + ((maxLength == null) ? 0 : maxLength.hashCode());
|
||||
result = prime * result + ((maximum == null) ? 0 : maximum.hashCode());
|
||||
result = prime * result + ((min == null) ? 0 : min.hashCode());
|
||||
result = prime * result + ((minLength == null) ? 0 : minLength.hashCode());
|
||||
result = prime * result + ((minimum == null) ? 0 : minimum.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((pattern == null) ? 0 : pattern.hashCode());
|
||||
result = prime * result + ((required == null) ? 0 : required.hashCode());
|
||||
result = prime * result + ((secondaryParam == null) ? 0 : secondaryParam.hashCode());
|
||||
result = prime * result + ((setter == null) ? 0 : setter.hashCode());
|
||||
result = prime * result + ((unescapedDescription == null) ? 0 : unescapedDescription.hashCode());
|
||||
result = prime * result + ((vendorExtensions == null) ? 0 : vendorExtensions.hashCode());
|
||||
result = prime * result + ((isString == null) ? 0 : isString.hashCode());
|
||||
result = prime * result + ((isInteger == null) ? 0 : isInteger.hashCode());
|
||||
result = prime * result + ((isLong == null) ? 0 : isLong.hashCode());
|
||||
result = prime * result + ((isFloat == null) ? 0 : isFloat.hashCode());
|
||||
result = prime * result + ((isDouble == null) ? 0 : isDouble.hashCode());
|
||||
result = prime * result + ((isByteArray == null) ? 0 : isByteArray.hashCode());
|
||||
result = prime * result + ((isBinary == null) ? 0 : isBinary.hashCode());
|
||||
result = prime * result + ((isBoolean == null) ? 0 : isBoolean.hashCode());
|
||||
result = prime * result + ((isDate == null) ? 0 : isDate.hashCode());
|
||||
result = prime * result + ((isDateTime == null) ? 0 : isDateTime.hashCode());
|
||||
result = prime * result + ((isMapContainer == null) ? 0 : isMapContainer.hashCode());
|
||||
result = prime * result + ((isListContainer == null) ? 0 : isListContainer.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@@ -132,12 +191,54 @@ public class CodegenProperty {
|
||||
if (this.isEnum != other.isEnum) {
|
||||
return false;
|
||||
}
|
||||
if (this.isReadOnly != other.isReadOnly && (this.isReadOnly == null || !this.isReadOnly.equals(other.isReadOnly))) {
|
||||
return false;
|
||||
}
|
||||
if (this._enum != other._enum && (this._enum == null || !this._enum.equals(other._enum))) {
|
||||
return false;
|
||||
}
|
||||
if (this.allowableValues != other.allowableValues && (this.allowableValues == null || !this.allowableValues.equals(other.allowableValues))) {
|
||||
return false;
|
||||
}
|
||||
if (this.vendorExtensions != other.vendorExtensions && (this.vendorExtensions == null || !this.vendorExtensions.equals(other.vendorExtensions))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isString != other.isString && (this.isString == null || !this.isString.equals(other.isString))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isInteger != other.isInteger && (this.isInteger == null || !this.isInteger.equals(other.isInteger))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isLong != other.isLong && (this.isLong == null || !this.isLong.equals(other.isLong))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isFloat != other.isFloat && (this.isFloat == null || !this.isFloat.equals(other.isFloat))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isDouble != other.isDouble && (this.isDouble == null || !this.isDouble.equals(other.isDouble))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isByteArray != other.isByteArray && (this.isByteArray == null || !this.isByteArray.equals(other.isByteArray))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isBoolean != other.isBoolean && (this.isBoolean == null || !this.isBoolean.equals(other.isBoolean))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isDate != other.isDate && (this.isDate == null || !this.isDate.equals(other.isDate))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isDateTime != other.isDateTime && (this.isDateTime == null || !this.isDateTime.equals(other.isDateTime))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isBinary != other.isBinary && (this.isBinary == null || !this.isBinary.equals(other.isBinary))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isListContainer != other.isListContainer && (this.isListContainer == null || !this.isListContainer.equals(other.isListContainer))) {
|
||||
return false;
|
||||
}
|
||||
if (this.isMapContainer != other.isMapContainer && (this.isMapContainer == null || !this.isMapContainer.equals(other.isMapContainer))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,11 +19,11 @@ import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
|
||||
|
||||
protected CodegenConfig config;
|
||||
protected ClientOptInput opts = null;
|
||||
protected Swagger swagger = null;
|
||||
protected ClientOptInput opts;
|
||||
protected Swagger swagger;
|
||||
|
||||
@Override
|
||||
public Generator opts(ClientOptInput opts) {
|
||||
@@ -129,6 +129,13 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
if (info.getVersion() != null) {
|
||||
config.additionalProperties().put("version", info.getVersion());
|
||||
}
|
||||
if (info.getTermsOfService() != null) {
|
||||
config.additionalProperties().put("termsOfService", info.getTermsOfService());
|
||||
}
|
||||
}
|
||||
|
||||
if(swagger.getVendorExtensions() != null) {
|
||||
config.vendorExtensions().putAll(swagger.getVendorExtensions());
|
||||
}
|
||||
|
||||
StringBuilder hostBuilder = new StringBuilder();
|
||||
@@ -176,6 +183,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
sortedModelKeys = updatedKeys;
|
||||
}
|
||||
|
||||
// store all processed models
|
||||
Map<String,Object> allProcessedModels = new HashMap<String, Object>();
|
||||
|
||||
// process models only
|
||||
for (String name : sortedModelKeys) {
|
||||
try {
|
||||
//don't generate models that have an import mapping
|
||||
@@ -189,6 +200,26 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
Map<String, Object> models = processModels(config, modelMap, definitions);
|
||||
models.putAll(config.additionalProperties());
|
||||
|
||||
allProcessedModels.put(name, models);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Could not process model '" + name + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
// post process all processed models
|
||||
allProcessedModels = config.postProcessAllModels(allProcessedModels);
|
||||
|
||||
// generate files based on processed models
|
||||
for (String name: allProcessedModels.keySet()) {
|
||||
Map<String, Object> models = (Map<String, Object>)allProcessedModels.get(name);
|
||||
|
||||
try {
|
||||
//don't generate models that have an import mapping
|
||||
if(config.importMapping().containsKey(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
allModels.add(((List<Object>) models.get("models")).get(0));
|
||||
|
||||
for (String templateName : config.modelTemplateFiles().keySet()) {
|
||||
@@ -211,6 +242,28 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
writeToFile(filename, tmpl.execute(models));
|
||||
files.add(new File(filename));
|
||||
}
|
||||
|
||||
// to generate model test files
|
||||
for (String templateName : config.modelTestTemplateFiles().keySet()) {
|
||||
String suffix = config.modelTestTemplateFiles().get(templateName);
|
||||
String filename = config.modelTestFileFolder() + File.separator + config.toModelTestFilename(name) + suffix;
|
||||
if (!config.shouldOverwrite(filename)) {
|
||||
continue;
|
||||
}
|
||||
String templateFile = getFullTemplateFile(config, templateName);
|
||||
String template = readTemplate(templateFile);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
@Override
|
||||
public Reader getTemplate(String name) {
|
||||
return getTemplateReader(getFullTemplateFile(config, name + ".mustache"));
|
||||
}
|
||||
})
|
||||
.defaultValue("")
|
||||
.compile(template);
|
||||
writeToFile(filename, tmpl.execute(models));
|
||||
files.add(new File(filename));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Could not generate model '" + name + "'", e);
|
||||
}
|
||||
@@ -218,7 +271,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
if (System.getProperty("debugModels") != null) {
|
||||
System.out.println("############ Model info ############");
|
||||
LOGGER.info("############ Model info ############");
|
||||
Json.prettyPrint(allModels);
|
||||
}
|
||||
|
||||
@@ -249,6 +302,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
operation.put("classVarName", config.toApiVarName(tag));
|
||||
operation.put("importPath", config.toApiImport(tag));
|
||||
|
||||
if(!config.vendorExtensions().isEmpty()) {
|
||||
operation.put("vendorExtensions", config.vendorExtensions());
|
||||
}
|
||||
|
||||
// Pass sortParamsByRequiredFlag through to the Mustache template...
|
||||
boolean sortParamsByRequiredFlag = true;
|
||||
if (this.config.additionalProperties().containsKey(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG)) {
|
||||
@@ -288,13 +345,37 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
writeToFile(filename, tmpl.execute(operation));
|
||||
files.add(new File(filename));
|
||||
}
|
||||
|
||||
// to generate api test files
|
||||
for (String templateName : config.apiTestTemplateFiles().keySet()) {
|
||||
String filename = config.apiTestFilename(templateName, tag);
|
||||
if (!config.shouldOverwrite(filename) && new File(filename).exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String templateFile = getFullTemplateFile(config, templateName);
|
||||
String template = readTemplate(templateFile);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
@Override
|
||||
public Reader getTemplate(String name) {
|
||||
return getTemplateReader(getFullTemplateFile(config, name + ".mustache"));
|
||||
}
|
||||
})
|
||||
.defaultValue("")
|
||||
.compile(template);
|
||||
|
||||
writeToFile(filename, tmpl.execute(operation));
|
||||
files.add(new File(filename));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Could not generate api file for '" + tag + "'", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (System.getProperty("debugOperations") != null) {
|
||||
System.out.println("############ Operation info ############");
|
||||
LOGGER.info("############ Operation info ############");
|
||||
Json.prettyPrint(allOperations);
|
||||
}
|
||||
|
||||
@@ -333,7 +414,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
config.postProcessSupportingFileData(bundle);
|
||||
|
||||
if (System.getProperty("debugSupportingFiles") != null) {
|
||||
System.out.println("############ Supporting file info ############");
|
||||
LOGGER.info("############ Supporting file info ############");
|
||||
Json.prettyPrint(bundle);
|
||||
}
|
||||
|
||||
@@ -392,18 +473,14 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
File outputFile = new File(outputFilename);
|
||||
OutputStream out = new FileOutputStream(outputFile, false);
|
||||
if (in != null && out != null) {
|
||||
System.out.println("writing file " + outputFile);
|
||||
if (in != null) {
|
||||
LOGGER.info("writing file " + outputFile);
|
||||
IOUtils.copy(in, out);
|
||||
} else {
|
||||
if (in == null) {
|
||||
System.out.println("can't open " + templateFile + " for input");
|
||||
}
|
||||
if (out == null) {
|
||||
System.out.println("can't open " + outputFile + " for output");
|
||||
LOGGER.error("can't open " + templateFile + " for input");
|
||||
}
|
||||
}
|
||||
|
||||
files.add(outputFile);
|
||||
}
|
||||
}
|
||||
@@ -412,13 +489,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config.processSwagger(swagger);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
private void processMimeTypes(List<String> mimeTypeList, Map<String, Object> operation, String source) {
|
||||
private static void processMimeTypes(List<String> mimeTypeList, Map<String, Object> operation, String source) {
|
||||
if (mimeTypeList != null && mimeTypeList.size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
int count = 0;
|
||||
@@ -439,7 +514,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> sortModelsByInheritance(final Map<String, Model> definitions) {
|
||||
private static List<String> sortModelsByInheritance(final Map<String, Model> definitions) {
|
||||
List<String> sortedModelKeys = new ArrayList<String>(definitions.keySet());
|
||||
Comparator<String> cmp = new Comparator<String>() {
|
||||
@Override
|
||||
@@ -512,7 +587,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations, Path path) {
|
||||
if (operation != null) {
|
||||
if (System.getProperty("debugOperations") != null) {
|
||||
LOGGER.debug("processOperation: resourcePath= " + resourcePath + "\t;" + httpMethod + " " + operation + "\n");
|
||||
LOGGER.info("processOperation: resourcePath= " + resourcePath + "\t;" + httpMethod + " " + operation
|
||||
+ "\n");
|
||||
}
|
||||
List<String> tags = operation.getTags();
|
||||
if (tags == null) {
|
||||
@@ -561,14 +637,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
continue;
|
||||
}
|
||||
Map<String, SecuritySchemeDefinition> authMethods = new HashMap<String, SecuritySchemeDefinition>();
|
||||
// NOTE: Use only the first security requirement for now.
|
||||
// See the "security" field of "Swagger Object":
|
||||
// https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#swagger-object
|
||||
// "there is a logical OR between the security requirements"
|
||||
if (securities.size() > 1) {
|
||||
LOGGER.warn("More than 1 security requirements are found, using only the first one");
|
||||
}
|
||||
Map<String, List<String>> security = securities.get(0);
|
||||
for (Map<String, List<String>> security: securities) {
|
||||
for (String securityName : security.keySet()) {
|
||||
SecuritySchemeDefinition securityDefinition = fromSecurity(securityName);
|
||||
if (securityDefinition != null) {
|
||||
@@ -591,6 +660,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!authMethods.isEmpty()) {
|
||||
co.authMethods = config.fromSecurity(authMethods);
|
||||
co.hasAuthMethods = true;
|
||||
@@ -609,10 +679,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
|
||||
private String generateParameterId(Parameter parameter) {
|
||||
private static String generateParameterId(Parameter parameter) {
|
||||
return parameter.getName() + ":" + parameter.getIn();
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String sanitizeTag(String tag) {
|
||||
// remove spaces and make strong case
|
||||
String[] parts = tag.split(" ");
|
||||
@@ -625,6 +696,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return buf.toString().replaceAll("[^a-zA-Z ]", "");
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
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>();
|
||||
@@ -685,6 +757,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return operations;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> processModels(CodegenConfig config, Map<String, Model> definitions, Map<String, Model> allDefinitions) {
|
||||
Map<String, Object> objs = new HashMap<String, Object>();
|
||||
objs.put("package", config.modelPackage());
|
||||
@@ -697,29 +770,34 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
mo.put("model", cm);
|
||||
mo.put("importPath", config.toModelImport(key));
|
||||
models.add(mo);
|
||||
|
||||
allImports.addAll(cm.imports);
|
||||
}
|
||||
objs.put("models", models);
|
||||
|
||||
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
|
||||
Set<String> importSet = new TreeSet<String>();
|
||||
for (String nextImport : allImports) {
|
||||
Map<String, String> im = new LinkedHashMap<String, String>();
|
||||
String mapping = config.importMapping().get(nextImport);
|
||||
if (mapping == null) {
|
||||
mapping = config.toModelImport(nextImport);
|
||||
}
|
||||
if (mapping != null && !config.defaultIncludes().contains(mapping)) {
|
||||
im.put("import", mapping);
|
||||
imports.add(im);
|
||||
importSet.add(mapping);
|
||||
}
|
||||
// add instantiation types
|
||||
mapping = config.instantiationTypes().get(nextImport);
|
||||
if (mapping != null && !config.defaultIncludes().contains(mapping)) {
|
||||
im.put("import", mapping);
|
||||
imports.add(im);
|
||||
importSet.add(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
|
||||
for(String s: importSet) {
|
||||
Map<String, String> item = new HashMap<String, String>();
|
||||
item.put("import", s);
|
||||
imports.add(item);
|
||||
}
|
||||
|
||||
objs.put("imports", imports);
|
||||
config.postProcessModels(objs);
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Mod;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.parameters.RefParameter;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.util.Json;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -14,8 +14,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class InlineModelResolver {
|
||||
private Swagger swagger = null;
|
||||
private boolean skipMatches = false;
|
||||
private Swagger swagger;
|
||||
private boolean skipMatches;
|
||||
static Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class);
|
||||
|
||||
Map<String, Model> addedModels = new HashMap<String, Model>();
|
||||
Map<String, String> generatedSignature = new HashMap<String, String>();
|
||||
@@ -60,8 +61,19 @@ public class InlineModelResolver {
|
||||
Property inner = am.getItems();
|
||||
|
||||
if(inner instanceof ObjectProperty) {
|
||||
String modelName = uniqueName(bp.getName());
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
am.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
am.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,36 +100,38 @@ public class InlineModelResolver {
|
||||
}
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) property;
|
||||
if(ap.getItems() instanceof ObjectProperty) {
|
||||
ObjectProperty op = (ObjectProperty) ap.getItems();
|
||||
Map<String, Property> props = op.getProperties();
|
||||
flattenProperties(props, "path");
|
||||
}
|
||||
} else if (property instanceof MapProperty) {
|
||||
MapProperty op = (MapProperty) property;
|
||||
|
||||
Property innerProperty = op.getAdditionalProperties();
|
||||
if(innerProperty instanceof ObjectProperty) {
|
||||
ModelImpl innerModel = new ModelImpl();
|
||||
// TODO: model props
|
||||
innerModel.setTitle(property.getTitle());
|
||||
property.getVendorExtensions();
|
||||
property.getRequired();
|
||||
property.getReadOnly();
|
||||
property.getAccess();
|
||||
innerModel.setDescription(property.getDescription());
|
||||
innerModel.setExample(property.getExample());
|
||||
innerModel.setName(property.getName());
|
||||
innerModel.setXml(property.getXml());
|
||||
|
||||
innerModel.setAdditionalProperties(innerProperty);
|
||||
Property inner = ap.getItems();
|
||||
|
||||
if(inner instanceof ObjectProperty) {
|
||||
String modelName = uniqueName("inline_response_" + key);
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
response.setSchema(new RefProperty(existing));
|
||||
ap.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
response.setSchema(new RefProperty(modelName));
|
||||
ap.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
} else if (property instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) property;
|
||||
|
||||
Property innerProperty = mp.getAdditionalProperties();
|
||||
if(innerProperty instanceof ObjectProperty) {
|
||||
String modelName = uniqueName("inline_response_" + key);
|
||||
ObjectProperty op = (ObjectProperty) innerProperty;
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
mp.setAdditionalProperties(new RefProperty(existing));
|
||||
} else {
|
||||
mp.setAdditionalProperties(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
@@ -157,8 +171,6 @@ public class InlineModelResolver {
|
||||
m.setItems(new RefProperty(existing));
|
||||
}
|
||||
}
|
||||
} else if (model instanceof ComposedModel) {
|
||||
ComposedModel m = (ComposedModel) model;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,7 +194,7 @@ public class InlineModelResolver {
|
||||
public String uniqueName(String key) {
|
||||
int count = 0;
|
||||
boolean done = false;
|
||||
key = key.replaceAll("[^a-z_\\.A-Z0-9 ]", "");
|
||||
key = key.replaceAll("[^a-z_\\.A-Z0-9 ]", ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
while (!done) {
|
||||
String name = key;
|
||||
if (count > 0) {
|
||||
@@ -206,7 +218,12 @@ public class InlineModelResolver {
|
||||
Map<String, Model> modelsToAdd = new HashMap<String, Model>();
|
||||
for (String key : properties.keySet()) {
|
||||
Property property = properties.get(key);
|
||||
if (property instanceof ObjectProperty && ((ObjectProperty)property).getProperties().size() > 0) {
|
||||
if(property instanceof ObjectProperty && ((ObjectProperty)property).getProperties() == null) {
|
||||
MapProperty mp = new MapProperty();
|
||||
mp.setAdditionalProperties(new StringProperty());
|
||||
properties.put(key, mp);
|
||||
}
|
||||
else if (property instanceof ObjectProperty && ((ObjectProperty)property).getProperties().size() > 0) {
|
||||
String modelName = uniqueName(path + "_" + key);
|
||||
|
||||
ObjectProperty op = (ObjectProperty) property;
|
||||
@@ -222,6 +239,48 @@ public class InlineModelResolver {
|
||||
addGenerated(modelName, model);
|
||||
swagger.addDefinition(modelName, model);
|
||||
}
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) property;
|
||||
Property inner = ap.getItems();
|
||||
|
||||
if (inner instanceof ObjectProperty) {
|
||||
String modelName = uniqueName(path + "_" + key);
|
||||
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
flattenProperties(op.getProperties(), path);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
|
||||
if (existing != null) {
|
||||
ap.setItems(new RefProperty(existing));
|
||||
} else {
|
||||
ap.setItems(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
} else if (property instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) property;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
if (inner instanceof ObjectProperty) {
|
||||
String modelName = uniqueName(path + "_" + key);
|
||||
|
||||
ObjectProperty op = (ObjectProperty) inner;
|
||||
flattenProperties(op.getProperties(), path);
|
||||
|
||||
Model innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
|
||||
if (existing != null) {
|
||||
mp.setAdditionalProperties(new RefProperty(existing));
|
||||
} else {
|
||||
mp.setAdditionalProperties(new RefProperty(modelName));
|
||||
addGenerated(modelName, innerModel);
|
||||
swagger.addDefinition(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (propsToUpdate.size() > 0) {
|
||||
@@ -235,53 +294,36 @@ public class InlineModelResolver {
|
||||
}
|
||||
}
|
||||
|
||||
public Model modelFromProperty(ArrayProperty object, String path) {
|
||||
String access = object.getAccess();
|
||||
@SuppressWarnings("static-method")
|
||||
public Model modelFromProperty(ArrayProperty object, @SuppressWarnings("unused") String path) {
|
||||
String description = object.getDescription();
|
||||
String example = object.getExample();
|
||||
String name = object.getName();
|
||||
Integer position = object.getPosition();
|
||||
Boolean readOnly = object.getReadOnly();
|
||||
Boolean required = object.getRequired();
|
||||
String title = object.getTitle();
|
||||
Map<String, Object> extensions = object.getVendorExtensions();
|
||||
Xml xml = object.getXml();
|
||||
|
||||
// object.getItems()
|
||||
// Map<String, Property> properties = object.getProperties();
|
||||
String example = null;
|
||||
|
||||
Object obj = object.getExample();
|
||||
if(obj != null) {
|
||||
example = obj.toString();
|
||||
}
|
||||
Property inner = object.getItems();
|
||||
if (inner instanceof ObjectProperty) {
|
||||
ArrayModel model = new ArrayModel();
|
||||
model.setDescription(description);
|
||||
model.setExample(example);
|
||||
// model.setName(name);
|
||||
// model.setXml(xml);
|
||||
|
||||
model.setItems(object.getItems());
|
||||
return model;
|
||||
}
|
||||
|
||||
// if(properties != null) {
|
||||
// flattenProperties(properties, path);
|
||||
// model.setProperties(properties);
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Model modelFromProperty(ObjectProperty object, String path) {
|
||||
String access = object.getAccess();
|
||||
String description = object.getDescription();
|
||||
String example = object.getExample();
|
||||
String name = object.getName();
|
||||
Integer position = object.getPosition();
|
||||
Boolean readOnly = object.getReadOnly();
|
||||
Boolean required = object.getRequired();
|
||||
String title = object.getTitle();
|
||||
Map<String, Object> extensions = object.getVendorExtensions();
|
||||
Xml xml = object.getXml();
|
||||
String example = null;
|
||||
|
||||
Object obj = object.getExample();
|
||||
if(obj != null) {
|
||||
example = obj.toString();
|
||||
}
|
||||
String name = object.getName();
|
||||
Xml xml = object.getXml();
|
||||
Map<String, Property> properties = object.getProperties();
|
||||
|
||||
ModelImpl model = new ModelImpl();
|
||||
@@ -298,17 +340,15 @@ public class InlineModelResolver {
|
||||
return model;
|
||||
}
|
||||
|
||||
public Model modelFromProperty(MapProperty object, String path) {
|
||||
String access = object.getAccess();
|
||||
@SuppressWarnings("static-method")
|
||||
public Model modelFromProperty(MapProperty object, @SuppressWarnings("unused") String path) {
|
||||
String description = object.getDescription();
|
||||
String example = object.getExample();
|
||||
String name = object.getName();
|
||||
Integer position = object.getPosition();
|
||||
Boolean readOnly = object.getReadOnly();
|
||||
Boolean required = object.getRequired();
|
||||
String title = object.getTitle();
|
||||
Map<String, Object> extensions = object.getVendorExtensions();
|
||||
Xml xml = object.getXml();
|
||||
String example = null;
|
||||
|
||||
Object obj = object.getExample();
|
||||
if(obj != null) {
|
||||
example = obj.toString();
|
||||
}
|
||||
|
||||
ArrayModel model = new ArrayModel();
|
||||
model.setDescription(description);
|
||||
@@ -325,4 +365,5 @@ public class InlineModelResolver {
|
||||
public void setSkipMatches(boolean skipMatches) {
|
||||
this.skipMatches = skipMatches;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,15 +2,17 @@ package io.swagger.codegen;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.apache.commons.cli.BasicParser;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -25,6 +27,9 @@ import java.util.ServiceLoader;
|
||||
*/
|
||||
@Deprecated
|
||||
public class MetaGenerator extends AbstractGenerator {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MetaGenerator.class);
|
||||
|
||||
static Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
|
||||
static String configString;
|
||||
|
||||
@@ -57,8 +62,6 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
}
|
||||
|
||||
protected void generate(String[] args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String targetLanguage = null;
|
||||
String outputFolder = null;
|
||||
String name = null;
|
||||
String targetPackage = "io.swagger.codegen";
|
||||
@@ -71,12 +74,9 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
options.addOption("n", "name", true, "the human-readable name of the generator");
|
||||
options.addOption("p", "package", true, "the package to put the main class into (defaults to io.swagger.codegen");
|
||||
|
||||
ClientOptInput clientOptInput = new ClientOptInput();
|
||||
Swagger swagger = null;
|
||||
CommandLine cmd = null;
|
||||
try {
|
||||
CommandLineParser parser = new BasicParser();
|
||||
|
||||
cmd = parser.parse(options, args);
|
||||
if (cmd.hasOption("h")) {
|
||||
usage(options);
|
||||
@@ -85,12 +85,11 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
if (cmd.hasOption("n")) {
|
||||
name = cmd.getOptionValue("n");
|
||||
} else {
|
||||
System.out.println("name is required");
|
||||
System.out.println("name is required"); //FIXME replace by LOGGER
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
if (cmd.hasOption("l")) {
|
||||
targetLanguage = cmd.getOptionValue("l");
|
||||
}
|
||||
if (cmd.hasOption("p")) {
|
||||
targetPackage = cmd.getOptionValue("p");
|
||||
@@ -98,7 +97,7 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
if (cmd.hasOption("o")) {
|
||||
outputFolder = cmd.getOptionValue("o");
|
||||
} else {
|
||||
System.out.println("output folder is required");
|
||||
System.out.println("output folder is required"); // FIXME replace by LOGGER
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
@@ -106,7 +105,7 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
System.out.println("writing to folder " + outputFolder);
|
||||
LOGGER.info("writing to folder " + outputFolder);
|
||||
File outputFolderLocation = new File(outputFolder);
|
||||
if (!outputFolderLocation.exists()) {
|
||||
outputFolderLocation.mkdirs();
|
||||
@@ -157,11 +156,10 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
String template = readTemplate(templateDir + File.separator + support.templateFile);
|
||||
Template tmpl = Mustache.compiler()
|
||||
.withLoader(new Mustache.TemplateLoader() {
|
||||
@Override
|
||||
public Reader getTemplate(String name) {
|
||||
return getTemplateReader(templateDir + File.separator + name + ".mustache");
|
||||
}
|
||||
|
||||
;
|
||||
})
|
||||
.defaultValue("")
|
||||
.compile(template);
|
||||
@@ -171,11 +169,11 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
} else {
|
||||
String template = readTemplate(templateDir + File.separator + support.templateFile);
|
||||
FileUtils.writeStringToFile(new File(outputFilename), template);
|
||||
System.out.println("copying file to " + outputFilename);
|
||||
LOGGER.info("copying file to " + outputFilename);
|
||||
files.add(new File(outputFilename));
|
||||
}
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public class SupportingFile {
|
||||
this.destinationFilename = destinationFilename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("SupportingFile:").append("\n");
|
||||
|
||||
@@ -7,10 +7,17 @@ import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import config.ConfigParser;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
public class AuthParser {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AuthParser.class);
|
||||
|
||||
public static List<AuthorizationValue> parse(String urlEncodedAuthStr) {
|
||||
List<AuthorizationValue> auths = new ArrayList<AuthorizationValue>();
|
||||
if (isNotEmpty(urlEncodedAuthStr)) {
|
||||
@@ -18,7 +25,7 @@ public class AuthParser {
|
||||
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"));
|
||||
auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0]), URLDecoder.decode(kvPair[1]), "header")); // FIXME replace the deprecated method by decode(string, encoding). Which encoding is used ? Default UTF-8 ?
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +45,7 @@ public class AuthParser {
|
||||
.append(URLEncoder.encode(v.getValue(), "UTF-8"));
|
||||
} catch (Exception e) {
|
||||
// continue
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
|
||||
@@ -36,18 +36,20 @@ import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
*/
|
||||
public class CodegenConfigurator {
|
||||
|
||||
public static final Logger LOG = LoggerFactory.getLogger(CodegenConfigurator.class);
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(CodegenConfigurator.class);
|
||||
|
||||
private String lang;
|
||||
private String inputSpec;
|
||||
private String outputDir;
|
||||
private boolean verbose = false;
|
||||
private boolean skipOverwrite = false;
|
||||
private boolean verbose;
|
||||
private boolean skipOverwrite;
|
||||
private String templateDir;
|
||||
private String auth;
|
||||
private String apiPackage;
|
||||
private String modelPackage;
|
||||
private String invokerPackage;
|
||||
private String modelNamePrefix;
|
||||
private String modelNameSuffix;
|
||||
private String groupId;
|
||||
private String artifactId;
|
||||
private String artifactVersion;
|
||||
@@ -97,6 +99,24 @@ public class CodegenConfigurator {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getModelNamePrefix() {
|
||||
return modelNamePrefix;
|
||||
}
|
||||
|
||||
public CodegenConfigurator setModelNamePrefix(String prefix) {
|
||||
this.modelNamePrefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getModelNameSuffix() {
|
||||
return modelNameSuffix;
|
||||
}
|
||||
|
||||
public CodegenConfigurator setModelNameSuffix(String suffix) {
|
||||
this.modelNameSuffix = suffix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isVerbose() {
|
||||
return verbose;
|
||||
}
|
||||
@@ -300,6 +320,8 @@ public class CodegenConfigurator {
|
||||
checkAndSetAdditionalProperty(artifactId, CodegenConstants.ARTIFACT_ID);
|
||||
checkAndSetAdditionalProperty(artifactVersion, CodegenConstants.ARTIFACT_VERSION);
|
||||
checkAndSetAdditionalProperty(templateDir, toAbsolutePathStr(templateDir), CodegenConstants.TEMPLATE_DIR);
|
||||
checkAndSetAdditionalProperty(modelNamePrefix, CodegenConstants.MODEL_NAME_PREFIX);
|
||||
checkAndSetAdditionalProperty(modelNameSuffix, CodegenConstants.MODEL_NAME_SUFFIX);
|
||||
|
||||
handleDynamicProperties(config);
|
||||
|
||||
@@ -349,7 +371,7 @@ public class CodegenConfigurator {
|
||||
if (!verbose) {
|
||||
return;
|
||||
}
|
||||
LOG.info("\nVERBOSE MODE: ON. Additional debug options are injected" +
|
||||
LOGGER.info("\nVERBOSE MODE: ON. Additional debug options are injected" +
|
||||
"\n - [debugSwagger] prints the swagger specification as interpreted by the codegen" +
|
||||
"\n - [debugModels] prints models passed to the template engine" +
|
||||
"\n - [debugOperations] prints operations passed to the template engine" +
|
||||
@@ -390,10 +412,9 @@ public class CodegenConfigurator {
|
||||
|
||||
if (isNotEmpty(configFile)) {
|
||||
try {
|
||||
CodegenConfigurator result = Json.mapper().readValue(new File(configFile), CodegenConfigurator.class);
|
||||
return result;
|
||||
return Json.mapper().readValue(new File(configFile), CodegenConfigurator.class);
|
||||
} catch (IOException e) {
|
||||
LOG.error("Unable to deserialize config file: " + configFile, e);
|
||||
LOGGER.error("Unable to deserialize config file: " + configFile, e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ExampleGenerator {
|
||||
if (examples == null) {
|
||||
if (mediaTypes == null) {
|
||||
// assume application/json for this
|
||||
mediaTypes = Arrays.asList("application/json");
|
||||
mediaTypes = Arrays.asList("application/json"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
}
|
||||
for (String mediaType : mediaTypes) {
|
||||
Map<String, String> kv = new HashMap<String, String>();
|
||||
@@ -88,15 +88,14 @@ public class ExampleGenerator {
|
||||
} else if (property instanceof ArrayProperty) {
|
||||
Property innerType = ((ArrayProperty) property).getItems();
|
||||
if (innerType != null) {
|
||||
Object[] output = new Object[]{
|
||||
return new Object[]{
|
||||
resolvePropertyToExample(mediaType, innerType, processedModels)
|
||||
};
|
||||
return output;
|
||||
}
|
||||
} else if (property instanceof DateProperty) {
|
||||
return new java.util.Date(System.currentTimeMillis());
|
||||
return "2000-01-23T04:56:07.000+0000";
|
||||
} else if (property instanceof DateTimeProperty) {
|
||||
return new java.util.Date(System.currentTimeMillis());
|
||||
return "2000-01-23T04:56:07.000+0000";
|
||||
} else if (property instanceof DecimalProperty) {
|
||||
return new BigDecimal(1.3579);
|
||||
} else if (property instanceof DoubleProperty) {
|
||||
@@ -143,16 +142,14 @@ public class ExampleGenerator {
|
||||
ModelImpl impl = (ModelImpl) model;
|
||||
Map<String, Object> values = new HashMap<String, Object>();
|
||||
|
||||
if (impl != null && impl.getProperties() != null) {
|
||||
if (impl.getProperties() != null) {
|
||||
for (String propertyName : impl.getProperties().keySet()) {
|
||||
Property property = impl.getProperties().get(propertyName);
|
||||
values.put(propertyName, resolvePropertyToExample(mediaType, property, processedModels));
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,8 @@ import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -33,13 +31,11 @@ public class XmlExampleGenerator {
|
||||
public static String TAG_END = "</";
|
||||
private static String EMPTY = "";
|
||||
protected Map<String, Model> examples;
|
||||
protected SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
protected SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
|
||||
public XmlExampleGenerator(Map<String, Model> examples) {
|
||||
this.examples = examples;
|
||||
if (examples == null) {
|
||||
examples = new HashMap<String, Model>();
|
||||
this.examples = new HashMap<String, Model>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +70,6 @@ public class XmlExampleGenerator {
|
||||
Map<String, Property> elements = new LinkedHashMap<String, Property>();
|
||||
|
||||
String name = modelName;
|
||||
String namespace;
|
||||
String prefix;
|
||||
Boolean wrapped;
|
||||
|
||||
Xml xml = model.getXml();
|
||||
if (xml != null) {
|
||||
if (xml.getName() != null) {
|
||||
@@ -117,6 +109,7 @@ public class XmlExampleGenerator {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String quote(String string) {
|
||||
return "\"" + string + "\"";
|
||||
}
|
||||
@@ -173,37 +166,37 @@ public class XmlExampleGenerator {
|
||||
protected String getExample(Property property) {
|
||||
if (property instanceof DateTimeProperty) {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample();
|
||||
return property.getExample().toString();
|
||||
} else {
|
||||
return dtFormat.format(new Date());
|
||||
return "2000-01-23T04:56:07.000Z";
|
||||
}
|
||||
} else if (property instanceof StringProperty) {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample();
|
||||
return property.getExample().toString();
|
||||
} else {
|
||||
return "string";
|
||||
}
|
||||
} else if (property instanceof DateProperty) {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample();
|
||||
return property.getExample().toString();
|
||||
} else {
|
||||
return dateFormat.format(new Date());
|
||||
return "2000-01-23T04:56:07.000Z";
|
||||
}
|
||||
} else if (property instanceof IntegerProperty) {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample();
|
||||
return property.getExample().toString();
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
} else if (property instanceof BooleanProperty) {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample();
|
||||
return property.getExample().toString();
|
||||
} else {
|
||||
return "true";
|
||||
}
|
||||
} else if (property instanceof LongProperty) {
|
||||
if (property.getExample() != null) {
|
||||
return property.getExample();
|
||||
return property.getExample().toString();
|
||||
} else {
|
||||
return "123456";
|
||||
}
|
||||
@@ -211,14 +204,17 @@ public class XmlExampleGenerator {
|
||||
return "not implemented " + property;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String openTag(String name) {
|
||||
return "<" + name + ">";
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String closeTag(String name) {
|
||||
return "</" + name + ">";
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String indent(int indent) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < indent; i++) {
|
||||
|
||||
@@ -0,0 +1,518 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractCSharpCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
protected boolean optionalAssemblyInfoFlag = true;
|
||||
protected boolean optionalProjectFileFlag = false;
|
||||
protected boolean optionalMethodArgumentFlag = true;
|
||||
protected boolean useDateTimeOffsetFlag = false;
|
||||
protected boolean useCollection = false;
|
||||
protected boolean returnICollection = false;
|
||||
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String packageName = "IO.Swagger";
|
||||
protected String sourceFolder = "src" + File.separator + packageName;
|
||||
|
||||
protected Set<String> collectionTypes;
|
||||
protected Set<String> mapTypes;
|
||||
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(AbstractCSharpCodegen.class);
|
||||
|
||||
public AbstractCSharpCodegen() {
|
||||
super();
|
||||
|
||||
outputFolder = "generated-code" + File.separator + this.getName();
|
||||
embeddedTemplateDir = templateDir = this.getName();
|
||||
|
||||
collectionTypes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"IList", "List",
|
||||
"ICollection", "Collection",
|
||||
"IEnumerable")
|
||||
);
|
||||
|
||||
mapTypes = new HashSet<String>(
|
||||
Arrays.asList("IDictionary")
|
||||
);
|
||||
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names in API methods (endpoints)
|
||||
"localVarPath", "localVarPathParams", "localVarQueryParams", "localVarHeaderParams",
|
||||
"localVarFormParams", "localVarFileParams", "localVarStatusCode", "localVarResponse",
|
||||
"localVarPostBody", "localVarHttpHeaderAccepts", "localVarHttpHeaderAccept",
|
||||
"localVarHttpContentTypes", "localVarHttpContentType",
|
||||
"localVarStatusCode",
|
||||
// C# reserved words
|
||||
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked",
|
||||
"class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else",
|
||||
"enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for",
|
||||
"foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock",
|
||||
"long", "namespace", "new", "null", "object", "operator", "out", "override", "params",
|
||||
"private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed",
|
||||
"short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw",
|
||||
"true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using",
|
||||
"virtual", "void", "volatile", "while")
|
||||
);
|
||||
|
||||
// TODO: Either include fully qualified names here or handle in DefaultCodegen via lastIndexOf(".") search
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"string",
|
||||
"bool?",
|
||||
"double?",
|
||||
"int?",
|
||||
"long?",
|
||||
"float?",
|
||||
"byte[]",
|
||||
"ICollection",
|
||||
"Collection",
|
||||
"List",
|
||||
"Dictionary",
|
||||
"DateTime?",
|
||||
"DateTimeOffset?",
|
||||
"String",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Int32",
|
||||
"Int64",
|
||||
"Float",
|
||||
"Guid",
|
||||
"Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
|
||||
instantiationTypes.put("array", "List");
|
||||
instantiationTypes.put("list", "List");
|
||||
instantiationTypes.put("map", "Dictionary");
|
||||
|
||||
// Nullable types here assume C# 2 support is not part of base
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("binary", "byte[]");
|
||||
typeMapping.put("boolean", "bool?");
|
||||
typeMapping.put("integer", "int?");
|
||||
typeMapping.put("float", "float?");
|
||||
typeMapping.put("long", "long?");
|
||||
typeMapping.put("double", "double?");
|
||||
typeMapping.put("number", "double?");
|
||||
typeMapping.put("datetime", "DateTime?");
|
||||
typeMapping.put("date", "DateTime?");
|
||||
typeMapping.put("file", "Stream");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("uuid", "Guid");
|
||||
}
|
||||
|
||||
public void setReturnICollection(boolean returnICollection) {
|
||||
this.returnICollection = returnICollection;
|
||||
}
|
||||
|
||||
public void setUseCollection(boolean useCollection) {
|
||||
this.useCollection = useCollection;
|
||||
if (useCollection) {
|
||||
typeMapping.put("array", "Collection");
|
||||
typeMapping.put("list", "Collection");
|
||||
|
||||
instantiationTypes.put("array", "Collection");
|
||||
instantiationTypes.put("list", "Collection");
|
||||
}
|
||||
}
|
||||
|
||||
public void setOptionalMethodArgumentFlag(boolean flag) {
|
||||
this.optionalMethodArgumentFlag = flag;
|
||||
}
|
||||
|
||||
protected void addOption(String key, String description, String defaultValue) {
|
||||
CliOption option = new CliOption(key, description);
|
||||
if (defaultValue != null) option.defaultValue(defaultValue);
|
||||
cliOptions.add(option);
|
||||
}
|
||||
|
||||
protected void addSwitch(String key, String description, Boolean defaultValue) {
|
||||
CliOption option = CliOption.newBoolean(key, description);
|
||||
if (defaultValue != null) option.defaultValue(defaultValue.toString());
|
||||
cliOptions.add(option);
|
||||
}
|
||||
|
||||
public void useDateTimeOffset(boolean flag) {
|
||||
this.useDateTimeOffsetFlag = flag;
|
||||
if (flag) typeMapping.put("datetime", "DateTimeOffset?");
|
||||
else typeMapping.put("datetime", "DateTime?");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
// {{packageVersion}}
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
|
||||
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
}
|
||||
|
||||
// {{sourceFolder}}
|
||||
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||
setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, this.sourceFolder);
|
||||
}
|
||||
|
||||
// {{packageName}}
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
}
|
||||
|
||||
// {{useDateTimeOffset}}
|
||||
if (additionalProperties.containsKey(CodegenConstants.USE_DATETIME_OFFSET)) {
|
||||
useDateTimeOffset(Boolean.valueOf(additionalProperties.get(CodegenConstants.USE_DATETIME_OFFSET).toString()));
|
||||
}
|
||||
additionalProperties.put(CodegenConstants.USE_DATETIME_OFFSET, useDateTimeOffsetFlag);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.USE_COLLECTION)) {
|
||||
setUseCollection(Boolean.valueOf(additionalProperties.get(CodegenConstants.USE_COLLECTION).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.RETURN_ICOLLECTION)) {
|
||||
setReturnICollection(Boolean.valueOf(additionalProperties.get(CodegenConstants.RETURN_ICOLLECTION).toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
// check to see if model name is same as the property name
|
||||
// which will result in compilation error
|
||||
// if found, prepend with _ to workaround the limitation
|
||||
if (var.name.equals(cm.name)) {
|
||||
var.name = "_" + var.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
super.postProcessOperations(objs);
|
||||
if (objs != null) {
|
||||
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) {
|
||||
|
||||
// Check return types for collection
|
||||
if (operation.returnType != null) {
|
||||
String typeMapping;
|
||||
int namespaceEnd = operation.returnType.lastIndexOf(".");
|
||||
if (namespaceEnd > 0) {
|
||||
typeMapping = operation.returnType.substring(namespaceEnd);
|
||||
} else {
|
||||
typeMapping = operation.returnType;
|
||||
}
|
||||
|
||||
if (this.collectionTypes.contains(typeMapping)) {
|
||||
operation.isListContainer = true;
|
||||
operation.returnContainer = operation.returnType;
|
||||
if (this.returnICollection && (
|
||||
typeMapping.startsWith("List") ||
|
||||
typeMapping.startsWith("Collection"))) {
|
||||
// NOTE: ICollection works for both List<T> and Collection<T>
|
||||
int genericStart = typeMapping.indexOf("<");
|
||||
if (genericStart > 0) {
|
||||
operation.returnType = "ICollection" + typeMapping.substring(genericStart);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
operation.returnContainer = operation.returnType;
|
||||
operation.isMapContainer = this.mapTypes.contains(typeMapping);
|
||||
}
|
||||
}
|
||||
|
||||
processOperation(operation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
protected void processOperation(CodegenOperation operation) {
|
||||
// default noop
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
return name;
|
||||
}
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => PetId
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
return name;
|
||||
}
|
||||
|
||||
// camelize(lower) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the example value of the property
|
||||
*
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the example value of the property
|
||||
*/
|
||||
@Override
|
||||
public String toExampleValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
StringProperty dp = (StringProperty) p;
|
||||
if (dp.getExample() != null) {
|
||||
return "\"" + dp.getExample().toString() + "\"";
|
||||
}
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
BooleanProperty dp = (BooleanProperty) p;
|
||||
if (dp.getExample() != null) {
|
||||
return dp.getExample().toString();
|
||||
}
|
||||
} else if (p instanceof DateProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DateTimeProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getExample() != null) {
|
||||
return dp.getExample().toString();
|
||||
}
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getExample() != null) {
|
||||
return dp.getExample().toString();
|
||||
}
|
||||
} else if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getExample() != null) {
|
||||
return dp.getExample().toString();
|
||||
}
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getExample() != null) {
|
||||
return dp.getExample().toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default value of the property
|
||||
*
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the default value of the property
|
||||
*/
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
StringProperty dp = (StringProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "\"" + dp.getDefault().toString() + "\"";
|
||||
}
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
BooleanProperty dp = (BooleanProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof DateProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DateTimeProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type;
|
||||
if (typeMapping.containsKey(swaggerType.toLowerCase())) {
|
||||
type = typeMapping.get(swaggerType.toLowerCase());
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@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 toModelName(String name) {
|
||||
name = sanitizeName(modelNamePrefix + name + modelNameSuffix);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return outputFolder + ".Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return outputFolder + ".Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiTestFilename(String name) {
|
||||
return toApiName(name) + "Tests";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
return toModelName(name) + "Tests";
|
||||
}
|
||||
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setPackageVersion(String packageVersion) {
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenResponse;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
{
|
||||
/**
|
||||
* Name of the sub-directory in "src/main/resource" where to find the
|
||||
* Mustache template for the JAX-RS Codegen.
|
||||
*/
|
||||
protected static final String JAXRS_TEMPLATE_DIRECTORY_NAME = "JavaJaxRS";
|
||||
protected String implFolder = "src/main/java";
|
||||
protected String title = "Swagger Server";
|
||||
|
||||
public AbstractJavaJAXRSServerCodegen()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
// ================
|
||||
// ABSTRACT METHODS
|
||||
// ================
|
||||
|
||||
@Override
|
||||
public abstract String getHelp();
|
||||
|
||||
@Override
|
||||
public abstract String getName();
|
||||
|
||||
// ===============
|
||||
// COMMONS METHODS
|
||||
// ===============
|
||||
|
||||
@Override
|
||||
public CodegenType getTag()
|
||||
{
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if ( "/".equals(swagger.getBasePath()) ) {
|
||||
swagger.setBasePath("");
|
||||
}
|
||||
|
||||
String host = swagger.getHost();
|
||||
String port = "8080"; // Default value for a JEE Server
|
||||
if ( host != null ) {
|
||||
String[] parts = host.split(":");
|
||||
if ( parts.length > 1 ) {
|
||||
port = parts[1];
|
||||
}
|
||||
}
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
if ( swagger.getPaths() != null ) {
|
||||
for ( String pathname : swagger.getPaths().keySet() ) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if ( path.getOperations() != null ) {
|
||||
for ( Operation operation : path.getOperations() ) {
|
||||
if ( operation.getTags() != null ) {
|
||||
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
for ( String tag : operation.getTags() ) {
|
||||
Map<String, String> value = new HashMap<String, String>();
|
||||
value.put("tag", tag);
|
||||
value.put("hasMore", "true");
|
||||
tags.add(value);
|
||||
}
|
||||
if ( tags.size() > 0 ) {
|
||||
tags.get(tags.size() - 1).remove("hasMore");
|
||||
}
|
||||
if ( operation.getTags().size() > 0 ) {
|
||||
String tag = operation.getTags().get(0);
|
||||
operation.setTags(Arrays.asList(tag));
|
||||
}
|
||||
operation.setVendorExtension("x-tags", tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if ( operations != null ) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for ( CodegenOperation operation : ops ) {
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if ( responses != null ) {
|
||||
for ( CodegenResponse resp : responses ) {
|
||||
if ( "0".equals(resp.code) ) {
|
||||
resp.code = "200";
|
||||
}
|
||||
}
|
||||
}
|
||||
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).trim();
|
||||
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).split(",")[1].trim();
|
||||
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).trim();
|
||||
operation.returnContainer = "Set";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(final String name) {
|
||||
String computed = name;
|
||||
if ( computed.length() == 0 ) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
computed = sanitizeName(computed);
|
||||
return camelize(computed) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if ( templateName.endsWith("Impl.mustache") ) {
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java";
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if ( templateName.endsWith("Factory.mustache") ) {
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java";
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if ( templateName.endsWith("Service.mustache") ) {
|
||||
int ix = result.lastIndexOf('.');
|
||||
result = result.substring(0, ix) + "Service.java";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String implFileFolder(String output) {
|
||||
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
return super.shouldOverwrite(filename) && !filename.endsWith("ServiceImpl.java") && !filename.endsWith("ServiceFactory.java");
|
||||
}
|
||||
}
|
||||
@@ -9,17 +9,21 @@ import java.io.File;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
protected String modelPropertyNaming= "camelCase";
|
||||
|
||||
public AbstractTypeScriptClientCodegen() {
|
||||
super();
|
||||
supportsInheritance = true;
|
||||
reservedWords = new HashSet<String>(Arrays.asList("abstract", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield"));
|
||||
setReservedWordsLowerCase(Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"varLocalPath", "queryParameters", "headerParams", "formParams", "useFormData", "varLocalDeferred",
|
||||
"requestOptions",
|
||||
// Typescript reserved words
|
||||
"abstract", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(Arrays.asList(
|
||||
"string",
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
@@ -27,7 +31,12 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Object"));
|
||||
"Object",
|
||||
"Array",
|
||||
"Date",
|
||||
"number",
|
||||
"any"
|
||||
));
|
||||
instantiationTypes.put("array", "Array");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
@@ -47,7 +56,27 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
typeMapping.put("integer", "number");
|
||||
typeMapping.put("Map", "any");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, CodegenConstants.MODEL_PROPERTY_NAMING_DESC).defaultValue("camelCase"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
|
||||
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,14 +89,15 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
public String toParamName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$"))
|
||||
@@ -78,24 +108,36 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*"))
|
||||
if (isReservedWord(name) || name.matches("^\\d.*"))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
public String toVarName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
return getNameUsingModelPropertyNaming(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
name = name + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name))
|
||||
throw new RuntimeException(name
|
||||
+ " (reserved word) cannot be used as a model name");
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = camelize("object_" + name);
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
@@ -134,7 +176,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
return type;
|
||||
} else
|
||||
type = swaggerType;
|
||||
return type;
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,10 +188,38 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
// append _ at the beginning, e.g. _return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
return escapeReservedWord(camelize(sanitizeName(operationId), true));
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
public void setModelPropertyNaming(String naming) {
|
||||
if ("original".equals(naming) || "camelCase".equals(naming) ||
|
||||
"PascalCase".equals(naming) || "snake_case".equals(naming)) {
|
||||
this.modelPropertyNaming = naming;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid model property naming '" +
|
||||
naming + "'. Must be 'original', 'camelCase', " +
|
||||
"'PascalCase' or 'snake_case'");
|
||||
}
|
||||
}
|
||||
|
||||
public String getModelPropertyNaming() {
|
||||
return this.modelPropertyNaming;
|
||||
}
|
||||
|
||||
public String getNameUsingModelPropertyNaming(String name) {
|
||||
switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
|
||||
case original: return name;
|
||||
case camelCase: return camelize(name, true);
|
||||
case PascalCase: return camelize(name);
|
||||
case snake_case: return underscore(name);
|
||||
default: throw new IllegalArgumentException("Invalid model property naming '" +
|
||||
name + "'. Must be 'original', 'camelCase', " +
|
||||
"'PascalCase' or 'snake_case'");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,9 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
* unmarshalling problems and any other RuntimeException will be considered as ApiErrors.
|
||||
*/
|
||||
protected boolean onlyOneSuccess = true;
|
||||
Logger LOGGER = LoggerFactory.getLogger(AkkaScalaClientCodegen.class);
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(AkkaScalaClientCodegen.class);
|
||||
|
||||
public AkkaScalaClientCodegen() {
|
||||
super();
|
||||
@@ -74,7 +76,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
apiPackage = mainPackage + ".api";
|
||||
modelPackage = mainPackage + ".model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"abstract", "case", "catch", "class", "def", "do", "else", "extends",
|
||||
"false", "final", "finally", "for", "forSome", "if", "implicit",
|
||||
@@ -154,14 +156,17 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "akka-scala";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Scala client library base on Akka/Spray.";
|
||||
}
|
||||
@@ -176,6 +181,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
@@ -270,7 +276,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
if (capitalized) {
|
||||
identifier = StringUtils.capitalize(identifier);
|
||||
}
|
||||
if (identifier.matches("[a-zA-Z_$][\\w_$]+") && !reservedWords.contains(identifier)) {
|
||||
if (identifier.matches("[a-zA-Z_$][\\w_$]+") && !isReservedWord(identifier)) {
|
||||
return identifier;
|
||||
}
|
||||
return escapeReservedWord(identifier);
|
||||
@@ -321,6 +327,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (!p.getRequired()) {
|
||||
return "None";
|
||||
|
||||
@@ -15,8 +15,11 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AndroidClientCodegen.class);
|
||||
public static final String USE_ANDROID_MAVEN_GRADLE_PLUGIN = "useAndroidMavenGradlePlugin";
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
@@ -26,17 +29,27 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
protected String sourceFolder = projectFolder + "/java";
|
||||
protected Boolean useAndroidMavenGradlePlugin = true;
|
||||
|
||||
// requestPackage and authPackage are used by the "volley" template/library
|
||||
protected String requestPackage = "io.swagger.client.request";
|
||||
protected String authPackage = "io.swagger.client.auth";
|
||||
|
||||
public AndroidClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/android";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
embeddedTemplateDir = templateDir = "android-java";
|
||||
embeddedTemplateDir = templateDir = "android";
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"postBody", "path", "queryParams", "headerParams", "formParams",
|
||||
"contentTypes", "contentType", "response", "builder", "httpEntity",
|
||||
"authNames", "basePath", "apiInvoker",
|
||||
|
||||
// android reserved words
|
||||
"abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
|
||||
@@ -67,18 +80,27 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, "artifactId for use in the generated build.gradle and pom.xml"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, "artifact version for use in the generated build.gradle and pom.xml"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
|
||||
cliOptions.add(new CliOption(USE_ANDROID_MAVEN_GRADLE_PLUGIN, "A flag to toggle android-maven gradle plugin.")
|
||||
.defaultValue("true"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_ANDROID_MAVEN_GRADLE_PLUGIN, "A flag to toggle android-maven gradle plugin.")
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
supportedLibraries.put("<default>", "HTTP client: Apache HttpClient 4.3.6. JSON processing: Gson 2.3.1");
|
||||
supportedLibraries.put("volley", "HTTP client: Volley 1.0.19");
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setEnum(supportedLibraries);
|
||||
cliOptions.add(library);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "android";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates an Android client library.";
|
||||
}
|
||||
@@ -93,6 +115,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
@@ -130,7 +153,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@@ -142,7 +165,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -157,14 +180,18 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
name = camelize(sanitizeName(name));
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = "Object" + name;
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,12 +207,16 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
return camelize(operationId, true);
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,22 +262,63 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
additionalProperties.put(USE_ANDROID_MAVEN_GRADLE_PLUGIN, useAndroidMavenGradlePlugin);
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
additionalProperties.put(USE_ANDROID_MAVEN_GRADLE_PLUGIN, useAndroidMavenGradlePlugin);
|
||||
if (additionalProperties.containsKey(CodegenConstants.LIBRARY)) {
|
||||
this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY));
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(getLibrary())) {
|
||||
addSupportingFilesForDefault();
|
||||
} else if ("volley".equals(getLibrary())) {
|
||||
addSupportingFilesForVolley();
|
||||
}
|
||||
}
|
||||
|
||||
private void addSupportingFilesForDefault() {
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
|
||||
supportingFiles.add(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
|
||||
supportingFiles.add(new SupportingFile("apiInvoker.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiInvoker.java"));
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiInvoker.java"));
|
||||
supportingFiles.add(new SupportingFile("httpPatch.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "HttpPatch.java"));
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "HttpPatch.java"));
|
||||
supportingFiles.add(new SupportingFile("jsonUtil.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "JsonUtil.java"));
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "JsonUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiException.java"));
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "Pair.java"));
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "Pair.java"));
|
||||
}
|
||||
|
||||
private void addSupportingFilesForVolley() {
|
||||
// supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
// supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
|
||||
supportingFiles.add(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
|
||||
supportingFiles.add(new SupportingFile("apiInvoker.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiInvoker.java"));
|
||||
supportingFiles.add(new SupportingFile("jsonUtil.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "JsonUtil.java"));
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache",
|
||||
(sourceFolder + File.separator + invokerPackage).replace(".", File.separator), "Pair.java"));
|
||||
supportingFiles.add(new SupportingFile("request/getrequest.mustache",
|
||||
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "GetRequest.java"));
|
||||
supportingFiles.add(new SupportingFile("request/postrequest.mustache",
|
||||
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "PostRequest.java"));
|
||||
supportingFiles.add(new SupportingFile("request/putrequest.mustache",
|
||||
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "PutRequest.java"));
|
||||
supportingFiles.add(new SupportingFile("request/deleterequest.mustache",
|
||||
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "DeleteRequest.java"));
|
||||
supportingFiles.add(new SupportingFile("request/patchrequest.mustache",
|
||||
(sourceFolder + File.separator + requestPackage).replace(".", File.separator), "PatchRequest.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/apikeyauth.mustache",
|
||||
(sourceFolder + File.separator + authPackage).replace(".", File.separator), "ApiKeyAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/httpbasicauth.mustache",
|
||||
(sourceFolder + File.separator + authPackage).replace(".", File.separator), "HttpBasicAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/authentication.mustache",
|
||||
(sourceFolder + File.separator + authPackage).replace(".", File.separator), "Authentication.java"));
|
||||
}
|
||||
|
||||
public Boolean getUseAndroidMavenGradlePlugin() {
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class AspNet5ServerCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(AspNet5ServerCodegen.class);
|
||||
|
||||
public AspNet5ServerCodegen() {
|
||||
super();
|
||||
|
||||
outputFolder = "generated-code" + File.separator + this.getName();
|
||||
|
||||
modelTemplateFiles.put("model.mustache", ".cs");
|
||||
apiTemplateFiles.put("controller.mustache", ".cs");
|
||||
|
||||
// contextually reserved words
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList("var", "async", "await", "dynamic", "yield")
|
||||
);
|
||||
|
||||
cliOptions.clear();
|
||||
|
||||
// CLI options
|
||||
addOption(CodegenConstants.PACKAGE_NAME,
|
||||
"C# package name (convention: Title.Case).",
|
||||
this.packageName);
|
||||
|
||||
addOption(CodegenConstants.PACKAGE_VERSION,
|
||||
"C# package version.",
|
||||
this.packageVersion);
|
||||
|
||||
addOption(CodegenConstants.SOURCE_FOLDER,
|
||||
CodegenConstants.SOURCE_FOLDER_DESC,
|
||||
sourceFolder);
|
||||
|
||||
// CLI Switches
|
||||
addSwitch(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC,
|
||||
this.sortParamsByRequiredFlag);
|
||||
|
||||
addSwitch(CodegenConstants.USE_DATETIME_OFFSET,
|
||||
CodegenConstants.USE_DATETIME_OFFSET_DESC,
|
||||
this.useDateTimeOffsetFlag);
|
||||
|
||||
addSwitch(CodegenConstants.USE_COLLECTION,
|
||||
CodegenConstants.USE_COLLECTION_DESC,
|
||||
this.useCollection);
|
||||
|
||||
addSwitch(CodegenConstants.RETURN_ICOLLECTION,
|
||||
CodegenConstants.RETURN_ICOLLECTION_DESC,
|
||||
this.returnICollection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "aspnet5";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates an ASP.NET 5 Web API server.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
apiPackage = packageName + ".Controllers";
|
||||
modelPackage = packageName + ".Models";
|
||||
|
||||
supportingFiles.add(new SupportingFile("global.json", "", "global.json"));
|
||||
supportingFiles.add(new SupportingFile("build.mustache", "", "build.sh"));
|
||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", this.sourceFolder, "Dockerfile"));
|
||||
supportingFiles.add(new SupportingFile("gitignore", this.sourceFolder, ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("appsettings.json", this.sourceFolder, "appsettings.json"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("project.mustache", this.sourceFolder, "project.json"));
|
||||
supportingFiles.add(new SupportingFile("Startup.mustache", this.sourceFolder, "Startup.cs"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("Properties" + File.separator + "launchSettings.json", this.sourceFolder + File.separator + "Properties", "launchSettings.json"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("wwwroot" + File.separator + "README.md", this.sourceFolder + File.separator + "wwwroot", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("wwwroot" + File.separator + "index.html", this.sourceFolder + File.separator + "wwwroot", "index.html"));
|
||||
supportingFiles.add(new SupportingFile("wwwroot" + File.separator + "web.config", this.sourceFolder + File.separator + "wwwroot", "web.config"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + "Controllers";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + "Models";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processOperation(CodegenOperation operation) {
|
||||
super.processOperation(operation);
|
||||
|
||||
// HACK: Unlikely in the wild, but we need to clean operation paths for MVC Routing
|
||||
if (operation.path != null) {
|
||||
String original = operation.path;
|
||||
operation.path = operation.path.replace("?", "/");
|
||||
if (!original.equals(operation.path)) {
|
||||
LOGGER.warn("Normalized " + original + " to " + operation.path + ". Please verify generated source.");
|
||||
}
|
||||
}
|
||||
|
||||
// Converts, for example, PUT to HttpPut for controller attributes
|
||||
operation.httpMethod = "Http" + operation.httpMethod.substring(0, 1) + operation.httpMethod.substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,6 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
@@ -33,7 +31,7 @@ public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
protected String sourceFolder = "src/main/scala";
|
||||
protected String clientName = "SwaggerClient";
|
||||
protected String authScheme = "";
|
||||
protected boolean authPreemptive = false;
|
||||
protected boolean authPreemptive;
|
||||
protected boolean asyncHttpClient = !authScheme.isEmpty();
|
||||
|
||||
public AsyncScalaClientCodegen() {
|
||||
@@ -45,8 +43,13 @@ public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"config", "path", "contentTypes", "contentType", "queryParams", "headerParams",
|
||||
"formParams", "postBody", "resFuture", "client", "reader",
|
||||
|
||||
// scala reserved words
|
||||
"abstract", "case", "catch", "class", "def", "do", "else", "extends",
|
||||
"false", "final", "finally", "for", "forSome", "if", "implicit",
|
||||
"import", "lazy", "match", "new", "null", "object", "override", "package",
|
||||
@@ -111,14 +114,17 @@ public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "async-scala";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates an Asynchronous Scala client library.";
|
||||
}
|
||||
@@ -133,6 +139,7 @@ public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
@@ -182,6 +189,7 @@ public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
return "null";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
@@ -8,6 +10,7 @@ import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.models.Model;
|
||||
@@ -26,263 +29,239 @@ import org.apache.commons.lang.WordUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
@SuppressWarnings({"unused", "hiding"})
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
|
||||
protected boolean optionalMethodArgumentFlag = true;
|
||||
protected String packageName = "IO.Swagger";
|
||||
protected String packageVersion = "1.0.0";
|
||||
private static final String NET45 = "v4.5";
|
||||
private static final String NET35 = "v3.5";
|
||||
|
||||
protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase() + "}";
|
||||
protected String packageTitle = "Swagger Library";
|
||||
protected String packageProductName = "SwaggerLibrary";
|
||||
protected String packageDescription = "A library generated from a Swagger doc";
|
||||
protected String packageCompany = "Swagger";
|
||||
protected String packageCopyright = "No Copyright";
|
||||
protected String clientPackage = "IO.Swagger.Client";
|
||||
protected String sourceFolder = "src" + File.separator + "main" + File.separator + "csharp";
|
||||
protected String localVariablePrefix = "";
|
||||
|
||||
protected String targetFramework = NET45;
|
||||
protected String targetFrameworkNuget = "net45";
|
||||
protected boolean supportsAsync = Boolean.TRUE;
|
||||
|
||||
|
||||
protected final Map<String, String> frameworks;
|
||||
|
||||
public CSharpClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code" + File.separator + "csharp";
|
||||
modelTemplateFiles.put("model.mustache", ".cs");
|
||||
apiTemplateFiles.put("api.mustache", ".cs");
|
||||
embeddedTemplateDir = templateDir = "csharp";
|
||||
apiPackage = "IO.Swagger.Api";
|
||||
modelPackage = "IO.Swagger.Model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
|
||||
);
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".cs");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".cs");
|
||||
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"string",
|
||||
"bool?",
|
||||
"double?",
|
||||
"int?",
|
||||
"long?",
|
||||
"float?",
|
||||
"byte[]",
|
||||
"List",
|
||||
"Dictionary",
|
||||
"DateTime?",
|
||||
"String",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
instantiationTypes.put("array", "List");
|
||||
instantiationTypes.put("map", "Dictionary");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("boolean", "bool?");
|
||||
typeMapping.put("integer", "int?");
|
||||
typeMapping.put("float", "float?");
|
||||
typeMapping.put("long", "long?");
|
||||
typeMapping.put("double", "double?");
|
||||
typeMapping.put("number", "double?");
|
||||
typeMapping.put("datetime", "DateTime?");
|
||||
typeMapping.put("date", "DateTime?");
|
||||
typeMapping.put("file", "Stream");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
typeMapping.put("object", "Object");
|
||||
// C# client default
|
||||
setSourceFolder("src" + File.separator + "main" + File.separator + "csharp");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "C# package name (convention: Camel.Case).")
|
||||
.defaultValue("IO.Swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "C# package version.").defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.OPTIONAL_METHOD_ARGUMENT, "C# Optional method argument, e.g. void square(int x=10) (.net 4.0+ only). Default: false").defaultValue("false"));
|
||||
|
||||
// CLI options
|
||||
addOption(CodegenConstants.PACKAGE_NAME,
|
||||
"C# package name (convention: Title.Case).",
|
||||
this.packageName);
|
||||
|
||||
addOption(CodegenConstants.PACKAGE_VERSION,
|
||||
"C# package version.",
|
||||
this.packageVersion);
|
||||
|
||||
addOption(CodegenConstants.SOURCE_FOLDER,
|
||||
CodegenConstants.SOURCE_FOLDER_DESC,
|
||||
sourceFolder);
|
||||
|
||||
addOption(CodegenConstants.OPTIONAL_PROJECT_GUID,
|
||||
CodegenConstants.OPTIONAL_PROJECT_GUID_DESC,
|
||||
null);
|
||||
|
||||
CliOption framework = new CliOption(
|
||||
CodegenConstants.DOTNET_FRAMEWORK,
|
||||
CodegenConstants.DOTNET_FRAMEWORK_DESC
|
||||
);
|
||||
frameworks = new ImmutableMap.Builder<String, String>()
|
||||
.put(NET35, ".NET Framework 3.5 compatible")
|
||||
.put(NET45, ".NET Framework 4.5+ compatible")
|
||||
.build();
|
||||
framework.defaultValue(this.targetFramework);
|
||||
framework.setEnum(frameworks);
|
||||
cliOptions.add(framework);
|
||||
|
||||
// CLI Switches
|
||||
addSwitch(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC,
|
||||
this.sortParamsByRequiredFlag);
|
||||
|
||||
addSwitch(CodegenConstants.USE_DATETIME_OFFSET,
|
||||
CodegenConstants.USE_DATETIME_OFFSET_DESC,
|
||||
this.useDateTimeOffsetFlag);
|
||||
|
||||
addSwitch(CodegenConstants.USE_COLLECTION,
|
||||
CodegenConstants.USE_COLLECTION_DESC,
|
||||
this.useCollection);
|
||||
|
||||
addSwitch(CodegenConstants.RETURN_ICOLLECTION,
|
||||
CodegenConstants.RETURN_ICOLLECTION_DESC,
|
||||
this.returnICollection);
|
||||
|
||||
addSwitch(CodegenConstants.OPTIONAL_METHOD_ARGUMENT,
|
||||
"C# Optional method argument, e.g. void square(int x=10) (.net 4.0+ only).",
|
||||
this.optionalMethodArgumentFlag);
|
||||
|
||||
addSwitch(CodegenConstants.OPTIONAL_ASSEMBLY_INFO,
|
||||
CodegenConstants.OPTIONAL_ASSEMBLY_INFO_DESC,
|
||||
this.optionalAssemblyInfoFlag);
|
||||
|
||||
addSwitch(CodegenConstants.OPTIONAL_PROJECT_FILE,
|
||||
CodegenConstants.OPTIONAL_PROJECT_FILE_DESC,
|
||||
this.optionalProjectFileFlag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
|
||||
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
apiPackage = packageName + ".Api";
|
||||
modelPackage = packageName + ".Model";
|
||||
clientPackage = packageName + ".Client";
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
}
|
||||
|
||||
additionalProperties.put("clientPackage", clientPackage);
|
||||
|
||||
// Add properties used by AssemblyInfo.mustache
|
||||
additionalProperties.put("packageTitle", packageTitle);
|
||||
additionalProperties.put("packageProductName", packageProductName);
|
||||
additionalProperties.put("packageDescription", packageDescription);
|
||||
additionalProperties.put("packageCompany", packageCompany);
|
||||
additionalProperties.put("packageCopyright", packageCopyright);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.DOTNET_FRAMEWORK)) {
|
||||
setTargetFramework((String) additionalProperties.get(CodegenConstants.DOTNET_FRAMEWORK));
|
||||
}
|
||||
|
||||
if (NET35.equals(this.targetFramework)) {
|
||||
setTargetFrameworkNuget("net35");
|
||||
setSupportsAsync(Boolean.FALSE);
|
||||
if(additionalProperties.containsKey("supportsAsync")){
|
||||
additionalProperties.remove("supportsAsync");
|
||||
}
|
||||
} else {
|
||||
setTargetFrameworkNuget("net45");
|
||||
setSupportsAsync(Boolean.TRUE);
|
||||
additionalProperties.put("supportsAsync", this.supportsAsync);
|
||||
}
|
||||
|
||||
additionalProperties.put("targetFrameworkNuget", this.targetFrameworkNuget);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_FILE)) {
|
||||
setOptionalProjectFileFlag(Boolean.valueOf(
|
||||
additionalProperties.get(CodegenConstants.OPTIONAL_PROJECT_FILE).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_PROJECT_GUID)) {
|
||||
setPackageGuid((String) additionalProperties.get(CodegenConstants.OPTIONAL_PROJECT_GUID));
|
||||
}
|
||||
additionalProperties.put("packageGuid", packageGuid);
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_METHOD_ARGUMENT)) {
|
||||
setOptionalMethodArgumentFlag(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.OPTIONAL_METHOD_ARGUMENT).toString()));
|
||||
}
|
||||
additionalProperties.put("optionalMethodArgument", optionalMethodArgumentFlag);
|
||||
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache",
|
||||
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "Configuration.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache",
|
||||
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiClient.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiException.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponse.mustache",
|
||||
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "ApiResponse.cs"));
|
||||
supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
|
||||
supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.OPTIONAL_ASSEMBLY_INFO)) {
|
||||
setOptionalAssemblyInfoFlag(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.OPTIONAL_ASSEMBLY_INFO).toString()));
|
||||
}
|
||||
|
||||
String packageFolder = sourceFolder + File.separator + packageName.replace(".", java.io.File.separator);
|
||||
String clientPackageDir = sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator);
|
||||
|
||||
//Compute the relative path to the bin directory where the external assemblies live
|
||||
//This is necessary to properly generate the project file
|
||||
int packageDepth = packageFolder.length() - packageFolder.replace(java.io.File.separator, "").length();
|
||||
String binRelativePath = "..\\";
|
||||
for (int i = 0; i < packageDepth; i = i + 1)
|
||||
binRelativePath += "..\\";
|
||||
binRelativePath += "vendor\\";
|
||||
additionalProperties.put("binRelativePath", binRelativePath);
|
||||
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache",
|
||||
clientPackageDir, "Configuration.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache",
|
||||
clientPackageDir, "ApiClient.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
clientPackageDir, "ApiException.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponse.mustache",
|
||||
clientPackageDir, "ApiResponse.cs"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
|
||||
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "compile-mono.sh"));
|
||||
supportingFiles.add(new SupportingFile("packages.config.mustache", "vendor" + java.io.File.separator, "packages.config"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
|
||||
if (optionalAssemblyInfoFlag) {
|
||||
supportingFiles.add(new SupportingFile("AssemblyInfo.mustache", packageFolder + File.separator + "Properties", "AssemblyInfo.cs"));
|
||||
}
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, clientPackage + ".csproj"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
super.postProcessOperations(objs);
|
||||
if (objs != null) {
|
||||
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.returnContainer = operation.returnType;
|
||||
if (this.returnICollection && (
|
||||
operation.returnType.startsWith("List") ||
|
||||
operation.returnType.startsWith("Collection"))) {
|
||||
// NOTE: ICollection works for both List<T> and Collection<T>
|
||||
int genericStart = operation.returnType.indexOf("<");
|
||||
if (genericStart > 0) {
|
||||
operation.returnType = "ICollection" + operation.returnType.substring(genericStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "csharp";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a CSharp client library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
return name;
|
||||
}
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => PetId
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
return name;
|
||||
}
|
||||
|
||||
// camelize(lower) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
|
||||
@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.toLowerCase())) {
|
||||
type = typeMapping.get(swaggerType.toLowerCase());
|
||||
if (languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId));
|
||||
}
|
||||
|
||||
public void setOptionalMethodArgumentFlag(boolean flag) {
|
||||
this.optionalMethodArgumentFlag = flag;
|
||||
public void setOptionalAssemblyInfoFlag(boolean flag) {
|
||||
this.optionalAssemblyInfoFlag = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
|
||||
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
|
||||
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
@@ -291,6 +270,13 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
public void setOptionalProjectFileFlag(boolean flag) {
|
||||
this.optionalProjectFileFlag = flag;
|
||||
}
|
||||
|
||||
public void setPackageGuid(String packageGuid) {
|
||||
this.packageGuid = packageGuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
@@ -349,8 +335,13 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
}
|
||||
}
|
||||
public void setTargetFramework(String dotnetFramework) {
|
||||
if(!frameworks.containsKey(dotnetFramework)){
|
||||
LOGGER.warn("Invalid .NET framework version, defaulting to " + this.targetFramework);
|
||||
} else {
|
||||
this.targetFramework = dotnetFramework;
|
||||
}
|
||||
return objs;
|
||||
LOGGER.info("Generating code for .NET Framework " + this.targetFramework);
|
||||
}
|
||||
|
||||
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
@@ -471,7 +462,11 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
}
|
||||
public void setTargetFrameworkNuget(String targetFrameworkNuget) {
|
||||
this.targetFrameworkNuget = targetFrameworkNuget;
|
||||
}
|
||||
|
||||
return null;
|
||||
public void setSupportsAsync(Boolean supportsAsync){
|
||||
this.supportsAsync = supportsAsync;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
private static final String PROJECT_LICENSE_URL = "projectLicenseUrl";
|
||||
private static final String BASE_NAMESPACE = "baseNamespace";
|
||||
|
||||
protected String projectName = null;
|
||||
protected String projectDescription = null;
|
||||
protected String projectVersion = null;
|
||||
protected String baseNamespace = null;
|
||||
protected String projectName;
|
||||
protected String projectDescription;
|
||||
protected String projectVersion;
|
||||
protected String baseNamespace;
|
||||
|
||||
protected String sourceFolder = "src";
|
||||
|
||||
@@ -172,7 +172,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
name = name.replaceAll("[^a-zA-Z0-9_-]+", "");
|
||||
name = name.replaceAll("[^a-zA-Z0-9_-]+", ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
name = dashize(name);
|
||||
return name;
|
||||
}
|
||||
@@ -196,6 +196,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return operations;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String namespaceToFolder(String ns) {
|
||||
return ns.replace(".", File.separator).replace("-", "_");
|
||||
}
|
||||
|
||||
@@ -31,8 +31,12 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
apiPackage = "IO.Swagger.Api";
|
||||
modelPackage = "IO.Swagger.Model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names in API methods (endpoints)
|
||||
"path", "queryParams", "headerParams", "formParams", "fileParams", "postBody",
|
||||
"authSettings", "response", "StatusCode",
|
||||
// C# reserved word
|
||||
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
|
||||
);
|
||||
|
||||
@@ -135,14 +139,17 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CsharpDotNet2";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a C# .Net 2.0 client library.";
|
||||
}
|
||||
@@ -157,6 +164,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
@@ -164,7 +172,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@@ -176,7 +184,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -198,7 +206,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -207,8 +215,10 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@@ -257,7 +267,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiPackage = "lib.api";
|
||||
modelPackage = "lib.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"abstract", "as", "assert", "async", "async*", "await",
|
||||
"break", "case", "catch", "class", "const", "continue",
|
||||
@@ -76,6 +76,9 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("Date", "DateTime");
|
||||
typeMapping.put("date", "DateTime");
|
||||
typeMapping.put("File", "MultipartFile");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "String");
|
||||
|
||||
cliOptions.add(new CliOption(BROWSER_CLIENT, "Is the client browser based"));
|
||||
cliOptions.add(new CliOption(PUB_NAME, "Name in generated pubspec"));
|
||||
@@ -84,14 +87,17 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, "source folder for generated code"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "dart";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Dart client library.";
|
||||
}
|
||||
@@ -157,6 +163,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
@@ -164,7 +171,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@@ -176,7 +183,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -192,7 +199,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@@ -214,15 +221,10 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "{}";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "[]";
|
||||
}
|
||||
|
||||
return super.toDefaultValue(p);
|
||||
}
|
||||
|
||||
@@ -259,7 +261,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@ import java.util.HashSet;
|
||||
|
||||
public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String packageName = "io.swagger";
|
||||
protected String packageVersion = null;
|
||||
protected String packageVersion;
|
||||
|
||||
protected String invokerPackage = "io.swagger";
|
||||
protected String sourceFolder = "src/main/flex";
|
||||
protected String sourceFolder = "flash";
|
||||
|
||||
public FlashClientCodegen() {
|
||||
super();
|
||||
@@ -63,12 +63,15 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("DateTime", "Date");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("file", "File");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "String");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("File", "flash.filesystem.File");
|
||||
|
||||
// from
|
||||
reservedWords = new HashSet<String>(Arrays.asList("add", "for", "lt", "tellTarget", "and",
|
||||
setReservedWordsLowerCase(Arrays.asList("add", "for", "lt", "tellTarget", "and",
|
||||
"function", "ne", "this", "break", "ge", "new", "typeof", "continue", "gt", "not",
|
||||
"var", "delete", "if", "on", "void", "do", "ifFrameLoaded", "onClipEvent", "while",
|
||||
"else", "in", "or", "with", "eq", "le", "return"));
|
||||
@@ -80,7 +83,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
.defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, "source folder for generated " +
|
||||
"code. e.g. src/main/flex"));
|
||||
"code. e.g. flash"));
|
||||
|
||||
}
|
||||
|
||||
@@ -121,8 +124,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
//modelPackage = invokerPackage + File.separatorChar + "client" + File.separatorChar + "model";
|
||||
//apiPackage = invokerPackage + File.separatorChar + "client" + File.separatorChar + "api";
|
||||
|
||||
final String invokerFolder = (sourceFolder + File.separator + invokerPackage + File.separator
|
||||
+ "swagger" + File.separator).replace(".", File.separator).replace('.', File.separatorChar);
|
||||
final String invokerFolder = (sourceFolder + File.separator + "src/" + invokerPackage + File.separator).replace(".", File.separator).replace('.', File.separatorChar);
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiInvoker.as", invokerFolder + "common", "ApiInvoker.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiUrlHelper.as", invokerFolder + "common", "ApiUrlHelper.as"));
|
||||
@@ -130,14 +132,15 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
supportingFiles.add(new SupportingFile("ListWrapper.as", invokerFolder + "common", "ListWrapper.as"));
|
||||
supportingFiles.add(new SupportingFile("SwaggerApi.as", invokerFolder + "common", "SwaggerApi.as"));
|
||||
supportingFiles.add(new SupportingFile("XMLWriter.as", invokerFolder + "common", "XMLWriter.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiError.as", invokerFolder + "exception", "ApiErrors.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiError.as", invokerFolder + "exception", "ApiError.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiErrorCodes.as", invokerFolder + "exception", "ApiErrorCodes.as"));
|
||||
supportingFiles.add(new SupportingFile("ApiClientEvent.as", invokerFolder + "event", "ApiClientEvent.as"));
|
||||
supportingFiles.add(new SupportingFile("Response.as", invokerFolder + "event", "Response.as"));
|
||||
supportingFiles.add(new SupportingFile("build.properties", sourceFolder, "build.properties"));
|
||||
supportingFiles.add(new SupportingFile("build.xml", sourceFolder, "build.xml"));
|
||||
supportingFiles.add(new SupportingFile("AirExecutorApp-app.xml", sourceFolder + File.separatorChar
|
||||
+ "bin", "AirExecutorApp-app.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.txt", sourceFolder, "README.txt"));
|
||||
//supportingFiles.add(new SupportingFile("AirExecutorApp-app.xml", sourceFolder + File.separatorChar
|
||||
// + "bin", "AirExecutorApp-app.xml"));
|
||||
supportingFiles.add(new SupportingFile("ASAXB-0.1.1.swc", sourceFolder + File.separatorChar
|
||||
+ "lib", "ASAXB-0.1.1.swc"));
|
||||
supportingFiles.add(new SupportingFile("as3corelib.swc", sourceFolder + File.separatorChar
|
||||
@@ -156,14 +159,17 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return str.replaceAll("\\.", "_");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "flash";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Flash client library.";
|
||||
}
|
||||
@@ -175,25 +181,19 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar
|
||||
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar + "src/"
|
||||
+ apiPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar
|
||||
return (outputFolder + File.separatorChar + sourceFolder + File.separatorChar + "src/"
|
||||
+ modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return getSwaggerType(p);
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
if (p instanceof ArrayProperty || p instanceof MapProperty) {
|
||||
return getSwaggerType(p);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@@ -214,6 +214,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
return "null";
|
||||
@@ -248,22 +249,18 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
return "0";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "new Dictionary()";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new Array()";
|
||||
} else {
|
||||
return "null";
|
||||
return "NaN";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@@ -275,7 +272,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = camelize(dropDots(name), true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -291,7 +288,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@@ -303,7 +300,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@@ -315,7 +312,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. PhoneNumberApi.rb => phone_number_api.rb
|
||||
return camelize(name) + "Api";
|
||||
@@ -346,7 +343,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
@@ -368,7 +365,4 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import config.ConfigParser;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.Operation;
|
||||
@@ -14,7 +16,13 @@ import io.swagger.util.Yaml;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FlaskConnexionCodegen.class);
|
||||
|
||||
public static final String CONTROLLER_PACKAGE = "controllerPackage";
|
||||
public static final String DEFAULT_CONTROLLER = "defaultController";
|
||||
|
||||
@@ -65,7 +73,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
embeddedTemplateDir = templateDir = "flaskConnexion";
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"and", "del", "from", "not", "while", "as", "elif", "global", "or", "with",
|
||||
"assert", "else", "if", "pass", "yield", "break", "except", "import",
|
||||
@@ -132,6 +140,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiPackage() {
|
||||
return controllerPackage;
|
||||
}
|
||||
@@ -142,6 +151,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
@@ -152,6 +162,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "python-flask";
|
||||
}
|
||||
@@ -162,9 +173,10 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a python server library using the connexion project. By default, " +
|
||||
"it will also generate service classes--which you can disable with the `-Dnoservice` environment variable.";
|
||||
return "Generates a Python server library using the Connexion project. By default, " +
|
||||
"it will also generate service classes -- which you can disable with the `-Dnoservice` environment variable.";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,7 +257,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
private static List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
||||
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||
@@ -255,7 +267,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
private static List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
Multimap<String, CodegenOperation> opsByPath = ArrayListMultimap.create();
|
||||
|
||||
for (CodegenOperation op : ops) {
|
||||
@@ -285,7 +297,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
try {
|
||||
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
for (Map<String, Object> operations : getOperations(objs)) {
|
||||
@@ -300,7 +312,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
operationId = super.toOperationId(operationId);
|
||||
operationId = super.toOperationId(operationId); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
// Use the part after the last dot, e.g.
|
||||
// controllers.defaultController.addPet => addPet
|
||||
operationId = operationId.replaceAll(".*\\.", "");
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
static Logger LOGGER = LoggerFactory.getLogger(GoClientCodegen.class);
|
||||
|
||||
protected String packageName = "swagger";
|
||||
protected String packageVersion = "1.0.0";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "go";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
return "Generates a Go client library (beta).";
|
||||
}
|
||||
|
||||
public GoClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/go";
|
||||
modelTemplateFiles.put("model.mustache", ".go");
|
||||
apiTemplateFiles.put("api.mustache", ".go");
|
||||
templateDir = "go";
|
||||
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"break", "default", "func", "interface", "select",
|
||||
"case", "defer", "go", "map", "struct",
|
||||
"chan", "else", "goto", "package", "switch",
|
||||
"const", "fallthrough", "if", "range", "type",
|
||||
"continue", "for", "import", "return", "var")
|
||||
);
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"map",
|
||||
"array")
|
||||
);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"string",
|
||||
"bool",
|
||||
"uint",
|
||||
"uint32",
|
||||
"uint64",
|
||||
"int",
|
||||
"int32",
|
||||
"int64",
|
||||
"float32",
|
||||
"float64",
|
||||
"complex64",
|
||||
"complex128",
|
||||
"rune",
|
||||
"byte")
|
||||
);
|
||||
|
||||
instantiationTypes.clear();
|
||||
/*instantiationTypes.put("array", "GoArray");
|
||||
instantiationTypes.put("map", "GoMap");*/
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int32");
|
||||
typeMapping.put("long", "int64");
|
||||
typeMapping.put("float", "float32");
|
||||
typeMapping.put("double", "float64");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("Date", "time.Time");
|
||||
typeMapping.put("DateTime", "time.Time");
|
||||
typeMapping.put("password", "string");
|
||||
typeMapping.put("File", "*os.File");
|
||||
typeMapping.put("file", "*os.File");
|
||||
// map binary to string as a workaround
|
||||
// the correct solution is to use []byte
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("time.Time", "time");
|
||||
importMapping.put("*os.File", "os");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
|
||||
.defaultValue("swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.")
|
||||
.defaultValue("1.0.0"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
//super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
}
|
||||
else {
|
||||
setPackageName("swagger");
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
|
||||
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
|
||||
}
|
||||
else {
|
||||
setPackageVersion("1.0.0");
|
||||
}
|
||||
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
|
||||
modelPackage = packageName;
|
||||
apiPackage = packageName;
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + packageName;
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$"))
|
||||
return name;
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => PetId
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if(isReservedWord(name) || name.matches("^\\d.*"))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if(isReservedWord(name))
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if(p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return "[]" + 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if(isReservedWord(operationId))
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
|
||||
return camelize(operationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
for (CodegenOperation operation : operations) {
|
||||
// http method verb conversion (e.g. PUT => Put)
|
||||
operation.httpMethod = camelize(operation.httpMethod.toLowerCase());
|
||||
}
|
||||
|
||||
// remove model imports to avoid error
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
if (imports == null)
|
||||
return objs;
|
||||
|
||||
Iterator<Map<String, String>> iterator = imports.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String _import = iterator.next().get("import");
|
||||
if (_import.startsWith(apiPackage()))
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// remove model imports to avoid error
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
final String prefix = modelPackage();
|
||||
Iterator<Map<String, String>> iterator = imports.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String _import = iterator.next().get("import");
|
||||
if (_import.startsWith(prefix))
|
||||
iterator.remove();
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String type) {
|
||||
return !defaultIncludes.contains(type)
|
||||
&& !languageSpecificPrimitives.contains(type);
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public void setPackageVersion(String packageVersion) {
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Swagger;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class HaskellServantCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "src";
|
||||
protected String apiVersion = "0.0.1";
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -l flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
public String getName() {
|
||||
return "haskell-servant";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
public String getHelp() {
|
||||
return "Generates a HaskellServantCodegen library.";
|
||||
}
|
||||
|
||||
public HaskellServantCodegen() {
|
||||
super();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/HaskellServantCodegen";
|
||||
|
||||
/**
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
* a different extension
|
||||
*/
|
||||
modelTemplateFiles.put(
|
||||
"model.mustache", // the template to use
|
||||
".hs"); // the extension for each file to write
|
||||
|
||||
/**
|
||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||
* as with models, add multiple entries with different extensions for multiple files per
|
||||
* class
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"api.mustache", // the template to use
|
||||
".hs"); // the extension for each file to write
|
||||
|
||||
/**
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "haskell-servant";
|
||||
|
||||
/**
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
apiPackage = "Api";
|
||||
|
||||
/**
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
modelPackage = "Model";
|
||||
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
// from https://wiki.haskell.org/Keywords
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"as", "case", "of",
|
||||
"class", "data", // "data family", "data instance",
|
||||
"default", "deriving", // "deriving instance",
|
||||
"do",
|
||||
"forall", "foreign", "hiding",
|
||||
"id",
|
||||
"if", "then", "else",
|
||||
"import", "infix", "infixl", "infixr",
|
||||
"instance", "let", "in",
|
||||
"mdo", "module", "newtype",
|
||||
"proc", "qualified", "rec",
|
||||
"type", // "type family", "type instance",
|
||||
"where"
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
|
||||
/**
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("stack.mustache", "", "stack.yaml"));
|
||||
supportingFiles.add(new SupportingFile("haskell-servant-codegen.mustache", "", "haskell-servant-codegen.cabal"));
|
||||
supportingFiles.add(new SupportingFile("Setup.mustache", "", "Setup.hs"));
|
||||
supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
|
||||
supportingFiles.add(new SupportingFile("Apis.mustache", "lib", "Apis.hs"));
|
||||
supportingFiles.add(new SupportingFile("Utils.mustache", "lib", "Utils.hs"));
|
||||
supportingFiles.add(new SupportingFile("Client.mustache", "client", "Main.hs"));
|
||||
supportingFiles.add(new SupportingFile("Server.mustache", "server", "Main.hs"));
|
||||
|
||||
/**
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Bool",
|
||||
"String",
|
||||
"Int",
|
||||
"Integer",
|
||||
"Float",
|
||||
"Char",
|
||||
"Double",
|
||||
"List",
|
||||
"FilePath"
|
||||
)
|
||||
);
|
||||
|
||||
typeMapping.clear();
|
||||
// typeMapping.put("enum", "NSString");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("set", "Set");
|
||||
typeMapping.put("boolean", "Bool");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Integer");
|
||||
typeMapping.put("float", "Float");
|
||||
// typeMapping.put("byte", "Byte");
|
||||
typeMapping.put("short", "Int");
|
||||
typeMapping.put("char", "Char");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("DateTime", "Integer");
|
||||
// typeMapping.put("object", "Map");
|
||||
typeMapping.put("file", "FilePath");
|
||||
|
||||
importMapping.clear();
|
||||
importMapping.put("Map", "qualified Data.Map as Map");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reseved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return name + "_";
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separatorChar + "lib" + File.separatorChar + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separatorChar + "lib" + File.separatorChar + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if(p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return "Map.Map String " + getTypeDeclaration(inner);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
* @see io.swagger.models.properties.Property
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
private String capturePath(String path, List<CodegenParameter> pathParams) {
|
||||
for (CodegenParameter p : pathParams) {
|
||||
String pName = "{"+p.baseName+"}";
|
||||
if (path.indexOf(pName) >= 0) {
|
||||
path = path.replace(pName, "Capture " + "\""+p.baseName+"\" " + p.dataType);
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String queryPath(String path, List<CodegenParameter> queryParams) {
|
||||
for (CodegenParameter p : queryParams) {
|
||||
path += " :> QueryParam \"" + p.baseName + "\" " + p.dataType;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String bodyPath(String path, List<CodegenParameter> bodyParams) {
|
||||
for (CodegenParameter p : bodyParams) {
|
||||
path += " :> ReqBody '[JSON] " + p.dataType;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String formPath(String path, List<CodegenParameter> formParams) {
|
||||
String names = "Form";
|
||||
for (CodegenParameter p : formParams) {
|
||||
if(p.dataType.equals("FilePath")){
|
||||
// file data processing
|
||||
}
|
||||
names += p.baseName;
|
||||
}
|
||||
if(formParams.size() > 0){
|
||||
path += " :> ReqBody '[FormUrlEncoded] " + names;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String headerPath(String path, List<CodegenParameter> headerParams) {
|
||||
for (CodegenParameter p : headerParams) {
|
||||
path += " :> Header \"" + p.baseName + "\" " + p.dataType;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
private String filterReturnType(String rt) {
|
||||
if (rt == null || rt.equals("null")) {
|
||||
return "()";
|
||||
} else if (rt.indexOf(" ") >= 0) {
|
||||
return "(" + rt + ")";
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
private String addReturnPath(String path, String httpMethod, String returnType) {
|
||||
return path + " :> " + upperCaseFirst(httpMethod) + " '[JSON] " + filterReturnType(returnType);
|
||||
}
|
||||
|
||||
private String joinStrings(String sep, List<String> ss) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : ss) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(sep);
|
||||
}
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String replacePathSplitter(String path) {
|
||||
String[] ps = path.replaceFirst("/", "").split("/", 0);
|
||||
List<String> rs = new ArrayList<String>();
|
||||
for (String p : ps) {
|
||||
if (p.indexOf("{") < 0) {
|
||||
rs.add("\"" + p + "\"");
|
||||
} else {
|
||||
rs.add(p);
|
||||
}
|
||||
}
|
||||
return joinStrings(" :> ", rs);
|
||||
}
|
||||
|
||||
private String upperCaseFirst(String str) {
|
||||
char[] array = str.toLowerCase().toCharArray();
|
||||
array[0] = Character.toUpperCase(array[0]);
|
||||
return new String(array);
|
||||
}
|
||||
|
||||
private String parseScheme(String basePath) {
|
||||
return "Http";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger){
|
||||
CodegenOperation op = super.fromOperation(resourcePath, httpMethod, operation, definitions, swagger);
|
||||
String path = op.path;
|
||||
op.nickname = addReturnPath(headerPath(formPath(bodyPath(queryPath(capturePath(replacePathSplitter(path), op.pathParams), op.queryParams), op.bodyParams), op.formParams), op.headerParams), op.httpMethod, op.returnType);
|
||||
return op;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,6 @@ import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
@@ -22,6 +20,7 @@ public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
@@ -32,6 +31,7 @@ public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "jmeter";
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a JMeter .jmx file.";
|
||||
}
|
||||
@@ -97,6 +98,7 @@ public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// supportingFiles.add(new SupportingFile("testdata-localhost.mustache", "input", "testdata-localhost.csv"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for (String pathname : swagger.getPaths().keySet()) {
|
||||
@@ -126,6 +128,7 @@ public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
public JavaCXFServerCodegen()
|
||||
{
|
||||
super();
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-server";
|
||||
outputFolder = "generated-code/JavaJaxRS-CXF";
|
||||
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
super.embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf";
|
||||
|
||||
for ( int i = 0; i < cliOptions.size(); i++ ) {
|
||||
if ( CodegenConstants.LIBRARY.equals(cliOptions.get(i).getOpt()) ) {
|
||||
cliOptions.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
|
||||
cliOptions.add(new CliOption("title", "a title describing the application"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts()
|
||||
{
|
||||
super.processOpts();
|
||||
sourceFolder = "gen" + File.separator + "java";
|
||||
|
||||
modelTemplateFiles.clear();
|
||||
modelTemplateFiles.put("entityModel.mustache", ".java");
|
||||
|
||||
supportingFiles.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs-cxf";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp()
|
||||
{
|
||||
return "Generates a Java JAXRS Server application based on Apache CXF framework.";
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,35 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.FormParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.DoubleProperty;
|
||||
import io.swagger.models.properties.FloatProperty;
|
||||
import io.swagger.models.properties.IntegerProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("hiding")
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class);
|
||||
public static final String FULL_JAVA_UTIL = "fullJavaUtil";
|
||||
public static final String DEFAULT_LIBRARY = "<default>";
|
||||
public static final String DATE_LIBRARY = "dateLibrary";
|
||||
public static final String USE_RX_JAVA = "useRxJava";
|
||||
|
||||
public static final String RETROFIT_1 = "retrofit";
|
||||
public static final String RETROFIT_2 = "retrofit2";
|
||||
|
||||
protected String dateLibrary = "default";
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-java-client";
|
||||
@@ -52,9 +37,11 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String projectFolder = "src" + File.separator + "main";
|
||||
protected String sourceFolder = projectFolder + File.separator + "java";
|
||||
protected String localVariablePrefix = "";
|
||||
protected boolean fullJavaUtil = false;
|
||||
protected boolean fullJavaUtil;
|
||||
protected String javaUtilPrefix = "";
|
||||
protected Boolean serializableModel = false;
|
||||
protected boolean serializeBigDecimalAsString = false;
|
||||
protected boolean useRxJava = false;
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
@@ -65,8 +52,13 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// used as internal variables, can collide with parameter names
|
||||
"path", "queryParams", "headerParams", "formParams", "postBody", "accepts", "accept", "contentTypes",
|
||||
"contentType", "authNames",
|
||||
|
||||
// language reserved words
|
||||
"abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
|
||||
@@ -99,21 +91,32 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
|
||||
cliOptions.add(new CliOption(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util")
|
||||
.defaultValue("false"));
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, CodegenConstants
|
||||
.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC));
|
||||
cliOptions.add(CliOption.newBoolean(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
|
||||
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
|
||||
supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.1.1");
|
||||
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
|
||||
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1");
|
||||
supportedLibraries.put("retrofit", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
|
||||
supportedLibraries.put("retrofit2", "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2)");
|
||||
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
|
||||
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2). Enable the RxJava adapter using '-DuseRxJava=true'.");
|
||||
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
library.setEnum(supportedLibraries);
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
cliOptions.add(library);
|
||||
|
||||
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
|
||||
Map<String, String> dateOptions = new HashMap<String, String>();
|
||||
dateOptions.put("java8", "Java 8 native");
|
||||
dateOptions.put("joda", "Joda");
|
||||
dateLibrary.setEnum(dateOptions);
|
||||
|
||||
cliOptions.add(dateLibrary);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,7 +170,6 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.LOCAL_VARIABLE_PREFIX)) {
|
||||
this.setLocalVariablePrefix((String) additionalProperties.get(CodegenConstants.LOCAL_VARIABLE_PREFIX));
|
||||
}
|
||||
@@ -180,18 +182,28 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.setLibrary((String) additionalProperties.get(CodegenConstants.LIBRARY));
|
||||
}
|
||||
|
||||
if(additionalProperties.containsKey(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING)) {
|
||||
this.setSerializeBigDecimalAsString(Boolean.valueOf(additionalProperties.get(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING).toString()));
|
||||
}
|
||||
|
||||
// need to put back serializableModel (boolean) into additionalProperties as value in additionalProperties is string
|
||||
additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel);
|
||||
|
||||
if (additionalProperties.containsKey(FULL_JAVA_UTIL)) {
|
||||
this.setFullJavaUtil(Boolean.valueOf(additionalProperties.get(FULL_JAVA_UTIL).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA)) {
|
||||
this.setUseRxJava(Boolean.valueOf(additionalProperties.get(USE_RX_JAVA).toString()));
|
||||
}
|
||||
if (fullJavaUtil) {
|
||||
javaUtilPrefix = "java.util.";
|
||||
}
|
||||
additionalProperties.put(FULL_JAVA_UTIL, fullJavaUtil);
|
||||
additionalProperties.put("javaUtilPrefix", javaUtilPrefix);
|
||||
|
||||
importMapping.put("List", "java.util.List");
|
||||
|
||||
if (fullJavaUtil) {
|
||||
typeMapping.put("array", "java.util.List");
|
||||
typeMapping.put("map", "java.util.Map");
|
||||
@@ -211,27 +223,39 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
this.sanitizeConfig();
|
||||
|
||||
|
||||
// optional jackson mappings for BigDecimal support
|
||||
importMapping.put("ToStringSerializer", "com.fasterxml.jackson.databind.ser.std.ToStringSerializer");
|
||||
importMapping.put("JsonSerialize", "com.fasterxml.jackson.databind.annotation.JsonSerialize");
|
||||
|
||||
// imports for pojos
|
||||
importMapping.put("ApiModelProperty", "io.swagger.annotations.ApiModelProperty");
|
||||
importMapping.put("ApiModel", "io.swagger.annotations.ApiModel");
|
||||
importMapping.put("JsonProperty", "com.fasterxml.jackson.annotation.JsonProperty");
|
||||
importMapping.put("JsonValue", "com.fasterxml.jackson.annotation.JsonValue");
|
||||
importMapping.put("Objects", "java.util.Objects");
|
||||
importMapping.put("StringUtil", invokerPackage + ".StringUtil");
|
||||
|
||||
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
|
||||
supportingFiles.add(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(outputFolder, new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
writeOptional(outputFolder, new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
writeOptional(outputFolder, new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
|
||||
writeOptional(outputFolder, new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
|
||||
|
||||
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
||||
if ("feign".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("FormAwareEncoder.mustache", invokerFolder, "FormAwareEncoder.java"));
|
||||
} else {
|
||||
}
|
||||
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
|
||||
}
|
||||
|
||||
if (!("feign".equals(getLibrary()) || "retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary()))) {
|
||||
if (!("feign".equals(getLibrary()) || usesAnyRetrofitLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache", invokerFolder, "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
|
||||
@@ -248,12 +272,40 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java"));
|
||||
// "build.sbt" is for development with SBT
|
||||
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
|
||||
} else if ("retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary())) {
|
||||
} else if (usesAnyRetrofitLibrary()) {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||
supportingFiles.add(new SupportingFile("CollectionFormats.mustache", invokerFolder, "CollectionFormats.java"));
|
||||
} else if("jersey2".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
||||
}
|
||||
|
||||
if(additionalProperties.containsKey(DATE_LIBRARY)) {
|
||||
this.dateLibrary = additionalProperties.get(DATE_LIBRARY).toString();
|
||||
}
|
||||
|
||||
if("joda".equals(dateLibrary)) {
|
||||
typeMapping.put("date", "LocalDate");
|
||||
typeMapping.put("DateTime", "DateTime");
|
||||
|
||||
importMapping.put("LocalDate", "org.joda.time.LocalDate");
|
||||
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||
}
|
||||
else if ("java8".equals(dateLibrary)) {
|
||||
additionalProperties.put("java8", "true");
|
||||
additionalProperties.put("javaVersion", "1.8");
|
||||
typeMapping.put("date", "LocalDate");
|
||||
typeMapping.put("DateTime", "LocalDateTime");
|
||||
importMapping.put("LocalDate", "java.time.LocalDate");
|
||||
importMapping.put("LocalDateTime", "java.time.LocalDateTime");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean usesAnyRetrofitLibrary() {
|
||||
return getLibrary() != null && getLibrary().contains(RETROFIT_1);
|
||||
}
|
||||
|
||||
private boolean usesRetrofit2Library() {
|
||||
return getLibrary() != null && getLibrary().contains(RETROFIT_2);
|
||||
}
|
||||
|
||||
private void sanitizeConfig() {
|
||||
@@ -294,7 +346,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
if("_".equals(name)) {
|
||||
name = "_u";
|
||||
@@ -310,7 +362,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -324,17 +376,21 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
public String toModelName(final String name) {
|
||||
final String sanitizedName = sanitizeName(modelNamePrefix + name + modelNameSuffix);
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
final String camelizedName = camelize(sanitizedName);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(camelizedName)) {
|
||||
final String modelName = "Object" + camelizedName;
|
||||
LOGGER.warn(camelizedName + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
return camelizedName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -430,7 +486,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if (languageSpecificPrimitives.contains(type) || type.indexOf(".") >= 0) {
|
||||
if (languageSpecificPrimitives.contains(type) || type.indexOf(".") >= 0 ||
|
||||
type.equals("Map") || type.equals("List")) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
@@ -449,27 +506,74 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
|
||||
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
|
||||
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
|
||||
final Model parentModel = allDefinitions.get(codegenModel.parentSchema);
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
codegenModel = JavaClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
if(serializeBigDecimalAsString) {
|
||||
if (property.baseType.equals("BigDecimal")) {
|
||||
// we serialize BigDecimal as `string` to avoid precision loss
|
||||
property.vendorExtensions.put("extraAnnotation", "@JsonSerialize(using = ToStringSerializer.class)");
|
||||
|
||||
// this requires some more imports to be added for this model...
|
||||
model.imports.add("ToStringSerializer");
|
||||
model.imports.add("JsonSerialize");
|
||||
}
|
||||
}
|
||||
|
||||
if ("array".equals(property.containerType)) {
|
||||
model.imports.add("ArrayList");
|
||||
} else if ("map".equals(property.containerType)) {
|
||||
model.imports.add("HashMap");
|
||||
}
|
||||
|
||||
if(!BooleanUtils.toBoolean(model.isEnum)) {
|
||||
// needed by all pojos, but not enums
|
||||
model.imports.add("ApiModelProperty");
|
||||
model.imports.add("ApiModel");
|
||||
// comment out below as it's in the model template
|
||||
//model.imports.add("Objects");
|
||||
|
||||
final String lib = getLibrary();
|
||||
if(StringUtils.isEmpty(lib) || "feign".equals(lib) || "jersey2".equals(lib)) {
|
||||
model.imports.add("JsonProperty");
|
||||
|
||||
if(BooleanUtils.toBoolean(model.hasEnums)) {
|
||||
model.imports.add("JsonValue");
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
@@ -530,8 +634,20 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
if("retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary())) {
|
||||
// Remove imports of List, ArrayList, Map and HashMap as they are
|
||||
// imported in the template already.
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
Pattern pattern = Pattern.compile("java\\.util\\.(List|ArrayList|Map|HashMap)");
|
||||
for (Iterator<Map<String, String>> itr = imports.iterator(); itr.hasNext();) {
|
||||
String _import = itr.next().get("import");
|
||||
if (pattern.matcher(_import).matches()) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if(usesAnyRetrofitLibrary()) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
@@ -547,7 +663,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
}
|
||||
if ("retrofit2".equals(getLibrary()) && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/"))
|
||||
if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/"))
|
||||
operation.path = operation.path.substring(1);
|
||||
}
|
||||
}
|
||||
@@ -555,6 +671,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for (String pathname : swagger.getPaths().keySet()) {
|
||||
@@ -580,7 +697,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private String getAccept(Operation operation) {
|
||||
private static String getAccept(Operation operation) {
|
||||
String accepts = null;
|
||||
String defaultContentType = "application/json";
|
||||
if (operation.getProduces() != null && !operation.getProduces().isEmpty()) {
|
||||
@@ -606,18 +723,19 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return accepts;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String type) {
|
||||
return super.needToImport(type) && type.indexOf(".") < 0;
|
||||
}
|
||||
|
||||
private String findCommonPrefixOfVars(List<String> vars) {
|
||||
private static String findCommonPrefixOfVars(List<String> vars) {
|
||||
String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
|
||||
// exclude trailing characters that should be part of a valid variable
|
||||
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
|
||||
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
|
||||
}
|
||||
|
||||
private String toEnumVarName(String value) {
|
||||
private static String toEnumVarName(String value) {
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
@@ -626,7 +744,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
// This generator uses inline classes to define enums, which breaks when
|
||||
// dealing with models that have subTypes. To clean this up, we will analyze
|
||||
// the parent and child models, look for enums that match, and remove
|
||||
@@ -698,6 +816,9 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.localVariablePrefix = localVariablePrefix;
|
||||
}
|
||||
|
||||
public void setSerializeBigDecimalAsString(boolean s) {
|
||||
this.serializeBigDecimalAsString = s;
|
||||
}
|
||||
|
||||
public Boolean getSerializableModel() {
|
||||
return serializableModel;
|
||||
@@ -707,8 +828,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.serializableModel = serializableModel;
|
||||
}
|
||||
|
||||
private String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim();
|
||||
private static String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim(); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
if(Strings.isNullOrEmpty(packageName)) {
|
||||
return "invalidPackageName";
|
||||
@@ -719,4 +840,12 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setFullJavaUtil(boolean fullJavaUtil) {
|
||||
this.fullJavaUtil = fullJavaUtil;
|
||||
}
|
||||
|
||||
public void setUseRxJava(boolean useRxJava) {
|
||||
this.useRxJava = useRxJava;
|
||||
}
|
||||
|
||||
public void setDateLibrary(String library) {
|
||||
this.dateLibrary = library;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,21 @@ import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.util.Yaml;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class JavaInflectorServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
protected String title = "Swagger Inflector";
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaInflectorServerCodegen.class);
|
||||
|
||||
protected String title = "Swagger Inflector";
|
||||
protected String implFolder = "src/main/java";
|
||||
public JavaInflectorServerCodegen() {
|
||||
super();
|
||||
|
||||
sourceFolder = "src/main/java";
|
||||
sourceFolder = "src/gen/java";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
embeddedTemplateDir = templateDir = "JavaInflector";
|
||||
@@ -35,6 +40,7 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"byte[]",
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
@@ -45,14 +51,17 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "inflector";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Java Inflector Server application.";
|
||||
}
|
||||
@@ -62,14 +71,16 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
super.processOpts();
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("web.mustache", "src/main/webapp/WEB-INF", "web.xml"));
|
||||
supportingFiles.add(new SupportingFile("inflector.mustache", "", "inflector.yaml"));
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(outputFolder, new SupportingFile("web.mustache", "src/main/webapp/WEB-INF", "web.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("inflector.mustache", "", "inflector.yaml"));
|
||||
supportingFiles.add(new SupportingFile("swagger.mustache",
|
||||
"src/main/swagger",
|
||||
"swagger.yaml")
|
||||
);
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache",
|
||||
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "StringUtil.java"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,21 +127,6 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
// handle default value for enum, e.g. available => StatusEnum.available
|
||||
if (var.isEnum && var.defaultValue != null && !"null".equals(var.defaultValue)) {
|
||||
var.defaultValue = var.datatypeWithEnum + "." + var.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if (operations != null) {
|
||||
@@ -165,6 +161,18 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
return objs;
|
||||
}
|
||||
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if ( templateName.endsWith("api.mustache") ) {
|
||||
int ix = result.indexOf(sourceFolder);
|
||||
String beg = result.substring(0, ix);
|
||||
String end = result.substring(ix + sourceFolder.length());
|
||||
new java.io.File(beg + implFolder).mkdirs();
|
||||
result = beg + implFolder + end;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
@@ -173,7 +181,7 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
try {
|
||||
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
@@ -184,11 +192,7 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
if (name.length() == 0) {
|
||||
return "DefaultController";
|
||||
}
|
||||
name = name.replaceAll("[^a-zA-Z0-9]+", "_");
|
||||
name = name.replaceAll("[^a-zA-Z0-9]+", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
return camelize(name)+ "Controller";
|
||||
}
|
||||
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
return super.shouldOverwrite(filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
|
||||
public JavaJerseyServerCodegen()
|
||||
{
|
||||
super();
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-server";
|
||||
outputFolder = "generated-code/JavaJaxRS-Jersey";
|
||||
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
apiTemplateFiles.put("apiService.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "jersey1_18";
|
||||
|
||||
for ( int i = 0; i < cliOptions.size(); i++ ) {
|
||||
if ( CodegenConstants.LIBRARY.equals(cliOptions.get(i).getOpt()) ) {
|
||||
cliOptions.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
|
||||
Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
|
||||
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "Jersey core 1.18.1");
|
||||
library.setEnum(supportedLibraries);
|
||||
|
||||
cliOptions.add(library);
|
||||
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
|
||||
cliOptions.add(new CliOption("title", "a title describing the application"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs"; // TODO should be renamed as "jaxrs-jersey"
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp()
|
||||
{
|
||||
return "Generates a Java JAXRS Server application based on Jersey framework.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
if("null".equals(property.example)) {
|
||||
property.example = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER) ) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
|
||||
supportingFiles.clear();
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiOriginFilter.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("NotFoundException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "NotFoundException.java"));
|
||||
writeOptional(outputFolder, new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "StringUtil.java"));
|
||||
|
||||
if ( additionalProperties.containsKey("dateLibrary") ) {
|
||||
setDateLibrary(additionalProperties.get("dateLibrary").toString());
|
||||
additionalProperties.put(dateLibrary, "true");
|
||||
}
|
||||
|
||||
if ( "joda".equals(dateLibrary) ) {
|
||||
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java"));
|
||||
} else if ( "java8".equals(dateLibrary) ) {
|
||||
supportingFiles.add(new SupportingFile("LocalDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("LocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java"));
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -4,56 +4,95 @@ import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
protected String title = "Swagger Server";
|
||||
public class JavaResteasyServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
|
||||
public JaxRSServerCodegen() {
|
||||
super.processOpts();
|
||||
protected String dateLibrary = "default";
|
||||
protected String title = "Swagger Server";
|
||||
protected String implFolder = "src/main/java";
|
||||
|
||||
public static final String DATE_LIBRARY = "dateLibrary";
|
||||
|
||||
public JavaResteasyServerCodegen() {
|
||||
|
||||
super();
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-server";
|
||||
artifactId = "swagger-jaxrs-resteasy-server";
|
||||
|
||||
outputFolder = System.getProperty("swagger.codegen.jaxrs.genfolder", "generated-code/javaJaxRS");
|
||||
outputFolder = "generated-code/javaJaxRS";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
apiTemplateFiles.put("apiService.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
|
||||
embeddedTemplateDir = templateDir = "JavaJaxRS";
|
||||
apiPackage = System.getProperty("swagger.codegen.jaxrs.apipackage", "io.swagger.api");
|
||||
modelPackage = System.getProperty("swagger.codegen.jaxrs.modelpackage", "io.swagger.model");
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
|
||||
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
embeddedTemplateDir = templateDir = "JavaJaxRS" + File.separator + "resteasy";
|
||||
|
||||
for (int i = 0; i < cliOptions.size(); i++) {
|
||||
if (CodegenConstants.LIBRARY.equals(cliOptions.get(i).getOpt())) {
|
||||
cliOptions.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
|
||||
Map<String, String> dateOptions = new HashMap<String, String>();
|
||||
dateOptions.put("java8", "Java 8 native");
|
||||
dateOptions.put("joda", "Joda");
|
||||
dateLibrary.setEnum(dateOptions);
|
||||
|
||||
cliOptions.add(dateLibrary);
|
||||
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
|
||||
Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
|
||||
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "Resteasy core 3.0.11");
|
||||
library.setEnum(supportedLibraries);
|
||||
|
||||
cliOptions.add(library);
|
||||
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "jaxrs";
|
||||
return "jaxrs-resteasy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Java JAXRS Server application.";
|
||||
return "Generates a Java JAXRS-Resteasy Server application.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("gradle.mustache", "", "build.gradle"));
|
||||
writeOptional(outputFolder, new SupportingFile("settingsGradle.mustache", "", "settings.gradle"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache",
|
||||
@@ -62,9 +101,47 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("NotFoundException.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "NotFoundException.java"));
|
||||
supportingFiles.add(new SupportingFile("web.mustache",
|
||||
writeOptional(outputFolder, new SupportingFile("web.mustache",
|
||||
("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("jboss-web.mustache",
|
||||
("src/main/webapp/WEB-INF"), "jboss-web.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("RestApplication.mustache",
|
||||
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache",
|
||||
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "StringUtil.java"));
|
||||
|
||||
if (additionalProperties.containsKey("dateLibrary")) {
|
||||
setDateLibrary(additionalProperties.get("dateLibrary").toString());
|
||||
additionalProperties.put(dateLibrary, "true");
|
||||
}
|
||||
|
||||
if ("joda".equals(dateLibrary)) {
|
||||
typeMapping.put("date", "LocalDate");
|
||||
typeMapping.put("DateTime", "DateTime");
|
||||
|
||||
importMapping.put("LocalDate", "org.joda.time.LocalDate");
|
||||
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||
|
||||
supportingFiles.add(new SupportingFile("JacksonConfig.mustache",
|
||||
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "JacksonConfig.java"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java"));
|
||||
} else if ("java8".equals(dateLibrary)) {
|
||||
additionalProperties.put("java8", "true");
|
||||
additionalProperties.put("javaVersion", "1.8");
|
||||
typeMapping.put("date", "LocalDate");
|
||||
typeMapping.put("DateTime", "LocalDateTime");
|
||||
importMapping.put("LocalDate", "java.time.LocalDate");
|
||||
importMapping.put("LocalDateTime", "java.time.LocalDateTime");
|
||||
|
||||
supportingFiles.add(new SupportingFile("LocalDateTimeProvider.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("LocalDateProvider.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,28 +172,39 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
co.baseName = basePath;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if("/".equals(swagger.getBasePath())) {
|
||||
if ("/".equals(swagger.getBasePath())) {
|
||||
swagger.setBasePath("");
|
||||
}
|
||||
if(swagger != null && swagger.getPaths() != null) {
|
||||
for(String pathname : swagger.getPaths().keySet()) {
|
||||
|
||||
String host = swagger.getHost();
|
||||
String port = "8080";
|
||||
if (host != null) {
|
||||
String[] parts = host.split(":");
|
||||
if (parts.length > 1) {
|
||||
port = parts[1];
|
||||
}
|
||||
}
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for (String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if(path.getOperations() != null) {
|
||||
for(Operation operation : path.getOperations()) {
|
||||
if(operation.getTags() != null) {
|
||||
if (path.getOperations() != null) {
|
||||
for (Operation operation : path.getOperations()) {
|
||||
if (operation.getTags() != null) {
|
||||
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
for(String tag : operation.getTags()) {
|
||||
for (String tag : operation.getTags()) {
|
||||
Map<String, String> value = new HashMap<String, String>();
|
||||
value.put("tag", tag);
|
||||
value.put("hasMore", "true");
|
||||
tags.add(value);
|
||||
}
|
||||
if(tags.size() > 0) {
|
||||
if (tags.size() > 0) {
|
||||
tags.get(tags.size() - 1).remove("hasMore");
|
||||
}
|
||||
if(operation.getTags().size() > 0) {
|
||||
if (operation.getTags().size() > 0) {
|
||||
String tag = operation.getTags().get(0);
|
||||
operation.setTags(Arrays.asList(tag));
|
||||
}
|
||||
@@ -128,27 +216,22 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
// handle default value for enum, e.g. available => StatusEnum.available
|
||||
if (var.isEnum && var.defaultValue != null && !"null".equals(var.defaultValue)) {
|
||||
var.defaultValue = var.datatypeWithEnum + "." + var.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
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.hasConsumes == Boolean.TRUE) {
|
||||
Map<String, String> firstType = operation.consumes.get(0);
|
||||
if (firstType != null) {
|
||||
if ("multipart/form-data".equals(firstType.get("mediaType"))) {
|
||||
operation.isMultipart = Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if (responses != null) {
|
||||
for (CodegenResponse resp : responses) {
|
||||
@@ -195,6 +278,7 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
|
||||
@@ -204,19 +288,12 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java";
|
||||
|
||||
String output = System.getProperty("swagger.codegen.jaxrs.impl.source");
|
||||
if(output == null) {
|
||||
output = "src" + File.separator + "main" + File.separator + "java";
|
||||
}
|
||||
result = result.replace(apiFileFolder(), implFileFolder(output));
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if (templateName.endsWith("Factory.mustache")) {
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java";
|
||||
|
||||
String output = System.getProperty("swagger.codegen.jaxrs.impl.source");
|
||||
if (output != null) {
|
||||
result = result.replace(apiFileFolder(), implFileFolder(output));
|
||||
}
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if (templateName.endsWith("Service.mustache")) {
|
||||
int ix = result.lastIndexOf('.');
|
||||
result = result.substring(0, ix) + "Service.java";
|
||||
@@ -225,11 +302,44 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private String implFileFolder(String output) {
|
||||
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
return super.shouldOverwrite(filename) && !filename.endsWith("ServiceImpl.java") && !filename.endsWith("ServiceFactory.java");
|
||||
}
|
||||
|
||||
public void setDateLibrary(String library) {
|
||||
this.dateLibrary = library;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
if(serializeBigDecimalAsString) {
|
||||
if (property.baseType.equals("BigDecimal")) {
|
||||
// we serialize BigDecimal as `string` to avoid precision loss
|
||||
property.vendorExtensions.put("extraAnnotation", "@JsonSerialize(using = ToStringSerializer.class)");
|
||||
|
||||
// this requires some more imports to be added for this model...
|
||||
model.imports.add("ToStringSerializer");
|
||||
model.imports.add("JsonSerialize");
|
||||
}
|
||||
}
|
||||
|
||||
if(model.isEnum == null || model.isEnum) {
|
||||
|
||||
final String lib = getLibrary();
|
||||
if(StringUtils.isEmpty(lib)) {
|
||||
model.imports.add("JsonProperty");
|
||||
|
||||
if(model.hasEnums != null || model.hasEnums == true) {
|
||||
model.imports.add("JsonValue");
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,32 @@ import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.models.Info;
|
||||
import io.swagger.models.License;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.DateProperty;
|
||||
import io.swagger.models.properties.DateTimeProperty;
|
||||
import io.swagger.models.properties.DoubleProperty;
|
||||
import io.swagger.models.properties.FloatProperty;
|
||||
import io.swagger.models.properties.IntegerProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,11 +43,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class JavascriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("hiding")
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavascriptClientCodegen.class);
|
||||
|
||||
private static final String PROJECT_NAME = "projectName";
|
||||
@@ -39,14 +52,18 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
private static final String PROJECT_DESCRIPTION = "projectDescription";
|
||||
private static final String PROJECT_VERSION = "projectVersion";
|
||||
private static final String PROJECT_LICENSE_NAME = "projectLicenseName";
|
||||
private static final String USE_PROMISES = "usePromises";
|
||||
private static final String OMIT_MODEL_METHODS = "omitModelMethods";
|
||||
|
||||
protected String projectName = null;
|
||||
protected String moduleName = null;
|
||||
protected String projectDescription = null;
|
||||
protected String projectVersion = null;
|
||||
protected String projectName;
|
||||
protected String moduleName;
|
||||
protected String projectDescription;
|
||||
protected String projectVersion;
|
||||
|
||||
protected String sourceFolder = "src";
|
||||
protected String localVariablePrefix = "";
|
||||
protected boolean usePromises = false;
|
||||
protected boolean omitModelMethods = false;
|
||||
|
||||
public JavascriptClientCodegen() {
|
||||
super();
|
||||
@@ -58,7 +75,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
modelPackage = "model";
|
||||
|
||||
// reference: http://www.w3schools.com/js/js_reserved.asp
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"abstract", "arguments", "boolean", "break", "byte",
|
||||
"case", "catch", "char", "class", "const",
|
||||
@@ -96,6 +113,12 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
"version of the project (Default: using info.version or \"1.0.0\")"));
|
||||
cliOptions.add(new CliOption(PROJECT_LICENSE_NAME,
|
||||
"name of the license the project uses (Default: using info.license.name)"));
|
||||
cliOptions.add(new CliOption(USE_PROMISES,
|
||||
"use Promises as return values from the client API, instead of superagent callbacks")
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
cliOptions.add(new CliOption(OMIT_MODEL_METHODS,
|
||||
"omits generation of getters and setters for model classes")
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,6 +156,9 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
typeMapping.put("double", "Number");
|
||||
typeMapping.put("number", "Number");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
typeMapping.put("Date", "Date");
|
||||
// binary not supported in JavaScript client right now, using String as a workaround
|
||||
typeMapping.put("binary", "String");
|
||||
|
||||
importMapping.clear();
|
||||
}
|
||||
@@ -159,14 +185,20 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||
sourceFolder = (String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER);
|
||||
}
|
||||
if (additionalProperties.containsKey(USE_PROMISES)) {
|
||||
usePromises = Boolean.parseBoolean((String)additionalProperties.get(USE_PROMISES));
|
||||
}
|
||||
if (additionalProperties.containsKey(OMIT_MODEL_METHODS)) {
|
||||
omitModelMethods = Boolean.parseBoolean((String)additionalProperties.get(OMIT_MODEL_METHODS));
|
||||
}
|
||||
|
||||
if (swagger.getInfo() != null) {
|
||||
Info info = swagger.getInfo();
|
||||
if (projectName == null && info.getTitle() != null) {
|
||||
if (StringUtils.isBlank(projectName) && info.getTitle() != null) {
|
||||
// when projectName is not specified, generate it from info.title
|
||||
projectName = dashize(info.getTitle());
|
||||
}
|
||||
if (projectVersion == null) {
|
||||
if (StringUtils.isBlank(projectVersion)) {
|
||||
// when projectVersion is not specified, use info.version
|
||||
projectVersion = info.getVersion();
|
||||
}
|
||||
@@ -183,13 +215,13 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
|
||||
// default values
|
||||
if (projectName == null) {
|
||||
if (StringUtils.isBlank(projectName)) {
|
||||
projectName = "swagger-js-client";
|
||||
}
|
||||
if (moduleName == null) {
|
||||
if (StringUtils.isBlank(moduleName)) {
|
||||
moduleName = camelize(underscore(projectName));
|
||||
}
|
||||
if (projectVersion == null) {
|
||||
if (StringUtils.isBlank(projectVersion)) {
|
||||
projectVersion = "1.0.0";
|
||||
}
|
||||
if (projectDescription == null) {
|
||||
@@ -202,9 +234,12 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
additionalProperties.put(PROJECT_VERSION, projectVersion);
|
||||
additionalProperties.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, localVariablePrefix);
|
||||
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder);
|
||||
additionalProperties.put(USE_PROMISES, usePromises);
|
||||
additionalProperties.put(OMIT_MODEL_METHODS, omitModelMethods);
|
||||
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", sourceFolder, "index.js"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", sourceFolder, "ApiClient.js"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -225,7 +260,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final"
|
||||
|
||||
if("_".equals(name)) {
|
||||
name = "_u";
|
||||
@@ -241,7 +276,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -256,16 +291,20 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final"
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
name = camelize(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = "Object" + name;
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -276,7 +315,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
return name;
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -289,59 +328,76 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return getSwaggerType(p); // TODO: + "/* <" + getTypeDeclaration(inner) + "> */";
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner) + ">";
|
||||
return "{String: " + getTypeDeclaration(inner) + "}";
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
return "[]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
return "{}";
|
||||
if (p instanceof StringProperty) {
|
||||
StringProperty dp = (StringProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "'" + dp.getDefault() + "'";
|
||||
}
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
BooleanProperty dp = (BooleanProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof DateProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DateTimeProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString()+"l";
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
return "null";
|
||||
|
||||
// added for Javascript
|
||||
} else if (p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty)p;
|
||||
return "new " +rp.getSimpleRef() + "()";
|
||||
}
|
||||
|
||||
return super.toDefaultValue(p);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toDefaultValueWithParam(String name, Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
return " = new Array();";
|
||||
} else if (p instanceof MapProperty) {
|
||||
return " = {}";
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
return " = data." + name + ";";
|
||||
|
||||
// added for Javascript
|
||||
} else if (p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty)p;
|
||||
return ".constructFromObject(data." + name + ");";
|
||||
String type = normalizeType(getTypeDeclaration(p));
|
||||
if (p instanceof RefProperty) {
|
||||
return " = " + type + ".constructFromObject(data['" + name + "']);";
|
||||
} else {
|
||||
return " = ApiClient.convertToType(data['" + name + "'], " + type + ");";
|
||||
}
|
||||
}
|
||||
|
||||
return super.toDefaultValueWithParam(name, p);
|
||||
/**
|
||||
* Normalize type by wrapping primitive types with single quotes.
|
||||
*
|
||||
* @param type Primitive type
|
||||
* @return Normalized type
|
||||
*/
|
||||
public String normalizeType(String type) {
|
||||
return type.replaceAll("\\b(Boolean|Integer|Number|String|Date)\\b", "'$1'");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
@@ -367,12 +423,25 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
return operationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, definitions, swagger);
|
||||
if (op.returnType != null) {
|
||||
op.returnType = normalizeType(op.returnType);
|
||||
}
|
||||
return op;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -382,12 +451,41 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
codegenModel = JavascriptClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
// Generate and store argument list string of each operation into
|
||||
// vendor-extension: x-codegen-argList.
|
||||
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) {
|
||||
List<String> argList = new ArrayList();
|
||||
boolean hasOptionalParams = false;
|
||||
for (CodegenParameter p : operation.allParams) {
|
||||
if (p.required != null && p.required) {
|
||||
argList.add(p.paramName);
|
||||
} else {
|
||||
hasOptionalParams = true;
|
||||
}
|
||||
}
|
||||
if (hasOptionalParams) {
|
||||
argList.add("opts");
|
||||
}
|
||||
if (!usePromises) {
|
||||
argList.add("callback");
|
||||
}
|
||||
operation.vendorExtensions.put("x-codegen-argList", StringUtils.join(argList, ", "));
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
@@ -431,46 +529,38 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
allowableValues.put("enumVars", enumVars);
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
if("retrofit".equals(getLibrary())) {
|
||||
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.hasConsumes == Boolean.TRUE) {
|
||||
Map<String, String> firstType = operation.consumes.get(0);
|
||||
if (firstType != null) {
|
||||
if ("multipart/form-data".equals(firstType.get("mediaType"))) {
|
||||
operation.isMultipart = Boolean.TRUE;
|
||||
// set vendor-extension: x-codegen-hasMoreRequired
|
||||
CodegenProperty lastRequired = null;
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
if (var.required != null && var.required) {
|
||||
lastRequired = var;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
}
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
if (var == lastRequired) {
|
||||
var.vendorExtensions.put("x-codegen-hasMoreRequired", false);
|
||||
} else if (var.required != null && var.required) {
|
||||
var.vendorExtensions.put("x-codegen-hasMoreRequired", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String type) {
|
||||
return !defaultIncludes.contains(type)
|
||||
&& !languageSpecificPrimitives.contains(type);
|
||||
}
|
||||
|
||||
private String findCommonPrefixOfVars(List<String> vars) {
|
||||
private static String findCommonPrefixOfVars(List<String> vars) {
|
||||
String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
|
||||
// exclude trailing characters that should be part of a valid variable
|
||||
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
|
||||
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
|
||||
}
|
||||
|
||||
private String toEnumVarName(String value) {
|
||||
private static String toEnumVarName(String value) {
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
@@ -479,7 +569,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
}
|
||||
|
||||
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
// This generator uses inline classes to define enums, which breaks when
|
||||
// dealing with models that have subTypes. To clean this up, we will analyze
|
||||
// the parent and child models, look for enums that match, and remove
|
||||
@@ -527,7 +617,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
private String sanitizePackageName(String packageName) {
|
||||
private static String sanitizePackageName(String packageName) { // FIXME parameter should not be assigned. Also declare it as "final"
|
||||
packageName = packageName.trim();
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
if(Strings.isNullOrEmpty(packageName)) {
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public JavascriptClosureAngularClientCodegen() {
|
||||
super();
|
||||
|
||||
supportsInheritance = false;
|
||||
setReservedWordsLowerCase(Arrays.asList("abstract",
|
||||
"continue", "for", "new", "switch", "assert", "default", "if",
|
||||
"package", "synchronized", "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", "const", "super", "while"));
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(Arrays.asList(
|
||||
"string",
|
||||
"boolean",
|
||||
"number",
|
||||
"Object",
|
||||
"Blob",
|
||||
"Date"));
|
||||
instantiationTypes.put("array", "Array");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("Array", "Array");
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("boolean", "boolean");
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("int", "number");
|
||||
typeMapping.put("float", "number");
|
||||
typeMapping.put("number", "number");
|
||||
typeMapping.put("long", "number");
|
||||
typeMapping.put("short", "number");
|
||||
typeMapping.put("char", "string");
|
||||
typeMapping.put("double", "number");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("Object", "Object");
|
||||
typeMapping.put("File", "Blob");
|
||||
typeMapping.put("file", "Blob");
|
||||
typeMapping.put("integer", "number");
|
||||
typeMapping.put("Map", "Object");
|
||||
typeMapping.put("map", "Object");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
defaultIncludes = new HashSet<String>(Arrays.asList(
|
||||
"Object",
|
||||
"Array",
|
||||
"Blob"
|
||||
));
|
||||
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
outputFolder = "generated-code/javascript-closure-angular";
|
||||
modelTemplateFiles.put("model.mustache", ".js");
|
||||
apiTemplateFiles.put("api.mustache", ".js");
|
||||
embeddedTemplateDir = templateDir = "Javascript-Closure-Angular";
|
||||
apiPackage = "API.Client";
|
||||
modelPackage = "API.Client";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "javascript-closure-angular";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Javascript AngularJS client library annotated with Google Closure Compiler annotations" +
|
||||
"(https://developers.google.com/closure/compiler/docs/js-for-compiler?hl=en)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@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 toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$"))
|
||||
return name;
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => PetId
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*"))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name))
|
||||
throw new RuntimeException(name
|
||||
+ " (reserved word) cannot be used as a model name");
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@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 "Object<!string, "+ getTypeDeclaration(inner) + ">";
|
||||
} else if (p instanceof FileProperty) {
|
||||
return "Object";
|
||||
}
|
||||
String type = super.getTypeDeclaration(p);
|
||||
if (type.equals("boolean") ||
|
||||
type.equals("Date") ||
|
||||
type.equals("number") ||
|
||||
type.equals("string")) {
|
||||
return type;
|
||||
}
|
||||
return apiPackage + "." + type;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
cm.imports = new TreeSet(cm.imports);
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
// handle default value for enum, e.g. available => StatusEnum.available
|
||||
if (var.isEnum && var.defaultValue != null && !"null".equals(var.defaultValue)) {
|
||||
var.defaultValue = var.datatypeWithEnum + "." + var.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
if (objs.get("imports") instanceof List) {
|
||||
List<Map<String, String>> imports = (ArrayList<Map<String, String>>)objs.get("imports");
|
||||
Collections.sort(imports, new Comparator<Map<String, String>>() {
|
||||
public int compare(Map<String, String> o1, Map<String, String> o2) {
|
||||
return o1.get("import").compareTo(o2.get("import"));
|
||||
}
|
||||
});
|
||||
objs.put("imports", imports);
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,29 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.util.Yaml;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
||||
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected int serverPort = 8080;
|
||||
protected String projectName = "swagger-server";
|
||||
@@ -49,7 +60,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"break", "case", "class", "catch", "const", "continue", "debugger",
|
||||
"default", "delete", "do", "else", "export", "extends", "finally",
|
||||
@@ -78,18 +89,9 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"api",
|
||||
"swagger.yaml")
|
||||
);
|
||||
supportingFiles.add(new SupportingFile("index.mustache",
|
||||
"",
|
||||
"index.js")
|
||||
);
|
||||
supportingFiles.add(new SupportingFile("package.mustache",
|
||||
"",
|
||||
"package.json")
|
||||
);
|
||||
supportingFiles.add(new SupportingFile("README.mustache",
|
||||
"",
|
||||
"README.md")
|
||||
);
|
||||
writeOptional(outputFolder, new SupportingFile("index.mustache", "", "index.js"));
|
||||
writeOptional(outputFolder, new SupportingFile("package.mustache", "", "package.json"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
if (System.getProperty("noservice") == null) {
|
||||
apiTemplateFiles.put(
|
||||
"service.mustache", // the template to use
|
||||
@@ -97,6 +99,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiPackage() {
|
||||
return "controllers";
|
||||
}
|
||||
@@ -107,6 +110,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
@@ -117,6 +121,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "nodejs";
|
||||
}
|
||||
@@ -127,6 +132,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a nodejs server library using the swagger-tools project. By default, " +
|
||||
"it will also generate service classes--which you can disable with the `-Dnoservice` environment variable.";
|
||||
@@ -173,6 +179,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
for (CodegenOperation operation : operations) {
|
||||
operation.httpMethod = operation.httpMethod.toLowerCase();
|
||||
|
||||
List<CodegenParameter> params = operation.allParams;
|
||||
if (params != null && params.size() == 0) {
|
||||
operation.allParams = null;
|
||||
@@ -200,7 +207,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
private static List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
||||
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||
@@ -210,7 +217,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
private static List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
Multimap<String, CodegenOperation> opsByPath = ArrayListMultimap.create();
|
||||
|
||||
for (CodegenOperation op : ops) {
|
||||
@@ -233,14 +240,67 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return opsByPathList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
String host = swagger.getHost();
|
||||
String port = "8080";
|
||||
if (host != null) {
|
||||
String[] parts = host.split(":");
|
||||
if (parts.length > 1) {
|
||||
port = parts[1];
|
||||
}
|
||||
}
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
|
||||
if (swagger.getInfo() != null) {
|
||||
Info info = swagger.getInfo();
|
||||
if (info.getTitle() != null) {
|
||||
// when info.title is defined, use it for projectName
|
||||
// used in package.json
|
||||
projectName = dashize(info.getTitle());
|
||||
this.additionalProperties.put("projectName", projectName);
|
||||
}
|
||||
}
|
||||
|
||||
// need vendor extensions for x-swagger-router-controller
|
||||
Map<String, Path> paths = swagger.getPaths();
|
||||
if(paths != null) {
|
||||
for(String pathname : paths.keySet()) {
|
||||
Path path = paths.get(pathname);
|
||||
Map<HttpMethod, Operation> operationMap = path.getOperationMap();
|
||||
if(operationMap != null) {
|
||||
for(HttpMethod method : operationMap.keySet()) {
|
||||
Operation operation = operationMap.get(method);
|
||||
String tag = "default";
|
||||
if(operation.getTags() != null && operation.getTags().size() > 0) {
|
||||
tag = toApiName(operation.getTags().get(0));
|
||||
}
|
||||
if(operation.getOperationId() == null) {
|
||||
operation.setOperationId(getOrGenerateOperationId(operation, pathname, method.toString()));
|
||||
}
|
||||
operation.getVendorExtensions().put("x-swagger-router-controller", toApiName(tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
Swagger swagger = (Swagger)objs.get("swagger");
|
||||
if(swagger != null) {
|
||||
try {
|
||||
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
|
||||
SimpleModule module = new SimpleModule();
|
||||
module.addSerializer(Double.class, new JsonSerializer<Double>() {
|
||||
@Override
|
||||
public void serialize(Double val, JsonGenerator jgen,
|
||||
SerializerProvider provider) throws IOException, JsonProcessingException {
|
||||
jgen.writeNumber(new BigDecimal(val));
|
||||
}
|
||||
});
|
||||
objs.put("swagger-yaml", Yaml.mapper().registerModule(module).writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
for (Map<String, Object> operations : getOperations(objs)) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.swagger.codegen.languages;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
@@ -13,6 +14,8 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -84,11 +87,19 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("List", "NSArray");
|
||||
typeMapping.put("object", "NSObject");
|
||||
typeMapping.put("file", "NSURL");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "NSString");
|
||||
|
||||
|
||||
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names in API methods (endpoints)
|
||||
"resourcePath", "pathParams", "queryParams", "headerParams",
|
||||
"responseContentType", "requestContentType", "authSettings",
|
||||
"formParams", "localVarFiles", "bodyParam",
|
||||
// objc reserved words
|
||||
"auto", "else", "long", "switch",
|
||||
"break", "enum", "register", "typedef",
|
||||
"case", "extern", "return", "union",
|
||||
@@ -133,14 +144,17 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(new CliOption(LICENSE, "License to use in the podspec file.").defaultValue("MIT"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "objc";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates an Objective-C client library.";
|
||||
}
|
||||
@@ -211,12 +225,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@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;
|
||||
@@ -239,12 +249,12 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if (languageSpecificPrimitives.contains(type) && !foundationClasses.contains(type)) {
|
||||
return toModelName(type);
|
||||
return toModelNameWithoutReservedWordCheck(type);
|
||||
}
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
return toModelName(type);
|
||||
return toModelNameWithoutReservedWordCheck(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -304,7 +314,24 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
type = type.replaceAll("[^0-9a-zA-Z_]", "_");
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(type)) {
|
||||
LOGGER.warn(type+ " (reserved word) cannot be used as model name. Renamed to " + ("object_" + type) + " before further processing");
|
||||
type = "object_" + type; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
return toModelNameWithoutReservedWordCheck(type);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert input to proper model name according to ObjC style guide
|
||||
* without checking for reserved words
|
||||
*
|
||||
* @param type Model anme
|
||||
* @return model Name in ObjC style guide
|
||||
*/
|
||||
public String toModelNameWithoutReservedWordCheck(String type) {
|
||||
type = type.replaceAll("[^0-9a-zA-Z_]", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// language build-in classes
|
||||
if (typeMapping.keySet().contains(type) ||
|
||||
@@ -316,7 +343,15 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
// custom classes
|
||||
else {
|
||||
return classPrefix + camelize(type);
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) { // set model suffix
|
||||
type = type + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) { // set model prefix
|
||||
type = modelNamePrefix + "_" + type;
|
||||
}
|
||||
|
||||
return classPrefix + camelize(type); // add class prefix
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,6 +391,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return classPrefix + camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return classPrefix + camelize(name) + "Api";
|
||||
}
|
||||
@@ -363,7 +399,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all upper case, do noting
|
||||
if (name.matches("^[A-Z_]$")) {
|
||||
@@ -381,7 +417,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, prepend `_`
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -395,10 +431,12 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public String escapeSpecialWord(String name) {
|
||||
return "var_" + name;
|
||||
}
|
||||
@@ -411,8 +449,9 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
@@ -446,6 +485,21 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
@Override
|
||||
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.allParams.isEmpty()) {
|
||||
String firstParamName = operation.allParams.get(0).paramName;
|
||||
operation.vendorExtensions.put("firstParamAltName", camelize(firstParamName));
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default value of the property
|
||||
*
|
||||
|
||||
@@ -13,25 +13,31 @@ import io.swagger.models.properties.Property;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public static final String MODULE_NAME = "moduleName";
|
||||
public static final String MODULE_VERSION = "moduleVersion";
|
||||
protected String moduleName = "SwaggerClient";
|
||||
protected String moduleName = "WWW::SwaggerClient";
|
||||
protected String modulePathPart = moduleName.replaceAll("::", Matcher.quoteReplacement(File.separator));
|
||||
protected String moduleVersion = "1.0.0";
|
||||
|
||||
protected static int emptyFunctionNameCounter = 0;
|
||||
|
||||
public PerlClientCodegen() {
|
||||
super();
|
||||
modelPackage = File.separatorChar + "Object";
|
||||
outputFolder = "generated-code" + File.separatorChar + "perl";
|
||||
modelTemplateFiles.put("object.mustache", ".pm");
|
||||
apiTemplateFiles.put("api.mustache", ".pm");
|
||||
modelTestTemplateFiles.put("object_test.mustache", ".t");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".t");
|
||||
embeddedTemplateDir = templateDir = "perl";
|
||||
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"else", "lock", "qw",
|
||||
"__END__", "elsif", "lt", "qx",
|
||||
@@ -42,7 +48,8 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"cmp", "ge", "package", "until",
|
||||
"continue", "gt", "q", "while",
|
||||
"CORE", "if", "qq", "xor",
|
||||
"do", "le", "qr", "y"
|
||||
"do", "le", "qr", "y",
|
||||
"return"
|
||||
)
|
||||
);
|
||||
|
||||
@@ -64,17 +71,22 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("boolean", "boolean");
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("date", "DateTime");
|
||||
typeMapping.put("dateTime", "DateTime");
|
||||
typeMapping.put("DateTime", "DateTime");
|
||||
typeMapping.put("password", "string");
|
||||
typeMapping.put("array", "ARRAY");
|
||||
typeMapping.put("map", "HASH");
|
||||
typeMapping.put("object", "object");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(MODULE_NAME, "Perl module name (convention: CamelCase).").defaultValue("SwaggerClient"));
|
||||
cliOptions.add(new CliOption(MODULE_NAME, "Perl module name (convention: CamelCase or Long::Module).").defaultValue("SwaggerClient"));
|
||||
cliOptions.add(new CliOption(MODULE_VERSION, "Perl module version.").defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants.ENSURE_UNIQUE_PARAMS_DESC));
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC).defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants
|
||||
.ENSURE_UNIQUE_PARAMS_DESC).defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
}
|
||||
|
||||
@@ -91,27 +103,31 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
if (additionalProperties.containsKey(MODULE_NAME)) {
|
||||
setModuleName((String) additionalProperties.get(MODULE_NAME));
|
||||
setModulePathPart(moduleName.replaceAll("::", Matcher.quoteReplacement(File.separator)));
|
||||
} else {
|
||||
additionalProperties.put(MODULE_NAME, moduleName);
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "ApiClient.pm"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "Configuration.pm"));
|
||||
supportingFiles.add(new SupportingFile("BaseObject.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "Object/BaseObject.pm"));
|
||||
supportingFiles.add(new SupportingFile("ApiFactory.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "ApiFactory.pm"));
|
||||
supportingFiles.add(new SupportingFile("Role.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "Role.pm"));
|
||||
supportingFiles.add(new SupportingFile("AutoDoc.mustache", ("lib/WWW/" + moduleName + "/Role").replace('/', File.separatorChar), "AutoDoc.pm"));
|
||||
supportingFiles.add(new SupportingFile("autodoc.script.mustache", ("bin/").replace('/', File.separatorChar), "autodoc"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", ("lib/" + modulePathPart).replace('/', File.separatorChar), "ApiClient.pm"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", ("lib/" + modulePathPart).replace('/', File.separatorChar), "Configuration.pm"));
|
||||
supportingFiles.add(new SupportingFile("ApiFactory.mustache", ("lib/" + modulePathPart).replace('/', File.separatorChar), "ApiFactory.pm"));
|
||||
supportingFiles.add(new SupportingFile("Role.mustache", ("lib/" + modulePathPart).replace('/', File.separatorChar), "Role.pm"));
|
||||
supportingFiles.add(new SupportingFile("AutoDoc.mustache", ("lib/" + modulePathPart + "/Role").replace('/', File.separatorChar), "AutoDoc.pm"));
|
||||
supportingFiles.add(new SupportingFile("autodoc.script.mustache", "bin", "autodoc"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "perl";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Perl client library.";
|
||||
}
|
||||
@@ -123,11 +139,23 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return (outputFolder + "/lib/WWW/" + moduleName + apiPackage()).replace('/', File.separatorChar);
|
||||
return (outputFolder + "/lib/" + modulePathPart + apiPackage()).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + "/lib/WWW/" + moduleName + modelPackage()).replace('/', File.separatorChar);
|
||||
return (outputFolder + "/lib/" + modulePathPart + modelPackage()).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return (outputFolder + "/t").replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return (outputFolder + "/t").replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,9 +187,10 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
return type;
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
@@ -171,14 +200,13 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String toVarName(String name) {
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
name = underscore(name);
|
||||
name = underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// parameter name starting with number won't compile
|
||||
// need to escape it by appending _ at the beginning
|
||||
if (name.matches("^\\d.*")) {
|
||||
name = "_" + name;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -191,10 +219,14 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(name)) {
|
||||
escapeReservedWord(name); // e.g. return => _return
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name;
|
||||
}
|
||||
|
||||
// add prefix/suffic to model name
|
||||
name = modelNamePrefix + name + modelNameSuffix;
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
@@ -206,10 +238,20 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
return toModelFilename(name) + "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiTestFilename(String name) {
|
||||
return toApiFilename(name) + "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. phone_number_api.rb => PhoneNumberApi.rb
|
||||
return camelize(name) + "Api";
|
||||
@@ -226,14 +268,17 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
//rename to empty_function_name_1 (e.g.) if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
operationId = underscore("empty_function_name_" + emptyFunctionNameCounter++);
|
||||
LOGGER.warn("Empty method name (operationId) found. Renamed to " + operationId);
|
||||
return operationId;
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId));
|
||||
return underscore("call_" + operationId);
|
||||
}
|
||||
|
||||
return underscore(operationId);
|
||||
@@ -243,6 +288,10 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.moduleName = moduleName;
|
||||
}
|
||||
|
||||
public void setModulePathPart(String modulePathPart) {
|
||||
this.modulePathPart = modulePathPart;
|
||||
}
|
||||
|
||||
public void setModuleVersion(String moduleVersion) {
|
||||
this.moduleVersion = moduleVersion;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("hiding")
|
||||
static Logger LOGGER = LoggerFactory.getLogger(PhpClientCodegen.class);
|
||||
|
||||
public static final String VARIABLE_NAMING_CONVENTION = "variableNamingConvention";
|
||||
@@ -41,12 +42,20 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
outputFolder = "generated-code" + File.separator + "php";
|
||||
modelTemplateFiles.put("model.mustache", ".php");
|
||||
apiTemplateFiles.put("api.mustache", ".php");
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".php");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".php");
|
||||
embeddedTemplateDir = templateDir = "php";
|
||||
apiPackage = invokerPackage + "\\Api";
|
||||
modelPackage = invokerPackage + "\\Model";
|
||||
testPackage = invokerPackage + "\\Tests";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variables used in api methods (endpoints)
|
||||
"resourcePath", "httpBody", "queryParams", "headerParams",
|
||||
"formParams", "_header_accept", "_tempBody",
|
||||
|
||||
// PHP reserved words
|
||||
"__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor")
|
||||
);
|
||||
|
||||
@@ -76,7 +85,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
String primitives = "'" + StringUtils.join(languageSpecificPrimitives, "', '") + "'";
|
||||
additionalProperties.put("primitives", primitives);
|
||||
|
||||
// ref: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#data-types
|
||||
// ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("long", "int");
|
||||
@@ -85,14 +94,14 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("byte", "int");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("date", "\\DateTime");
|
||||
typeMapping.put("datetime", "\\DateTime");
|
||||
typeMapping.put("Date", "\\DateTime");
|
||||
typeMapping.put("DateTime", "\\DateTime");
|
||||
typeMapping.put("file", "\\SplFileObject");
|
||||
typeMapping.put("map", "map");
|
||||
typeMapping.put("array", "array");
|
||||
typeMapping.put("list", "array");
|
||||
typeMapping.put("object", "object");
|
||||
typeMapping.put("DateTime", "\\DateTime");
|
||||
typeMapping.put("binary", "ByteArray");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
@@ -111,9 +120,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
public String toPackagePath(String packageName, String basePath) {
|
||||
packageName = packageName.replace(invokerPackage, "");
|
||||
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (basePath != null && basePath.length() > 0) {
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar;
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
}
|
||||
|
||||
String regFirstPathSeparator;
|
||||
@@ -139,14 +148,17 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
.replaceAll(regLastPathSeparator+ "$", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "php";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a PHP client library.";
|
||||
}
|
||||
@@ -211,6 +223,8 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toPackagePath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", getPackagePath(), "README.md"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", getPackagePath(), ".travis.yml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -223,10 +237,21 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return (outputFolder + "/" + toPackagePath(apiPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + "/" + toPackagePath(modelPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return (outputFolder + "/" + toPackagePath(testPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return (outputFolder + "/" + toPackagePath(testPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
@@ -304,7 +329,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
if ("camelCase".equals(variableNamingConvention)) {
|
||||
// return the name in camelCase style
|
||||
@@ -334,14 +359,20 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
|
||||
name = name.replaceAll("[^\\w\\\\]+", "_");
|
||||
name = name.replaceAll("[^\\w\\\\]+", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(name)) {
|
||||
escapeReservedWord(name); // e.g. return => _return
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
// add prefix and/or suffic only if name does not start wth \ (e.g. \DateTime)
|
||||
if (!name.matches("^\\\\.*")) {
|
||||
name = modelNamePrefix + name + modelNameSuffix;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
@@ -355,6 +386,12 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
// should be the same as the model name
|
||||
return toModelName(name) + "Test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
@@ -363,8 +400,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
|
||||
@@ -15,8 +15,8 @@ import java.util.HashSet;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String packageName = null;
|
||||
protected String packageVersion = null;
|
||||
protected String packageName;
|
||||
protected String packageVersion;
|
||||
|
||||
public PythonClientCodegen() {
|
||||
super();
|
||||
@@ -51,21 +51,29 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("DateTime", "datetime");
|
||||
typeMapping.put("object", "object");
|
||||
typeMapping.put("file", "file");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "str");
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable name used in API methods (endpoints)
|
||||
"all_params", "resource_path", "path_params", "query_params",
|
||||
"header_params", "form_params", "local_var_files", "body_params", "auth_settings",
|
||||
// python reserved words
|
||||
"and", "del", "from", "not", "while", "as", "elif", "global", "or", "with",
|
||||
"assert", "else", "if", "pass", "yield", "break", "except", "import",
|
||||
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
|
||||
"return", "def", "for", "lambda", "try"));
|
||||
"return", "def", "for", "lambda", "try", "self"));
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "python package name (convention: snake_case).")
|
||||
.defaultValue("swagger_client"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "python package version.")
|
||||
.defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC));
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC).defaultValue(Boolean.TRUE.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,14 +116,17 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return str.replaceAll("\\.", "_");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "python";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Python client library.";
|
||||
}
|
||||
@@ -130,6 +141,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return outputFolder + File.separatorChar + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separatorChar + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
@@ -167,7 +179,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
@@ -185,7 +197,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = name.replaceAll("^_*", "");
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -200,14 +212,15 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(modelNamePrefix + name + modelNameSuffix); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
@@ -218,8 +231,17 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + underscore(dropDots("object_" + name)));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
name = name + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
// underscore the model file name
|
||||
@@ -255,14 +277,15 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return underscore(sanitizeName(operationId));
|
||||
@@ -281,7 +304,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
*
|
||||
* (PEP 0008) Python packages should also have short, all-lowercase names,
|
||||
* although the use of underscores is discouraged.
|
||||
*
|
||||
* @param packageName Package name
|
||||
* @return Python package name that conforms to PEP 0008
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String generatePackageName(String packageName) {
|
||||
return underscore(packageName.replaceAll("[^\\w]+", ""));
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"sample1", // replace with static values
|
||||
"sample2")
|
||||
@@ -121,6 +121,9 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("map", "QMap");
|
||||
typeMapping.put("file", "SWGHttpRequestInputFileElement");
|
||||
typeMapping.put("object", PREFIX + "Object");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "QString");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
|
||||
@@ -140,6 +143,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
@@ -150,6 +154,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "qt5cpp";
|
||||
}
|
||||
@@ -160,6 +165,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a qt5 C++ client library.";
|
||||
}
|
||||
@@ -189,6 +195,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@@ -14,15 +14,34 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RubyClientCodegen.class);
|
||||
public static final String GEM_NAME = "gemName";
|
||||
public static final String MODULE_NAME = "moduleName";
|
||||
public static final String GEM_VERSION = "gemVersion";
|
||||
protected String gemName = null;
|
||||
protected String moduleName = null;
|
||||
public static final String GEM_LICENSE = "gemLicense";
|
||||
public static final String GEM_HOMEPAGE = "gemHomepage";
|
||||
public static final String GEM_SUMMARY = "gemSummary";
|
||||
public static final String GEM_DESCRIPTION = "gemDescription";
|
||||
public static final String GEM_AUTHOR = "gemAuthor";
|
||||
public static final String GEM_AUTHOR_EMAIL = "gemAuthorEmail";
|
||||
|
||||
protected String gemName;
|
||||
protected String moduleName;
|
||||
protected String gemVersion = "1.0.0";
|
||||
protected String specFolder = "spec";
|
||||
protected String libFolder = "lib";
|
||||
protected String gemLicense = "Apache-2.0";
|
||||
protected String gemHomepage = "http://swagger.io";
|
||||
protected String gemSummary = "A ruby wrapper for the swagger APIs";
|
||||
protected String gemDescription = "This gem maps to a swagger API";
|
||||
protected String gemAuthor = "";
|
||||
protected String gemAuthorEmail = "";
|
||||
|
||||
protected static int emptyMethodNameCounter = 0;
|
||||
|
||||
public RubyClientCodegen() {
|
||||
super();
|
||||
@@ -33,11 +52,18 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiTemplateFiles.put("api.mustache", ".rb");
|
||||
embeddedTemplateDir = templateDir = "ruby";
|
||||
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".rb");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".rb");
|
||||
|
||||
typeMapping.clear();
|
||||
languageSpecificPrimitives.clear();
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"local_var_path", "query_params", "header_params", "_header_accept", "_header_accept_result",
|
||||
"_header_content_type", "form_params", "post_body", "auth_names",
|
||||
// ruby reserved keywords
|
||||
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
|
||||
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
|
||||
"break", "do", "false", "next", "rescue", "then", "when", "END", "case",
|
||||
@@ -68,6 +94,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("map", "Hash");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("file", "File");
|
||||
typeMapping.put("binary", "String");
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
Iterator<CliOption> itr = cliOptions.iterator();
|
||||
@@ -83,6 +110,23 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(new CliOption(MODULE_NAME, "top module name (convention: CamelCase, usually corresponding" +
|
||||
" to gem name).").defaultValue("SwaggerClient"));
|
||||
cliOptions.add(new CliOption(GEM_VERSION, "gem version.").defaultValue("1.0.0"));
|
||||
|
||||
cliOptions.add(new CliOption(GEM_LICENSE, "gem license. ").
|
||||
defaultValue("Apache-2.0"));
|
||||
|
||||
cliOptions.add(new CliOption(GEM_HOMEPAGE, "gem homepage. ").
|
||||
defaultValue("http://swagger.io"));
|
||||
|
||||
cliOptions.add(new CliOption(GEM_SUMMARY, "gem summary. ").
|
||||
defaultValue("A ruby wrapper for the swagger APIs"));
|
||||
|
||||
cliOptions.add(new CliOption(GEM_DESCRIPTION, "gem description. ").
|
||||
defaultValue("This gem maps to a swagger API"));
|
||||
|
||||
cliOptions.add(new CliOption(GEM_AUTHOR, "gem author (only one is supported)."));
|
||||
|
||||
cliOptions.add(new CliOption(GEM_AUTHOR_EMAIL, "gem author email (only one is supported)."));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,11 +154,36 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
if (additionalProperties.containsKey(GEM_VERSION)) {
|
||||
setGemVersion((String) additionalProperties.get(GEM_VERSION));
|
||||
} else {
|
||||
}else {
|
||||
// not set, pass the default value to template
|
||||
additionalProperties.put(GEM_VERSION, gemVersion);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GEM_LICENSE)) {
|
||||
setGemLicense((String) additionalProperties.get(GEM_LICENSE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GEM_HOMEPAGE)) {
|
||||
setGemHomepage((String) additionalProperties.get(GEM_HOMEPAGE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GEM_SUMMARY)) {
|
||||
setGemSummary((String) additionalProperties.get(GEM_SUMMARY));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GEM_DESCRIPTION)) {
|
||||
setGemDescription((String) additionalProperties.get(GEM_DESCRIPTION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GEM_AUTHOR)) {
|
||||
setGemAuthor((String) additionalProperties.get(GEM_AUTHOR));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GEM_AUTHOR_EMAIL)) {
|
||||
setGemAuthorEmail((String) additionalProperties.get(GEM_AUTHOR_EMAIL));
|
||||
}
|
||||
|
||||
|
||||
// use constant model/api package (folder path)
|
||||
setModelPackage("models");
|
||||
setApiPackage("api");
|
||||
@@ -126,32 +195,42 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("api_error.mustache", gemFolder, "api_error.rb"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", gemFolder, "configuration.rb"));
|
||||
supportingFiles.add(new SupportingFile("version.mustache", gemFolder, "version.rb"));
|
||||
String modelFolder = gemFolder + File.separator + modelPackage.replace("/", File.separator);
|
||||
supportingFiles.add(new SupportingFile("base_object.mustache", modelFolder, "base_object.rb"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ruby";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Ruby client library.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Ruby module name from the gem name, e.g. use "SwaggerClient" for "swagger_client".
|
||||
*
|
||||
* @param gemName Ruby gem name
|
||||
* @return Ruby module naame
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String generateModuleName(String gemName) {
|
||||
return camelize(gemName.replaceAll("[^\\w]+", "_"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Ruby gem name from the module name, e.g. use "swagger_client" for "SwaggerClient".
|
||||
*
|
||||
* @param moduleName Ruby module naame
|
||||
* @return Ruby gem name
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String generateGemName(String moduleName) {
|
||||
return underscore(moduleName.replaceAll("[^\\w]+", ""));
|
||||
}
|
||||
@@ -166,10 +245,21 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return outputFolder + File.separator + libFolder + File.separator + gemName + File.separator + apiPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + libFolder + File.separator + gemName + File.separator + modelPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return outputFolder + File.separator + specFolder + File.separator + apiPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return outputFolder + File.separator + specFolder + File.separator + modelPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
@@ -236,13 +326,13 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
return type;
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@@ -254,7 +344,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -269,11 +359,13 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = camelize("object_" + name);
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
@@ -284,8 +376,10 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
if (isReservedWord(name)) {
|
||||
String filename = underscore("object_" + name);
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + filename);
|
||||
return filename;
|
||||
}
|
||||
|
||||
// underscore the model file name
|
||||
@@ -296,12 +390,22 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. PhoneNumberApi.rb => phone_number_api.rb
|
||||
return underscore(name) + "_api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiTestFilename(String name) {
|
||||
return toApiName(name) + "_spec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
return toModelName(name) + "_spec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
@@ -313,14 +417,18 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
// rename to empty_method_name_1 (e.g.) if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
operationId = underscore("empty_method_name_" + emptyMethodNameCounter++);
|
||||
LOGGER.warn("Empty method name (operationId) found. Renamed to " + operationId);
|
||||
return operationId;
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = underscore("call_" + operationId);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
return underscore(sanitizeName(operationId));
|
||||
@@ -347,4 +455,28 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setGemVersion(String gemVersion) {
|
||||
this.gemVersion = gemVersion;
|
||||
}
|
||||
|
||||
public void setGemDescription(String gemDescription) {
|
||||
this.gemDescription = gemDescription;
|
||||
}
|
||||
|
||||
public void setGemSummary(String gemSummary) {
|
||||
this.gemSummary = gemSummary;
|
||||
}
|
||||
|
||||
public void setGemLicense(String gemLicense) {
|
||||
this.gemLicense = gemLicense;
|
||||
}
|
||||
|
||||
public void setGemHomepage(String gemHomepage) {
|
||||
this.gemHomepage = gemHomepage;
|
||||
}
|
||||
|
||||
public void setGemAuthor(String gemAuthor) {
|
||||
this.gemAuthor = gemAuthor;
|
||||
}
|
||||
|
||||
public void setGemAuthorEmail(String gemAuthorEmail) {
|
||||
this.gemAuthorEmail = gemAuthorEmail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src/main/scala";
|
||||
protected String authScheme = "";
|
||||
protected boolean authPreemptive = false;
|
||||
protected boolean authPreemptive;
|
||||
protected boolean asyncHttpClient = !authScheme.isEmpty();
|
||||
|
||||
public ScalaClientCodegen() {
|
||||
@@ -47,8 +47,13 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"path", "contentTypes", "contentType", "queryParams", "headerParams",
|
||||
"formParams", "postBody", "mp", "basePath", "apiInvoker",
|
||||
|
||||
// scala reserved words
|
||||
"abstract", "case", "catch", "class", "def", "do", "else", "extends",
|
||||
"false", "final", "finally", "for", "forSome", "if", "implicit",
|
||||
"import", "lazy", "match", "new", "null", "object", "override", "package",
|
||||
@@ -91,6 +96,9 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("object", "Any");
|
||||
typeMapping.put("file", "File");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "String");
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
@@ -112,14 +120,17 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "scala";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Scala client library.";
|
||||
}
|
||||
@@ -134,6 +145,7 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
@@ -183,6 +195,7 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
return "null";
|
||||
@@ -222,7 +235,7 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
apiPackage = "com.wordnik.client.api";
|
||||
modelPackage = "com.wordnik.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
@@ -67,6 +67,9 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("long", "Long");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "String");
|
||||
|
||||
additionalProperties.put("appName", "Swagger Sample");
|
||||
additionalProperties.put("appName", "Swagger Sample");
|
||||
@@ -123,14 +126,17 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "scalatra";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Scala server application with Scalatra.";
|
||||
}
|
||||
@@ -145,6 +151,7 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
embeddedTemplateDir = templateDir = "silex";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor")
|
||||
);
|
||||
@@ -65,7 +65,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
instantiationTypes.put("array", "array");
|
||||
instantiationTypes.put("map", "map");
|
||||
|
||||
// ref: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#data-types
|
||||
// ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("long", "int");
|
||||
@@ -81,6 +81,9 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("array", "array");
|
||||
typeMapping.put("list", "array");
|
||||
typeMapping.put("object", "object");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", packagePath.replace('/', File.separatorChar), "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.json", packagePath.replace('/', File.separatorChar), "composer.json"));
|
||||
@@ -88,14 +91,17 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
supportingFiles.add(new SupportingFile(".htaccess", packagePath.replace('/', File.separatorChar), ".htaccess"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "silex-PHP";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Silex server library.";
|
||||
}
|
||||
@@ -110,6 +116,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return (outputFolder + "/" + apiPackage()).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + "/" + modelPackage()).replace('/', File.separatorChar);
|
||||
}
|
||||
@@ -148,6 +155,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
@@ -157,7 +165,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public String toVarName(String name) {
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
name = underscore(name);
|
||||
name = underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// parameter name starting with number won't compile
|
||||
// need to escape it by appending _ at the beginning
|
||||
@@ -177,7 +185,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
escapeReservedWord(name); // e.g. return => _return
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.swagger.codegen.languages;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
@@ -19,10 +18,15 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String gemName = null;
|
||||
protected String moduleName = null;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SinatraServerCodegen.class);
|
||||
|
||||
protected String gemName;
|
||||
protected String moduleName;
|
||||
protected String gemVersion = "1.0.0";
|
||||
protected String libFolder = "lib";
|
||||
|
||||
@@ -39,7 +43,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
typeMapping.clear();
|
||||
languageSpecificPrimitives.clear();
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
|
||||
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
|
||||
@@ -60,6 +64,9 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
typeMapping.put("String", "string");
|
||||
typeMapping.put("List", "array");
|
||||
typeMapping.put("map", "map");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
cliOptions.clear();
|
||||
@@ -81,14 +88,17 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
supportingFiles.add(new SupportingFile("swagger.mustache","","swagger.yaml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "sinatra";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Sinatra server library.";
|
||||
}
|
||||
@@ -135,6 +145,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
@@ -142,7 +153,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@@ -154,7 +165,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
name = underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@@ -170,7 +181,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@@ -182,7 +193,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@@ -194,7 +205,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. PhoneNumberApi.rb => phone_number_api.rb
|
||||
return underscore(name) + "_api";
|
||||
@@ -212,7 +223,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
@@ -226,7 +237,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
try {
|
||||
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
embeddedTemplateDir = templateDir = "slim";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor")
|
||||
);
|
||||
@@ -67,7 +67,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
instantiationTypes.put("array", "array");
|
||||
instantiationTypes.put("map", "map");
|
||||
|
||||
// ref: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#data-types
|
||||
// ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("long", "int");
|
||||
@@ -83,6 +83,9 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
typeMapping.put("array", "array");
|
||||
typeMapping.put("list", "array");
|
||||
typeMapping.put("object", "object");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", packagePath.replace('/', File.separatorChar), "README.md"));
|
||||
supportingFiles.add(new SupportingFile("composer.json", packagePath.replace('/', File.separatorChar), "composer.json"));
|
||||
@@ -90,14 +93,17 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
supportingFiles.add(new SupportingFile(".htaccess", packagePath.replace('/', File.separatorChar), ".htaccess"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "slim";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Slim Framework server library.";
|
||||
}
|
||||
@@ -112,6 +118,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
return (outputFolder + "/" + apiPackage()).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return (outputFolder + "/" + modelPackage()).replace('/', File.separatorChar);
|
||||
}
|
||||
@@ -162,6 +169,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
return super.getTypeDeclaration(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
@@ -172,8 +180,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
if ("camelCase".equals(variableNamingConvention)) {
|
||||
// return the name in camelCase style
|
||||
@@ -203,7 +210,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
escapeReservedWord(name); // e.g. return => _return
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user