Skip to content

Commit

Permalink
fix camel-casing of TS type field names
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Sep 1, 2020
1 parent 9b9dace commit 370c365
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions generators/tstypes/testdata/todo_types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Item is a to-do item.
export interface Item {
// created_at is the time the to-do item was created.
created_at?: Date
// createdAt is the time the to-do item was created.
createdAt?: Date

// id is the id of the item. This field is read-only.
id?: number
Expand Down
7 changes: 4 additions & 3 deletions generators/tstypes/tstypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ func writeFields(w io.Writer, s *schema.Schema, fields []schema.Field) {

// writeField to writer.
func writeField(w io.Writer, s *schema.Schema, f schema.Field) {
fmt.Fprintf(w, " // %s is %s%s\n", f.Name, f.Description, schemautil.FormatExtra(f))
name := format.JsName(f.Name)
fmt.Fprintf(w, " // %s is %s%s\n", name, f.Description, schemautil.FormatExtra(f))
if f.Required {
fmt.Fprintf(w, " %s: %s\n", f.Name, jsType(s, f))
fmt.Fprintf(w, " %s: %s\n", name, jsType(s, f))
} else {
fmt.Fprintf(w, " %s?: %s\n", f.Name, jsType(s, f))
fmt.Fprintf(w, " %s?: %s\n", name, jsType(s, f))
}
}

Expand Down

0 comments on commit 370c365

Please sign in to comment.