Skip to content
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

Allow BaseModel keywords as option names #10715

Merged
merged 1 commit into from
Nov 23, 2021
Merged
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
Allow keywords as defaults
  • Loading branch information
sarah-witt committed Nov 23, 2021
commit b986b1f3dae98456decd1e57e7465a7cfb5f6740
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from datamodel_code_generator.format import CodeFormatter, PythonVersion
from datamodel_code_generator.parser import LiteralType
from datamodel_code_generator.parser.openapi import OpenAPIParser
from pydantic import BaseModel

from ..constants import OPENAPI_SCHEMA_PROPERTIES
from ..utils import sanitize_openapi_object_properties
Expand All @@ -23,7 +24,7 @@

def normalize_option_name(option_name):
# https://github.com/koxudaxi/datamodel-code-generator/blob/0.8.3/datamodel_code_generator/model/base.py#L82-L84
if iskeyword(option_name):
if iskeyword(option_name) or hasattr(BaseModel, option_name):
option_name += '_'

return option_name.replace('-', '_')
Expand Down