forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
40 lines (29 loc) · 1.25 KB
/
config.py
File metadata and controls
40 lines (29 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pathlib import Path
from typing import Dict, Optional
import yaml
from pydantic import BaseModel
class ClassOverride(BaseModel):
class_name: str
module_name: str
class Config(BaseModel):
class_overrides: Optional[Dict[str, ClassOverride]]
project_name_override: Optional[str]
package_name_override: Optional[str]
field_prefix: Optional[str]
def load_config(self) -> None:
""" Sets globals based on Config """
from openapi_python_client import Project
from . import utils
from .parser import reference
if self.class_overrides is not None:
for class_name, class_data in self.class_overrides.items():
reference.class_overrides[class_name] = reference.Reference(**dict(class_data))
Project.project_name_override = self.project_name_override
Project.package_name_override = self.package_name_override
if self.field_prefix is not None:
utils.FIELD_PREFIX = self.field_prefix
@staticmethod
def load_from_path(path: Path) -> None:
""" Creates a Config from provided JSON or YAML file and sets a bunch of globals from it """
config_data = yaml.safe_load(path.read_text())
Config(**config_data).load_config()