Skip to content

Commit e0a0f5e

Browse files
authored
Use z-prefixed Go generated files (#1268)
1 parent f48afda commit e0a0f5e

7 files changed

Lines changed: 26 additions & 20 deletions

File tree

.gitattributes

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
nodejs/src/generated/* eol=lf linguist-generated=true
55
dotnet/src/Generated/* eol=lf linguist-generated=true
66
python/copilot/generated/* eol=lf linguist-generated=true
7-
go/generated_session_events.go eol=lf linguist-generated=true
8-
go/rpc/generated_rpc.go eol=lf linguist-generated=true
7+
go/zsession_events.go eol=lf linguist-generated=true
8+
go/zsession_encoding.go eol=lf linguist-generated=true
9+
go/rpc/zrpc.go eol=lf linguist-generated=true
10+
go/rpc/zrpc_encoding.go eol=lf linguist-generated=true

go/rpc/generated_rpc_api_shape_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ func parseGeneratedRPC(t *testing.T) (*ast.File, *token.FileSet) {
5353
t.Fatal("locate test file")
5454
}
5555
fileSet := token.NewFileSet()
56-
file, err := parser.ParseFile(fileSet, filepath.Join(filepath.Dir(currentFile), "generated_rpc.go"), nil, 0)
56+
file, err := parser.ParseFile(fileSet, filepath.Join(filepath.Dir(currentFile), "zrpc.go"), nil, 0)
5757
if err != nil {
58-
t.Fatalf("parse generated_rpc.go: %v", err)
58+
t.Fatalf("parse zrpc.go: %v", err)
5959
}
6060
return file, fileSet
6161
}
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/rpc/zrpc_encoding.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/zsession_encoding.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/codegen/go.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,10 +2498,16 @@ function goEncodingBlocksCode(blocks: string[] | undefined): string {
24982498
return joinGoCode(lines);
24992499
}
25002500

2501+
function goDoNotEditHeader(schemaFileName: string): string[] {
2502+
return [
2503+
`// Code generated by scripts/codegen/go.ts; DO NOT EDIT.`,
2504+
`// Source: ${schemaFileName}`,
2505+
];
2506+
}
2507+
25012508
function goGeneratedEncodingFileCode(schemaFileName: string, packageName: string, generatedEncodingCode: string, wrapComments = false): string {
25022509
const lines: string[] = [];
2503-
lines.push(`// AUTO-GENERATED FILE - DO NOT EDIT`);
2504-
lines.push(`// Generated from: ${schemaFileName}`);
2510+
lines.push(...goDoNotEditHeader(schemaFileName));
25052511
lines.push(``);
25062512
lines.push(`package ${packageName}`);
25072513
lines.push(``);
@@ -2692,8 +2698,7 @@ function generateGoSessionEventsCode(schema: JSONSchema7): GoGeneratedTypeCode {
26922698

26932699
// Assemble file
26942700
const out: string[] = [];
2695-
out.push(`// AUTO-GENERATED FILE - DO NOT EDIT`);
2696-
out.push(`// Generated from: session-events.schema.json`);
2701+
out.push(...goDoNotEditHeader("session-events.schema.json"));
26972702
out.push(``);
26982703
out.push(`package copilot`);
26992704
out.push(``);
@@ -2895,7 +2900,7 @@ async function generateSessionEvents(schemaPath?: string): Promise<void> {
28952900
const generatedTypeCode = stripTrailingGoWhitespace(generatedSessionCode.typeCode);
28962901
const generatedEncodingCode = stripTrailingGoWhitespace(generatedSessionCode.encodingCode);
28972902

2898-
const outPath = await writeGeneratedFile("go/generated_session_events.go", generatedTypeCode);
2903+
const outPath = await writeGeneratedFile("go/zsession_events.go", generatedTypeCode);
28992904
console.log(` ✓ ${outPath}`);
29002905

29012906
await formatGoFile(outPath);
@@ -3058,8 +3063,7 @@ async function generateRpc(schemaPath?: string): Promise<void> {
30583063

30593064
// Build method wrappers
30603065
const lines: string[] = [];
3061-
lines.push(`// AUTO-GENERATED FILE - DO NOT EDIT`);
3062-
lines.push(`// Generated from: api.schema.json`);
3066+
lines.push(...goDoNotEditHeader("api.schema.json"));
30633067
lines.push(``);
30643068
lines.push(`package rpc`);
30653069
lines.push(``);
@@ -3102,7 +3106,7 @@ async function generateRpc(schemaPath?: string): Promise<void> {
31023106
emitClientSessionApiRegistration(lines, schema.clientSession, resolveType);
31033107
}
31043108

3105-
const outPath = await writeGeneratedFile("go/rpc/generated_rpc.go", wrapGeneratedGoComments(lines.join("\n")));
3109+
const outPath = await writeGeneratedFile("go/rpc/zrpc.go", wrapGeneratedGoComments(lines.join("\n")));
31063110
console.log(` ✓ ${outPath}`);
31073111

31083112
await formatGoFile(outPath);

0 commit comments

Comments
 (0)