From 88e9dc56cba7e9cc4777e958327904600dd912ef Mon Sep 17 00:00:00 2001 From: mherman22 Date: Fri, 6 Dec 2024 14:01:05 +0300 Subject: [PATCH] add a fix for references --- .../docs/swagger/SwaggerGenerationUtil.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerGenerationUtil.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerGenerationUtil.java index 6b226ddcb..f3ab6e6ec 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerGenerationUtil.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerGenerationUtil.java @@ -35,8 +35,9 @@ import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; @@ -59,16 +60,10 @@ public class SwaggerGenerationUtil { private static final Logger logger = LoggerFactory.getLogger(SwaggerGenerationUtil.class); - // Static list to hold resource handlers - private static final List> resourceHandlers = new ArrayList>(); + private static final Map, DelegatingResourceHandler> resourceHandlers = new HashMap, DelegatingResourceHandler>(); - /** - * Adds a resource handler to the internal list. - * - * @param resourceHandler the resource handler to add - */ public static void addResourceHandler(DelegatingResourceHandler resourceHandler) { - resourceHandlers.add(resourceHandler); + resourceHandlers.put(resourceHandler.getClass(), resourceHandler); } /** @@ -250,7 +245,7 @@ private static ModelImpl addFullProperties(DelegatingResourceHandler resource public static Property determinePropertyForField(DelegatingResourceHandler resourceHandler, String propertyName, String operationType) { Class genericType = getGenericType(resourceHandler.getClass()); if (genericType == null) { - //worst case scenario, no parameterized superclass / interface found in the class hierarchy + // Worst case scenario, no parameterized superclass / interface found in the class hierarchy throw new IllegalArgumentException("No generic type for resource handler"); } @@ -258,6 +253,7 @@ public static Property determinePropertyForField(DelegatingResourceHandler re Field field = genericType.getDeclaredField(propertyName); return createPropertyForType(field.getType(), operationType, field); } catch (NoSuchFieldException e) { + logger.warn("Field {} not found in class {}", propertyName, genericType.getName()); return new StringProperty(); } } @@ -317,7 +313,7 @@ public static Property createPropertyForType(Class type, String operationType * or "null" if no match is found */ public static String getResourceNameBySupportedClass(Class supportedClass) { - for (DelegatingResourceHandler resourceHandler : resourceHandlers) { + for (DelegatingResourceHandler resourceHandler : resourceHandlers.values()) { Resource annotation = resourceHandler.getClass().getAnnotation(Resource.class); SubResource subResourceAnnotation = resourceHandler.getClass().getAnnotation(SubResource.class);