diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java index 6ce57c38d..98b8c0f76 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java @@ -145,9 +145,11 @@ public Model getCREATEModel(Representation rep) { .property("concept", new RefProperty("#/definitions/ConceptCreate")) .property("orderer", new RefProperty("#/definitions/UserCreate")) .property("previousOrder", new RefProperty("#/definitions/OrderCreate")) - .property("orderReason", new RefProperty("#/definitions/ConceptCreate")); + .property("orderReason", new RefProperty("#/definitions/ConceptCreate")) + .property("orderReasonNonCoded", new StringProperty()) + .property("instructions", new StringProperty()) + .property("commentToFulfiller", new StringProperty()); } - //FIXME missing prop: type return model; } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java index a4b1e4de0..9e4970296 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java @@ -229,7 +229,7 @@ public Model getCREATEModel(Representation rep) { @Override public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + return getCREATEModel(rep); } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermResource1_9.java index 7f7ea6705..c188c85a0 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermResource1_9.java @@ -13,6 +13,7 @@ import io.swagger.models.ModelImpl; import io.swagger.models.properties.RefProperty; import io.swagger.models.properties.StringProperty; +import io.swagger.models.properties.UUIDProperty; import org.apache.commons.lang3.StringUtils; import org.openmrs.ConceptReferenceTerm; import org.openmrs.api.ConceptService; @@ -95,28 +96,26 @@ public DelegatingResourceDescription getCreatableProperties() { @Override public Model getGETModel(Representation rep) { ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("code", new StringProperty()) - .property("version", new StringProperty()); - - } if (rep instanceof DefaultRepresentation) { - model - .property("conceptSource", new RefProperty("#/definitions/ConceptsourceGetRef")); + model.property("uuid", new UUIDProperty()); + model.property("conceptSource", new RefProperty("#/definitions/ConceptsourceGetRef")); + model.property("code", new StringProperty()); + model.property("version", new StringProperty()); } else if (rep instanceof FullRepresentation) { - model - .property("conceptSource", new RefProperty("#/definitions/ConceptsourceGet")); + model.property("uuid", new UUIDProperty()); + model.property("conceptSource", new RefProperty("#/definitions/ConceptsourceGetFull")); + model.property("code", new StringProperty()); + model.property("version", new StringProperty()); + model.property("auditInfo", new StringProperty()); } return model; - } @Override public Model getCREATEModel(Representation rep) { return ((ModelImpl) super.getCREATEModel(rep)) .property("code", new StringProperty()) - .property("conceptSource", new StringProperty()) + .property("conceptSource", new RefProperty("#/definitions/ConceptsourceCreate")) .property("version", new StringProperty()) .required("code").required("conceptSource"); diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptProposalResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptProposalResource2_0.java index 732d251f9..2f7bf47db 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptProposalResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptProposalResource2_0.java @@ -9,6 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0; +import io.swagger.models.Model; +import io.swagger.models.ModelImpl; +import io.swagger.models.properties.DateProperty; +import io.swagger.models.properties.RefProperty; +import io.swagger.models.properties.StringProperty; import org.openmrs.Concept; import org.openmrs.ConceptProposal; import org.openmrs.User; @@ -107,6 +112,49 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } + @Override + public Model getGETModel(Representation rep) { + ModelImpl model = (ModelImpl) super.getGETModel(rep); + if (rep instanceof DefaultRepresentation) { + model.property("uuid", new StringProperty().example("uuid")); + model.property("display", new StringProperty()); + model.property("encounter", new RefProperty("#/definitions/EncounterGetRef")); + model.property("originalText", new StringProperty()); + model.property("finalText", new StringProperty()); + model.property("state", new StringProperty()); + model.property("comments", new StringProperty()); + model.property("occurrences", new StringProperty()); + model.property("creator", new RefProperty("#/definitions/UserGetRef")); + model.property("dateCreated", new DateProperty()); + } else if (rep instanceof FullRepresentation) { + model.property("uuid", new StringProperty().example("uuid")); + model.property("display", new StringProperty()); + model.property("encounter", new RefProperty("#/definitions/EncounterGet")); + model.property("obsConcept", new RefProperty("#/definitions/ConceptGet")); + model.property("obs", new RefProperty("#/definitions/ObsGet")); + model.property("mappedConcept", new RefProperty("#/definitions/ConceptGet")); + model.property("originalText", new StringProperty()); + model.property("finalText", new StringProperty()); + model.property("state", new StringProperty()); + model.property("comments", new StringProperty()); + model.property("occurrences", new StringProperty()); + model.property("creator", new RefProperty("#/definitions/UserGet")); + model.property("dateCreated", new DateProperty()); + model.property("changedBy", new RefProperty("#/definitions/UserGet")); + model.property("dateChanged", new DateProperty()); + } else if (rep instanceof RefRepresentation) { + model.property("uuid", new StringProperty().example("uuid")); + model.property("display", new StringProperty()); + model.property("encounter", new RefProperty("#/definitions/EncounterGetRef")); + model.property("originalText", new StringProperty()); + model.property("state", new StringProperty()); + model.property("occurrences", new StringProperty()); + model.property("changedBy", new RefProperty("#/definitions/UserGetRef")); + model.property("dateChanged", new DateProperty()); + } + return model; + } + @PropertyGetter("occurrences") public Integer getOccurrencesProperty(ConceptProposal proposal) { Map> proposalsMap = getProposalsMapByOriginalText(false); @@ -128,6 +176,15 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return description; } + @Override + public Model getCREATEModel(Representation rep) { + return new ModelImpl() + .property("originalText", new StringProperty()) + .property("mappedConcept", new RefProperty("#/definitions/ConceptCreate")) + .property("encounter", new RefProperty("#/definitions/EncounterCreate")) + .property("obsConcept", new RefProperty("#/definitions/ConceptCreate")); + } + @Override public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { DelegatingResourceDescription description = new DelegatingResourceDescription(); @@ -139,6 +196,17 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe return description; } + @Override + public Model getUPDATEModel(Representation rep) { + ModelImpl model = (ModelImpl) super.getUPDATEModel(rep); + return model + .property("finalText", new StringProperty()) + .property("mappedConcept", new RefProperty("#/definitions/ConceptCreate")) + .property("encounter", new RefProperty("#/definitions/EncounterCreate")) + .property("obsConcept", new RefProperty("#/definitions/ConceptCreate")) + .property("comments", new StringProperty()); + } + @Override public ConceptProposal getByUniqueId(String uniqueId) { return Context.getConceptService().getConceptProposalByUuid(uniqueId); diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptStateConversionResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptStateConversionResource2_0.java index 0795e84e2..13d6398f0 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptStateConversionResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptStateConversionResource2_0.java @@ -114,19 +114,19 @@ public Model getCREATEModel(Representation rep) { ModelImpl model = new ModelImpl(); if (rep instanceof DefaultRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreateRef"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreateRef"))); + .property("concept", new RefProperty("#/definitions/ConceptCreate")) + .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreate"))) + .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreate"))); } else if (rep instanceof FullRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowGet"))) + .property("concept", new RefProperty("#/definitions/ConceptCreateFull")) + .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreateFull"))) .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGet"))); } else if (rep instanceof RefRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreateRef"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreateRef"))); + .property("concept", new RefProperty("#/definitions/ConceptCreate")) + .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreate"))) + .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreate"))); } return model; } 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 9f235ba9b..d0232bf2f 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 @@ -74,44 +74,44 @@ import java.util.Set; public class SwaggerSpecificationCreator { - + private static Swagger swagger; - + private String host; - + private String basePath; - + private List schemes; - + private String baseUrl; - + private static List searchHandlerDocs; - + PrintStream originalErr; - + PrintStream originalOut; - + private QueryParameter subclassTypeParameter = new QueryParameter().name("t") - .description("The type of Subclass Resource to return") - .type("string"); - + .description("The type of Subclass Resource to return") + .type("string"); + Map originalLevels = new HashMap(); - + private Logger log = Logger.getLogger(this.getClass()); - + public SwaggerSpecificationCreator() { } - + public SwaggerSpecificationCreator host(String host) { this.host = host; return this; } - + public SwaggerSpecificationCreator basePath(String basePath) { this.basePath = basePath; return this; } - + public SwaggerSpecificationCreator scheme(Scheme scheme) { if (schemes == null) { this.schemes = new ArrayList(); @@ -121,7 +121,7 @@ public SwaggerSpecificationCreator scheme(Scheme scheme) { } return this; } - + /** * Regenerate the swagger spec from scratch */ @@ -132,6 +132,7 @@ private void BuildJSON() { try { initSwagger(); addPaths(); + addDefaultDefinitions(); // addSubclassOperations(); //FIXME uncomment after fixing the method } catch (Exception e) { @@ -143,7 +144,7 @@ private void BuildJSON() { } } } - + public String getJSON() { if (isCached()) { log.info("Returning a cached copy of Swagger specification"); @@ -154,24 +155,24 @@ public String getJSON() { } return createJSON(); } - + private void addDefaultDefinitions() { // schema of the default response // received from fetchAll and search operations swagger.addDefinition("FetchAll", new ModelImpl() - .property("results", new ArrayProperty() - .items(new ObjectProperty() - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("links", new ArrayProperty() - .items(new ObjectProperty() - .property("rel", new StringProperty().example("self")) - .property("uri", new StringProperty(StringProperty.Format.URI))))))); + .property("results", new ArrayProperty() + .items(new ObjectProperty() + .property("uuid", new StringProperty()) + .property("display", new StringProperty()) + .property("links", new ArrayProperty() + .items(new ObjectProperty() + .property("rel", new StringProperty().example("self")) + .property("uri", new StringProperty(StringProperty.Format.URI))))))); } - + private void toggleLogs(boolean targetState) { if (Context.getAdministrationService().getGlobalProperty(RestConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME) - .equals("true")) { + .equals("true")) { if (targetState == RestConstants.SWAGGER_LOGS_OFF) { // turn off the log4j loggers List loggers = Collections. list(LogManager.getCurrentLoggers()); @@ -180,19 +181,19 @@ private void toggleLogs(boolean targetState) { originalLevels.put(logger.hashCode(), logger.getLevel()); logger.setLevel(Level.OFF); } - + // silence stderr and stdout originalErr = System.err; System.setErr(new PrintStream(new OutputStream() { - + public void write(int b) { // noop } })); - + originalOut = System.out; System.setOut(new PrintStream(new OutputStream() { - + public void write(int b) { // noop } @@ -203,95 +204,95 @@ public void write(int b) { for (Logger logger : loggers) { logger.setLevel(originalLevels.get(logger.hashCode())); } - + System.setErr(originalErr); System.setOut(originalOut); } } } - + private void initSwagger() { final Info info = new Info() - .version(OpenmrsConstants.OPENMRS_VERSION_SHORT) - .title("OpenMRS API Docs") - .description("OpenMRS RESTful API documentation generated by Swagger") - .contact(new Contact().name("OpenMRS").url("http://openmrs.org")) - .license(new License().name("MPL-2.0 w/ HD").url("http://openmrs.org/license")); - + .version(OpenmrsConstants.OPENMRS_VERSION_SHORT) + .title("OpenMRS API Docs") + .description("OpenMRS RESTful API documentation generated by Swagger") + .contact(new Contact().name("OpenMRS").url("http://openmrs.org")) + .license(new License().name("MPL-2.0 w/ HD").url("http://openmrs.org/license")); + swagger - .info(info) - .host(this.host) - .basePath(this.basePath) - .schemes(this.schemes) - .securityDefinition("basic_auth", new BasicAuthDefinition()) - .security(new SecurityRequirement().requirement("basic_auth")) - .consumes("application/json") - .produces("application/json") - .externalDocs(new ExternalDocs() - .description("Find more info on REST Module Wiki") - .url("https://wiki.openmrs.org/x/xoAaAQ")); + .info(info) + .host(this.host) + .basePath(this.basePath) + .schemes(this.schemes) + .securityDefinition("basic_auth", new BasicAuthDefinition()) + .security(new SecurityRequirement().requirement("basic_auth")) + .consumes("application/json") + .produces("application/json") + .externalDocs(new ExternalDocs() + .description("Find more info on REST Module Wiki") + .url("https://wiki.openmrs.org/x/xoAaAQ")); } - + private List getModuleVersions() { List moduleVersions = new ArrayList(); - + for (Module module : ModuleFactory.getLoadedModules()) { moduleVersions.add(new ModuleVersion(module.getModuleId(), module.getVersion())); } - + return moduleVersions; } - + private boolean testOperationImplemented(OperationEnum operation, DelegatingResourceHandler resourceHandler) { Method method; try { switch (operation) { case get: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "getAll", RequestContext.class); - + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } - + break; case getSubresource: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "getAll", String.class, - RequestContext.class); - + RequestContext.class); + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } - + break; case getWithUUID: case getSubresourceWithUUID: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "getByUniqueId", String.class); - + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID); } - + break; case getWithDoSearch: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "search", RequestContext.class); - + if (method == null) { return false; } else { method.invoke(resourceHandler, new RequestContext()); } - + break; case postCreate: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "create", SimpleObject.class, - RequestContext.class); - + RequestContext.class); + if (method == null) { return false; } else { @@ -308,19 +309,19 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso resourceHandler.save(null); } } - + break; case postSubresource: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "create", String.class, - SimpleObject.class, RequestContext.class); - + SimpleObject.class, RequestContext.class); + if (method == null) { return false; } else { try { // to avoid saving data to the database, we pass a null SimpleObject method.invoke(resourceHandler, null, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, - new RequestContext()); + new RequestContext()); } catch (InvocationTargetException e) { if (e.getCause() instanceof ResourceDoesNotSupportOperationException) { @@ -334,262 +335,262 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso resourceHandler.save(null); } } - + break; case postUpdate: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "update", String.class, - SimpleObject.class, RequestContext.class); - + SimpleObject.class, RequestContext.class); + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, - buildPOSTUpdateSimpleObject(resourceHandler), new RequestContext()); + buildPOSTUpdateSimpleObject(resourceHandler), new RequestContext()); } - + break; case postUpdateSubresouce: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "update", String.class, String.class, - SimpleObject.class, RequestContext.class); - + SimpleObject.class, RequestContext.class); + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, - RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resourceHandler), - new RequestContext()); + RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resourceHandler), + new RequestContext()); } - + break; case delete: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "delete", String.class, String.class, - RequestContext.class); - + RequestContext.class); + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, "", - new RequestContext()); + new RequestContext()); } - + break; case deleteSubresource: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "delete", String.class, String.class, - String.class, RequestContext.class); - + String.class, RequestContext.class); + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, - RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, "", new RequestContext()); + RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, "", new RequestContext()); } break; case purge: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "purge", String.class, - RequestContext.class); - + RequestContext.class); + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } - + break; case purgeSubresource: method = ReflectionUtils.findMethod(resourceHandler.getClass(), "purge", String.class, String.class, - RequestContext.class); - + RequestContext.class); + if (method == null) { return false; } else { method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, - RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); + RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } } return true; } catch (Exception e) { return !(e instanceof ResourceDoesNotSupportOperationException) - && !(e.getCause() instanceof ResourceDoesNotSupportOperationException); + && !(e.getCause() instanceof ResourceDoesNotSupportOperationException); } } - + private void sortResourceHandlers(List> resourceHandlers) { Collections.sort(resourceHandlers, new Comparator>() { - + @Override public int compare(DelegatingResourceHandler left, DelegatingResourceHandler right) { return isSubclass(left).compareTo(isSubclass(right)); } - + private Boolean isSubclass(DelegatingResourceHandler resourceHandler) { return resourceHandler.getClass().getAnnotation(SubResource.class) != null; } }); } - + private SimpleObject buildPOSTUpdateSimpleObject(DelegatingResourceHandler resourceHandler) { SimpleObject simpleObject = new SimpleObject(); - + for (String property : resourceHandler.getUpdatableProperties().getProperties().keySet()) { simpleObject.put(property, property); } - + return simpleObject; } - + private Path buildFetchAllPath(Path path, - DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - + DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { + Operation getOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.get, resourceHandler)) { - + getOperation = createOperation(resourceHandler, "get", resourceName, null, - OperationEnum.get); + OperationEnum.get); } } else { if (testOperationImplemented(OperationEnum.getSubresource, resourceHandler)) { getOperation = createOperation(resourceHandler, "get", resourceName, resourceParentName, - OperationEnum.getSubresource); + OperationEnum.getSubresource); } } - + if (getOperation != null) { path.setGet(getOperation); } - + return path; } - + private Path buildGetWithUUIDPath(Path path, - DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - + DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { + Operation getOperation = null; - + if (testOperationImplemented(OperationEnum.getWithUUID, resourceHandler)) { if (resourceParentName == null) { getOperation = createOperation(resourceHandler, "get", resourceName, null, - OperationEnum.getWithUUID); + OperationEnum.getWithUUID); } else { getOperation = createOperation(resourceHandler, "get", resourceName, resourceParentName, - OperationEnum.getSubresourceWithUUID); + OperationEnum.getSubresourceWithUUID); } } - + if (getOperation != null) { path.get(getOperation); } return path; } - + private Path buildCreatePath(Path path, - DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - + DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { + Operation postCreateOperation = null; - + if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.postCreate, resourceHandler)) { postCreateOperation = createOperation(resourceHandler, "post", resourceName, null, - OperationEnum.postCreate); + OperationEnum.postCreate); } } else { if (testOperationImplemented(OperationEnum.postSubresource, resourceHandler)) { postCreateOperation = createOperation(resourceHandler, "post", resourceName, resourceParentName, - OperationEnum.postSubresource); + OperationEnum.postSubresource); } } - + if (postCreateOperation != null) { path.post(postCreateOperation); } return path; } - + private Path buildUpdatePath(Path path, - DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - + DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { + Operation postUpdateOperation = null; - + if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.postUpdate, resourceHandler)) { postUpdateOperation = createOperation(resourceHandler, "post", resourceName, resourceParentName, - OperationEnum.postUpdate); + OperationEnum.postUpdate); } } else { if (testOperationImplemented(OperationEnum.postUpdateSubresouce, resourceHandler)) { postUpdateOperation = createOperation(resourceHandler, "post", resourceName, resourceParentName, - OperationEnum.postUpdateSubresouce); + OperationEnum.postUpdateSubresouce); } } - + if (postUpdateOperation != null) { path.post(postUpdateOperation); } return path; } - + private Path buildDeletePath(Path path, - DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - + DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { + Operation deleteOperation = null; - + if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.delete, resourceHandler)) { deleteOperation = createOperation(resourceHandler, "delete", resourceName, resourceParentName, - OperationEnum.delete); + OperationEnum.delete); } } else { if (testOperationImplemented(OperationEnum.deleteSubresource, resourceHandler)) { deleteOperation = createOperation(resourceHandler, "delete", resourceName, resourceParentName, - OperationEnum.deleteSubresource); + OperationEnum.deleteSubresource); } } - + if (deleteOperation != null) { path.delete(deleteOperation); } return path; } - + private Path buildPurgePath(Path path, DelegatingResourceHandler resourceHandler, - String resourceName, String resourceParentName) { - + String resourceName, String resourceParentName) { + if (path.getDelete() != null) { // just add optional purge parameter Operation deleteOperation = path.getDelete(); - + deleteOperation.setSummary("Delete or purge resource by uuid"); deleteOperation.setDescription("The resource will be voided/retired unless purge = 'true'"); - + QueryParameter purgeParam = new QueryParameter().name("purge").type("boolean"); deleteOperation.parameter(purgeParam); } else { // create standalone purge operation with required Operation purgeOperation = null; - + if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.purge, resourceHandler)) { purgeOperation = createOperation(resourceHandler, "delete", resourceName, null, - OperationEnum.purge); + OperationEnum.purge); } } else { if (testOperationImplemented(OperationEnum.purgeSubresource, resourceHandler)) { purgeOperation = createOperation(resourceHandler, "delete", resourceName, resourceParentName, - OperationEnum.purgeSubresource); + OperationEnum.purgeSubresource); } } - + if (purgeOperation != null) { path.delete(purgeOperation); } } - + return path; } - + private void addIndividualPath(String resourceParentName, String resourceName, Path path, - String pathSuffix) { + String pathSuffix) { if (!path.getOperations().isEmpty()) { if (resourceParentName == null) { swagger.path("/" + resourceName + pathSuffix, path); @@ -598,71 +599,71 @@ private void addIndividualPath(String resourceParentName, String resourceName, P } } } - + private String buildSearchParameterDependencyString(Set dependencies) { StringBuffer sb = new StringBuffer(); - + sb.append("Must be used with "); - + List searchParameterNames = new ArrayList(); for (SearchParameter dependency : dependencies) { searchParameterNames.add(dependency.getName()); } sb.append(StringUtils.join(searchParameterNames, ", ")); - + String ret = sb.toString(); int ind = ret.lastIndexOf(", "); - + if (ind > -1) { ret = new StringBuilder(ret).replace(ind, ind + 2, " and ").toString(); } - + return ret; } - + private void addSearchOperations(DelegatingResourceHandler resourceHandler, String resourceName, - String resourceParentName, Path getAllPath) { + String resourceParentName, Path getAllPath) { if (resourceName == null) { return; } boolean hasDoSearch = testOperationImplemented(OperationEnum.getWithDoSearch, resourceHandler); boolean hasSearchHandler = hasSearchHandler(resourceName, resourceParentName); boolean wasNew = false; - + if (hasSearchHandler || hasDoSearch) { Operation operation; // query parameter Parameter q = new QueryParameter().name("q") - .description("The search query") - .type("string"); - + .description("The search query") + .type("string"); + if (getAllPath.getOperations().isEmpty() || getAllPath.getGet() == null) { // create search-only operation operation = new Operation(); operation.tag(resourceParentName == null ? resourceName : resourceParentName); operation.produces("application/json").produces("application/xml"); - + // if the path has no operations, add a note that at least one search parameter must be specified operation.setSummary("Search for " + resourceName); operation.setDescription("At least one search parameter must be specified"); - + // representations query parameter Parameter v = new QueryParameter().name("v") - .description("The representation to return (ref, default, full or custom)") - .type("string") - ._enum(Arrays.asList("ref", "default", "full", "custom")); - + .description("The representation to return (ref, default, full or custom)") + .type("string") + ._enum(Arrays.asList("ref", "default", "full", "custom")); + // This implies that the resource has no custom SearchHandler or doGetAll, but has doSearch implemented // As there is only one query param 'q', mark it as required if (!hasSearchHandler) { q.setRequired(true); } - + operation.setParameters(buildPagingParameters()); operation.parameter(v).parameter(q); operation.addResponse("200", new Response() - .description(resourceName + " response") - .schema(new RefProperty("#/definitions/FetchAll"))); + .description(resourceName + " response") + .schema(new RefProperty("#/definitions/FetchAll"))); if (((BaseDelegatingResource) resourceHandler).hasTypesDefined()) { operation.parameter(subclassTypeParameter); } @@ -674,18 +675,18 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S operation.setDescription("All search parameters are optional"); operation.parameter(q); } - + Map parameterMap = new HashMap(); - + if (hasSearchHandler) { // FIXME: this isn't perfect, it doesn't cover the case where multiple parameters are required together // FIXME: See https://github.com/OAI/OpenAPI-Specification/issues/256 for (SearchHandler searchHandler : Context.getService(RestService.class).getAllSearchHandlers()) { - + String supportedResourceWithVersion = searchHandler.getSearchConfig().getSupportedResource(); String supportedResource = supportedResourceWithVersion.substring(supportedResourceWithVersion - .indexOf('/') + 1); - + .indexOf('/') + 1); + if (resourceName.equals(supportedResource)) { for (SearchQuery searchQuery : searchHandler.getSearchConfig().getSearchQueries()) { // parameters with no dependencies @@ -705,147 +706,147 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S } } } - + for (Parameter p : parameterMap.values()) { operation.parameter(p); } operation.setOperationId("getAll" + getOperationTitle(resourceHandler, true)); - + if (wasNew) { getAllPath.setGet(operation); } } } - + private void addPaths() { // get all registered resource handlers List> resourceHandlers = Context.getService(RestService.class).getResourceHandlers(); sortResourceHandlers(resourceHandlers); - + // generate swagger JSON for each handler for (DelegatingResourceHandler resourceHandler : resourceHandlers) { - + // get name and parent if it's a subresource Resource annotation = resourceHandler.getClass().getAnnotation(Resource.class); - + String resourceParentName = null; String resourceName = null; - + if (annotation != null) { // top level resource resourceName = annotation.name().substring(annotation.name().indexOf('/') + 1); } else { // subresource SubResource subResourceAnnotation = resourceHandler.getClass().getAnnotation(SubResource.class); - + if (subResourceAnnotation != null) { Resource parentResourceAnnotation = subResourceAnnotation.parent().getAnnotation(Resource.class); - + resourceName = subResourceAnnotation.path(); resourceParentName = parentResourceAnnotation.name().substring( - parentResourceAnnotation.name().indexOf('/') + 1); + parentResourceAnnotation.name().indexOf('/') + 1); } } - + // subclass operations are handled separately in another method if (resourceHandler instanceof DelegatingSubclassHandler) continue; - + // set up paths Path rootPath = new Path(); Path uuidPath = new Path(); - + ///////////////////////// // GET all // ///////////////////////// Path rootPathGetAll = buildFetchAllPath(rootPath, resourceHandler, resourceName, - resourceParentName); + resourceParentName); addIndividualPath(resourceParentName, resourceName, rootPathGetAll, ""); - + ///////////////////////// // GET search // ///////////////////////// addSearchOperations(resourceHandler, resourceName, resourceParentName, rootPathGetAll); - + ///////////////////////// // POST create // ///////////////////////// Path rootPathPostCreate = buildCreatePath(rootPathGetAll, resourceHandler, resourceName, - resourceParentName); + resourceParentName); addIndividualPath(resourceParentName, resourceName, rootPathPostCreate, ""); - + ///////////////////////// // GET with UUID // ///////////////////////// Path uuidPathGetAll = buildGetWithUUIDPath(uuidPath, resourceHandler, resourceName, - resourceParentName); + resourceParentName); addIndividualPath(resourceParentName, resourceName, uuidPathGetAll, "/{uuid}"); - + ///////////////////////// // POST update // ///////////////////////// Path uuidPathPostUpdate = buildUpdatePath(uuidPathGetAll, resourceHandler, resourceName, - resourceParentName); + resourceParentName); addIndividualPath(resourceParentName, resourceName, uuidPathPostUpdate, "/{uuid}"); - + ///////////////////////// // DELETE // ///////////////////////// Path uuidPathDelete = buildDeletePath(uuidPathPostUpdate, resourceHandler, resourceName, - resourceParentName); - + resourceParentName); + ///////////////////////// // DELETE (purge) // ///////////////////////// Path uuidPathPurge = buildPurgePath(uuidPathDelete, resourceHandler, resourceName, - resourceParentName); + resourceParentName); addIndividualPath(resourceParentName, resourceName, uuidPathPurge, "/{uuid}"); } } - + private void addSubclassOperations() { // FIXME: this needs to be improved a lot List> resourceHandlers = Context.getService(RestService.class).getResourceHandlers(); for (DelegatingResourceHandler resourceHandler : resourceHandlers) { - + if (!(resourceHandler instanceof DelegatingSubclassHandler)) continue; - + Class resourceClass = ((DelegatingSubclassHandler) resourceHandler).getSuperclass(); String resourceName = resourceClass.getSimpleName().toLowerCase(); - + // 1. add non-optional enum property to model Path path = swagger.getPath("/" + resourceName); if (path == null) continue; - + // FIXME: implement other operations when required Operation post = path.getPost(); if (post == null) continue; - + Model definition = swagger.getDefinitions().get(StringUtils.capitalize(resourceName) + "Create"); if (definition == null) continue; - + Map properties = definition.getProperties(); - + // 2. merge subclass properties into definition for (Map.Entry prop : resourceHandler.getGETModel(Representation.FULL).getProperties() - .entrySet()) { + .entrySet()) { if (properties.get(prop.getKey()) == null) { properties.put(prop.getKey(), prop.getValue()); } } - + // 3. update description post.setDescription("Certain properties may be required depending on type"); } } - + @Deprecated private List getParametersListForSearchHandlers( - String resourceName, String searchHandlerId, int queryIndex) { + String resourceName, String searchHandlerId, int queryIndex) { List parameters = new ArrayList(); String resourceURL = getResourceUrl(getBaseUrl(), resourceName); for (SearchHandlerDoc searchDoc : searchHandlerDocs) { @@ -872,35 +873,35 @@ private List getParameter } return parameters; } - + private String createJSON() { return Json.pretty(swagger); } - + private Parameter buildRequiredUUIDParameter(String name, String desc) { return new PathParameter().name(name).description(desc).type("string"); } - + private List buildPagingParameters() { List params = new ArrayList(); - + Parameter limit = new QueryParameter().name("limit") - .description("The number of results to return").type("integer"); - + .description("The number of results to return").type("integer"); + Parameter startIndex = new QueryParameter().name("startIndex") - .description("The offset at which to start").type("integer"); - + .description("The offset at which to start").type("integer"); + params.add(limit); params.add(startIndex); - + return params; } - + private Parameter buildPOSTBodyParameter(String resourceName, String resourceParentName, - OperationEnum operationEnum) { + OperationEnum operationEnum) { BodyParameter bodyParameter = new BodyParameter(); bodyParameter.setRequired(true); - + switch (operationEnum) { case postCreate: case postSubresource: @@ -912,16 +913,16 @@ private Parameter buildPOSTBodyParameter(String resourceName, String resourcePar bodyParameter.setName("resource"); bodyParameter.setDescription("Resource properties to update"); } - + bodyParameter.schema(new RefModel(getSchemaRef(resourceName, resourceParentName, operationEnum))); - + return bodyParameter; } - + private String getSchemaName(String resourceName, String resourceParentName, OperationEnum operationEnum) { - + String suffix = ""; - + switch (operationEnum) { case get: case getSubresource: @@ -938,65 +939,65 @@ private String getSchemaName(String resourceName, String resourceParentName, Ope suffix = "Update"; break; } - + String modelRefName; - + if (resourceParentName == null) { modelRefName = StringUtils.capitalize(resourceName) + suffix; } else { modelRefName = StringUtils.capitalize(resourceParentName) + StringUtils.capitalize(resourceName) + suffix; } - + // get rid of slashes in model names String[] split = modelRefName.split("\\/"); StringBuilder ret = new StringBuilder(); for (String s : split) { ret.append(StringUtils.capitalize(s)); } - + return ret.toString(); } - + private String getSchemaRef(String resourceName, String resourceParentName, OperationEnum operationEnum) { return "#/definitions/" + getSchemaName(resourceName, resourceParentName, operationEnum); } - + private String getOperationTitle(DelegatingResourceHandler resourceHandler, Boolean pluralize) { StringBuilder ret = new StringBuilder(); English inflector = new English(); - + // get rid of slashes String simpleClassName = resourceHandler.getClass().getSimpleName(); - + // get rid of 'Resource' and version number suffixes simpleClassName = simpleClassName.replaceAll("\\d_\\d{1,2}$", ""); simpleClassName = simpleClassName.replaceAll("Resource$", ""); - + // pluralize if require if (pluralize) { String[] words = simpleClassName.split("(? resourceHandler) { - + DelegatingResourceHandler resourceHandler) { + String definitionName = getSchemaName(resourceName, resourceParentName, operationEnum); Model model = null; Model modelRef = null; Model modelFull = null; - + if (definitionName.endsWith("Get")) { model = resourceHandler.getGETModel(Representation.DEFAULT); modelRef = resourceHandler.getGETModel(Representation.REF); @@ -1007,7 +1008,7 @@ private void createDefinition(OperationEnum operationEnum, String resourceName, } else if (definitionName.endsWith("Update")) { model = resourceHandler.getUPDATEModel(Representation.DEFAULT); } - + if (model != null) { swagger.addDefinition(definitionName, model); } @@ -1018,7 +1019,7 @@ private void createDefinition(OperationEnum operationEnum, String resourceName, swagger.addDefinition(definitionName + "Full", modelFull); } } - + /** * @param resourceHandler * @param operationName get, post, delete @@ -1029,110 +1030,110 @@ private void createDefinition(OperationEnum operationEnum, String resourceName, * @return */ private Operation createOperation(DelegatingResourceHandler resourceHandler, String operationName, - String resourceName, String resourceParentName, OperationEnum operationEnum) { - + String resourceName, String resourceParentName, OperationEnum operationEnum) { + Operation operation = new Operation() - .tag(resourceParentName == null ? resourceName : resourceParentName) - .consumes("application/json").produces("application/json"); - + .tag(resourceParentName == null ? resourceName : resourceParentName) + .consumes("application/json").produces("application/json"); + // create definition if (operationName.equals("post") || operationName.equals("get") ) { createDefinition(operationEnum, resourceName, resourceParentName, resourceHandler); } - + // create all possible responses // 200 response (Successful operation) Response response200 = new Response().description(resourceName + " response"); - + // 201 response (Successfully created) Response response201 = new Response().description(resourceName + " response"); - + // 204 delete success Response response204 = new Response().description("Delete successful"); - + // 401 response (User not logged in) Response response401 = new Response().description("User not logged in"); - + // 404 (Object with given uuid doesn't exist) Response response404 = new Response() - .description("Resource with given uuid doesn't exist"); - + .description("Resource with given uuid doesn't exist"); + // create all possible query params // representations query parameter Parameter v = new QueryParameter().name("v") - .description("The representation to return (ref, default, full or custom)") - .type("string") - ._enum(Arrays.asList("ref", "default", "full", "custom")); - + .description("The representation to return (ref, default, full or custom)") + .type("string") + ._enum(Arrays.asList("ref", "default", "full", "custom")); + if (operationEnum == OperationEnum.get) { - + operation.setSummary("Fetch all non-retired"); operation.setOperationId("getAll" + getOperationTitle(resourceHandler, true)); operation.addResponse("200", response200.schema(new ArrayProperty( - new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get))))); - + new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get))))); + operation.setParameters(buildPagingParameters()); operation.parameter(v); if (((BaseDelegatingResource) resourceHandler).hasTypesDefined()) { operation.parameter(subclassTypeParameter); } - + } else if (operationEnum == OperationEnum.getWithUUID) { - + operation.setSummary("Fetch by uuid"); operation.setOperationId("get" + getOperationTitle(resourceHandler, false)); operation.parameter(v); operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to filter by")); operation.addResponse("200", - response200.schema(new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))); + response200.schema(new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))); operation.addResponse("404", response404); - + } else if (operationEnum == OperationEnum.postCreate) { - + operation.setSummary("Create with properties in request"); operation.setOperationId("create" + getOperationTitle(resourceHandler, false)); operation.parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postCreate)); operation.addResponse("201", response201); - + } else if (operationEnum == OperationEnum.postUpdate) { - + operation.setSummary("Edit with given uuid, only modifying properties in request"); operation.setOperationId("update" + getOperationTitle(resourceHandler, false)); operation.parameter(buildRequiredUUIDParameter("uuid", "uuid of resource to update")); operation.parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdate)); operation.addResponse("201", response201); - + } else if (operationEnum == OperationEnum.getSubresource) { - + operation.setSummary("Fetch all non-retired " + resourceName + " subresources"); operation.setOperationId("getAll" + getOperationTitle(resourceHandler, true)); operation.setParameters(buildPagingParameters()); operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); operation.parameter(v); operation.addResponse("200", response200.schema(new ObjectProperty() - .property("results", new ArrayProperty( - new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))))); - + .property("results", new ArrayProperty( + new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))))); + } else if (operationEnum == OperationEnum.postSubresource) { - + operation.setSummary("Create " + resourceName + " subresource with properties in request"); operation.setOperationId("create" + getOperationTitle(resourceHandler, false)); operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); operation.parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postSubresource)); operation.addResponse("201", response201); - + } else if (operationEnum == OperationEnum.postUpdateSubresouce) { - + operation.setSummary("edit " + resourceName - + " subresource with given uuid, only modifying properties in request"); + + " subresource with given uuid, only modifying properties in request"); operation.setOperationId("update" + getOperationTitle(resourceHandler, false)); operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); operation.parameter(buildRequiredUUIDParameter("uuid", "uuid of resource to update")); operation - .parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdateSubresouce)); + .parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdateSubresouce)); operation.addResponse("201", response201); - + } else if (operationEnum == OperationEnum.getSubresourceWithUUID) { operation.setSummary("Fetch " + resourceName + " subresources by uuid"); operation.setOperationId("get" + getOperationTitle(resourceHandler, false)); @@ -1140,17 +1141,17 @@ private Operation createOperation(DelegatingResourceHandler resourceHandler, operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to filter by")); operation.parameter(v); operation.addResponse("200", response200.schema(new RefProperty(getSchemaRef(resourceName, resourceParentName, - OperationEnum.getSubresourceWithUUID)))); + OperationEnum.getSubresourceWithUUID)))); operation.addResponse("404", response404); - + } else if (operationEnum == OperationEnum.delete) { - + operation.setSummary("Delete resource by uuid"); operation.setOperationId("delete" + getOperationTitle(resourceHandler, false)); operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to delete")); operation.response(204, response204); operation.response(404, response404); - + } else if (operationEnum == OperationEnum.deleteSubresource) { operation.setSummary("Delete " + resourceName + " subresource by uuid"); operation.setOperationId("delete" + getOperationTitle(resourceHandler, false)); @@ -1158,33 +1159,33 @@ private Operation createOperation(DelegatingResourceHandler resourceHandler, operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to delete")); operation.response(204, response204); operation.response(404, response404); - + } else if (operationEnum == OperationEnum.purge) { - + operation.setSummary("Purge resource by uuid"); operation.setOperationId("purge" + getOperationTitle(resourceHandler, false)); operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to delete")); operation.response(204, response204); - + } else if (operationEnum == OperationEnum.purgeSubresource) { - + operation.setSummary("Purge " + resourceName + " subresource by uuid"); operation.setOperationId("purge" + getOperationTitle(resourceHandler, false)); operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to delete")); operation.response(204, response204); } - + operation.response(401, response401); - + return operation; } - + private static List fillSearchHandlers(List searchHandlers, String url) { - + List searchHandlerDocList = new ArrayList(); String baseUrl = url.replace("/rest", ""); - + for (int i = 0; i < searchHandlers.size(); i++) { if (searchHandlers.get(i) != null) { SearchHandler searchHandler = searchHandlers.get(i); @@ -1192,22 +1193,22 @@ private static List fillSearchHandlers(List sea searchHandlerDocList.add(searchHandlerDoc); } } - + return searchHandlerDocList; } - + private String getResourceUrl(String baseUrl, String resourceName) { //Set the root url. return baseUrl + "/v1/" + resourceName; } - + public boolean hasSearchHandler(String resourceName, String resourceParentName) { if (resourceParentName != null) { resourceName = RestConstants.VERSION_1 + "/" + resourceParentName + "/" + resourceName; } else { resourceName = RestConstants.VERSION_1 + "/" + resourceName; } - + List searchHandlers = Context.getService(RestService.class).getAllSearchHandlers(); for (SearchHandler searchHandler : searchHandlers) { if (searchHandler.getSearchConfig().getSupportedResource().equals(resourceName)) { @@ -1216,24 +1217,24 @@ public boolean hasSearchHandler(String resourceName, String resourceParentName) } return false; } - + public String getBaseUrl() { return baseUrl; } - + public Swagger getSwagger() { return swagger; } - + /** * @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; } - + public static void clearCache() { swagger = null; } - + }