Skip to content

Commit

Permalink
Merge pull request #10 from sayari-analytics/update-generator
Browse files Browse the repository at this point in the history
Update generator
  • Loading branch information
davidkonigsberg authored Feb 5, 2024
2 parents 7ac98b3 + da5982d commit 3dbf193
Show file tree
Hide file tree
Showing 563 changed files with 86,600 additions and 253,986 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ install:
test: install
go test ./...
npm install -g @fern-api/[email protected]
seed test --workspace sdk --fixture bytes
seed test --workspace sdk --fixture enum-query-params
seed test --workspace sdk --fixture response-property
seed test --workspace sdk --fixture file-upload
seed test --workspace sdk --fixture idempotency-headers
seed test --workspace sdk --fixture literal
seed test --workspace sdk --fixture literal-headers
seed test --workspace sdk --fixture plain-text
seed test --workspace sdk --fixture streaming

.PHONY: fixtures
Expand Down
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This generator is used via the [Fern CLI](https://github.com/fern-api/fern), by

```yml
- name: fernapi/fern-go-sdk
version: 0.9.0
version: 0.13.0
output:
location: local-file-system
path: ../../generated/go
Expand All @@ -61,6 +61,24 @@ on the local filesystem. The Go generator needs to know where to resolve its imp
statements from, so you will either need to add an import path or module configuration
to do so.

### Package name

You can customzie the name of the package generated with the following `generators.yml` configuration:

```yaml
default-group: local
groups:
local:
generators:
- name: fernapi/fern-go-sdk
version: 0.13.0
config:
packageName: acme
output:
location: local-file-system
path: ../../generated/go
```

### Import path

> This is recommended if you plan to depend on the generated Go SDK from within your project,
Expand All @@ -75,7 +93,7 @@ groups:
local:
generators:
- name: fernapi/fern-go-sdk
version: 0.4.0
version: 0.13.0
config:
importPath: github.com/<YOUR_ORGANIZATION>/<YOUR_REPOSITORY>/generated/go
output:
Expand All @@ -101,7 +119,7 @@ groups:
local:
generators:
- name: fernapi/fern-go-sdk
version: 0.4.0
version: 0.13.0
config:
module:
path: github.com/<YOUR_ORGANIZATION>/<YOUR_REPOSITORY>
Expand All @@ -123,7 +141,7 @@ groups:
local:
generators:
- name: fernapi/fern-go-sdk
version: 0.4.0
version: 0.13.0
config:
module:
path: github.com/<YOUR_ORGANIZATION>/<YOUR_REPOSITORY>
Expand All @@ -149,7 +167,7 @@ option described above.
## Explicit Null
By default, it's impossible to send an explicit JSON `null` for optional parameters. You can opt-in to
By default, it's impossible to send an explicit JSON `null` for optional parameters. You can opt-in to
generating a generic `Optional[T]` type that can be used to distinguish between a `nil` value (nothing
is sent), a non-`nil` value (the value is sent), and an explicit null (a `null` value is sent). This is
particularly useful for `PATCH` endpoints.
Expand Down Expand Up @@ -177,7 +195,7 @@ groups:
local:
generators:
- name: fernapi/fern-go-sdk
version: 0.4.0
version: 0.13.0
config:
enableExplicitNull: true
output:
Expand All @@ -191,15 +209,15 @@ Note that this feature requires generics, so the generated `go.mod` will be upgr

All generator releases are published in the [Releases section of the GitHub repository](https://github.com/fern-api/fern-go/releases). You can directly use these version numbers in your generator configuration files.

For instance, if you want to use version `0.3.0` of the Go generator:
For instance, if you want to use version `0.12.1` of the Go generator:

```yaml
default-group: local
groups:
local:
generators:
- name: fernapi/fern-go-sdk
version: 0.3.0
version: 0.12.1
output:
location: local-file-system
path: ../../generated/go
Expand Down
2 changes: 2 additions & 0 deletions cmd/fern-go-fiber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
generatorConfig, err := generator.NewConfig(
config.DryRun,
config.EnableExplicitNull,
config.IncludeLegacyClientOptions,
includeReadme,
config.Organization,
config.Version,
config.IrFilepath,
config.ImportPath,
config.PackageName,
config.Module,
)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/fern-go-model/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
generatorConfig, err := generator.NewConfig(
config.DryRun,
config.EnableExplicitNull,
config.IncludeLegacyClientOptions,
includeReadme,
config.Organization,
config.Version,
config.IrFilepath,
config.ImportPath,
config.PackageName,
config.Module,
)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/fern-go-model/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,22 @@ func TestUndiscriminatedUnion(t *testing.T) {
require.NoError(t, json.Unmarshal([]byte(`{"body": "something"}`), request))

assert.Equal(t, "something", request.Body.String)
assert.Empty(t, request.Body.StringLiteral())
assert.Empty(t, request.Body.FernStringLiteral())

unionLiteral := new(undiscriminated.Union)
require.NoError(t, json.Unmarshal([]byte(`"fern"`), unionLiteral))

// Test that the string takes precedence over the literal because
// they aren't specified in the correct order.
assert.Empty(t, unionLiteral.StringLiteral())
assert.Empty(t, unionLiteral.FernStringLiteral())
assert.Equal(t, "fern", unionLiteral.String)

unionWithLiteral := new(undiscriminated.UnionWithLiteral)
require.NoError(t, json.Unmarshal([]byte(`"fern"`), unionWithLiteral))

// Test that the literal is used as long as it's actually observed
// on the wire.
assert.Equal(t, "fern", unionWithLiteral.StringLiteral())
assert.Equal(t, "fern", unionWithLiteral.FernStringLiteral())
assert.Empty(t, unionWithLiteral.String)
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/fern-go-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
generatorConfig, err := generator.NewConfig(
config.DryRun,
config.EnableExplicitNull,
config.IncludeLegacyClientOptions,
includeReadme,
config.Organization,
config.Version,
config.IrFilepath,
config.ImportPath,
config.PackageName,
config.Module,
)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/fern-api/fern-go
go 1.19

require (
github.com/fern-api/generator-exec-go v0.0.491
github.com/google/uuid v1.4.0
github.com/fern-api/generator-exec-go v0.0.534
github.com/google/uuid v1.6.0
github.com/hmdsefi/gograph v0.4.0
github.com/stretchr/testify v1.8.4
go.uber.org/multierr v1.11.0
golang.org/x/mod v0.14.0
golang.org/x/tools v0.16.0
golang.org/x/tools v0.17.0
)

require (
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fern-api/generator-exec-go v0.0.491 h1:arIA8hvze7fr2Zh5y/xtUY3WaFIvxJCZnfMF/CqIqJM=
github.com/fern-api/generator-exec-go v0.0.491/go.mod h1:Z7V5lZnaD8PblJAynK087662md2wBNhQcAl+W6IIydw=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/fern-api/generator-exec-go v0.0.534 h1:oYH+0bF2LCnEl4pOJHslPtQnU6Efpkv1pE4HPXHCb9Y=
github.com/fern-api/generator-exec-go v0.0.534/go.mod h1:Z7V5lZnaD8PblJAynK087662md2wBNhQcAl+W6IIydw=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hmdsefi/gograph v0.4.0 h1:eiWprSQ+lSogrcay0yvgvJWEMsVT/VsZ+NR4uW2k+2k=
github.com/hmdsefi/gograph v0.4.0/go.mod h1:WH2SdTvyHkgBFqLBAqPIHyISWY4FNKYrGhJlgjB1jfE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -14,8 +14,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM=
golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
52 changes: 29 additions & 23 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ var (
// Config represents the common configuration required from all of
// the commands (e.g. fern-go-{client,model}).
type Config struct {
DryRun bool
EnableExplicitNull bool
Organization string
CoordinatorURL string
CoordinatorTaskID string
Version string
IrFilepath string
ImportPath string
Module *generator.ModuleConfig
Writer *writer.Config
DryRun bool
EnableExplicitNull bool
IncludeLegacyClientOptions bool
Organization string
CoordinatorURL string
CoordinatorTaskID string
Version string
IrFilepath string
ImportPath string
PackageName string
Module *generator.ModuleConfig
Writer *writer.Config
}

// GeneratorFunc is a function that generates files.
Expand Down Expand Up @@ -185,16 +187,18 @@ func newConfig(configFilename string) (*Config, error) {
coordinatorTaskID = config.Environment.Remote.Id
}
return &Config{
DryRun: config.DryRun,
EnableExplicitNull: customConfig.EnableExplicitNull,
Organization: config.Organization,
CoordinatorURL: coordinatorURL,
CoordinatorTaskID: coordinatorTaskID,
Version: outputVersionFromGeneratorConfig(config),
IrFilepath: config.IrFilepath,
ImportPath: customConfig.ImportPath,
Module: moduleConfig,
Writer: writerConfig,
DryRun: config.DryRun,
IncludeLegacyClientOptions: customConfig.IncludeLegacyClientOptions,
EnableExplicitNull: customConfig.EnableExplicitNull,
Organization: config.Organization,
CoordinatorURL: coordinatorURL,
CoordinatorTaskID: coordinatorTaskID,
Version: outputVersionFromGeneratorConfig(config),
IrFilepath: config.IrFilepath,
ImportPath: customConfig.ImportPath,
PackageName: customConfig.PackageName,
Module: moduleConfig,
Writer: writerConfig,
}, nil
}

Expand Down Expand Up @@ -233,9 +237,11 @@ func readConfig(configFilename string) (*generatorexec.GeneratorConfig, error) {
}

type customConfig struct {
EnableExplicitNull bool `json:"enableExplicitNull,omitempty"`
ImportPath string `json:"importPath,omitempty"`
Module *moduleConfig `json:"module,omitempty"`
EnableExplicitNull bool `json:"enableExplicitNull,omitempty"`
IncludeLegacyClientOptions bool `json:"includeLegacyClientOptions,omitempty"`
ImportPath string `json:"importPath,omitempty"`
PackageName string `json:"packageName,omitempty"`
Module *moduleConfig `json:"module,omitempty"`
}

type moduleConfig struct {
Expand Down
Loading

0 comments on commit 3dbf193

Please sign in to comment.