77 A simple utility to translate JSON into a Go type definition.
88*/
99
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+
1229 let data ;
1330 let scope ;
1431 let go = "" ;
@@ -35,7 +52,7 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
3552 } ;
3653 }
3754
38- typename = format ( typename || "AutoGenerated" ) ;
55+ typename = format ( typename ) ;
3956 append ( `type ${ typename } ` ) ;
4057
4158 parseScope ( scope ) ;
@@ -498,7 +515,7 @@ if (typeof module != 'undefined') {
498515 let filename = null
499516
500517 function jsonToGoWithErrorHandling ( json ) {
501- const output = jsonToGo ( json )
518+ const output = jsonToGov2 ( json )
502519 if ( output . error ) {
503520 console . error ( output . error )
504521 process . exitCode = 1
0 commit comments