Skip to content

Add a setting to override the package version #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add a setting to override the package version
A generate package version actually depends on the version of the
OpenAPI spec and on the version of the generator. Upgrading the
generator version may break backward compatibility of the client. This
gives the user the possibility to bump its client version to reflect
changes in the generated code even though the spec has not changed.
  • Loading branch information
fyhertz committed Nov 3, 2020
commit d5a7c71ee8f8bc0cf2605b105c558a8cdecd91ed
3 changes: 2 additions & 1 deletion openapi_python_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Project:
TEMPLATE_FILTERS = {"snakecase": utils.snake_case, "kebabcase": utils.kebab_case}
project_name_override: Optional[str] = None
package_name_override: Optional[str] = None
package_version_override: Optional[str] = None

def __init__(self, *, openapi: GeneratorData) -> None:
self.openapi: GeneratorData = openapi
Expand All @@ -42,7 +43,7 @@ def __init__(self, *, openapi: GeneratorData) -> None:
self.package_description: str = utils.remove_string_escapes(
f"A client library for accessing {self.openapi.title}"
)
self.version: str = openapi.version
self.version: str = self.package_version_override or openapi.version

self.env.filters.update(self.TEMPLATE_FILTERS)

Expand Down
2 changes: 2 additions & 0 deletions openapi_python_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Config(BaseModel):
class_overrides: Optional[Dict[str, ClassOverride]]
project_name_override: Optional[str]
package_name_override: Optional[str]
package_version_override: Optional[str]
field_prefix: Optional[str]

def load_config(self) -> None:
Expand All @@ -29,6 +30,7 @@ def load_config(self) -> None:

Project.project_name_override = self.project_name_override
Project.package_name_override = self.package_name_override
Project.package_version_override = self.package_version_override

if self.field_prefix is not None:
utils.FIELD_PREFIX = self.field_prefix
Expand Down
9 changes: 7 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ def test_class_overrides(self):
assert reference.class_overrides["Class1"] == reference.Reference(**override1)
assert reference.class_overrides["Class2"] == reference.Reference(**override2)

def test_project_and_package_name_overrides(self):
config = Config(project_name_override="project-name", package_name_override="package_name")
def test_project_and_package_name_and_package_version_overrides(self):
config = Config(
project_name_override="project-name",
package_name_override="package_name",
package_version_override="package_version",
)
config.load_config()

from openapi_python_client import Project

assert Project.project_name_override == "project-name"
assert Project.package_name_override == "package_name"
assert Project.package_version_override == "package_version"

def test_field_prefix(self):
Config(field_prefix="blah").load_config()
Expand Down