Skip to content

Commit

Permalink
Add a comment header to generated files (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfarzan authored Jun 9, 2020
1 parent 49fb6d9 commit e27d846
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go/cmd/typegen/typegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions go/pkg/swagger/language/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions go/pkg/swagger/language/ts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e27d846

Please sign in to comment.