Skip to content

Instantly share code, notes, and snippets.

@wlinds
Created February 4, 2025 15:27
Show Gist options
  • Save wlinds/e26dd09f6d255cc05f6704bbd3cc8d94 to your computer and use it in GitHub Desktop.
Save wlinds/e26dd09f6d255cc05f6704bbd3cc8d94 to your computer and use it in GitHub Desktop.
openapi_to_excel.py
import json
import requests
import pandas as pd
def openapi_to_excel(url, output_file):
response = requests.get(url)
spec = response.json()
first_path = next(iter(spec['paths']))
print(f"Example path structure for {first_path}:")
print(json.dumps(spec['paths'][first_path], indent=2))
data = []
for path, path_info in spec['paths'].items():
for method, details in path_info.items():
if method.upper() in ['GET', 'POST']:
data.append({
'Method': method.upper(),
'Endpoint': path,
'Description': details.get('summary', '') or details.get('description', ''),
'Parameters': str([p.get('name') for p in details.get('parameters', [])]),
'Schema': str(details.get('requestBody', {}).get('content', {}).get('application/json', {}).get('schema', {}))
})
df = pd.DataFrame(data).to_excel(output_file, index=False)
openapi_to_excel('http://localhost:5000/openapi.json', 'api_documentation.xlsx')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment