7
7
A simple utility to translate JSON into a Go type definition.
8
8
*/
9
9
10
- function jsonToGo ( json , typename , flatten = true , example = false , allOmitempty = false )
11
- {
10
+ // for backwards compatibility
11
+ function jsonToGo ( json , typename = "AutoGenerated" , flatten = true , example = false , allOmitempty = false ) {
12
+ return jsonToGov2 (
13
+ json ,
14
+ {
15
+ typename : typename ,
16
+ flatten : flatten ,
17
+ example : example ,
18
+ allOmitempty : allOmitempty ,
19
+ } )
20
+ }
21
+
22
+ // new jsonToGo interface
23
+ function jsonToGov2 ( json , options = { } ) {
24
+ let typename = options . typename || "AutoGenerated"
25
+ let flatten = options . flatten === undefined ? true : options . flatten
26
+ let example = options . example === undefined ? false : options . example
27
+ let allOmitempty = options . allOmitempty === undefined ? false : options . allOmitempty
28
+
12
29
let data ;
13
30
let scope ;
14
31
let go = "" ;
@@ -35,7 +52,7 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
35
52
} ;
36
53
}
37
54
38
- typename = format ( typename || "AutoGenerated" ) ;
55
+ typename = format ( typename ) ;
39
56
append ( `type ${ typename } ` ) ;
40
57
41
58
parseScope ( scope ) ;
@@ -498,7 +515,7 @@ if (typeof module != 'undefined') {
498
515
let filename = null
499
516
500
517
function jsonToGoWithErrorHandling ( json ) {
501
- const output = jsonToGo ( json )
518
+ const output = jsonToGov2 ( json )
502
519
if ( output . error ) {
503
520
console . error ( output . error )
504
521
process . exitCode = 1
0 commit comments