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

Fix parameter field name #446

Merged
merged 1 commit into from
Dec 14, 2024
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
9 changes: 4 additions & 5 deletions fastapi_code_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,12 @@ def get_parameter_type(
path: List[str],
) -> Optional[Argument]:
parameters = self.resolve_object(parameters, ParameterObject)
if parameters.name is None:
raise RuntimeError("parameters.name is None") # pragma: no cover
orig_name = parameters.name
name = self.model_resolver.get_valid_field_name(parameters.name)
if snake_case:
name = stringcase.snakecase(parameters.name)
else:
name = parameters.name
name = stringcase.snakecase(name)

schema: Optional[JsonSchemaObject] = None
data_type: Optional[DataType] = None
Expand Down Expand Up @@ -307,8 +308,6 @@ def get_parameter_type(
default = repr(schema.default) if schema.has_default else None
self.imports_for_fastapi.append(field.imports)
self.data_types.append(field.data_type)
if field.name is None:
raise RuntimeError("field.name is None") # pragma: no cover
return Argument(
name=UsefulStr(field.name),
type_hint=UsefulStr(field.type_hint),
Expand Down