Skip to content

feat(go): [DRAFT] Add support for response headers #7502

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

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
341ca1a
feat(go): Add support for response headers
amckinney Jun 12, 2025
0f66bbe
Spec out the endpoint generator
amckinney Jun 12, 2025
da9ad75
Start wiring up the 'Caller' interface
amckinney Jun 12, 2025
c80a9b4
Iterate on RawClient generation
amckinney Jun 13, 2025
3d0dfc9
Add RawClient constructor
amckinney Jun 16, 2025
148b4e7
Wire up the raw client generator
amckinney Jun 16, 2025
f8a8a84
Generate the (partial) raw_client.go file
amckinney Jun 16, 2025
93ae82e
Start implementing method stubs
amckinney Jun 16, 2025
ec9ba42
Add GoZeroValueMapper
amckinney Jun 16, 2025
f347d51
Add support for generating go.mod
amckinney Jun 17, 2025
8e0fd6f
Generate zero values on error cases
amckinney Jun 17, 2025
0cb1bec
Update GoTypeMapper for named types
amckinney Jun 18, 2025
bfe2c8c
Add support for resolving stream type reference
amckinney Jun 18, 2025
e5b5527
Add support for bytes requests
amckinney Jun 18, 2025
bb5d7fa
Refactor EndpointSignatureInfo return types
amckinney Jun 18, 2025
38494e9
Resolve endpoint-specific base url
amckinney Jun 18, 2025
b219d38
Write query parameters, if any
amckinney Jun 18, 2025
7d6709a
Write headers (w/ internal.MergeHeaders)
amckinney Jun 18, 2025
20c4c18
Implement the GoValueFormatter
amckinney Jun 18, 2025
764374f
Generate header values
amckinney Jun 20, 2025
4eab833
Add support for IdempotentRequestOption
amckinney Jun 20, 2025
b18600a
Generate status code error handling
amckinney Jun 20, 2025
a00a8ce
Start building out response handling
amckinney Jun 20, 2025
8222798
Add support for writing generic struct pointers
amckinney Jun 20, 2025
e0d4874
Write raw response handling
amckinney Jun 20, 2025
5effe61
Add multiline support for arguments
amckinney Jun 23, 2025
c72b566
Call internal.EncodeURL
amckinney Jun 23, 2025
625dc67
Handle idempotent request options
amckinney Jun 23, 2025
19ddb37
Support endpoints with no response values
amckinney Jun 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions generators/go-v2/ast/src/ast/Func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export class Func extends AstNode {
this.func = new Method({ name, parameters, return_, body, docs });
}

public get name(): string {
return this.func.name;
}

public get parameters(): Parameter[] {
return this.func.parameters;
}
Expand All @@ -29,6 +25,10 @@ export class Func extends AstNode {
return this.func.return_;
}

public get name(): string | undefined {
return this.func.name;
}

public get body(): CodeBlock | undefined {
return this.func.body;
}
Expand Down
8 changes: 6 additions & 2 deletions generators/go-v2/ast/src/ast/FuncInvocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ export declare namespace FuncInvocation {
func: GoTypeReference;
/* The arguments passed to the method */
arguments_: AstNode[];
/* Whether to write the invocation on multiple lines */
multiline?: boolean;
}
}

export class FuncInvocation extends AstNode {
private func: GoTypeReference;
private arguments_: AstNode[];
private multiline: boolean | undefined;

constructor({ func, arguments_ }: FuncInvocation.Args) {
constructor({ func, arguments_, multiline = true }: FuncInvocation.Args) {
super();

this.func = func;
this.arguments_ = arguments_;
this.multiline = multiline;
}

public write(writer: Writer): void {
writer.writeNode(this.func);
writeArguments({ writer, arguments_: this.arguments_ });
writeArguments({ writer, arguments_: this.arguments_, multiline: this.multiline });
}
}
19 changes: 18 additions & 1 deletion generators/go-v2/ast/src/ast/GoTypeReference.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Type } from "./Type";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";

Expand All @@ -7,17 +8,21 @@ export declare namespace GoTypeReference {
name: string;
/* The import path of the Go type */
importPath: string;
/* The generic type parameters, if any */
generics?: Type[] | undefined;
}
}

export class GoTypeReference extends AstNode {
public readonly name: string;
public readonly importPath: string;
public readonly generics: Type[] | undefined;

constructor({ name, importPath }: GoTypeReference.Args) {
constructor({ name, importPath, generics }: GoTypeReference.Args) {
super();
this.name = name;
this.importPath = importPath;
this.generics = generics;
}

public write(writer: Writer): void {
Expand All @@ -27,5 +32,17 @@ export class GoTypeReference extends AstNode {
}
const alias = writer.addImport(this.importPath);
writer.write(`${alias}.${this.name}`);
if (this.generics != null) {
writer.write("[");
this.generics.forEach((generic, idx) => {
if (idx > 0) {
writer.write(", ");
}
if (generic != null) {
generic.write(writer);
}
});
writer.write("]");
}
}
}
12 changes: 7 additions & 5 deletions generators/go-v2/ast/src/ast/Method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { Writer } from "./core/Writer";

export declare namespace Method {
interface Args {
/* The name of the method */
name: string;
/* The parameters of the method */
parameters: Parameter[];
/* The return type of the method */
return_: Type[];
/* The name of the method */
name?: string;
/* The body of the method */
body?: CodeBlock;
/* Documentation for the method */
Expand All @@ -24,9 +24,9 @@ export declare namespace Method {
}

export class Method extends AstNode {
public readonly name: string;
public readonly parameters: Parameter[];
public readonly return_: Type[];
public readonly name: string | undefined;
public readonly body: CodeBlock | undefined;
public readonly docs: string | undefined;
public readonly typeReference: GoTypeReference | undefined;
Expand All @@ -43,11 +43,13 @@ export class Method extends AstNode {

public write(writer: Writer): void {
writer.writeNode(new Comment({ docs: this.docs }));
writer.write("func ");
writer.write("func");
if (this.typeReference != null) {
this.writeReceiver({ writer, typeReference: this.typeReference });
}
writer.write(`${this.name}`);
if (this.name != null) {
writer.write(` ${this.name}`);
}
if (this.parameters.length === 0) {
writer.write("() ");
} else {
Expand Down
8 changes: 6 additions & 2 deletions generators/go-v2/ast/src/ast/MethodInvocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@ export declare namespace MethodInvocation {
method: string;
/* The arguments passed to the method */
arguments_: AstNode[];
/* Whether to write the invocation on multiple lines */
multiline?: boolean;
}
}

export class MethodInvocation extends AstNode {
private on: AstNode;
private method: string;
private arguments_: AstNode[];
private multiline: boolean | undefined;

constructor({ method, arguments_, on }: MethodInvocation.Args) {
constructor({ method, arguments_, on, multiline }: MethodInvocation.Args) {
super();

this.on = on;
this.method = method;
this.arguments_ = arguments_;
this.multiline = multiline;
}

public write(writer: Writer): void {
this.on.write(writer);
writer.write(".");
writer.write(this.method);
writeArguments({ writer, arguments_: this.arguments_ });
writeArguments({ writer, arguments_: this.arguments_, multiline: this.multiline });
}
}
23 changes: 23 additions & 0 deletions generators/go-v2/ast/src/ast/Pointer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";

export declare namespace Pointer {
interface Args {
/* The value of the pointer */
node: AstNode;
}
}

export class Pointer extends AstNode {
public readonly node: AstNode;

constructor({ node }: Pointer.Args) {
super();
this.node = node;
}

public write(writer: Writer): void {
writer.write("*");
this.node.write(writer);
}
}
28 changes: 28 additions & 0 deletions generators/go-v2/ast/src/ast/Selector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";

export declare namespace Selector {
interface Args {
/* The node to select from */
on: AstNode;
/* The node to select (e.g. a field name) */
selector: AstNode;
}
}

export class Selector extends AstNode {
public readonly on: AstNode;
public readonly selector: AstNode;

constructor({ on, selector }: Selector.Args) {
super();
this.on = on;
this.selector = selector;
}

public write(writer: Writer): void {
writer.writeNode(this.on);
writer.write(".");
writer.writeNode(this.selector);
}
}
43 changes: 39 additions & 4 deletions generators/go-v2/ast/src/ast/Struct.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { CodeBlock } from "@fern-api/browser-compatible-base-generator";

import { Comment } from "./Comment";
import { Field } from "./Field";
import { Method } from "./Method";
import { Parameter } from "./Parameter";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";

Expand All @@ -13,13 +16,19 @@
/* Docs associated with the class */
docs?: string;
}

interface Constructor {
parameters: Parameter[];
body: AstNode;
}
}

export class Struct extends AstNode {
public readonly name: string;
public readonly importPath: string;
public readonly docs: string | undefined;

public constructor_: Struct.Constructor | undefined;
public readonly fields: Field[] = [];
public readonly methods: Method[] = [];

Expand All @@ -30,12 +39,16 @@
this.docs = docs;
}

public addField(field: Field): void {
this.fields.push(field);
public addConstructor(constructor: Struct.Constructor): void {
this.constructor_ = constructor;
}

public addMethod(method: Method): void {
this.methods.push(method);
public addField(...fields: Field[]): void {
this.fields.push(...fields);
}

public addMethod(...methods: Method[]): void {
this.methods.push(...methods);
}

public write(writer: Writer): void {
Expand All @@ -54,6 +67,11 @@
writer.writeLine("}");
}

if (this.constructor_ != null) {
writer.newLine();
this.writeConstructor({ writer, constructor: this.constructor_ });
}

if (this.methods.length > 0) {
writer.newLine();
for (const method of this.methods) {
Expand All @@ -62,4 +80,21 @@
}
}
}

private writeConstructor({ writer, constructor }: { writer: Writer; constructor: Struct.Constructor }): void {
writer.write(`func New${this.name}(`);
constructor.parameters.forEach((parameter, index) => {
if (index > 0) {
writer.write(", ");
}
writer.writeNode(parameter);
});
writer.write(`) *${this.name} {`);
writer.newLine();
writer.indent();
writer.writeNode(constructor.body);
writer.writeNewLineIfLastLineNot();
writer.dedent();
writer.writeLine(`}`);

Check failure on line 98 in generators/go-v2/ast/src/ast/Struct.ts

View workflow job for this annotation

GitHub Actions / eslint

Strings must use doublequote
}
}
Loading
Loading