0.45.0-rc44 - the absolute most bleeding-edge version of the CLI
Generator Version
0.23.5 - observed in fern-go-fiber and fern-go-model
Describe the Bug
When defining an API spec with a timestamp type on an undiscriminated union, I observed the latest version of the generator for fern-go-fiber (and fern-go-model in testing) acting up on the Go source code it generated:
> fern generate
# (snip deprecations)
[api]: ✓ All checks passed
┌─
[api]: fernapi/fern-go-fiber failed to parse Go code: logs\types.go:676:55: expected ';', found '{' (and 3 more errors)
[api]: fernapi/fern-openapi Downloaded to <>\models\openapi
┌─
│ ✓ fernapi/fern-openapi
│ x fernapi/fern-go-fiber
└─
Additional Context
After doing some magic to get local development working again, I did a deep dive:
Instrumented additional logging into generator/go with some fmt.Errorf wraps to drill down to the generated source (where this error is emitted, in generators/go/internal/generator/file_writer.go)
Added some printing of the troublesome generated source
Observed the following, since up to this point I had no idea what was going on:
> ..\..\fern\generators\go\build\fern-go-fiber.exe config.json
failed to run: failed to parse Go code: logs\types.go:676:55: expected ';', found '{' (and 3 more errors); source:
=-=
672: }
674: return json.Marshal(l.String)
675: }
676: if l.typ == "Timestamp" || l.Timestamp != time.Time{} {
^
677: return json.Marshal(l.Timestamp)
678: }
679: return nil, fmt.Errorf("type %T does not include a non-empty union type", l)
680: }
- Aha, that's a golang parser no-no!
- Found the generator source that controls this:
![image](https://github.com/user-attachments/assets/09e0b00a-39f7-4f56-a7c9-10fcfd9bde5d)
- Looks like it's in `VisitUndiscriminatedUnion`...
- To be safe, I wrap each full if statement in parentheses to resolve -> and a subsequent local build + execution shows successful generation.
I made the needed changes to fix this on a fork, will make a PR shortly stemming from this issue! I will leave the improved error / generated source logging changes as a separate commit to let them be cherry-picked out.
CLI Version
0.45.0-rc44
- the absolute most bleeding-edge version of the CLIGenerator Version
0.23.5
- observed infern-go-fiber
andfern-go-model
Describe the Bug
When defining an API spec with a timestamp type on an undiscriminated union, I observed the latest version of the generator for
fern-go-fiber
(andfern-go-model
in testing) acting up on the Go source code it generated:Additional Context
After doing some magic to get local development working again, I did a deep dive:
generator/go
with somefmt.Errorf
wraps to drill down to the generated source (where this error is emitted, ingenerators/go/internal/generator/file_writer.go
)676: if l.typ == "Timestamp" || l.Timestamp != time.Time{} { ^ 677: return json.Marshal(l.Timestamp) 678: } 679: return nil, fmt.Errorf("type %T does not include a non-empty union type", l) 680: }