Skip to content

Commit e27d846

Browse files
authored
Add a comment header to generated files (#158)
1 parent 49fb6d9 commit e27d846

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

go/cmd/typegen/typegen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func printTS(outPath string, refObjects map[swagger.Ref]swagger.Object, definiti
8080
RefObjects: refObjects,
8181
}
8282
for pkg, defs := range pkgs {
83-
var contents []string
83+
var contents = []string{lang.PrintHeaderComment()}
8484
header := lang.PrintHeader(defs)
8585
if header != "" {
8686
contents = append(contents, header)

go/pkg/swagger/language/languages.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type Language interface {
2626
// File returns the relative path to definition's client code.
2727
File(definition swagger.Definition) string
2828

29+
// PrintHeaderComment prints the top-level comment block.
30+
PrintHeaderComment() string
31+
2932
// PrintHeader prints everything appearing before any Definitions, such as import statements.
3033
//
3134
// definitions is the set of Definitions to be printed in the current file.

go/pkg/swagger/language/ts.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ func (ts TypeScript) PrintHeader(definitions []swagger.Definition) string {
7777
return strings.Join(result, "\n")
7878
}
7979

80+
// PrintHeaderComment implements Language.
81+
func (ts TypeScript) PrintHeaderComment() string {
82+
return `
83+
/**
84+
* CODE GENERATED BY 'typgen' BINARY.
85+
*
86+
* DO NOT EDIT.
87+
*/`
88+
}
89+
8090
// Indent adds two spaces to the beginning of every line in the string.
8191
func Indent(s string) string {
8292
splits := strings.Split(s, "\n")

0 commit comments

Comments
 (0)