Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@raphael
Copy link
Member

@raphael raphael commented Sep 6, 2025

Summary

  • Prevent same-path generation overwriting (struct + union marker).

Problem

  • In designs that:
    • put a user type into a shared package via Meta("struct:pkg:path", "types"), and
    • include that user type as a branch of a union, and
    • reference that user type from more than one service,
      generation could produce multiple files targeting the same output path (e.g., gen/types/summary.go). The later render overwrote the earlier one, leaving only the union "marker" method and dropping the struct definition.

When it shows up

  • After goa gen, you might see files like gen/types/.go contain only:
    func (*Type) Val() {}
  • Build errors such as: undefined: in code that references the struct.

Root cause

  • Generator wrote files sequentially without coalescing sections that shared the same path.

Fix

  • New merge-by-path step in generator.Generate: for each output path, merge headers (imports) and non-header sections, skipping duplicates, then render once. This ensures the struct and union marker end up in the same file.

Tests

  • generate_merge_test.go: minimal same-path merge unit test (struct + method).
  • generate_union_merge_integration_test.go: small DSL with user type in types/, union including that type, and two services referencing it; asserts both struct and union marker are present in gen/types/summary.go.
  • All repo tests + JSON-RPC integration tests pass.

Notes

  • Also simplified CLI usage template to avoid fmt parsing pitfalls when examples contain %.

… merge-by-path in generator.Generate\n- Add regression tests: same-path merge and union+user-type integration\n- Fix CLI usage template to avoid bad fmt formatting\n- Add debug comments then remove them (no-op now)\n\nThis fixes a bug where shared user types with union marker methods could be overwritten by later services, e.g. Summary/AlarmSummary emitted only detailsVal method. Tests ensure both struct and union marker coexist in types/*.go.\n\nRefs: aura gen failure, union value methods, struct:pkg:path
@raphael raphael enabled auto-merge (squash) September 6, 2025 04:25
…ad returns absolute PkgPath for gen/, fall back to "gen"\n- Prevents invalid import paths with backslashes in temp test workspaces\n\nFixes Windows failure in union merge integration test.
@raphael raphael merged commit c343c69 into v3 Sep 6, 2025
7 checks passed
@raphael raphael deleted the feat/merge-samepath-union-tests branch September 6, 2025 04:36
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.

1 participant