|
26 | 26 | generate, |
27 | 27 | get_version, |
28 | 28 | inferred_message, |
| 29 | + load_data_from_path, |
29 | 30 | ) |
30 | 31 | from datamodel_code_generator.__main__ import Exit |
31 | 32 | from datamodel_code_generator.config import GenerateConfig |
|
49 | 50 | MSGSPEC_LEGACY_BLACK_SKIP, |
50 | 51 | OPEN_API_DATA_PATH, |
51 | 52 | TIMESTAMP, |
| 53 | + run_generate_file_and_assert, |
52 | 54 | run_main_and_assert, |
53 | 55 | run_main_url_and_assert, |
54 | 56 | run_main_with_args, |
@@ -4218,6 +4220,24 @@ def test_main_openapi_non_operations_and_security(output_file: Path) -> None: |
4218 | 4220 | ) |
4219 | 4221 |
|
4220 | 4222 |
|
| 4223 | +def test_generate_openapi_keeps_referenced_path_item_original_unchanged(output_file: Path) -> None: |
| 4224 | + """Keep cached referenced OpenAPI path items unchanged while inheriting operation metadata.""" |
| 4225 | + input_path = OPEN_API_DATA_PATH / "referenced_path_item_mutation_guard" / "openapi.yaml" |
| 4226 | + path_item_path = OPEN_API_DATA_PATH / "referenced_path_item_mutation_guard" / "path-item.yml" |
| 4227 | + cached_path_item = load_data_from_path(path_item_path.resolve(), "utf-8") |
| 4228 | + |
| 4229 | + run_generate_file_and_assert( |
| 4230 | + input_path=input_path, |
| 4231 | + output_path=output_file, |
| 4232 | + input_file_type=InputFileType.OpenAPI, |
| 4233 | + assert_func=assert_file_content, |
| 4234 | + expected_file="referenced_path_item_mutation_guard.py", |
| 4235 | + disable_timestamp=True, |
| 4236 | + openapi_scopes=[OpenAPIScope.Schemas, OpenAPIScope.Paths], |
| 4237 | + unchanged_inputs={"cached path-item.yml": cached_path_item}, |
| 4238 | + ) |
| 4239 | + |
| 4240 | + |
4221 | 4241 | def test_main_openapi_webhooks_with_parameters(output_file: Path) -> None: |
4222 | 4242 | """Test OpenAPI generation with webhook-level and operation-level parameters.""" |
4223 | 4243 | run_main_and_assert( |
|
0 commit comments