Hosted

We offer online services, publicly and free of charge:

Hosting Sponsor Linode Logo

These services are beta and do not have any guarantee on service level

Docker Image

The openapi-generator-online Docker image can act as a self-hosted web application and API for generating code. This container can be incorporated into a CI pipeline, and requires at least two HTTP requests and some docker orchestration to access generated code.

Example usage:

  1. # Start container at port 8888 and save the container id
  2. CID=$(docker run -d -p 8888:8080 openapitools/openapi-generator-online)
  3. # allow for startup
  4. sleep 10
  5. # Get the IP of the running container (optional)
  6. GEN_IP=$(docker inspect --format '{{.NetworkSettings.IPAddress}}' ${CID})
  7. # Execute an HTTP request to generate a Ruby client
  8. curl -X POST --header 'Content-Type: application/json' \
  9. --header 'Accept: application/json' \
  10. -d '{"openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml"}' \
  11. 'http://localhost:8888/api/gen/clients/ruby'
  12. # Example output:
  13. # {"code":"c2d483.3.4672-40e9-91df-b9ffd18d22b8","link":"http://localhost:8888/api/gen/download/c2d483.3.4672-40e9-91df-b9ffd18d22b8"}
  14. # Download the generated zip file (using "code" provided from your output)
  15. wget http://localhost:8888/api/gen/download/c2d483.3.4672-40e9-91df-b9ffd18d22b8
  16. # Unzip the file
  17. unzip c2d483.3.4672-40e9-91df-b9ffd18d22b8
  18. # Shutdown the openapi generator image
  19. docker stop ${CID} && docker rm ${CID}

Local/Self-hosting

If you prefer to run the service locally, here are the steps:

  1. mvn clean install
  2. cd modules/openapi-generator-online
  3. mvn spring-boot:run

The online openapi-generator can be run via Docker as well.

For example, to generate Ruby API client, simply send the following HTTP request using curl:

  1. curl -X POST -H "content-type:application/json" -d '{"openAPIUrl":"https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml"}' \
  2. http://localhost:8080/api/gen/clients/ruby

Then you will receive a JSON response with the URL to download the zipped code.

To customize the SDK, you can POST to http://localhost:8080/gen/clients/{generator} with the following HTTP body:

  1. {
  2. "options": {},
  3. "openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml"
  4. }

Here, the options for a language can be obtained by submitting a GET request to http://locahost:8080/api/gen/clients/{generator}:

For example, curl http://localhost:8080/api/gen/clients/python returns

  1. "packageName":{
  2. "opt":"packageName",
  3. "description":"python package name (convention: snake_case).",
  4. "type":"string",
  5. "default":"openapi_client"
  6. },
  7. "packageVersion":{
  8. "opt":"packageVersion",
  9. "description":"python package version.",
  10. "type":"string",
  11. "default":"1.0.0"
  12. },
  13. "sortParamsByRequiredFlag":{
  14. "opt":"sortParamsByRequiredFlag",
  15. "description":"Sort method arguments to place required parameters before optional parameters.",
  16. "type":"boolean",
  17. "default":"true"
  18. }
  19. {}

To set package name to pet_store, the HTTP body of the request is as follows:

  1. {
  2. "options": {
  3. "packageName": "pet_store"
  4. },
  5. "openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml"
  6. }

and here is the curl command:

  1. curl -H "Content-type: application/json" \
  2. -X POST \
  3. -d '{"options": {"packageName": "pet_store"},"openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml"}' \
  4. http://localhost:8080/api/gen/clients/python

Instead of using openAPIUrl with an URL to the OpenAPI spec, one can include the spec in the JSON payload with spec:

  1. {
  2. "options": {},
  3. "spec": {
  4. "swagger": "2.0",
  5. "info": {
  6. "version": "1.0.0",
  7. "title": "Test API"
  8. },
  9. ...
  10. }
  11. }