Created
December 14, 2017 19:58
-
-
Save ramnov/65fdea2dda910e7a27a9ca92a94dc605 to your computer and use it in GitHub Desktop.
python script to generate client from swagger file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ----------------------------------------------------# | |
# GENERATE CLIENT FROM SWAGGER JSON | |
# ----------------------------------------------------# | |
# Generate client in C# using the swagger json file | |
import urllib, requests, json, ssl, os | |
service_name = 'ManualTransmissionService' | |
f = open('manual-transmission-service-swagger.json', "r") | |
swagger = f.read() | |
payload = { 'options' : { 'packageName' : service_name }, 'spec' : json.loads(swagger) } | |
# List of supported clients : http://generator.swagger.io/api/gen/clients | |
# Change csharp in url to java if you wish generate java client. | |
r = requests.post("http://generator.swagger.io/api/gen/clients/csharp",\ | |
headers = { "content-type" : "application/json"},\ | |
data = json.dumps(payload)) | |
ssl._create_default_https_context = ssl._create_unverified_context | |
urllib.request.urlretrieve(json.loads(r.text)['link'], "{}.zip".format(service_name)) | |
print("Client code location : {}".format(os.path.join(os.getcwd() , "{}.zip".format(service_name)))) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment