diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java index 9328f817a..26559f78a 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java @@ -77,8 +77,6 @@ public class SwaggerSpecificationCreator { private static Swagger swagger; - private static String cachedJson; - private String host; private String basePath; @@ -148,15 +146,14 @@ private void BuildJSON() { } public String getJSON() { - if (isCached() && cachedJson != null) { + if (isCached()) { log.info("Returning a cached copy of Swagger specification"); - return cachedJson; + initSwagger(); + } else { + swagger = new Swagger(); + BuildJSON(); } - - swagger = new Swagger(); - BuildJSON(); - cachedJson = createJSON(); - return cachedJson; + return createJSON(); } private void addDefaultDefinitions() { @@ -834,8 +831,8 @@ private void addSubclassOperations() { Map properties = definition.getProperties(); -// 2. merge subclass properties into definition - for (Map.Entry prop : SwaggerGenerationUtil.generateGETModel(resourceHandler, Representation.FULL).getProperties() + // 2. merge subclass properties into definition + for (Map.Entry prop : resourceHandler.getGETModel(Representation.FULL).getProperties() .entrySet()) { if (properties.get(prop.getKey()) == null) { properties.put(prop.getKey(), prop.getValue()); @@ -847,6 +844,36 @@ private void addSubclassOperations() { } } + @Deprecated + private List getParametersListForSearchHandlers( + String resourceName, String searchHandlerId, int queryIndex) { + List parameters = new ArrayList(); + String resourceURL = getResourceUrl(getBaseUrl(), resourceName); + for (SearchHandlerDoc searchDoc : searchHandlerDocs) { + if (searchDoc.getSearchHandlerId().equals(searchHandlerId) && searchDoc.getResourceURL().equals(resourceURL)) { + SearchQueryDoc queryDoc = searchDoc.getSearchQueriesDoc().get(queryIndex); + for (SearchParameter requiredParameter : queryDoc.getRequiredParameters()) { + org.openmrs.module.webservices.docs.swagger.Parameter parameter = new org.openmrs.module.webservices.docs.swagger.Parameter(); + parameter.setName(requiredParameter.getName()); + parameter.setIn("query"); + parameter.setDescription(""); + parameter.setRequired(true); + parameters.add(parameter); + } + for (SearchParameter optionalParameter : queryDoc.getOptionalParameters()) { + org.openmrs.module.webservices.docs.swagger.Parameter parameter = new org.openmrs.module.webservices.docs.swagger.Parameter(); + parameter.setName(optionalParameter.getName()); + parameter.setIn("query"); + parameter.setDescription(""); + parameter.setRequired(false); + parameters.add(parameter); + } + break; + } + } + return parameters; + } + private String createJSON() { return Json.pretty(swagger); } @@ -1202,12 +1229,11 @@ public Swagger getSwagger() { * @return true if and only if swagger is not null, and its paths are also set. */ public static boolean isCached() { - return swagger != null && swagger.getPaths() != null && !swagger.getPaths().isEmpty(); + return swagger != null && swagger.getPaths() != null; } public static void clearCache() { swagger = null; - cachedJson = null; } }