@@ -31,19 +31,21 @@ function run(urlStr, body, options) {
31
31
if ( path . path . pathFormat ) console . log ( `Format: ${ path . path . pathFormat } ` )
32
32
if ( cfg ?. [ "docs" ] !== undefined ) console . log ( `Docs: ${ cfg ?. [ "docs" ] . join ( ", " ) } ` )
33
33
comment = buildComment ( url , path , opts . method , res )
34
- return res . json ( )
35
- } )
36
- . then ( json => {
37
- const struct = jsonToGo ( JSON . stringify ( json ) , path . struct ) ;
38
- const content = buildContent ( struct . go , path , comment )
39
- write ( json , path , content )
34
+
40
35
if ( opts ?. body ) {
41
36
const paramStruct = jsonToGo ( opts ?. body , path . struct + "Param" ) ;
42
37
const paramContent = buildContent (
43
38
paramStruct . go , path , buildComment ( url , path , opts . method ) , true
44
39
)
45
40
writeParam ( JSON . stringify ( JSON . parse ( opts ?. body ) , null , "\t" ) , path , paramContent )
46
41
}
42
+
43
+ return res . json ( )
44
+ } )
45
+ . then ( json => {
46
+ const struct = jsonToGo ( JSON . stringify ( json ) , path . struct ) ;
47
+ const content = buildContent ( struct . go , path , comment )
48
+ write ( json , path , content )
47
49
} , ( ) => {
48
50
console . log ( )
49
51
console . log ( "Response Body is empty." )
@@ -62,7 +64,7 @@ function write(json, path, content) {
62
64
if ( err ) throw err ;
63
65
} ) ;
64
66
console . log ( )
65
- console . log ( "Generated Files :" )
67
+ console . log ( "Response Body :" )
66
68
console . log ( ` - ${ path . goFilePath } :1` )
67
69
console . log ( ` - ${ path . jsonFilePath } :1` )
68
70
}
@@ -74,8 +76,10 @@ function writeParam(json, path, content) {
74
76
fs . writeFile ( path . paramGoFilePath , content , ( err ) => {
75
77
if ( err ) throw err ;
76
78
} ) ;
77
- console . log ( ` - ${ path . paramJsonFilePath } :1` )
79
+ console . log ( )
80
+ console . log ( "Request Body Parameter:" )
78
81
console . log ( ` - ${ path . paramGoFilePath } :1` )
82
+ console . log ( ` - ${ path . paramJsonFilePath } :1` )
79
83
}
80
84
81
85
function buildOpts ( body , cliOpts ) {
@@ -92,7 +96,7 @@ function buildOpts(body, cliOpts) {
92
96
if ( ! cliOpts ?. method ) {
93
97
opts . method = "POST"
94
98
}
95
- if ( isJsonString ( cliOpts . headers ) ) {
99
+ if ( isJsonString ( body ) ) {
96
100
opts . body = body
97
101
} else {
98
102
const bodyObj = loadJsonOrYaml ( body )
@@ -113,7 +117,6 @@ function buildOpts(body, cliOpts) {
113
117
return opts
114
118
}
115
119
116
- // TODO: Paramにも対応する
117
120
function buildContent ( go , path , comment , isParam = false ) {
118
121
let content = `// Generated Code But Editable.
119
122
// Format The Code with \`go fmt\` or something and edit it manually to use it.
0 commit comments