Resolve map-types for selectors and slice elements#109
Merged
Conversation
fieldToSchema's SelectorExpr branch only tried the short-alias key (e.g. "view.Date") when looking up map-types, so fully-qualified config entries like "github.com/foo/bar/view.Date" never matched cross-package references. resolveArray never called MapType at all, so []view.Date / []Date slice fields always fell through to $ref even when the element type was configured as a primitive. Retry MapType with the resolved full import path in fieldToSchema's SelectorExpr branch, and add a MapType check in resolveArray for both the pkg-qualified and fully-qualified keys before the $ref fallback.
Coverage Report for CI Build 24845660006Coverage increased (+1.0%) to 52.998%Details
Uncovered Changes
Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
The SelectorExpr case used `t == ""` / `t != ""` gating around the canonicalType check, then re-tested `t` again afterwards. Collapsing both into a single early-return via applyMapType keeps behaviour identical and brings gocyclo back under the linter threshold after adding the full-path retry.
rafaeljusto
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
map-typesconfig entries only applied to bare-ident struct fields. Two other paths silently ignored them, so custom scalar wrappers (e.g. aview.Datethat marshals as a JSON string) still rendered as$refs to an object definition in the generated spec.fieldToSchema's*ast.SelectorExprbranch looked up map-types with the short package alias (view.Date) and never retried with the resolved full import path, so fully-qualified config keys never matched cross-package selector references.resolveArraynever calledMapTypeat all — slice elements like[]view.Dateor[]Datealways fell through to a$ref, regardless of config.Fix
fieldToSchema's selector branch, afterfindTyperesolves the full import path, retry viaapplyMapTypewith the fully-qualified key and return early on a hit.resolveArray, thread animportPaththrough both the ident branch (fromref.Package) and the selector branch (fromfindType), then tryMapTypeagainst both the short and fully-qualified keys before falling back to$ref.Net effect: a single config entry — in either form — now consistently covers the four reference shapes (single ident, single selector, slice ident, slice selector).
Before / after
Config:
Given:
Before
After
Tests
go test ./...passes.TestFieldToProperty/mapped typessubtest covers both short-form and fully-qualified config keys against all four reference shapes, via a newmappedstruct in testdata.