@@ -266,22 +266,60 @@ trait JaxrsApiReader extends ClassReader with ClassReaderUtils {
266
266
}
267
267
268
268
def getAllParamsFromFields (cls : Class [_]): List [Parameter ] = {
269
- (for (field <- getAllFields(cls)) yield {
270
- // only process fields with @ApiParam, @QueryParam, @HeaderParam, @PathParam
271
- if (field.getAnnotation(classOf [QueryParam ]) != null || field.getAnnotation(classOf [HeaderParam ]) != null ||
272
- field.getAnnotation(classOf [HeaderParam ]) != null || field.getAnnotation(classOf [PathParam ]) != null ||
273
- field.getAnnotation(classOf [ApiParam ]) != null ) {
269
+ // find getter/setters
270
+ (cls.getDeclaredMethods map {
271
+ method =>
272
+ if (method.getAnnotation(classOf [QueryParam ]) != null ||
273
+ method.getAnnotation(classOf [HeaderParam ]) != null ||
274
+ method.getAnnotation(classOf [PathParam ]) != null ||
275
+ method.getAnnotation(classOf [ApiParam ]) != null ) {
276
+ createParameterFromGetterOrSetter(method).toList
277
+ } else Nil
278
+ }).flatten.toList ++
279
+ (for (field <- getAllFields(cls)) yield {
280
+ // only process fields with @ApiParam, @QueryParam, @HeaderParam, @PathParam
281
+ if (field.getAnnotation(classOf [QueryParam ]) != null ||
282
+ field.getAnnotation(classOf [HeaderParam ]) != null ||
283
+ field.getAnnotation(classOf [PathParam ]) != null ||
284
+ field.getAnnotation(classOf [ApiParam ]) != null ) {
285
+ val param = new MutableParameter
286
+ param.dataType = processDataType(field.getType, field.getGenericType)
287
+ Option (field.getAnnotation(classOf [ApiParam ])) match {
288
+ case Some (annotation) => toAllowableValues(annotation.allowableValues)
289
+ case _ =>
290
+ }
291
+ val annotations = field.getAnnotations
292
+ processParamAnnotations(param, annotations)
293
+ }
294
+ else Nil
295
+ }).flatten.toList
296
+ }
297
+
298
+ private val getterPattern = """ get(.+)""" .r
299
+ private val setterPattern = """ set(.+)""" .r
300
+
301
+ private def createParameterFromGetterOrSetter (method : Method ): List [Parameter ] = {
302
+ (method.getName match {
303
+ case getterPattern(propertyName) =>
274
304
val param = new MutableParameter
275
- param.dataType = processDataType(field.getType, field.getGenericType)
276
- Option (field.getAnnotation(classOf [ApiParam ])) match {
305
+ // TODO: not sure this will work
306
+ param.dataType = processDataType(method.getReturnType, method.getGenericReturnType)
307
+ Some (param)
308
+ case setterPattern(propertyName) =>
309
+ val param = new MutableParameter
310
+ // TODO: not sure this will work
311
+ param.dataType = processDataType(method.getParameterTypes()(0 ), method.getGenericParameterTypes()(0 ))
312
+ Some (param)
313
+ case _ => None
314
+ }).toList.map {
315
+ param =>
316
+ Option (method.getAnnotation(classOf [ApiParam ])) match {
277
317
case Some (annotation) => toAllowableValues(annotation.allowableValues)
278
318
case _ =>
279
319
}
280
- val annotations = field .getAnnotations
320
+ val annotations = method .getAnnotations
281
321
processParamAnnotations(param, annotations)
282
- }
283
- else List .empty
284
- }).flatten.toList
322
+ }.flatten
285
323
}
286
324
287
325
def pathFromMethod (method : Method ): String = {
@@ -374,4 +412,4 @@ class MutableParameter(param: Parameter) {
374
412
paramType,
375
413
paramAccess)
376
414
}
377
- }
415
+ }
0 commit comments