Skip to content

Commit

Permalink
Merge branch 'master' into add-model_template_dir-option
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi authored Dec 14, 2024
2 parents f0036cc + 7801309 commit e48f987
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 95 deletions.
1 change: 1 addition & 0 deletions fastapi_code_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def generate_code(
data_type_manager_type=data_model_types.data_type_manager,
dump_resolve_reference_action=data_model_types.dump_resolve_reference_action,
custom_template_dir=model_template_dir,
target_python_version=python_version,
)

with chdir(output_dir):
Expand Down
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
Loading

0 comments on commit e48f987

Please sign in to comment.