diff --git a/fastapi_code_generator/__main__.py b/fastapi_code_generator/__main__.py index f61415b..a551e87 100644 --- a/fastapi_code_generator/__main__.py +++ b/fastapi_code_generator/__main__.py @@ -127,10 +127,11 @@ def generate_code( parser = OpenAPIParser(input_text) with chdir(output_dir): models = parser.parse() + output = output_dir / model_path if not models: - return + # if no models (schemas), just generate an empty model file. + modules = {output: ("", input_name)} elif isinstance(models, str): - output = output_dir / model_path modules = {output: (models, input_name)} else: raise Exception('Modular references are not supported in this version') diff --git a/tests/data/expected/openapi/default_template/body_and_parameters/main.py b/tests/data/expected/openapi/default_template/body_and_parameters/main.py index 47bd8d9..3bf2b34 100644 --- a/tests/data/expected/openapi/default_template/body_and_parameters/main.py +++ b/tests/data/expected/openapi/default_template/body_and_parameters/main.py @@ -6,7 +6,7 @@ from typing import List, Optional, Union -from fastapi import FastAPI, Path, Query, UploadFile +from fastapi import FastAPI, Path, Query, Request from starlette.requests import Request from .models import ( @@ -37,7 +37,7 @@ def post_bar(request: Request) -> None: @app.post('/convert', response_model=bytes) -def convert(format: Optional[str] = 'pdf', file: UploadFile = ...) -> bytes: +def convert(format: Optional[str] = 'pdf', request: Request = ...) -> bytes: pass diff --git a/tests/data/expected/openapi/default_template/no_models/main.py b/tests/data/expected/openapi/default_template/no_models/main.py new file mode 100644 index 0000000..23674f7 --- /dev/null +++ b/tests/data/expected/openapi/default_template/no_models/main.py @@ -0,0 +1,23 @@ +# generated by fastapi-codegen: +# filename: no_models.yaml +# timestamp: 2020-06-19T00:00:00+00:00 + +from __future__ import annotations + +from fastapi import FastAPI + +app = FastAPI( + version='1.0.0', + title='Swagger Petstore', + license={'name': 'MIT'}, + description=None, + servers=[{'url': 'http://petstore.swagger.io/v1'}], +) + + +@app.get('/hello', response_model=str) +def hello() -> str: + """ + get hello message + """ + pass diff --git a/tests/data/expected/openapi/default_template/no_models/models.py b/tests/data/expected/openapi/default_template/no_models/models.py new file mode 100644 index 0000000..a2cf986 --- /dev/null +++ b/tests/data/expected/openapi/default_template/no_models/models.py @@ -0,0 +1,3 @@ +# generated by fastapi-codegen: +# filename: no_models.yaml +# timestamp: 2020-06-19T00:00:00+00:00 diff --git a/tests/data/openapi/default_template/no_models.yaml b/tests/data/openapi/default_template/no_models.yaml new file mode 100644 index 0000000..e906d43 --- /dev/null +++ b/tests/data/openapi/default_template/no_models.yaml @@ -0,0 +1,22 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore + license: + name: MIT + description: + +servers: + - url: http://petstore.swagger.io/v1 +paths: + /hello: + get: + summary: get hello message + operationId: hello + responses: + '200': + description: message string + content: + text/plain: + schema: + type: string