docs_src/generate_clients/tutorial004_py310.py
raw| 1 | import json |
| 2 | from pathlib import Path |
| 3 | |
| 4 | file_path = Path("./openapi.json") |
| 5 | openapi_content = json.loads(file_path.read_text()) |
| 6 | |
| 7 | for path_data in openapi_content["paths"].values(): |
| 8 | for operation in path_data.values(): |
| 9 | tag = operation["tags"][0] |
| 10 | operation_id = operation["operationId"] |
| 11 | to_remove = f"{tag}-" |
| 12 | new_operation_id = operation_id[len(to_remove) :] |
| 13 | operation["operationId"] = new_operation_id |
| 14 | |
| 15 | file_path.write_text(json.dumps(openapi_content)) |