Skip to content

Commit a97dad1

Browse files
rtaycherdbanty
andauthored
Switch YAML parser to ruamel.yaml which uses YAML 1.2 (openapi-generators#1042)
fixes openapi-generators#1041 ruamel.yaml understands yaml1.2 which yaml doesn't support. yaml 1.2 lacks norway issue --------- Co-authored-by: Dylan Anthony <dbanty@users.noreply.github.com>
1 parent 9b55d70 commit a97dad1

File tree

6 files changed

+434
-464
lines changed

6 files changed

+434
-464
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
default: major
3+
---
4+
5+
# Switch YAML parsing to 1.2
6+
7+
This change switches the YAML parsing library to `ruamel.yaml` which follows the YAML 1.2 specification.
8+
[There are breaking changes](https://yaml.readthedocs.io/en/latest/pyyaml/#defaulting-to-yaml-12-support) from YAML 1.1 to 1.2,
9+
though they will not affect most use cases.
10+
11+
PR #1042 fixes #1041. Thanks @rtaycher!

openapi_python_client/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
import httpcore
1313
import httpx
14-
import yaml
1514
from jinja2 import BaseLoader, ChoiceLoader, Environment, FileSystemLoader, PackageLoader
15+
from ruamel.yaml import YAML
16+
from ruamel.yaml.error import YAMLError
1617

1718
from openapi_python_client import utils
1819

@@ -350,8 +351,9 @@ def _load_yaml_or_json(data: bytes, content_type: Optional[str]) -> Union[Dict[s
350351
return GeneratorError(header=f"Invalid JSON from provided source: {err}")
351352
else:
352353
try:
353-
return yaml.safe_load(data)
354-
except yaml.YAMLError as err:
354+
yaml = YAML(typ="safe")
355+
return yaml.load(data)
356+
except YAMLError as err:
355357
return GeneratorError(header=f"Invalid YAML from provided source: {err}")
356358

357359

openapi_python_client/config.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from pathlib import Path
55
from typing import Dict, List, Optional, Union
66

7-
import yaml
87
from attr import define
98
from pydantic import BaseModel
9+
from ruamel.yaml import YAML
1010

1111

1212
class ClassOverride(BaseModel):
@@ -51,7 +51,8 @@ def load_from_path(path: Path) -> "ConfigFile":
5151
if mime == "application/json":
5252
config_data = json.loads(path.read_text())
5353
else:
54-
config_data = yaml.safe_load(path.read_text())
54+
yaml = YAML(typ="safe")
55+
config_data = yaml.load(path)
5556
config = ConfigFile(**config_data)
5657
return config
5758

0 commit comments

Comments
 (0)