jsonSegmentToGoName converts a snake_case JSON segment to a PascalCase Go field name using common conventions.
(seg string)
| 188 | // jsonSegmentToGoName converts a snake_case JSON segment to a |
| 189 | // PascalCase Go field name using common conventions. |
| 190 | func jsonSegmentToGoName(seg string) string { |
| 191 | words := strings.Split(seg, "_") |
| 192 | var b strings.Builder |
| 193 | for _, w := range words { |
| 194 | if w == "" { |
| 195 | continue |
| 196 | } |
| 197 | // Handle common acronyms. |
| 198 | upper := strings.ToUpper(w) |
| 199 | switch upper { |
| 200 | case "ID", "URL", "IP", "HTTP", "JSON", "API", "UI": |
| 201 | _, _ = b.WriteString(upper) |
| 202 | default: |
| 203 | _, _ = b.WriteString(strings.ToUpper(w[:1])) |
| 204 | _, _ = b.WriteString(w[1:]) |
| 205 | } |
| 206 | } |
| 207 | return b.String() |
| 208 | } |
| 209 | |
| 210 | // goTypeToSchemaType maps a Go reflect.Type to a JSON schema type |
| 211 | // string. |
no test coverage detected