-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Server stub generator HOWTO
Here is the documentation to generate a server stub for a couple different frameworks. If you want to contribute to make it better, please click on the "Edit" button to update the documentation.
- Erlang
- Node.js
- PHP Lumen
- PHP Slim
- PHP Silex
- Python Flask (Connexion)
- Python2 Flask (Connexion)
- Ruby on Rails5
- Ruby Sinatra
- Scala Scalatra
- Java JAX-RS 2.0 spec
- Java JAX-RS (Java JAX-RS (Jersey)
- Java JAX-RS (Apache CXF 2 / 3)
- Java JAX-RS (Resteasy)
- Java JAX-RS (Apache CXF framework on Java EE server supporting CDI)
- Java Spring MVC
- Java SpringBoot
- Java Undertow
- Java MSF4J
- Haskell Servant
- ASP.NET Core 1.0
- Go Server
- NancyFX
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g erlang-server \
-o samples/server/petstore/erlang
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
mvn clean package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g nodejs-server \
-o samples/server/petstore/nodejs
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
mvn clean package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g nodejs-server --additional-properties=googleCloudFunctions=true \
-o samples/server/petstore/nodejs-google-cloud-function
https://cloud.google.com/functions/docs/quickstart is a good starting point on how to deploy the generated code.
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
mvn clean package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g php-lumen \
-o samples/server/petstore/php-lumen
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
mvn clean package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g php-slim \
-o samples/server/petstore/php-slim
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
mvn clean package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g php-silex \
-o samples/server/petstore/php-silex
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g python-flask \
-o samples/server/petstore/flaskConnexion
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g python-flask \
-o samples/server/petstore/flaskConnexion-python2 \
-D supportPython2=true
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g rails5 \
-o samples/server/petstore/rails5
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g sinatra \
-o samples/server/petstore/sinatra
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g scalatra \
-o samples/server/petstore/scalatra
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g jaxrs-spec \
-o samples/server/petstore/jaxrs-spec
The default use Jersey 2.x
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g jaxrs \
-o samples/server/petstore/jaxrs/jersey2
To use Jersey 1.x:
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g jaxrs --library=jersey1 \
-o samples/server/petstore/jaxrs/jersey1
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g jaxrs-cxf \
-o samples/server/petstore/jaxrs-cxf
This Codegen only generate a minimalist server stub. You must add the CXF dependency to your classpath (eg: with Maven)
This Codegen will generate a complete web application stub.
The following features are supported using CLI-options:
- add beanvalidation annotations / use automatic serverside beanvalidation
- use the CXF3 Swagger2Feature for supplying a generated Swagger contract
- include Swagger-UI as a web-jar
- use the CXF WADLGenerator for supplying a generated WADL contract
- provide test classes for each operation (using JAXRSClientFactory)
- configuration dependencies:
- Jackson is used as provider (is already included as dependency of swagger-jaxrs)
- Spring is used for configuration of CXF
- use Spring-Boot for startup and for integration testing
- configuration file for Jboss is included (jboss-web.xml)
If you are using CXF v2.x, you must provided a custom ResourceComparator
class. This class will help CXF to choose the good resource interface for mapping an incomming request. The default behavior of CXF v2.x is not correct when many resources interface have the same global path.
See: See http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources
You can found this class here: https://github.com/hiveship/CXF2-resource-comparator/blob/master/src/main/java/CXFInterfaceComparator.java TODO: This class could be directly generated by the Codegen.
You must register this class into your JAX-RS configuration file:
<jaxrs:resourceComparator>
<bean class="your.package.CXFInterfaceComparator"/>
</jaxrs:resourceComparator>
This is no longer necessary if you are using CXF >=v3.x
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g jaxrs-resteasy \
-o samples/server/petstore/jaxrs-resteasy/default
Since 2.2.2
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g jaxrs-resteasy-eap \
-o samples/server/petstore/jaxrs-resteasy/eap
The following features are supported using CLI-options:
- This language will generate separate impl/interfaces.
- add beanvalidation annotations / use automatic serverside beanvalidation
- use the Resteasy SwaggerFeature for supplying a generated Swagger contract
- configuration file for Jboss is included (jboss-web.xml)
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g jaxrs-cxf-cdi \
-o samples/server/petstore/jaxrs-cxf-cdi
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g spring --library spring-mvc\
-o samples/server/petstore/spring-mvc
spring
generator uses SpringBoot
as the default library
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g spring \
-o samples/server/petstore/springboot
You can also set a Json file with basePackage & configPackage properties :
Example :
{
"basePackage":"io.swagger",
"configPackage":"io.swagger.config"
}
For use it add option -c myOptions.json
to the generation command
To Use-it :
in the generated folder try mvn package
for build jar.
Start your server java -jar target/swagger-springboot-server-1.0.0.jar
SpringBoot listening on default port 8080
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g undertow \
-o samples/server/petstore/undertow
Java Micro Services Framework For Java
MSF4J generator uses java-msf4j as the default library
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g msf4j \
-o samples/server/petstore/msf4j
Before you build/run service replace .deploy(new PetApi()) with your actual service class name in Application.java file like .deploy(new ApisAPI()) then it will start that service. If you have multiple service classes add them in , separated manner.
new MicroservicesRunner()
.deploy(new PetApi())
.start();
To Use-it : in the generated folder try mvn package
for build jar, then start your server: java -jar target/micro-service-server-1.0.0.jar
(Java Microservice listening on default port 8080)
Run the following command or simply go to http://127.0.0.1:8080/pet/12 from your browser:
curl http://127.0.0.1:8080/pet/12
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g haskell-servant \
-o samples/server/petstore/haskell-servant
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g aspnetcore \
-o samples/server/petstore/aspnet5
aspnet5
has been deprecated. Please use aspnetcore
instead.
If you're using Windows 10, please run the following to avoid any potential issue with file encoding:
set JAVA_OPTS=-Dfile.encoding=UTF-8
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
mvn clean package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g go-server \
-o samples/server/petstore/go-server
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
mvn clean package
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i http://petstore.swagger.io/v2/swagger.json \
-g nancyfx \
-o samples/server/petstore/nancyfx
- ada-server
- aspnetcore
- cpp-pistache-server
- cpp-restbed-server
- csharp-nancyfx
- erlang-server
- go-server
- haskell
- java-inflector
- java-msf4j
- java-pkmst
- java-play-framework
- java-undertow-server
- java-vertx
- jaxrs-cxf
- jaxrs-cxf-cdi
- jaxrs-jersey
- jaxrs-resteasy
- jaxrs-resteasy-eap
- jaxrs-spec
- kotlin-server
- nodejs-server
- php-lumen
- php-silex
- php-slim
- php-symfony
- php-ze-ph
- python-flask
- ruby-on-rails
- ruby-sinatra
- rust-server
- scala-finch
- scala-lagom-server
- scalatra
- spring