Skip to content

Commit 8e0d043

Browse files
authored
Merge pull request #83 from Asana/johnvu-change-add-step-to-convert-yaml-to-json-for-readme
Convert YAML to JSON for readme docs
2 parents c68ae4a + 5ce6c12 commit 8e0d043

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

.github/workflows/push_openapi_spec_to_readme.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,18 @@ jobs:
3030
parse-json-secrets: true
3131
- name: Check out repo 📚
3232
uses: actions/checkout@v5
33+
- name: Set up Python 🐍
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.x'
37+
- name: Install Python dependencies 📦
38+
run: |
39+
python -m pip install --upgrade pip
40+
pip install pyyaml
41+
- name: Convert YAML to JSON 🔄
42+
run: python convert_yaml_to_json.py
3343
- name: Run `openapi` command 🚀
3444
uses: readmeio/rdme@v10
3545
with:
3646
# id is the id of the API definition
37-
rdme: openapi upload defs/asana_oas.yaml --key=${{ env.README_API_KEY }} --slug=asana
47+
rdme: openapi upload defs/asana_oas.json --key=${{ env.README_API_KEY }} --slug=asana

convert_yaml_to_json.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Convert YAML OpenAPI specification to JSON format.
4+
"""
5+
6+
import json
7+
import yaml
8+
import os
9+
from pathlib import Path
10+
11+
12+
def convert_yaml_to_json():
13+
"""Convert YAML OpenAPI specifications to JSON format."""
14+
script_dir = Path(__file__).parent
15+
16+
# Files to convert
17+
yaml_files = [
18+
"asana_oas.yaml",
19+
"app_components_oas.yaml"
20+
]
21+
22+
for yaml_filename in yaml_files:
23+
yaml_file = script_dir / "defs" / yaml_filename
24+
json_filename = yaml_filename.replace('.yaml', '.json')
25+
json_file = script_dir / "defs" / json_filename
26+
27+
if not yaml_file.exists():
28+
print(f"Warning: YAML file not found: {yaml_file}")
29+
continue
30+
31+
# Load YAML file
32+
with open(yaml_file, 'r', encoding='utf-8') as f:
33+
yaml_data = yaml.safe_load(f)
34+
35+
# Write JSON file
36+
with open(json_file, 'w', encoding='utf-8') as f:
37+
json.dump(yaml_data, f, indent=2, ensure_ascii=False)
38+
39+
print(f"Successfully converted {yaml_file} to {json_file}")
40+
41+
42+
if __name__ == "__main__":
43+
convert_yaml_to_json()

0 commit comments

Comments
 (0)