Skip to content

Commit

Permalink
Merge branch 'main' into eden/improve-ts-timeout-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
eyw520 authored Nov 22, 2024
2 parents 8623c82 + e4299dd commit b9b008a
Show file tree
Hide file tree
Showing 252 changed files with 30,707 additions and 2,594 deletions.
9 changes: 9 additions & 0 deletions fern/pages/changelogs/go-sdk/2024-11-21.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 0.33.0
**`(feat):`** Add support for the `inlinePathParameters` configuration option, which generates path parameters in the generated request type (if any) instead of as separate positional parameters.
```yaml # generators.yml
- name: fern-api/fern-go-sdk
version: 0.33.0
config:
inlinePathParameters: true
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { z } from "zod";
import { ModuleConfigSchema } from "./ModuleConfigSchema";

export const BaseGoCustomConfigSchema = z.object({
module: ModuleConfigSchema.optional(),
packageName: z.string().optional(),
importPath: z.string().optional(),
module: ModuleConfigSchema.optional(),
union: z.string().optional(),

alwaysSendRequiredProperties: z.boolean().optional(),
enableExplicitNull: z.boolean().optional(),
exportedClientName: z.string().optional(),
includeLegacyClientOptions: z.boolean().optional(),
alwaysSendRequiredProperties: z.boolean().optional()
inlinePathParameters: z.boolean().optional(),
inlineFileProperties: z.boolean().optional(),
union: z.string().optional()
});

export type BaseGoCustomConfigSchema = z.infer<typeof BaseGoCustomConfigSchema>;
3 changes: 2 additions & 1 deletion generators/go-v2/ast/src/custom-config/ModuleConfigSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { z } from "zod";

export const ModuleConfigSchema = z.object({
path: z.string(),
version: z.string().optional()
version: z.string().optional(),
imports: z.record(z.string(), z.string()).optional()
});

export type ModuleConfigSchema = z.infer<typeof ModuleConfigSchema>;
36 changes: 26 additions & 10 deletions generators/go-v2/dynamic-snippets/src/DynamicSnippetsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ export class DynamicSnippetsGenerator extends AbstractDynamicSnippetsGenerator<D

this.context.errors.scope(Scope.PathParameters);
if (request.pathParameters != null) {
args.push(...this.getPathParameters({ namedParameters: request.pathParameters, snippet }));
const pathParameterFields = this.getPathParameters({ namedParameters: request.pathParameters, snippet });
args.push(...pathParameterFields.map((field) => field.value));
}
this.context.errors.unscope();

Expand Down Expand Up @@ -377,24 +378,36 @@ export class DynamicSnippetsGenerator extends AbstractDynamicSnippetsGenerator<D
const args: go.TypeInstantiation[] = [];

this.context.errors.scope(Scope.PathParameters);
const pathParameterFields: go.StructField[] = [];
if (request.pathParameters != null) {
args.push(...this.getPathParameters({ namedParameters: request.pathParameters, snippet }));
pathParameterFields.push(...this.getPathParameters({ namedParameters: request.pathParameters, snippet }));
}
this.context.errors.unscope();

args.push(this.getInlinedRequestArg({ request, snippet }));
if (!this.context.customConfig?.inlinePathParameters) {
args.push(...pathParameterFields.map((field) => field.value));
}
if (this.context.doesInlinedRequestExist({ request })) {
args.push(
this.getInlinedRequestArg({
request,
snippet,
pathParameterFields: this.context.customConfig?.inlinePathParameters ? pathParameterFields : []
})
);
}
return args;
}

private getInlinedRequestArg({
request,
snippet
snippet,
pathParameterFields
}: {
request: DynamicSnippets.InlinedRequest;
snippet: DynamicSnippets.EndpointSnippetRequest;
pathParameterFields: go.StructField[];
}): go.TypeInstantiation {
const fields: go.StructField[] = [];

this.context.errors.scope(Scope.QueryParameters);
const queryParameters = this.context.associateQueryParametersByWireValue({
parameters: request.queryParameters ?? [],
Expand Down Expand Up @@ -429,7 +442,7 @@ export class DynamicSnippetsGenerator extends AbstractDynamicSnippetsGenerator<D
name: this.context.getMethodName(request.declaration.name),
importPath: this.context.getImportPath(request.declaration.fernFilepath)
}),
fields: [...queryParameterFields, ...headerFields, ...requestBodyFields]
fields: [...pathParameterFields, ...queryParameterFields, ...headerFields, ...requestBodyFields]
});
}

Expand Down Expand Up @@ -507,15 +520,18 @@ export class DynamicSnippetsGenerator extends AbstractDynamicSnippetsGenerator<D
}: {
namedParameters: DynamicSnippets.NamedParameter[];
snippet: DynamicSnippets.EndpointSnippetRequest;
}): go.TypeInstantiation[] {
const args: go.TypeInstantiation[] = [];
}): go.StructField[] {
const args: go.StructField[] = [];

const pathParameters = this.context.associateByWireValue({
parameters: namedParameters,
values: snippet.pathParameters ?? {}
});
for (const parameter of pathParameters) {
args.push(this.context.dynamicTypeInstantiationMapper.convert(parameter));
args.push({
name: this.context.getTypeName(parameter.name.name),
value: this.context.dynamicTypeInstantiationMapper.convert(parameter)
});
}

return args;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4827,6 +4827,46 @@ func do() {
&acme.GetOrganizationUserRequest{},
)
}
------------------------
package example
import (
context "context"
acme "github.com/acme/acme-go"
client "github.com/acme/acme-go/client"
)
func do() {
client := client.NewClient()
client.User.SearchUsers(
context.TODO(),
"userId",
&acme.SearchUsersRequest{
Limit: acme.Int(
1,
),
},
)
}
------------------------
package example
import (
context "context"
client "github.com/acme/acme-go/client"
)
func do() {
client := client.NewClient()
client.User.GetOrganization(
context.TODO(),
"organizationId",
)
}
"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function buildDynamicSnippetsGenerator({
config: FernGeneratorExec.GeneratorConfig;
}): DynamicSnippetsGenerator {
const content = readFileSync(irFilepath, "utf-8");
const ir = DynamicSnippets.DynamicIntermediateRepresentation.parseOrThrow(JSON.parse(content));
const ir = DynamicSnippets.DynamicIntermediateRepresentation.parseOrThrow(JSON.parse(content), {
unrecognizedObjectKeys: "passthrough"
});
return new DynamicSnippetsGenerator({ ir, config, formatter: new GoFormatter() });
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export class DynamicSnippetsGeneratorContext {
return instances;
}

public doesInlinedRequestExist({ request }: { request: DynamicSnippets.InlinedRequest }): boolean {
// TODO: Reference the request wrapper's `includePathParameters` field.
return true;
}

public getRecord(value: unknown): Record<string, unknown> | undefined {
if (typeof value !== "object" || Array.isArray(value)) {
this.errors.add({
Expand Down
1 change: 1 addition & 0 deletions generators/go/cmd/fern-go-fiber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
includeReadme,
config.Whitelabel,
config.AlwaysSendRequiredProperties,
config.InlinePathParameters,
config.InlineFileProperties,
config.Organization,
config.Version,
Expand Down
1 change: 1 addition & 0 deletions generators/go/cmd/fern-go-model/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
includeReadme,
config.Whitelabel,
config.AlwaysSendRequiredProperties,
config.InlinePathParameters,
config.InlineFileProperties,
config.Organization,
config.Version,
Expand Down
1 change: 1 addition & 0 deletions generators/go/cmd/fern-go-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func run(config *cmd.Config, coordinator *coordinator.Client) ([]*generator.File
includeReadme,
config.Whitelabel,
config.AlwaysSendRequiredProperties,
config.InlinePathParameters,
config.InlineFileProperties,
config.Organization,
config.Version,
Expand Down
3 changes: 3 additions & 0 deletions generators/go/internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Config struct {
IncludeLegacyClientOptions bool
Whitelabel bool
AlwaysSendRequiredProperties bool
InlinePathParameters bool
InlineFileProperties bool
Organization string
CoordinatorURL string
Expand Down Expand Up @@ -201,6 +202,7 @@ func newConfig(configFilename string) (*Config, error) {

return &Config{
DryRun: config.DryRun,
InlinePathParameters: customConfig.InlinePathParameters,
InlineFileProperties: customConfig.InlineFileProperties,
IncludeLegacyClientOptions: customConfig.IncludeLegacyClientOptions,
EnableExplicitNull: customConfig.EnableExplicitNull,
Expand Down Expand Up @@ -257,6 +259,7 @@ func readConfig(configFilename string) (*generatorexec.GeneratorConfig, error) {

type customConfig struct {
EnableExplicitNull bool `json:"enableExplicitNull,omitempty"`
InlinePathParameters bool `json:"inlinePathParameters,omitempty"`
InlineFileProperties bool `json:"inlineFileProperties,omitempty"`
IncludeLegacyClientOptions bool `json:"includeLegacyClientOptions,omitempty"`
AlwaysSendRequiredProperties bool `json:"alwaysSendRequiredProperties,omitempty"`
Expand Down
Loading

0 comments on commit b9b008a

Please sign in to comment.