Skip to content

feat: add option to not prepend path to Model Classes with title names #560

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

Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions openapi_python_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Config(BaseModel):
project_name_override: Optional[str]
package_name_override: Optional[str]
package_version_override: Optional[str]
use_path_prefixes_for_title_model_names: bool = True
post_hooks: List[str] = [
"autoflake -i -r --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports .",
"isort .",
Expand Down
11 changes: 8 additions & 3 deletions openapi_python_client/parser/properties/model_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,14 @@ def build_model_property(
parent_name: The name of the property that this property is inside of (affects class naming)
config: Config data for this run of the generator, used to modifying names
"""
class_string = data.title or name
if parent_name:
class_string = f"{utils.pascal_case(parent_name)}{utils.pascal_case(class_string)}"
if not config.use_path_prefixes_for_title_model_names and data.title:
class_string = data.title
else:
title = data.title or name
if parent_name:
class_string = f"{utils.pascal_case(parent_name)}{utils.pascal_case(title)}"
else:
class_string = title
class_info = Class.from_string(string=class_string, config=config)

property_data = _process_properties(data=data, schemas=schemas, class_name=class_info.name, config=config)
Expand Down