diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e7dff9e..3e8680f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,8 +6,10 @@ "type": "shell", "linux": { "command": [ + "source .venv/bin/activate;", "python3 tools/build.py;", "java -jar openapi-generator-cli.jar generate -c test/python/openapi-generator-config.yaml -g python;", + "python3 test/python/replace.py;", "python3 -m pip install ./python_generated;" ] }, @@ -16,6 +18,7 @@ ".venv/Scripts/activate;", "python tools/build.py;", "java -jar openapi-generator-cli.jar generate -c test/python/openapi-generator-config.yaml -g python;", + "python test/python/replace.py;", "python -m pip install ./python_generated;" ] } diff --git a/test/python/replace.py b/test/python/replace.py new file mode 100644 index 0000000..ab9b5f9 --- /dev/null +++ b/test/python/replace.py @@ -0,0 +1,23 @@ +import glob + +for file in glob.glob("python_generated/openapi_client/models/*.py"): + with open(file, "r") as f: + text = f.read() + + indent = " " + + text = text.replace( + f"{indent}{indent}try:", + f"{indent}{indent}if match == 0:", + ) + text = text.replace( + f"{indent}{indent}except (ValidationError, ValueError) as e:", + f"{indent}{indent}else:", + ) + text = text.replace( + f"{indent}{indent}{indent}error_messages.append(str(e))", + f"{indent}{indent}{indent}pass", + ) + + with open(file, "w") as f: + f.write(text)