Commit 2895b80
refactor: improve robustness of type extraction and $ref parsing
This addresses code review feedback by replacing fragile string parsing
with proper AST-based extraction and adding validation for edge cases.
Changes:
1. Replace string-based type extraction with AST parsing
- extract_type_names() now uses ast.parse() instead of line splitting
- Handles comments, multiline docstrings, complex expressions correctly
- More robust against edge cases like "class Foo" in docstrings
2. Add validation for $ref parsing edge cases
- Validates $ref is not empty
- Handles fragment identifiers (#/definitions/Foo)
- Supports both / and \ path separators
- Raises clear errors for unsupported patterns
Why this matters:
- AST parsing is more reliable than regex/string manipulation
- Proper error handling prevents silent failures
- Validates assumptions about schema structure
Addresses code review Priority 1 items from code-reviewer agent.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent f3cd271 commit 2895b80
1 file changed
+45
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| 272 | + | |
272 | 273 | | |
273 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
274 | 291 | | |
275 | 292 | | |
276 | 293 | | |
| |||
414 | 431 | | |
415 | 432 | | |
416 | 433 | | |
417 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
418 | 440 | | |
419 | 441 | | |
420 | 442 | | |
421 | 443 | | |
422 | 444 | | |
423 | 445 | | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
449 | 467 | | |
450 | 468 | | |
451 | 469 | | |
| |||
0 commit comments