Skip to content

Commit ca1d434

Browse files
authored
Merge pull request #384 from notpushkin/patch-1
Allow modular output with custom templates
2 parents 71723ee + dd4a6ae commit ca1d434

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fastapi_code_generator/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ def generate_code(
117117
if not output_dir.exists():
118118
output_dir.mkdir(parents=True)
119119
if generate_routers:
120-
template_dir = BUILTIN_MODULAR_TEMPLATE_DIR
121120
Path(output_dir / "routers").mkdir(parents=True, exist_ok=True)
122121
if not template_dir:
123-
template_dir = BUILTIN_TEMPLATE_DIR
122+
template_dir = (
123+
BUILTIN_MODULAR_TEMPLATE_DIR if generate_routers else BUILTIN_TEMPLATE_DIR
124+
)
124125
if enum_field_as_literal:
125126
parser = OpenAPIParser(input_text, enum_field_as_literal=enum_field_as_literal)
126127
else:
@@ -195,7 +196,7 @@ def generate_code(
195196
set(tag.strip() for tag in str(specify_tags).split(","))
196197
)
197198

198-
for target in BUILTIN_MODULAR_TEMPLATE_DIR.rglob("routers.*"):
199+
for target in template_dir.rglob("routers.*"):
199200
relative_path = target.relative_to(template_dir)
200201
for router, tag in zip(routers, sorted_tags):
201202
if (

0 commit comments

Comments
 (0)