Skip to content

Fix DeepHashAccessor#[] and generate typed nested resource classes - #539

Open
razor-x wants to merge 1 commit into
mainfrom
codex/fix-nested-resource-access-in-ruby-sdk
Open

Fix DeepHashAccessor#[] and generate typed nested resource classes#539
razor-x wants to merge 1 commit into
mainfrom
codex/fix-nested-resource-access-in-ruby-sdk

Conversation

@razor-x

@razor-x razor-x commented Aug 6, 2026

Copy link
Copy Markdown
Member

Motivation

  • Fix a live bug where DeepHashAccessor#[] always returned nil and produced non-stable nested objects, and prevent response deserialization from aborting on invalid Ruby ivar names.
  • Ensure memoized/converted errors/warnings are refreshed after update_from_response to avoid stale data.
  • Provide static, documented nested resource types so nested properties have YARD docs and IDE autocompletion by generating BaseResource subclasses for nested objects and lists.
  • Leave the top-level decision about stripping unknown response keys (P3) unchanged for a later, separate decision.

Description

  • Corrected DeepHashAccessor: #[] now delegates to the generated singleton readers (accepting string or symbol keys) and create_accessor_methods now processes values once at construction to preserve identity. (lib/seam/deep_hash_accessor.rb).
  • Hardened BaseResource deserialization to return nil from load_from_response(nil), skip response keys that cannot be valid instance variable names, added BaseResource#[] for bracket access, and introduced resource_accessor / resource_list_accessor DSL and conversion logic to instantiate typed nested resources when present. (lib/seam/base_resource.rb).
  • Fixed stale memoization by resetting @errors_converted and @warnings_converted before delegating update_from_response in the resource support modules, and updated the emitted string literals used by the generator (codegen/lib/static-resources.tslib/seam/resources/resource_errors_support.rb and resource_warnings_support.rb).
  • Implemented nested-class discovery in the Ruby code generator: added merge-properties helper and updated codegen/lib/layouts/resource.ts and codegen/layouts/resource.hbs so generated lib/seam/resources/*.rb now emit documented nested BaseResource subclasses and declare resource_accessor / resource_list_accessor usages; numerous generated resource files were refreshed accordingly.
  • Added and updated specs to cover the fixes and generation: spec/deep_hash_accessor_spec.rb, spec/resources/base_resource_hash_spec.rb, and spec/resources/base_resource_spec.rb now assert bracket access, stable nested identity, nil handling for load_from_response(nil), skipping invalid attribute names, errors refresh on update, and that declared nested objects become generated typed resources.

Testing

  • Ran the unit specs with bundle exec rspec for the modified suites and they passed (including spec/deep_hash_accessor_spec.rb, spec/resources/base_resource_spec.rb, and spec/resources/base_resource_hash_spec.rb).
  • Ran the full test/lint/generation pipeline: npm run generate (generator run and idempotency check), rake lint, and rake test completed successfully after minor tooling fixes in the generator templates.
  • Performed TypeScript checks with npm run typecheck and JavaScript lint/format (npm run lint / prettier) during generator development and fixed reported issues; note that the local Node runtime triggered an engine warning because it is older than the project dev engine requirement (this did not prevent generation in this environment).
  • Verified that code generation is idempotent and that generated resource files now include nested typed classes and resource_accessor declarations as expected.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant