Commit cec1e8b
committed
fix: support arrow functions that return codecs in OpenAPI generator
When arrow functions that return codecs were
imported from a utils module, the OpenAPI generator would output empty
schemas ({}) instead of the correct type definitions.
Example that broke:
```typescript
// utils.ts
export const BooleanFromNullableWithFallback = () =>
fromNullable(t.union([BooleanFromString, t.boolean]), false);
// schema.ts
import { BooleanFromNullableWithFallback } from './utils';
const Wallet = t.type({
hasLargeNumberOfAddresses: BooleanFromNullableWithFallback() // INCORRECTLY Generates: {}
});
```
The generator couldn't resolve CallExpressions where the callee is an
arrow function. When it looked up the identifier and found an arrow
function, it had no logic to parse the function body, falling back to
an empty schema.
This fix:
- Adds parseFunctionBody() to extract and parse arrow function return values
- Detects when CallExpression callees resolve to arrow functions
- Uses findSymbolInitializer() for cross-file lookup of imported functions
Test covers the bug scenario: calling an arrow function factory
(BooleanFromNullableWithFallback()) within a codec property definition.1 parent c5000de commit cec1e8b
File tree
3 files changed
+102
-1
lines changed- packages/openapi-generator
- src
- test
- sample-types
3 files changed
+102
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
453 | 467 | | |
454 | 468 | | |
455 | 469 | | |
| |||
471 | 485 | | |
472 | 486 | | |
473 | 487 | | |
474 | | - | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
475 | 509 | | |
| 510 | + | |
476 | 511 | | |
477 | 512 | | |
478 | 513 | | |
| |||
Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments