@@ -17,6 +17,7 @@ const {
1717 camelCase,
1818 escapeIdentifier,
1919 escapePropertyOrMethodName,
20+ toJsonStr,
2021} = require ( './utils' ) ;
2122
2223const HTTP_VERBS = [
@@ -150,9 +151,9 @@ function buildMethodSpec(controllerSpec, op, options) {
150151 const methodName = getMethodName ( op . spec ) ;
151152 let args = [ ] ;
152153 const parameters = op . spec . parameters ;
154+ // Keep track of param names to avoid duplicates
155+ const paramNames = { } ;
153156 if ( parameters ) {
154- // Keep track of param names to avoid duplicates
155- const paramNames = { } ;
156157 args = parameters . map ( p => {
157158 const name = escapeIdentifier ( p . name ) ;
158159 if ( name in paramNames ) {
@@ -167,7 +168,35 @@ function buildMethodSpec(controllerSpec, op, options) {
167168 } `;
168169 } ) ;
169170 }
170- let returnType = 'any' ;
171+ if ( op . spec . requestBody ) {
172+ /**
173+ * requestBody:
174+ * description: Pet to add to the store
175+ * required: true
176+ * content:
177+ * application/json:
178+ * schema:
179+ * $ref: '#/components/schemas/NewPet'
180+ */
181+ let bodyType = { signature : 'any' } ;
182+ const content = op . spec . requestBody . content ;
183+ const jsonType = content && content [ 'application/json' ] ;
184+ if ( jsonType && jsonType . schema ) {
185+ bodyType = mapSchemaType ( jsonType . schema , options ) ;
186+ addImportsForType ( bodyType ) ;
187+ }
188+ let bodyName = 'body' ;
189+ if ( bodyName in paramNames ) {
190+ bodyName = `${ bodyName } ${ paramNames [ bodyName ] ++ } ` ;
191+ }
192+ const bodyParam = bodyName ; // + (op.spec.requestBody.required ? '' : '?');
193+ // Add body as the 1st param
194+ const bodySpec = '' ; // toJsonStr(op.spec.requestBody);
195+ args . unshift (
196+ `@requestBody(${ bodySpec } ) ${ bodyParam } : ${ bodyType . signature } ` ,
197+ ) ;
198+ }
199+ let returnType = { signature : 'any' } ;
171200 const responses = op . spec . responses ;
172201 if ( responses ) {
173202 /**
@@ -195,11 +224,15 @@ function buildMethodSpec(controllerSpec, op, options) {
195224 const signature = `async ${ methodName } (${ args . join ( ', ' ) } ): Promise<${
196225 returnType . signature
197226 } >`;
198- return {
227+ const methodSpec = {
199228 description : op . spec . description ,
200229 decoration : `@operation('${ op . verb } ', '${ op . path } ')` ,
201230 signature,
202231 } ;
232+ if ( op . spec [ 'x-implementation' ] ) {
233+ methodSpec . implementation = op . spec [ 'x-implementation' ] ;
234+ }
235+ return methodSpec ;
203236
204237 function addImportsForType ( typeSpec ) {
205238 if ( typeSpec . className && typeSpec . import ) {
0 commit comments