Skip to content

Instantly share code, notes, and snippets.

@markns
Created December 29, 2017 13:53
Show Gist options
  • Save markns/c3751208834aeec64af3cb968189eb58 to your computer and use it in GitHub Desktop.
Save markns/c3751208834aeec64af3cb968189eb58 to your computer and use it in GitHub Desktop.
auth0 go swagger client generation
#!/usr/bin/env bash
base_url=https://${tenant}.auth0.com/api/v2/api-docs
api-spec-converter ${base_url}/Client%20Grants --from=swagger_1 --to=swagger_2 > swagger/client-grants.json
api-spec-converter ${base_url}/Clients --from=swagger_1 --to=swagger_2 > swagger/clients.json
api-spec-converter ${base_url}/Connections --from=swagger_1 --to=swagger_2 > swagger/connections.json
api-spec-converter ${base_url}/Device%20Credentials --from=swagger_1 --to=swagger_2 > swagger/device-credentials.json
api-spec-converter ${base_url}/Grants --from=swagger_1 --to=swagger_2 > swagger/grants.json
api-spec-converter ${base_url}/Logs --from=swagger_1 --to=swagger_2 > swagger/logs.json
api-spec-converter ${base_url}/Resource%20Servers --from=swagger_1 --to=swagger_2 > swagger/resource-servers.json
api-spec-converter ${base_url}/Rules --from=swagger_1 --to=swagger_2 > swagger/rules.json
api-spec-converter ${base_url}/User%20Blocks --from=swagger_1 --to=swagger_2 > swagger/user-blocks.json
api-spec-converter ${base_url}/Users --from=swagger_1 --to=swagger_2 > swagger/users.json
api-spec-converter ${base_url}/Blacklists --from=swagger_1 --to=swagger_2 > swagger/blacklists.json
api-spec-converter ${base_url}/Emails --from=swagger_1 --to=swagger_2 > swagger/emails.json
api-spec-converter ${base_url}/Guardian --from=swagger_1 --to=swagger_2 > swagger/guardian.json
api-spec-converter ${base_url}/Jobs --from=swagger_1 --to=swagger_2 > swagger/jobs.json
api-spec-converter ${base_url}/Stats --from=swagger_1 --to=swagger_2 > swagger/stats.json
api-spec-converter ${base_url}/Tenants --from=swagger_1 --to=swagger_2 > swagger/tenants.json
api-spec-converter ${base_url}/Admin --from=swagger_1 --to=swagger_2 > swagger/admin.json
api-spec-converter ${base_url}/Tickets --from=swagger_1 --to=swagger_2 > swagger/tickets.json
python merge-swagger.py
swagger generate client -f swagger.json -A auth0_management --skip-validation --target ../../../auth0-management
import json
import os
swagger = None
for filename in os.listdir("swagger"):
component = json.load(open(os.path.join("swagger", filename)))
if not swagger:
swagger = component
else:
swagger['paths'].update(component['paths'])
swagger['definitions'].update(component['definitions'])
# fuck you auth0
# https://community.auth0.com/questions/9720/discrepancy-between-the-resource-server-api-respon
for t in ['get_resource-servers_by_id_response', 'get_resource-servers_response']:
x = swagger['definitions'][t]['properties']
x['id'] = {"description": "The id of the resource server.", "type": "string"}
x['name'] = {"description": "The name of the resource server.", "type": "string"}
json.dump(swagger, open("swagger.json", "w"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment