diff --git a/docs/llms-full.txt b/docs/llms-full.txt index 3d2dd3e3..3dffe78c 100644 --- a/docs/llms-full.txt +++ b/docs/llms-full.txt @@ -553,7 +553,7 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends. | Format | Status | Evidence | Notes | |--------|--------|----------|-------| -| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (34 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. | +| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (39 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. | | OpenAPI JSON | tested | `tests/main/test_main.py::test_generate_from_json_input` | Covered by the JSON conversion CLI test in `tests/main/test_main.py`. | | Remote HTTP `$ref` targets | tested | `tests/main/test_main.py::test_generate_remote_ref` | Covered by the remote `$ref` generation test against a live HTTP server. | @@ -562,7 +562,7 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends. | Suite | Fixtures | Example files | Notes | |-------|----------|---------------|-------| | Default template | 20 | `body_and_parameters.yaml`, `content_in_parameters.yaml`, `content_in_parameters_inline.yaml` | Core single-file generation scenarios exercised by the main CLI tests. | -| Coverage fixtures | 10 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. | +| Coverage fixtures | 14 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. | | Custom template overrides | 1 | `custom_security.yaml` | Template override coverage for `--template-dir`. | | Timestamp suppression | 1 | `simple.yaml` | Fixtures that exercise `--disable-timestamp`. | | Remote references | 1 | `body_and_parameters.yaml` | Fixtures whose `$ref` targets are resolved over HTTP at test time. | diff --git a/docs/supported_formats.md b/docs/supported_formats.md index 8d37ca37..9a33dc13 100644 --- a/docs/supported_formats.md +++ b/docs/supported_formats.md @@ -7,7 +7,7 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends. | Format | Status | Evidence | Notes | |--------|--------|----------|-------| -| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (34 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. | +| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (39 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. | | OpenAPI JSON | tested | `tests/main/test_main.py::test_generate_from_json_input` | Covered by the JSON conversion CLI test in `tests/main/test_main.py`. | | Remote HTTP `$ref` targets | tested | `tests/main/test_main.py::test_generate_remote_ref` | Covered by the remote `$ref` generation test against a live HTTP server. | @@ -16,7 +16,7 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends. | Suite | Fixtures | Example files | Notes | |-------|----------|---------------|-------| | Default template | 20 | `body_and_parameters.yaml`, `content_in_parameters.yaml`, `content_in_parameters_inline.yaml` | Core single-file generation scenarios exercised by the main CLI tests. | -| Coverage fixtures | 10 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. | +| Coverage fixtures | 14 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. | | Custom template overrides | 1 | `custom_security.yaml` | Template override coverage for `--template-dir`. | | Timestamp suppression | 1 | `simple.yaml` | Fixtures that exercise `--disable-timestamp`. | | Remote references | 1 | `body_and_parameters.yaml` | Fixtures whose `$ref` targets are resolved over HTTP at test time. | diff --git a/fastapi_code_generator/prompt_data.py b/fastapi_code_generator/prompt_data.py index 8d3ac75f..55d3cf64 100644 --- a/fastapi_code_generator/prompt_data.py +++ b/fastapi_code_generator/prompt_data.py @@ -532,7 +532,7 @@ '\n' '| Format | Status | Evidence | Notes |\n' '|--------|--------|----------|-------|\n' - '| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (34 ' + '| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (39 ' 'fixtures) | Primary fixture format exercised under ' '`tests/data/openapi/**/*.yaml`. |\n' '| OpenAPI JSON | tested | ' @@ -552,7 +552,7 @@ '`content_in_parameters.yaml`, ' '`content_in_parameters_inline.yaml` | Core single-file ' 'generation scenarios exercised by the main CLI tests. |\n' - '| Coverage fixtures | 10 | `callbacks.yaml`, ' + '| Coverage fixtures | 14 | `callbacks.yaml`, ' '`callbacks_with_operation_id.yaml`, `faux_immutability.yaml` ' '| Focused fixtures for callbacks, non-200 responses, and ' 'other regression edges. |\n' diff --git a/tests/data/expected/openapi/coverage/formatter_parent_pyproject/main.py b/tests/data/expected/openapi/coverage/formatter_parent_pyproject/main.py new file mode 100644 index 00000000..3763b7a0 --- /dev/null +++ b/tests/data/expected/openapi/coverage/formatter_parent_pyproject/main.py @@ -0,0 +1,20 @@ +# generated by fastapi-codegen: +# filename: api.yaml + +from __future__ import annotations + +from typing import List + +from fastapi import FastAPI + +from .models import Pet + +app = FastAPI( + version='1.0.0', + title='Swagger Petstore', +) + + +@app.get('/pets', response_model=List[Pet]) +def list_pets() -> List[Pet]: + pass diff --git a/tests/data/expected/openapi/coverage/formatter_parent_pyproject/models.py b/tests/data/expected/openapi/coverage/formatter_parent_pyproject/models.py new file mode 100644 index 00000000..a38b4480 --- /dev/null +++ b/tests/data/expected/openapi/coverage/formatter_parent_pyproject/models.py @@ -0,0 +1,11 @@ +# generated by fastapi-codegen: +# filename: api.yaml + +from __future__ import annotations + +from pydantic import BaseModel + + +class Pet(BaseModel): + id: int + name: str diff --git a/tests/data/expected/openapi/coverage/request_body_without_schema/main.py b/tests/data/expected/openapi/coverage/request_body_without_schema/main.py index f66564a0..e77709b8 100644 --- a/tests/data/expected/openapi/coverage/request_body_without_schema/main.py +++ b/tests/data/expected/openapi/coverage/request_body_without_schema/main.py @@ -11,6 +11,6 @@ ) -@app.post('/upload', response_model=None) +@app.post('/upload', response_model=None, status_code=204) def create_upload() -> None: pass diff --git a/tests/data/openapi/coverage/formatter_parent_pyproject/api.yaml b/tests/data/openapi/coverage/formatter_parent_pyproject/api.yaml new file mode 100644 index 00000000..34981329 --- /dev/null +++ b/tests/data/openapi/coverage/formatter_parent_pyproject/api.yaml @@ -0,0 +1,31 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Swagger Petstore +paths: + /pets: + get: + operationId: listPets + responses: + '200': + description: A paged array of pets + content: + application/json: + schema: + $ref: "#/components/schemas/Pets" +components: + schemas: + Pet: + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + Pets: + type: array + items: + $ref: "#/components/schemas/Pet" diff --git a/tests/data/openapi/coverage/formatter_parent_pyproject/pyproject.toml b/tests/data/openapi/coverage/formatter_parent_pyproject/pyproject.toml new file mode 100644 index 00000000..9a1a30ab --- /dev/null +++ b/tests/data/openapi/coverage/formatter_parent_pyproject/pyproject.toml @@ -0,0 +1,3 @@ +[tool.poetry] +name = "openapi-srv" +version = "0.1.0" diff --git a/tests/main/test_main.py b/tests/main/test_main.py index f110efcf..15440ad5 100644 --- a/tests/main/test_main.py +++ b/tests/main/test_main.py @@ -263,6 +263,24 @@ def test_generate_from_json_input(tmp_path: Path, output_dir: Path) -> None: validate_generated_code(output_dir) +@freeze_time("2020-06-19") +def test_generate_with_parent_pyproject_formatter_settings(tmp_path: Path) -> None: + fixture_dir = DATA_PATH / OPEN_API_COVERAGE_DIR_NAME / "formatter_parent_pyproject" + project_dir = tmp_path / "project" + output_dir = project_dir / "app3" + input_path = project_dir / "api.yaml" + project_dir.mkdir() + copy2(fixture_dir / "api.yaml", input_path) + copy2(fixture_dir / "pyproject.toml", project_dir / "pyproject.toml") + + run_cli_and_assert( + input_path=input_path, + output_path=output_dir, + expected_path=EXPECTED_OPENAPI_PATH / "coverage" / "formatter_parent_pyproject", + extra_args=["--disable-timestamp"], + ) + + @freeze_time("2020-06-19") def test_generate_request_body_without_schema(output_dir: Path) -> None: run_cli_and_assert(