Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp type causes "expected ';', found '{'" syntax error in generated types #5189

Open
csm-kb opened this issue Nov 17, 2024 · 0 comments · May be fixed by #5190
Open

Timestamp type causes "expected ';', found '{'" syntax error in generated types #5189

csm-kb opened this issue Nov 17, 2024 · 0 comments · May be fixed by #5190
Assignees
Labels
bug Issues reporting bugs. language/go product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages

Comments

@csm-kb
Copy link
Contributor

csm-kb commented Nov 17, 2024

CLI Version

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
  • 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.

@dannysheridan dannysheridan changed the title [Bug] Timestamp type causes "expected ';', found '{'" syntax error in generated types Timestamp type causes "expected ';', found '{'" syntax error in generated types Dec 1, 2024
@dannysheridan dannysheridan added product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages bug Issues reporting bugs. labels Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues reporting bugs. language/go product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages
Development

Successfully merging a pull request may close this issue.

3 participants