From e27d84627882fdea2932e1153baa348f82fff907 Mon Sep 17 00:00:00 2001 From: Frank Farzan Date: Tue, 9 Jun 2020 16:32:29 -0700 Subject: [PATCH] Add a comment header to generated files (#158) --- go/cmd/typegen/typegen.go | 2 +- go/pkg/swagger/language/languages.go | 3 +++ go/pkg/swagger/language/ts.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/go/cmd/typegen/typegen.go b/go/cmd/typegen/typegen.go index a733c4066..aa34d43c4 100644 --- a/go/cmd/typegen/typegen.go +++ b/go/cmd/typegen/typegen.go @@ -80,7 +80,7 @@ func printTS(outPath string, refObjects map[swagger.Ref]swagger.Object, definiti RefObjects: refObjects, } for pkg, defs := range pkgs { - var contents []string + var contents = []string{lang.PrintHeaderComment()} header := lang.PrintHeader(defs) if header != "" { contents = append(contents, header) diff --git a/go/pkg/swagger/language/languages.go b/go/pkg/swagger/language/languages.go index 593613383..b8717301b 100644 --- a/go/pkg/swagger/language/languages.go +++ b/go/pkg/swagger/language/languages.go @@ -26,6 +26,9 @@ type Language interface { // File returns the relative path to definition's client code. File(definition swagger.Definition) string + // PrintHeaderComment prints the top-level comment block. + PrintHeaderComment() string + // PrintHeader prints everything appearing before any Definitions, such as import statements. // // definitions is the set of Definitions to be printed in the current file. diff --git a/go/pkg/swagger/language/ts.go b/go/pkg/swagger/language/ts.go index d57b12256..19090adad 100644 --- a/go/pkg/swagger/language/ts.go +++ b/go/pkg/swagger/language/ts.go @@ -77,6 +77,16 @@ func (ts TypeScript) PrintHeader(definitions []swagger.Definition) string { return strings.Join(result, "\n") } +// PrintHeaderComment implements Language. +func (ts TypeScript) PrintHeaderComment() string { + return ` +/** + * CODE GENERATED BY 'typgen' BINARY. + * + * DO NOT EDIT. + */` +} + // Indent adds two spaces to the beginning of every line in the string. func Indent(s string) string { splits := strings.Split(s, "\n")