Skip to content

Commit ff420ee

Browse files
committed
refactor: introduce language-specific prefixes for accessing parameters
1 parent 4bf7866 commit ff420ee

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/cli.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,14 @@ const createEndpoints = async (destDir, lang, config) => {
113113
}
114114

115115
const placeholdersMap = {
116-
'p': 'req.params',
117-
'b': 'req.body'
116+
'js': {
117+
'p': 'req.params',
118+
'b': 'req.body',
119+
},
120+
'go': {
121+
'p': 'dto',
122+
'b': 'dto',
123+
}
118124
}
119125

120126
const parser = new Parser();
@@ -131,7 +137,7 @@ const createEndpoints = async (destDir, lang, config) => {
131137
// (used only with Express)
132138
"formatParamsAsJavaScriptObject": (params) => {
133139
return params.length > 0
134-
? '{ ' + Array.from(new Set(params), p => `"${p.substring(2)}": ${placeholdersMap[p.substring(0, 1)]}.${p.substring(2)}`).join(', ') + ' }'
140+
? '{ ' + Array.from(new Set(params), p => `"${p.substring(2)}": ${placeholdersMap['js'][p.substring(0, 1)]}.${p.substring(2)}`).join(', ') + ' }'
135141
: params;
136142
},
137143

@@ -156,7 +162,7 @@ const createEndpoints = async (destDir, lang, config) => {
156162
}
157163
return Array.from(
158164
new Set(params),
159-
p => `"${p.substring(2)}": dto.${capitalize(snake2camelCase(p.substring(2)))},`
165+
p => `"${p.substring(2)}": ${placeholdersMap['go'][p.substring(0, 1)]}.${capitalize(snake2camelCase(p.substring(2)))},`
160166
).join('\n\t\t\t');
161167
},
162168
}

0 commit comments

Comments
 (0)