Skip to content

Commit

Permalink
Merge pull request #446 from chantera/fix-parameter-field-name
Browse files Browse the repository at this point in the history
Fix parameter field name
  • Loading branch information
koxudaxi authored Dec 14, 2024
2 parents f0a94d6 + fbc3c08 commit 7801309
Showing 1 changed file with 4 additions and 5 deletions.
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

0 comments on commit 7801309

Please sign in to comment.