Skip to content

fix: recursive input types #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 6, 2025
Merged

fix: recursive input types #371

merged 9 commits into from
Aug 6, 2025

Conversation

barnabasJ
Copy link
Contributor

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

This commit fixes stack overflow issues when generating OpenAPI schemas
for embedded resources with self-references in create/update operations.

Changes:
- Add seen_input_types tracking to accumulator for recursion detection
- Pass parent resource context to embedded_type_input for proper naming
- Generate context-aware schema names (parent_type_attribute-input-action)
- Create $ref references for recursive types instead of inline definitions
- Ensure all referenced schemas are properly created and stored
- Fix accumulator flow to preserve schemas from request_body generation

This prevents infinite recursion and ensures OpenAPI client generation
tools can resolve all $ref references correctly.
- Add comprehensive test for recursive embedded input types without stack overflow
- Update existing test to expect $ref instead of inline schema for embedded inputs
- Verify that all referenced schemas are properly created in components
- Ensure OpenAPI client generation won't fail with missing $ref errors
Apply mix format to maintain consistent code style
Follow the same pattern as regular embedded types:
- Remove unnecessary minimal schema creation for recursive types
- Just return $ref for recursive types with schema names
- Return empty Schema{} for recursive types without names
- Let the non-recursive path create the actual schema

This simplifies the code and removes unnecessary complexity that
wasn't actually helping with recursion prevention.
Move the require Logger statement to module level for cleaner code organization
and remove accidental error logging that referenced undefined variable.
Move all schema generation and verification into the capture_log block
to ensure any warnings during the process are captured for verification.
This provides better test coverage for the recursion detection logging.
@barnabasJ barnabasJ changed the title Fix/recursive input types fix: recursive input types Aug 6, 2025
@barnabasJ barnabasJ self-assigned this Aug 6, 2025
@barnabasJ barnabasJ added the bug Something isn't working label Aug 6, 2025
@barnabasJ barnabasJ marked this pull request as ready for review August 6, 2025 13:35
@barnabasJ barnabasJ requested a review from zachdaniel August 6, 2025 13:35
@zachdaniel zachdaniel merged commit 2aab2c4 into main Aug 6, 2025
22 checks passed
@barnabasJ barnabasJ deleted the fix/recursive-input-types branch August 7, 2025 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants