Swagger Codegen Online Generators
One can also generate API client or server using the online generators (https://generator.swagger.io)
For example, to generate Ruby API client, simply send the following HTTP request using curl:
1curl -X POST -H "content-type:application/json" -d '{"swaggerUrl":"https://petstore.swagger.io/v2/swagger.json"}' https://generator.swagger.io/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 https://generator.swagger.io/api/gen/clients/{language}
with the following HTTP body:
1{2 "options": {},3 "swaggerUrl": "https://petstore.swagger.io/v2/swagger.json"4}
in which the options
for a language can be obtained by submitting a GET
request to https://generator.swagger.io/api/gen/clients/{language}
:
For example, curl https://generator.swagger.io/api/gen/clients/python
returns
1{2 "packageName": {3 "opt": "packageName",4 "description": "python package name (convention: snake_case).",5 "type": "string",6 "default": "swagger_client"7 },8 "packageVersion": {9 "opt": "packageVersion",10 "description": "python package version.",11 "type": "string",12 "default": "1.0.0"13 },14 "sortParamsByRequiredFlag": {15 "opt": "sortParamsByRequiredFlag",16 "description": "Sort method arguments to place required parameters before optional parameters.",17 "type": "boolean",18 "default": "true"19 }20}
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 "swaggerUrl": "https://petstore.swagger.io/v2/swagger.json"6}
and here is the curl command:
1curl -H "Content-type: application/json" -X POST -d '{"options": {"packageName": "pet_store"},"swaggerUrl": "https://petstore.swagger.io/v2/swagger.json"}' https://generator.swagger.io/api/gen/clients/python
Instead of using swaggerUrl
with an URL to the OpenAPI/Swagger spec, one can include the spec in the JSON payload with spec
, e.g.
1{2 "options": {},3 "spec": {4 "swagger": "2.0",5 "info": {6 "version": "1.0.0",7 "title": "Test API"8 },9 ...10 }11}