Skip to content

fix: camelize nested keys in read action typed map metadata#63

Merged
Torkan merged 1 commit intoash-project:mainfrom
mike1o1:fix/read-metadata-typed-map-casing
Apr 14, 2026
Merged

fix: camelize nested keys in read action typed map metadata#63
Torkan merged 1 commit intoash-project:mainfrom
mike1o1:fix/read-metadata-typed-map-casing

Conversation

@mike1o1
Copy link
Copy Markdown
Contributor

@mike1o1 mike1o1 commented Mar 30, 2026

Summary

Fixes #62

When a read action has metadata containing typed maps (e.g., {:array, :map} with field constraints), the codegen correctly generates camelCase TypeScript types, but the runtime RPC response returns snake_case nested keys. Mutation metadata is unaffected because it follows a separate formatting path through format_field_names/2.

Root cause

do_add_read_metadata merges raw metadata values into the result record. The record then goes through OutputFormatter.format_map, which looks up each key via ResourceFields.get_public_field_type_info. Since metadata fields aren't resource attributes, the type comes back as nil, and ValueFormatter.format/5 short-circuits, returning nested map values with their original atom keys unchanged.

Fix

Apply format_field_names/2 to each metadata value in do_add_read_metadata before merging into the record. This recursively camelizes nested map keys while leaving the metadata keys as atoms for OutputFormatter to handle in Stage 4, consistent with how resource attribute keys are formatted.

Scalar metadata values (strings, integers, booleans) pass through format_field_names unchanged via the other -> other clause, so existing behavior is preserved.


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

@Torkan
Copy link
Copy Markdown
Collaborator

Torkan commented Apr 14, 2026

Thanks for spotting this one! 😄

I'll merge it as-is, but also follow up with some minor changes to ensure that composite types without constraints, like :map for example, will get passed through as-is.

@Torkan Torkan merged commit a84e54f into ash-project:main Apr 14, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Read action metadata with typed maps returns snake_case nested keys instead of camelCase

2 participants