From 370c3659c52d568eddfc788ce96e739e153104e9 Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Tue, 1 Sep 2020 10:21:44 +0100 Subject: [PATCH] fix camel-casing of TS type field names --- generators/tstypes/testdata/todo_types.ts | 4 ++-- generators/tstypes/tstypes.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/generators/tstypes/testdata/todo_types.ts b/generators/tstypes/testdata/todo_types.ts index 2fd08d3..116de52 100644 --- a/generators/tstypes/testdata/todo_types.ts +++ b/generators/tstypes/testdata/todo_types.ts @@ -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 diff --git a/generators/tstypes/tstypes.go b/generators/tstypes/tstypes.go index 4ca2d2c..0471cff 100644 --- a/generators/tstypes/tstypes.go +++ b/generators/tstypes/tstypes.go @@ -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)) } }