Skip to content

Commit

Permalink
fix: + and - as a first character in names usually has a special meaning
Browse files Browse the repository at this point in the history
  • Loading branch information
RemkoMolier authored and LucasRoesler committed Jun 19, 2023
1 parent bb07fee commit 42fc660
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/generators/models/testdata/cases/parameter_model/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ paths:
in: query
schema:
"$ref": "#/components/schemas/referenced-status"
- name: "-1"
in: query
schema:
type: int
- name: "+1"
in: query
schema:
type: int
- $ref: "#/components/parameters/PageNumber"
responses:
"200":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type GetFooQueryParameters struct {
Param3 []string `json:"param3,omitempty" mapstructure:"param3,omitempty"`
// Param4:
Param4 ReferencedStatus `json:"param4,omitempty" mapstructure:"param4,omitempty"`
// Minus1:
Minus1 int `json:"-1,omitempty" mapstructure:"-1,omitempty"`
// Plus1:
Plus1 int `json:"+1,omitempty" mapstructure:"+1,omitempty"`
// Page: The current set of paged results to display, based on a 1-based array index
Page int32 `json:"page,omitempty" mapstructure:"page,omitempty"`
}
Expand Down Expand Up @@ -101,6 +105,26 @@ func (m *GetFooQueryParameters) SetParam4(val ReferencedStatus) {
m.Param4 = val
}

// GetMinus1 returns the Minus1 property
func (m GetFooQueryParameters) GetMinus1() int {
return m.Minus1
}

// SetMinus1 sets the Minus1 property
func (m *GetFooQueryParameters) SetMinus1(val int) {
m.Minus1 = val
}

// GetPlus1 returns the Plus1 property
func (m GetFooQueryParameters) GetPlus1() int {
return m.Plus1
}

// SetPlus1 sets the Plus1 property
func (m *GetFooQueryParameters) SetPlus1(val int) {
m.Plus1 = val
}

// GetPage returns the Page property
func (m GetFooQueryParameters) GetPage() int32 {
return m.Page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type GetFooQueryParameters struct {
Param3 []string `json:"param3,omitempty" mapstructure:"param3,omitempty"`
// Param4:
Param4 ReferencedStatus `json:"param4,omitempty" mapstructure:"param4,omitempty"`
// Minus1:
Minus1 int `json:"-1,omitempty" mapstructure:"-1,omitempty"`
// Plus1:
Plus1 int `json:"+1,omitempty" mapstructure:"+1,omitempty"`
// Page: The current set of paged results to display, based on a 1-based array index
Page int32 `json:"page,omitempty" mapstructure:"page,omitempty"`
}
Expand Down Expand Up @@ -101,6 +105,26 @@ func (m *GetFooQueryParameters) SetParam4(val ReferencedStatus) {
m.Param4 = val
}

// GetMinus1 returns the Minus1 property
func (m GetFooQueryParameters) GetMinus1() int {
return m.Minus1
}

// SetMinus1 sets the Minus1 property
func (m *GetFooQueryParameters) SetMinus1(val int) {
m.Minus1 = val
}

// GetPlus1 returns the Plus1 property
func (m GetFooQueryParameters) GetPlus1() int {
return m.Plus1
}

// SetPlus1 sets the Plus1 property
func (m *GetFooQueryParameters) SetPlus1(val int) {
m.Plus1 = val
}

// GetPage returns the Page property
func (m GetFooQueryParameters) GetPage() int32 {
return m.Page
Expand Down
8 changes: 8 additions & 0 deletions pkg/generators/templates/casing.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ func ToPascalCase(value string) string {
// Always upper the first character
if i == 0 {
toUpper = true
switch rune {
case '+':
b.WriteString("Plus")
continue
case '-':
b.WriteString("Minus")
continue
}
}
// Always upper the character after non-letter/non-digit skipping the character
if !unicode.IsLetter(rune) && !unicode.IsDigit(rune) {
Expand Down

0 comments on commit 42fc660

Please sign in to comment.