|
40 | 40 | Parameters, |
41 | 41 | ReferencePath, |
42 | 42 | Schemas, |
| 43 | + get_reference_simple_name, |
43 | 44 | parse_reference_path, |
44 | 45 | update_parameters_with_data, |
45 | 46 | update_schemas_with_data, |
@@ -324,17 +325,30 @@ def _create_schemas( |
324 | 325 | while still_making_progress: |
325 | 326 | still_making_progress = False |
326 | 327 | errors = [] |
327 | | - next_round = [] |
| 328 | + next_round: list[tuple[str, oai.Reference | oai.Schema]] = [] |
328 | 329 | # Only accumulate errors from the last round, since we might fix some along the way |
329 | 330 | for name, data in to_process: |
330 | | - if isinstance(data, oai.Reference): |
331 | | - schemas.errors.append(PropertyError(data=data, detail="Reference schemas are not supported.")) |
332 | | - continue |
| 331 | + schema_data: oai.Reference | oai.Schema | None = data |
333 | 332 | ref_path = parse_reference_path(f"#/components/schemas/{name}") |
334 | 333 | if isinstance(ref_path, ParseError): |
335 | 334 | schemas.errors.append(PropertyError(detail=ref_path.detail, data=data)) |
336 | 335 | continue |
337 | | - schemas_or_err = update_schemas_with_data(ref_path=ref_path, data=data, schemas=schemas, config=config) |
| 336 | + if isinstance(data, oai.Reference): |
| 337 | + # Fully dereference reference schemas |
| 338 | + seen = [name] |
| 339 | + while isinstance(schema_data, oai.Reference): |
| 340 | + data_ref_schema = get_reference_simple_name(schema_data.ref) |
| 341 | + if data_ref_schema in seen: |
| 342 | + schemas.errors.append(PropertyError(detail="Circular schema references found", data=data)) |
| 343 | + break |
| 344 | + # use derefenced schema definition for this schema |
| 345 | + schema_data = components.get(data_ref_schema) |
| 346 | + if isinstance(schema_data, oai.Schema): |
| 347 | + schemas_or_err = update_schemas_with_data( |
| 348 | + ref_path=ref_path, data=schema_data, schemas=schemas, config=config |
| 349 | + ) |
| 350 | + else: |
| 351 | + schemas.errors.append(PropertyError(detail="Referent schema not found", data=data)) |
338 | 352 | if isinstance(schemas_or_err, PropertyError): |
339 | 353 | next_round.append((name, data)) |
340 | 354 | errors.append(schemas_or_err) |
|
0 commit comments