Skip to content

Commit 7aaec1d

Browse files
authored
Merge pull request #49 from koxudaxi/support_ref_paramter
support $ref paramter
2 parents c106a6e + f4b1b9d commit 7aaec1d

File tree

6 files changed

+59
-53
lines changed

6 files changed

+59
-53
lines changed

fastapi_code_generator/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def generate_code(
5050
imports=parsed_object.imports,
5151
info=parsed_object.info,
5252
)
53-
results[relative_path] = format_code(result, PythonVersion.PY_38)
53+
results[relative_path] = format_code(
54+
result, PythonVersion.PY_38, Path().resolve()
55+
)
5456

5557
timestamp = datetime.now(timezone.utc).replace(microsecond=0).isoformat()
5658
header = f"""\

fastapi_code_generator/parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ def get_data_type(self, schema: JsonSchemaObject) -> DataType:
230230
def get_parameter_type(
231231
self, parameter: Dict[str, Union[str, Dict[str, str]]], snake_case: bool
232232
) -> Argument:
233+
ref: Optional[str] = parameter.get('$ref') # type: ignore
234+
if ref:
235+
if not ref.startswith('#/components'):
236+
raise NotImplementedError(f'{ref=} is not supported for parameters')
237+
parameter = get_model_by_path(self.components, ref[13:].split('/'))
233238
name: str = parameter["name"] # type: ignore
234239
orig_name = name
235240
if snake_case:

0 commit comments

Comments
 (0)