Skip to content

Map array<K, V> to type: object + additionalProperties#2002

Closed
krissss wants to merge 1 commit into
zircote:masterfrom
krissss:feat/2001-map-type-to-object
Closed

Map array<K, V> to type: object + additionalProperties#2002
krissss wants to merge 1 commit into
zircote:masterfrom
krissss:feat/2001-map-type-to-object

Conversation

@krissss
Copy link
Copy Markdown
Contributor

@krissss krissss commented Apr 23, 2026

Summary

  • TypeInfoTypeResolver now distinguishes between ordered lists and key-value maps using CollectionType::isList() and getCollectionKeyType()
  • array<K, V> (e.g. array<string, string>, array<int, User>) → type: object + additionalProperties
  • array<T>, T[], list<T>type: array + items (unchanged)
  • array{key: T} shape types also correctly map to type: object + additionalProperties

Closes #2001

Type of Change

  • Enhancement (improvement to existing functionality)

Key Decision

The distinction uses two checks on CollectionType:

  • isList()true for list<T> (PHP sequential array)
  • getCollectionKeyType() instanceof UnionTypetrue for default int|string keys (array<T>, T[])

Anything else (explicit single-type key like string, int, or a class) is treated as a map.

Test Plan

  • All 1038 tests pass (including updated expectations for arrayshape and nullablenestedtypedlistunion)
  • New test cases: stringMap (array<string, string>) and intKeyedMap (array<int, string>)
  • Existing array<T>, T[], list<T> cases unchanged

…#2001)

Distinguish between ordered lists and key-value maps in
TypeInfoTypeResolver by checking CollectionType::isList() and
keyType. Types with explicit key types (e.g. `array<string, string>`)
now produce `type: object` + `additionalProperties` instead of
`type: array` + `items`.
@krissss krissss closed this Apr 23, 2026
@DerManoMann
Copy link
Copy Markdown
Collaborator

What happened?

@krissss
Copy link
Copy Markdown
Contributor Author

krissss commented Apr 23, 2026

Apologies for the confusion — this PR was generated by AI and got pushed before I had a chance to review it carefully. I'm closing it for now and will re-submit after a proper review.

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.

Support array<K, V> mapping to type: object + additionalProperties

2 participants