Repository navigation
fix(golang): emit valid struct type for map fields - #315
chaitijain593-prog wants to merge 3 commits into
Conversation
Signed-off-by: chaitijain593 <chaitijain593@gmail.com>
|
Thank you for your first contribution to concerto-codegen, and for fixing the Go output for map fields. Your change comes with a visitor test and an updated snapshot, which makes it much easier to review. What happens next: I have asked the codegen maintainers to review this PR. If a review comment or a CI result needs your attention, please reply here and we will help where we can. Your commits need a DCO sign-off ( Drafted by an Accord Project agent, reviewed by a maintainer. |
|
Thank you for this contribution, and welcome to the Accord Project. Making the Go generator emit a valid struct type for map fields is a useful fix, and it's good to see you've included updated snapshots and unit tests in What happens next: the PR is in the concerto-codegen review queue and a maintainer will pick it up in due course. I can't give you a firm date. If you'd like to help it along, please keep the branch up to date with If you haven't already, please check that your commits carry a DCO sign-off ( Drafted by an Accord Project agent, reviewed by a maintainer. |
There was a problem hiding this comment.
Thank you for this fix, and welcome to the project. Turning x := make(map[K]V) into a plain Name map[K]V field is the right change: the old output is not valid inside a Go struct, and the new field name and JSON tag follow the same rules as the non-map path. The ?. guards and the updated snapshots match the change. One edge case remains: a model whose only DateTime use is inside a map still produces Go that will not compile. Handling that in containsDateTimeField, with a small test, would make the fix complete. The CI workflows beyond DCO are waiting for a maintainer to approve them, as is usual for a first contribution, and a maintainer review is still needed before this can merge.
Nothing blocking; some suggestions below. Findings: 1 should-fix, 1 nit.
Automated review by Mira, an Accord Project agent, at 933182a. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.
Signed-off-by: chaitijain593 <chaitijain593@gmail.com>
|
Thank you for the review and for catching the I have addressed both findings in the latest commit:
All local unit tests ( |
There was a problem hiding this comment.
🟡 Changes recommended
An inherited DateTime-valued map can trigger an unused time import in the child’s generated Go file, causing compilation to fail.
1 open issue
What changed in this PR
Fixes Concerto-to-Go map field generation for issue #314 by emitting exported, typed struct fields instead of initialization statements.
Changes:
- Emits valid map field declarations while preserving JSON property names.
- Adds null-safe scalar lookups and detects DateTime map types for the
timeimport. - Updates unit tests and generated-output snapshots.
| File | Description |
|---|---|
test/codegen/fromcto/golang/golangvisitor.js |
Tests map declarations, null lookups, and DateTime import detection. |
test/codegen/__snapshots__/codegen.js.snap |
Updates expected Go map fields to exported declarations. |
lib/codegen/fromcto/golang/golangvisitor.js |
Corrects map field output and extends type resolution and import detection. |
Review effort: Balanced
Signed-off-by: chaitijain593 <chaitijain593@gmail.com>
|
Addressed! Added the field.getParent() === classDecl check to prevent unused time imports on child classes inheriting maps, and added an inheritance regression test. |

Closes #314
Fixes GoLangVisitor struct field generation for map fields by emitting exported struct types (
Field map[Key]Value) instead of procedural initialization statements (field := make(...)), and adds optional chaining when resolving scalar map key/value types.Changes
GoLangVisitor.prototype.visitFieldto capitalize map property names and emit valid Go struct map field declarations (FieldName map[Key]Value \json:"name"``).?.isScalarDeclaration?.()) togetTypelookups to handle unresolved or cross-namespace types safely.test/codegen/fromcto/golang/golangvisitor.jsto assert the valid struct field declaration.getTypereturnsnull.test/codegen/__snapshots__/codegen.js.snap.Flags
Screenshots or Video
Related Issues
Author Checklist
--signoffoption of git commit.mainfromfork:branchname