openapi-generator/online-openapi-generator.md
William Cheng c32ef12c8e
Update documentation (#184)
* update documentation

* fix broken links

* minor fix

* add more section

* add line break to license

* add list of founding members

* fix typo
2018-04-22 21:34:55 +08:00

2.6 KiB

Online OpenAPI generator

One can also generate API client or server using the online openapi-generator.

Here are the steps to run it locally:

mvn clean install
cd openapi-generator-online
mvn jetty:run

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

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

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

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

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

in which the options for a language can be obtained by submitting a GET request to https://locahost:8080/api/gen/clients/{language}:

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

  "packageName":{
    "opt":"packageName",
    "description":"python package name (convention: snake_case).",
    "type":"string",
    "default":"openapi_client"
  },
  "packageVersion":{
    "opt":"packageVersion",
    "description":"python package version.",
    "type":"string",
    "default":"1.0.0"
  },
  "sortParamsByRequiredFlag":{
    "opt":"sortParamsByRequiredFlag",
    "description":"Sort method arguments to place required parameters before optional parameters.",
    "type":"boolean",
    "default":"true"
  }

{}

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

{
  "options": {
    "packageName": "pet_store"
  },
  "swaggerUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml"
}

and here is the curl command:

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

Instead of using swaggerUrl with an URL to the OpenAPI spec, one can include the spec in the JSON payload with spec, e.g.

{
  "options": {},
  "spec": {
    "swagger": "2.0",
    "info": {
      "version": "1.0.0",
      "title": "Test API"
    },
    ...
  }
}