Skip to content

Commit 6132045

Browse files
authored
Merge pull request #596 from koxudaxi/add-black-formatter-regression
Add formatter pyproject regression coverage
2 parents 3bf3c02 + b35b00f commit 6132045

9 files changed

Lines changed: 90 additions & 7 deletions

File tree

docs/llms-full.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends.
553553

554554
| Format | Status | Evidence | Notes |
555555
|--------|--------|----------|-------|
556-
| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (34 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. |
556+
| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (39 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. |
557557
| 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`. |
558558
| 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. |
559559

@@ -562,7 +562,7 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends.
562562
| Suite | Fixtures | Example files | Notes |
563563
|-------|----------|---------------|-------|
564564
| 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. |
565-
| Coverage fixtures | 10 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. |
565+
| Coverage fixtures | 14 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. |
566566
| Custom template overrides | 1 | `custom_security.yaml` | Template override coverage for `--template-dir`. |
567567
| Timestamp suppression | 1 | `simple.yaml` | Fixtures that exercise `--disable-timestamp`. |
568568
| Remote references | 1 | `body_and_parameters.yaml` | Fixtures whose `$ref` targets are resolved over HTTP at test time. |

docs/supported_formats.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends.
77

88
| Format | Status | Evidence | Notes |
99
|--------|--------|----------|-------|
10-
| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (34 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. |
10+
| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (39 fixtures) | Primary fixture format exercised under `tests/data/openapi/**/*.yaml`. |
1111
| 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`. |
1212
| 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. |
1313

@@ -16,7 +16,7 @@ Run `tox run -e schema-docs` after changing supported inputs or model backends.
1616
| Suite | Fixtures | Example files | Notes |
1717
|-------|----------|---------------|-------|
1818
| 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. |
19-
| Coverage fixtures | 10 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. |
19+
| Coverage fixtures | 14 | `callbacks.yaml`, `callbacks_with_operation_id.yaml`, `faux_immutability.yaml` | Focused fixtures for callbacks, non-200 responses, and other regression edges. |
2020
| Custom template overrides | 1 | `custom_security.yaml` | Template override coverage for `--template-dir`. |
2121
| Timestamp suppression | 1 | `simple.yaml` | Fixtures that exercise `--disable-timestamp`. |
2222
| Remote references | 1 | `body_and_parameters.yaml` | Fixtures whose `$ref` targets are resolved over HTTP at test time. |

fastapi_code_generator/prompt_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@
532532
'\n'
533533
'| Format | Status | Evidence | Notes |\n'
534534
'|--------|--------|----------|-------|\n'
535-
'| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (34 '
535+
'| OpenAPI YAML | tested | `tests/data/openapi/**/*.yaml` (39 '
536536
'fixtures) | Primary fixture format exercised under '
537537
'`tests/data/openapi/**/*.yaml`. |\n'
538538
'| OpenAPI JSON | tested | '
@@ -552,7 +552,7 @@
552552
'`content_in_parameters.yaml`, '
553553
'`content_in_parameters_inline.yaml` | Core single-file '
554554
'generation scenarios exercised by the main CLI tests. |\n'
555-
'| Coverage fixtures | 10 | `callbacks.yaml`, '
555+
'| Coverage fixtures | 14 | `callbacks.yaml`, '
556556
'`callbacks_with_operation_id.yaml`, `faux_immutability.yaml` '
557557
'| Focused fixtures for callbacks, non-200 responses, and '
558558
'other regression edges. |\n'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# generated by fastapi-codegen:
2+
# filename: api.yaml
3+
4+
from __future__ import annotations
5+
6+
from typing import List
7+
8+
from fastapi import FastAPI
9+
10+
from .models import Pet
11+
12+
app = FastAPI(
13+
version='1.0.0',
14+
title='Swagger Petstore',
15+
)
16+
17+
18+
@app.get('/pets', response_model=List[Pet])
19+
def list_pets() -> List[Pet]:
20+
pass
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# generated by fastapi-codegen:
2+
# filename: api.yaml
3+
4+
from __future__ import annotations
5+
6+
from pydantic import BaseModel
7+
8+
9+
class Pet(BaseModel):
10+
id: int
11+
name: str

tests/data/expected/openapi/coverage/request_body_without_schema/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
)
1212

1313

14-
@app.post('/upload', response_model=None)
14+
@app.post('/upload', response_model=None, status_code=204)
1515
def create_upload() -> None:
1616
pass
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
paths:
6+
/pets:
7+
get:
8+
operationId: listPets
9+
responses:
10+
'200':
11+
description: A paged array of pets
12+
content:
13+
application/json:
14+
schema:
15+
$ref: "#/components/schemas/Pets"
16+
components:
17+
schemas:
18+
Pet:
19+
required:
20+
- id
21+
- name
22+
properties:
23+
id:
24+
type: integer
25+
format: int64
26+
name:
27+
type: string
28+
Pets:
29+
type: array
30+
items:
31+
$ref: "#/components/schemas/Pet"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.poetry]
2+
name = "openapi-srv"
3+
version = "0.1.0"

tests/main/test_main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,24 @@ def test_generate_from_json_input(tmp_path: Path, output_dir: Path) -> None:
263263
validate_generated_code(output_dir)
264264

265265

266+
@freeze_time("2020-06-19")
267+
def test_generate_with_parent_pyproject_formatter_settings(tmp_path: Path) -> None:
268+
fixture_dir = DATA_PATH / OPEN_API_COVERAGE_DIR_NAME / "formatter_parent_pyproject"
269+
project_dir = tmp_path / "project"
270+
output_dir = project_dir / "app3"
271+
input_path = project_dir / "api.yaml"
272+
project_dir.mkdir()
273+
copy2(fixture_dir / "api.yaml", input_path)
274+
copy2(fixture_dir / "pyproject.toml", project_dir / "pyproject.toml")
275+
276+
run_cli_and_assert(
277+
input_path=input_path,
278+
output_path=output_dir,
279+
expected_path=EXPECTED_OPENAPI_PATH / "coverage" / "formatter_parent_pyproject",
280+
extra_args=["--disable-timestamp"],
281+
)
282+
283+
266284
@freeze_time("2020-06-19")
267285
def test_generate_request_body_without_schema(output_dir: Path) -> None:
268286
run_cli_and_assert(

0 commit comments

Comments
 (0)