diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java index 7aa1da2c0..06d365733 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java @@ -13,11 +13,8 @@ import java.util.List; import java.util.regex.Pattern; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; import org.openmrs.CareSetting; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -69,18 +66,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation public DelegatingResourceDescription getCreatableProperties() { throw new ResourceDoesNotSupportOperationException(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("careSettingType", new EnumProperty(CareSetting.CareSettingType.class)); - } - return model; - } - - /** + + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate() */ @Override diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java index b40c3fab0..d2c27ac32 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java @@ -24,11 +24,6 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -117,27 +112,5 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("drug"); return description; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - modelImpl.property("display", new StringProperty()).property("uuid", new StringProperty()) - .property("drug", new RefProperty("#/definitions/DrugGetRef")) - .property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermGetRef")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl.property("display", new StringProperty()).property("uuid", new StringProperty()) - .property("auditInfo", new StringProperty()).property("drug", new RefProperty("#/definitions/DrugGet")) - .property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermGet")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGet")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl().property("conceptReferenceTerm", new StringProperty().example("uuid")) - .property("conceptMapType", new StringProperty().example("uuid")) - .property("drug", new StringProperty().example("uuid")); - } + } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java index 820e8298e..b0ad0851b 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java @@ -18,10 +18,6 @@ import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.DrugResource1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; - /** * {@link org.openmrs.module.webservices.rest.web.annotation.Resource} for {@link org.openmrs.Drug}, * supporting standard CRUD operations @@ -59,22 +55,5 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("drugReferenceMaps", new RefProperty("#/definitions/DrugreferencemapGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("drugReferenceMaps", new RefProperty("#/definitions/DrugreferencemapGet")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("drugReferenceMaps", new RefProperty("#/definitions/DrugreferencemapCreate")); - } + } 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 98b8c0f76..ecfa2ca76 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 @@ -9,18 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; -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.apache.commons.lang.StringUtils; import org.openmrs.CareSetting; import org.openmrs.Order; import org.openmrs.OrderType; import org.openmrs.Patient; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.ConversionUtil; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -31,7 +25,6 @@ import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.api.PageableResult; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; -import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.InvalidSearchException; import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException; @@ -114,45 +107,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("encounter", new StringProperty().example("uuid")) - .property("orderType", new StringProperty().example("uuid")) - .property("action", new EnumProperty(Order.Action.class)) - .property("accessionNumber", new StringProperty()) - .property("dateActivated", new DateProperty()) - .property("scheduledDate", new DateProperty()) - .property("patient", new StringProperty().example("uuid")) - .property("concept", new StringProperty().example("uuid")) - .property("careSetting", new StringProperty().example("uuid")) - .property("dateStopped", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("orderer", new StringProperty().example("uuid")) - .property("previousOrder", new StringProperty().example("uuid")) - .property("urgency", new EnumProperty(Order.Urgency.class)) - .property("orderReason", new StringProperty().example("uuid")) - .property("orderReasonNonCoded", new StringProperty()) - .property("instructions", new StringProperty()) - .property("commentToFulfiller", new StringProperty()) - - .required("orderType").required("patient").required("concept"); - if (rep instanceof FullRepresentation) { - model - .property("encounter", new RefProperty("#/definitions/EncounterCreate")) - .property("patient", new RefProperty("#/definitions/PatientCreate")) - .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("orderReasonNonCoded", new StringProperty()) - .property("instructions", new StringProperty()) - .property("commentToFulfiller", new StringProperty()); - } - return model; - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java index e0eb1037e..4de8e4c48 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java @@ -13,11 +13,6 @@ import java.util.List; import java.util.regex.Pattern; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.OrderType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -151,33 +146,5 @@ public DelegatingResourceDescription getCreatableProperties() { d.addProperty("conceptClasses"); return d; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("javaClassName", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("conceptClasses", new ArrayProperty(new RefProperty("#/definitions/ConceptclassGetRef"))) - .property("parent", new RefProperty("#/definitions/OrdertypeGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("conceptClasses", new ArrayProperty(new RefProperty("#/definitions/ConceptclassGet"))) - .property("parent", new RefProperty("#/definitions/OrdertypeGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("javaClassName", new StringProperty()) - .property("parent", new StringProperty().example("uuid")) //FIXME type - .property("conceptClasses", new ArrayProperty(new StringProperty().example("uuid"))) - - .required("javaClassName"); - } + } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java index e605ecdf1..1bc26a49f 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java @@ -9,7 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.Person; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -59,23 +59,8 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.addProperty("birthtime"); return description; } - @Override - public Model getGETModel(Representation rep) { - return addNewProperties(super.getGETModel(rep), rep); - } - - @Override - public Model getCREATEModel(Representation rep) { - return addNewProperties(super.getCREATEModel(rep), rep); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return addNewProperties(super.getUPDATEModel(rep), rep); - } - - private Model addNewProperties(Model model, Representation rep) { - + + private Schema addNewProperties(Schema model, Representation rep) { return model; } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java index 3fad6b60f..201059bdf 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java @@ -9,12 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; import org.openmrs.PatientProgram; import org.openmrs.PatientState; import org.openmrs.api.context.Context; @@ -98,28 +92,7 @@ public DelegatingResourceDescription getCreatableProperties() { d.addProperty("voided"); return d; } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("states", new ArrayProperty(new RefProperty("#/definitions/ProgramenrollmentStateCreate"))) - .property("outcome", new RefProperty("#/definitions/ConceptCreate")); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() //FIXME use super. - .property("dateEnrolled", new DateProperty()) - .property("states", new ArrayProperty(new RefProperty("#/definitions/ProgramenrollmentStateCreate"))) - .property("outcome", new RefProperty("#/definitions/ConceptCreate")) - .property("location", new RefProperty("#/definitions/LocationCreate")) - .property("voided", new BooleanProperty()) - .property("dateCompleted", new DateProperty()) - - .required("dateEnrolled"); - - } - + @Override public DelegatingResourceDescription getUpdatableProperties() { DelegatingResourceDescription d = new DelegatingResourceDescription(); diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java index 123d687bc..db0afac2f 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Program; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -63,18 +59,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("outcomesConcept", new StringProperty().example("uuid")); - if (rep instanceof FullRepresentation) { - model - .property("outcomesConcept", new RefProperty("#/definitions/ConceptCreate")); - } - return model; - } - + @Override public DelegatingResourceDescription getCreatableProperties() { DelegatingResourceDescription description = new DelegatingResourceDescription(); @@ -86,5 +71,4 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("retired"); return description; } - } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java index a42d475fb..737475a84 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java @@ -9,8 +9,13 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; +import java.util.Arrays; import java.util.List; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.CareSetting; import org.openmrs.Order; @@ -19,7 +24,6 @@ import org.openmrs.TestOrder; import org.openmrs.api.OrderService; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.ConversionUtil; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; @@ -35,12 +39,6 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * Exposes the {@link org.openmrs.TestOrder} subclass as a type in * {@link org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.OrderResource1_8} @@ -128,49 +126,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe //this actually throws a ResourceDoesNotSupportOperationException return orderResource.getUpdatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class) - .getResourceBySupportedClass(Order.class); - ModelImpl orderModel = (ModelImpl) orderResource.getGETModel(rep); - orderModel - .property("laterality", new EnumProperty(TestOrder.Laterality.class)) - .property("clinicalHistory", new StringProperty()) - .property("numberOfRepeats", new IntegerProperty()); - - if (rep instanceof DefaultRepresentation) { - orderModel - .property("specimenSource", new RefProperty("#/definitions/ConceptGetRef")) - .property("frequency", new RefProperty("#/definitions/OrderfrequencyGetRef")); - } else if (rep instanceof FullRepresentation) { - orderModel - .property("specimenSource", new RefProperty("#/definitions/ConceptGet")) - .property("frequency", new RefProperty("#/definitions/OrderfrequencyGet")); - } - return orderModel; - } - - @Override - public Model getCREATEModel(Representation rep) { - OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class) - .getResourceBySupportedClass(Order.class); - ModelImpl orderModel = (ModelImpl) orderResource.getCREATEModel(rep); - return orderModel - .property("specimenSource", new StringProperty().example("uuid")) - .property("laterality", new EnumProperty(TestOrder.Laterality.class)) - .property("clinicalHistory", new StringProperty()) - .property("frequency", new StringProperty().example("uuid")) - .property("numberOfRepeats", new IntegerProperty()); - } - - @Override - public Model getUPDATEModel(Representation rep) { - OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class) - .getResourceBySupportedClass(Order.class); - return orderResource.getUPDATEModel(rep); - } - + public PageableResult getActiveOrders(Patient patient, RequestContext context) { String careSettingUuid = context.getRequest().getParameter("careSetting"); String asOfDateString = context.getRequest().getParameter("asOfDate"); diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/DrugIngredientResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/DrugIngredientResource1_11.java index 15dbb8976..9c25e03db 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/DrugIngredientResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/DrugIngredientResource1_11.java @@ -12,11 +12,6 @@ import java.util.ArrayList; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Drug; import org.openmrs.DrugIngredient; import org.openmrs.api.context.Context; @@ -84,43 +79,7 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("strength", new DoubleProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("ingredient", new RefProperty("#/definitions/ConceptGetRef")) - .property("units", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("ingredient", new RefProperty("#/definitions/ConceptGet")) - .property("units", new RefProperty("#/definitions/ConceptGet")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("ingredient", new StringProperty().example("uuid")) - .property("strength", new DoubleProperty()) - .property("units", new StringProperty().example("uuid")) - - .required("ingredient"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object) */ diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java index 14626f497..a49f50038 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.BooleanUtils; import org.openmrs.Concept; import org.openmrs.ConceptNumeric; @@ -41,21 +38,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return description; } - - @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("formFieldPath", new StringProperty()) - .property("formFieldNamespace", new StringProperty()); - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("formFieldPath", new StringProperty()) - .property("formFieldNamespace", new StringProperty()); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java index 5a272b267..319ef5e76 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java @@ -9,9 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.Person; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -62,26 +61,10 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.addProperty("deathdateEstimated"); return description; } - - @Override - public Model getGETModel(Representation rep) { - return addNewProperties(super.getGETModel(rep), rep); - } - - @Override - public Model getCREATEModel(Representation rep) { - return addNewProperties(super.getCREATEModel(rep), rep); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return addNewProperties(super.getUPDATEModel(rep), rep); - } - - private Model addNewProperties(Model model, Representation rep) { + + private Schema addNewProperties(Schema model, Representation rep) { if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - ((ModelImpl) model) - .property("deathdateEstimated", new BooleanProperty()._default(false)); + model.addProperty("deathdateEstimated", new BooleanSchema()._default(false)); } return model; } diff --git a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java index e54ac146d..866435e2f 100644 --- a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java +++ b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java @@ -27,13 +27,6 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - @Resource(name = RestConstants.VERSION_1 + "/ordergroup", supportedClass = OrderGroup.class, supportedOpenmrsVersions = { "1.12.* - 9.*" }) public class OrderGroupResource1_12 extends DataDelegatingCrudResource { @@ -127,46 +120,7 @@ public DelegatingResourceDescription getUpdatableProperties() { description.addProperty("orders"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - modelImpl.property("uuid", new StringProperty()).property("display", new StringProperty()) - .property("voided", new BooleanProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("encounter", new RefProperty("#/definitions/EncounterGetRef")) - .property("orders", new RefProperty("#/definitions/OrderGetRef")) - .property("orderSet", new RefProperty("#/definitions/OrdersetGetRef")); - - } else if (rep instanceof FullRepresentation) { - modelImpl.property("uuid", new StringProperty()).property("display", new StringProperty()) - .property("voided", new BooleanProperty()).property("auditInfo", new BooleanProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("encounter", new RefProperty("#/definitions/EncounterGetRef")) - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderGetRef"))) - .property("orderSet", new RefProperty("#/definitions/OrdersetGetRef")); - } else if (rep instanceof RefRepresentation) { - modelImpl.property("display", new StringProperty()).property("uuid", new StringProperty()); - - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl().property("patient", new StringProperty().example("uuid")) - .property("encounter", new StringProperty().example("uuid")) - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderCreate"))) - .property("orderSet", new StringProperty().example("uuid")); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl().property("orders", - new ArrayProperty(new RefProperty("#/definitions/OrderCreate"))); - } - + @PropertyGetter("display") public String getDisplayString(OrderGroup group) { if (group.getOrders() == null) diff --git a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java index 9ae07a777..93f2478ac 100644 --- a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java +++ b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java @@ -30,13 +30,6 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * {@link Resource} for OrderSetMembers, supporting standard CRUD operations */ @@ -103,45 +96,7 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("orderTemplate", new StringProperty()) - .property("orderTemplateType", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("orderType", new RefProperty("#/definitions/OrdertypeGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("orderType", new RefProperty("#/definitions/OrdertypeGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("orderType", new ObjectProperty() - .property("uuid", new StringProperty())) - .property("orderTemplate", new StringProperty()) - .property("concept", new StringProperty().example("uuid")) - .property("retired", new BooleanProperty()); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + @Override public OrderSetMember getByUniqueId(String uniqueId) { return Context.getOrderSetService().getOrderSetMemberByUuid(uniqueId); diff --git a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetResource1_12.java b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetResource1_12.java index 41176c265..e2e353985 100644 --- a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetResource1_12.java +++ b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetResource1_12.java @@ -9,16 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_12; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.RefProperty; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openmrs.OrderSet; import org.openmrs.OrderSetMember; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; @@ -107,31 +102,5 @@ public DelegatingResourceDescription getCreatableProperties() { d.addProperty("orderSetMembers"); return d; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("operator", new EnumProperty(OrderSet.Operator.class)); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("orderSetMembers", new ArrayProperty(new RefProperty( - "#/definitions/OrdersetOrdersetmemberGetRef"))); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("orderSetMembers", new ArrayProperty( - new RefProperty("#/definitions/OrdersetOrdersetmemberGet"))); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("operator", new EnumProperty(OrderSet.Operator.class)) - .property("orderSetMembers", - new ArrayProperty(new RefProperty("#/definitions/OrdersetOrdersetmemberCreate"))); - } + } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/AllergyResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/AllergyResource1_8.java index 9892c90e4..556f65653 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/AllergyResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/AllergyResource1_8.java @@ -9,17 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Patient; import org.openmrs.activelist.Allergy; -import org.openmrs.activelist.AllergySeverity; -import org.openmrs.activelist.AllergyType; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; @@ -62,32 +54,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)) - .property("allergyType", new EnumProperty(AllergyType.class)) - .property("reaction", new RefProperty("#/definitions/ConceptGetRef")) - .property("severity", new EnumProperty(AllergySeverity.class)) - .property("allergen", new RefProperty("#/definitions/ConceptGetRef")); - if (rep instanceof FullRepresentation) { - model - .property("reaction", new RefProperty("#/definitions/ConceptGet")) - .property("allergen", new RefProperty("#/definitions/ConceptGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("allergyType", new EnumProperty(AllergyType.class)) - .property("reaction", new ObjectProperty() - .property("uuid", new StringProperty())) - .property("severity", new EnumProperty(AllergySeverity.class)) - .property("allergen", new StringProperty()); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() */ @@ -127,7 +94,7 @@ public String getDisplayString(Allergy allergy) { /** * Annotated setter for allergen * - * @param allergen + * @param allergy * @param value */ @PropertySetter("allergen") @@ -158,4 +125,4 @@ protected PageableResult doSearch(RequestContext context) { return super.doSearch(context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java index 9ef1b74c0..6e06a8cc0 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java @@ -9,12 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.activelist.ActiveListItem; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -31,26 +25,7 @@ * {@link ActiveListItem} */ public abstract class BaseActiveListItemResource1_8 extends DataDelegatingCrudResource { - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("person", new StringProperty()) - .property("startDate", new DateProperty()) - .property("comments", new StringProperty()) - .property("startObs", new StringProperty()) - .property("stopObs", new StringProperty()) - - .required("person").required("startDate"); - if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonCreate")) - .property("startObs", new RefProperty("#/definitions/ObsCreate")) - .property("stopObs", new RefProperty("#/definitions/ObsCreate")); - } - return model; - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ @@ -90,30 +65,6 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("comments", new StringProperty()) - .property("voided", new BooleanProperty()); - if (rep instanceof DefaultRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGet")) - .property("activeListType", new StringProperty()) //FIXME type - .property("startObs", new RefProperty("#/definitions/ObsGet")) - .property("stopObs", new RefProperty("#/definitions/ObsGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGetRef")) - .property("activeListType", new StringProperty()) //FIXME type - .property("startObs", new RefProperty("#/definitions/ObsGetRef")) - .property("stopObs", new RefProperty("#/definitions/ObsGetRef")); - } - return model; - } - /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -174,4 +125,4 @@ public void purge(T delegate, RequestContext context) throws ResponseException { //delegate.setComments("Stopped from a REST web service call"); //Context.getActiveListService().removeActiveListItem(delegate, null); -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java index e062d1db3..bb9fc7db1 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java @@ -12,10 +12,6 @@ import java.util.ArrayList; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Cohort; import org.openmrs.Patient; import org.openmrs.api.context.Context; @@ -118,41 +114,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof RefRepresentation) { - modelImpl - .property("display", new StringProperty()); - } else if (rep instanceof DefaultRepresentation) { - modelImpl - .property("display", new StringProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("display", new StringProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("patient", new StringProperty().example("uuid")) - .required("patient"); - if (rep instanceof FullRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -279,4 +241,4 @@ public String getDisplayString(CohortMember1_8 member) { return member.getPatient().getPatientIdentifier().getIdentifier() + " - " + member.getPatient().getPersonName().getFullName(); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java index ff12bc660..48bd4b6b1 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java @@ -11,11 +11,6 @@ import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Cohort; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -90,38 +85,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("voided", new StringProperty()) - .property("memberIds", new ArrayProperty(new IntegerProperty())); //FIXME - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("memberIds", new ArrayProperty(new IntegerProperty())) //FIXME - .required("name").required("description").required("memberIds"); - } - - @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .required("name").required("description"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -204,4 +168,4 @@ protected NeedsPaging doSearch(RequestContext context) { return new NeedsPaging(cohorts, context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java index e4a8e25a0..be9568a8b 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java @@ -9,13 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; import org.openmrs.ConceptClass; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; -import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource; import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; @@ -67,11 +65,6 @@ public void purge(ConceptClass conceptClass, RequestContext context) throws Resp Context.getConceptService().purgeConceptClass(conceptClass); } - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @@ -80,5 +73,5 @@ protected NeedsPaging doGetAll(RequestContext context) { return new NeedsPaging(Context.getConceptService().getAllConceptClasses(context.getIncludeAll()), context); } - + } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java index 0de73cceb..ffe11f350 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.ConceptDatatype; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.SimpleObject; @@ -66,22 +62,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("hl7Abbreviation", new StringProperty()) - .property("retired", new BooleanProperty()); - } - return model; - } - - /** + + /** * @see DelegatingCrudResource#newDelegate() */ @Override @@ -146,4 +128,4 @@ protected NeedsPaging doGetAll(RequestContext context) { context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDescriptionResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDescriptionResource1_8.java index d5465bd38..15db1862c 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDescriptionResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDescriptionResource1_8.java @@ -10,11 +10,12 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; import org.openmrs.Concept; import org.openmrs.ConceptDescription; import org.openmrs.api.context.Context; @@ -67,36 +68,6 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof RefRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - } else if (rep instanceof DefaultRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("description", new StringProperty()) - .property("locale", new StringProperty()); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("description", new StringProperty()) - .property("locale", new StringProperty()); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("description", new StringProperty()) - .property("locale", new StringProperty().example("fr")) - .required("description").required("locale"); - } - /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -212,4 +183,4 @@ public String getLocaleAsString(ConceptDescription instance) { return instance.getLocale().toString(); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptMapResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptMapResource1_8.java index 798d54364..c689559bc 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptMapResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptMapResource1_8.java @@ -12,9 +12,6 @@ import java.util.ArrayList; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.openmrs.Concept; import org.openmrs.ConceptMap; import org.openmrs.api.context.Context; @@ -64,34 +61,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("source", new StringProperty()) //FIXME - .property("sourceCode", new StringProperty()); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("source", new StringProperty()) //FIXME - .property("sourceCode", new StringProperty()) - .property("comment", new StringProperty()); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("source", new StringProperty()) - .property("sourceCode", new StringProperty()) - .required("source").required("sourceCode"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -188,4 +158,4 @@ public void purge(ConceptMap delegate, RequestContext context) throws ResponseEx delegate.getConcept().removeConceptMapping(delegate); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptNameResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptNameResource1_8.java index 8088f9f54..d2652ef39 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptNameResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptNameResource1_8.java @@ -13,15 +13,9 @@ import java.util.Date; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Concept; import org.openmrs.ConceptName; -import org.openmrs.api.ConceptNameType; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; @@ -29,6 +23,7 @@ import org.openmrs.module.webservices.rest.web.annotation.SubResource; import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; +import org.openmrs.module.webservices.rest.web.representation.RefRepresentation; import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource; @@ -44,7 +39,13 @@ public class ConceptNameResource1_8 extends DelegatingSubResource { - + public ConceptResource1_8() { //RESTWS-439 //Concept numeric fields @@ -86,7 +79,7 @@ public ConceptResource1_8() { allowedMissingProperties.add("allowDecimal"); allowedMissingProperties.add("displayPrecision"); } - + @RepHandler(RefRepresentation.class) public SimpleObject asRef(Concept delegate) throws ConversionException { DelegatingResourceDescription description = new DelegatingResourceDescription(); @@ -98,38 +91,38 @@ public SimpleObject asRef(Concept delegate) throws ConversionException { description.addSelfLink(); return convertDelegateToRepresentation(delegate, description); } - + @RepHandler(FullRepresentation.class) public SimpleObject asFull(Concept delegate) throws ConversionException { DelegatingResourceDescription description = fullRepresentationDescription(delegate); return convertDelegateToRepresentation(delegate, description); } - + @RepHandler(value = NamedRepresentation.class, name = "fullchildren") public SimpleObject asFullChildren(Concept delegate) throws ConversionException { Set path = new HashSet(); path.add(delegate.getUuid()); assertNoCycles(delegate, path); - + return asFullChildrenInternal(delegate); } - + protected void assertNoCycles(Concept delegate, Set path) throws ConversionException { for (Concept member : delegate.getSetMembers()) { if (path.add(member.getUuid())) { assertNoCycles(member, path); } else { throw new ConversionException("Cycles in children are not supported. Concept with uuid " - + delegate.getUuid() + " repeats in a set."); + + delegate.getUuid() + " repeats in a set."); } path.remove(member.getUuid()); } } - + /** * It is used internally for the fullchildren representation. Contrary to the fullchildren * handler it does not check for cycles. - * + * * @param delegate * @return * @throws ConversionException @@ -143,14 +136,14 @@ public SimpleObject asFullChildrenInternal(Concept delegate) throws ConversionEx description.addProperty("answers", Representation.FULL); return convertDelegateToRepresentation(delegate, description); } - + @Override public List getAvailableRepresentations() { List availableRepresentations = super.getAvailableRepresentations(); availableRepresentations.add(new NamedRepresentation("fullchildren")); return availableRepresentations; } - + protected DelegatingResourceDescription fullRepresentationDescription(Concept delegate) { DelegatingResourceDescription description = new DelegatingResourceDescription(); description.addProperty("uuid"); @@ -161,12 +154,12 @@ protected DelegatingResourceDescription fullRepresentationDescription(Concept de description.addProperty("set"); description.addProperty("version"); description.addProperty("retired"); - + description.addProperty("names", Representation.DEFAULT); description.addProperty("descriptions", Representation.DEFAULT); - + description.addProperty("mappings", Representation.DEFAULT); - + description.addProperty("answers", Representation.DEFAULT); description.addProperty("setMembers", Representation.DEFAULT); description.addProperty("auditInfo"); @@ -183,7 +176,7 @@ protected DelegatingResourceDescription fullRepresentationDescription(Concept de } return description; } - + /** * @see DelegatingCrudResource#getRepresentationDescription(Representation) */ @@ -199,89 +192,23 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addProperty("set"); description.addProperty("version"); description.addProperty("retired"); - + description.addProperty("names", Representation.REF); description.addProperty("descriptions", Representation.REF); - + description.addProperty("mappings", Representation.REF); - + description.addProperty("answers", Representation.REF); description.addProperty("setMembers", Representation.REF); //description.addProperty("conceptMappings", Representation.REF); add as subresource - + description.addSelfLink(); description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL); return description; } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("name", new RefProperty("#/definitions/ConceptNameGet")) - .property("datatype", new RefProperty("#/definitions/ConceptdatatypeGetRef")) - .property("conceptClass", new RefProperty("#/definitions/ConceptclassGetRef")) - .property("set", new BooleanProperty()) - .property("version", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameGetRef"))) //FIXME - .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionGetRef"))) //FIXME - .property("mappings", new ArrayProperty(new RefProperty("#/definitions/ConceptMappingGetRef"))) //FIXME - .property("answers", new ArrayProperty(new ObjectProperty())) //FIXME - .property("setMembers", new ArrayProperty(new ObjectProperty())); //FIXME - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameCreate"))) - .property("datatype", new StringProperty().example("uuid")) - .property("set", new BooleanProperty()) - .property("version", new StringProperty()) - .property("answers", new ArrayProperty(new StringProperty().example("uuid"))) - .property("setMembers", new ArrayProperty(new StringProperty().example("uuid"))) - - //ConceptNumeric properties - .property("hiNormal", new StringProperty()) - .property("hiAbsolute", new StringProperty()) - .property("hiCritical", new StringProperty()) - .property("lowNormal", new StringProperty()) - .property("lowAbsolute", new StringProperty()) - .property("lowCritical", new StringProperty()) - .property("units", new StringProperty()) - .property("allowDecimal", new StringProperty()) - .property("displayPrecision", new StringProperty()) - - .required("names").required("datatype").required("conceptClass"); - if (rep instanceof DefaultRepresentation) { - model - .property("conceptClass", new StringProperty()) - .property("descriptions", new ArrayProperty(new StringProperty())) - .property("mappings", new ArrayProperty(new StringProperty())); - } - else if (rep instanceof FullRepresentation) { - model - .property("conceptClass", new RefProperty("#/definitions/ConceptclassCreate")) - .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionCreate"))) - .property("mappings", new ArrayProperty(new RefProperty("#/definitions/ConceptMappingCreate"))); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("name", new RefProperty("#/definitions/ConceptNameCreate")) - .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameCreate"))) - .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionCreate"))); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -291,14 +218,14 @@ public DelegatingResourceDescription getCreatableProperties() { description.addRequiredProperty("names"); description.addRequiredProperty("datatype"); description.addRequiredProperty("conceptClass"); - + description.addProperty("descriptions"); description.addProperty("set"); description.addProperty("version"); description.addProperty("mappings"); description.addProperty("answers"); description.addProperty("setMembers"); - + //ConceptNumeric properties description.addProperty("hiNormal"); description.addProperty("hiAbsolute"); @@ -311,21 +238,21 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("displayPrecision"); return description; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties() */ @Override public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { DelegatingResourceDescription description = super.getUpdatableProperties(); - + description.addProperty("name"); description.addProperty("names"); description.addProperty("descriptions"); - + return description; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getPropertiesToExposeAsSubResources() */ @@ -333,10 +260,10 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe public List getPropertiesToExposeAsSubResources() { return Arrays.asList("names", "descriptions", "conceptMappings"); } - + /** * Sets the name property to be the fully specified name of the Concept in the current locale - * + * * @param instance * @param name */ @@ -345,12 +272,12 @@ public static void setFullySpecifiedName(Concept instance, String name) { ConceptName fullySpecifiedName = new ConceptName(name, Context.getLocale()); instance.setFullySpecifiedName(fullySpecifiedName); } - + /** * It's needed, because of ConversionException: Don't know how to handle collection class: * interface java.util.Collection If request to update Concept updates ConceptName, adequate * resource takes care of it, so this method just adds new and removes deleted names. - * + * * @param instance * @param names * @throws NoSuchMethodException @@ -359,43 +286,57 @@ public static void setFullySpecifiedName(Concept instance, String name) { */ @PropertySetter("names") public static void setNames(Concept instance, List names) throws IllegalAccessException, - InvocationTargetException, NoSuchMethodException { - + InvocationTargetException, NoSuchMethodException { + new HibernateCollectionHelper( - instance) { - + instance) { + @Override +// public int compare(ConceptName left, ConceptName right) { +// if (Objects.equals(left.getUuid(), right.getUuid())) { +// return 0; +// } +// boolean areEqual = (Objects.equals(left.getName(), right.getName()) +// && Objects.equals(left.getConceptNameType(), right.getConceptNameType()) && Objects.equals( +// left.getLocale(), right.getLocale())); +// return areEqual ? 0 : 1; +// } public int compare(ConceptName left, ConceptName right) { - if (Objects.equals(left.getUuid(), right.getUuid())) { + if (safeEquals(left.getUuid(), right.getUuid())) { return 0; } - boolean areEqual = (Objects.equals(left.getName(), right.getName()) - && Objects.equals(left.getConceptNameType(), right.getConceptNameType()) && Objects.equals( - left.getLocale(), right.getLocale())); + boolean areEqual = safeEquals(left.getName(), right.getName()) + && safeEquals(left.getConceptNameType(), right.getConceptNameType()) + && safeEquals(left.getLocale(), right.getLocale()); return areEqual ? 0 : 1; } - + @Override public Collection getAll() { return instance.getNames(); } - + @Override public void add(ConceptName item) { instance.addName(item); } - + @Override public void remove(ConceptName item) { instance.removeName(item); } }.set(names); } - + + + private static boolean safeEquals(Object a, Object b) { + return (a == b) || (a != null && a.equals(b)); + } + /** * It's needed, because of ConversionException: Don't know how to handle collection class: * interface java.util.Collection - * + * * @param instance * @param descriptions * @throws NoSuchMethodException @@ -404,42 +345,54 @@ public void remove(ConceptName item) { */ @PropertySetter("descriptions") public static void setDescriptions(Concept instance, List descriptions) - throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { - + throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { + new HibernateCollectionHelper( - instance) { - + instance) { + @Override +// public int compare(ConceptDescription left, ConceptDescription right) { +// if (Objects.equals(left.getUuid(), right.getUuid())) { +// return 0; +// } +// boolean areEqual = (Objects.equals(left.getDescription(), right.getDescription()) && Objects.equals( +// left.getLocale(), right.getLocale())); +// return areEqual ? 0 : 1; +// } public int compare(ConceptDescription left, ConceptDescription right) { - if (Objects.equals(left.getUuid(), right.getUuid())) { + // Compare UUIDs + if (safeEquals(left.getUuid(), right.getUuid())) { return 0; } - boolean areEqual = (Objects.equals(left.getDescription(), right.getDescription()) && Objects.equals( - left.getLocale(), right.getLocale())); + + // Check if the description and locale are equal + boolean areEqual = safeEquals(left.getDescription(), right.getDescription()) + && safeEquals(left.getLocale(), right.getLocale()); + return areEqual ? 0 : 1; } - + @Override public Collection getAll() { return instance.getDescriptions(); } - + @Override public void add(ConceptDescription item) { instance.addDescription(item); } - + @Override public void remove(ConceptDescription item) { instance.removeDescription(item); } }.set(descriptions); } - + /** * It's needed, because of ConversionException: Don't know how to handle collection class: * interface java.util.Collection - * + * * @param instance * @param mappings */ @@ -450,15 +403,15 @@ public static void setMappings(Concept instance, List mappings) { instance.addConceptMapping(map); } } - + @PropertyGetter("mappings") public static List getMappings(Concept instance) { return new ArrayList(instance.getConceptMappings()); } - + /** * Gets the display name of the Concept delegate - * + * * @param instance the delegate instance to get the display name off */ @PropertyGetter("display") @@ -475,17 +428,17 @@ public String getDisplayString(Concept instance) { } } } - + /** * {@link #newDelegate(SimpleObject)} is used instead to support ConceptNumeric - * + * * @see DelegatingCrudResource#newDelegate() */ @Override public Concept newDelegate() { throw new ResourceDoesNotSupportOperationException("Should use newDelegate(SimpleObject) instead"); } - + @Override public Concept newDelegate(SimpleObject object) { String datatypeUuid = (String) object.get("datatype"); @@ -495,7 +448,7 @@ public Concept newDelegate(SimpleObject object) { return new Concept(); } } - + /** * @see DelegatingCrudResource#save(java.lang.Object) */ @@ -503,17 +456,17 @@ public Concept newDelegate(SimpleObject object) { public Concept save(Concept c) { return Context.getConceptService().saveConcept(c); } - + /** * Fetches a concept by uuid - * + * * @see DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public Concept getByUniqueId(String uuid) { return Context.getConceptService().getConceptByUuid(uuid); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) @@ -524,10 +477,10 @@ public void purge(Concept concept, RequestContext context) throws ResponseExcept return; Context.getConceptService().purgeConcept(concept); } - + /** * This does not include retired concepts - * + * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override @@ -535,7 +488,7 @@ protected NeedsPaging doGetAll(RequestContext context) { List allConcepts = Context.getConceptService().getAllConcepts(null, true, context.getIncludeAll()); return new NeedsPaging(allConcepts, context); } - + /** * Concept searches support the following additional query parameters: *
    @@ -544,7 +497,7 @@ protected NeedsPaging doGetAll(RequestContext context) { *
  • memberOf=(uuid): restricts to concepts that are set members of the given concept set's * uuid
  • *
- * + * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(RequestContext) */ @Override @@ -553,7 +506,7 @@ protected PageableResult doSearch(RequestContext context) { Integer startIndex = null; Integer limit = null; boolean canPage = true; - + // Collect information for answerTo and memberOf query parameters String answerToUuid = context.getRequest().getParameter("answerTo"); String memberOfUuid = context.getRequest().getParameter("memberOf"); @@ -567,27 +520,27 @@ protected PageableResult doSearch(RequestContext context) { log.error("Unexpected exception while retrieving answerTo Concept with UUID " + answerToUuid, ex); } } - + if (StringUtils.isNotBlank(memberOfUuid)) { Concept memberOf = service.getConceptByUuid(memberOfUuid); memberOfList = service.getConceptsByConceptSet(memberOf); canPage = false; // ConceptService does not support memberOf searches, so paging must be deferred. } - + // Only set startIndex and limit if we can return paged results if (canPage) { startIndex = context.getStartIndex(); limit = context.getLimit(); } - + List searchResults; - + // get the user's locales...and then convert that from a set to a list List locales = new ArrayList(LocaleUtility.getLocalesInOrder()); - + searchResults = service.getConcepts(context.getParameter("q"), locales, context.getIncludeAll(), null, null, null, - null, answerTo, startIndex, limit); - + null, answerTo, startIndex, limit); + // convert search results into list of concepts List results = new ArrayList(searchResults.size()); for (ConceptSearchResult csr : searchResults) { @@ -595,21 +548,21 @@ protected PageableResult doSearch(RequestContext context) { if (memberOfList == null || memberOfList.contains(csr.getConcept())) results.add(csr.getConcept()); } - + PageableResult result = null; if (canPage) { Integer count = service.getCountOfConcepts(context.getParameter("q"), locales, false, - Collections. emptyList(), Collections. emptyList(), - Collections. emptyList(), Collections. emptyList(), answerTo); + Collections. emptyList(), Collections. emptyList(), + Collections. emptyList(), Collections. emptyList(), answerTo); boolean hasMore = count > startIndex + limit; result = new AlreadyPaged(context, results, hasMore, Long.valueOf(count)); } else { result = new NeedsPaging(results, context); } - + return result; } - + @Override protected void delete(Concept c, String reason, RequestContext context) throws ResponseException { if (c.isRetired()) { @@ -618,7 +571,7 @@ protected void delete(Concept c, String reason, RequestContext context) throws R } Context.getConceptService().retireConcept(c, reason); } - + /** * @param instance * @return the list of Concepts or Drugs @@ -628,7 +581,7 @@ public static Object getAnswers(Concept instance) { List conceptAnswers = new ArrayList(); conceptAnswers.addAll(instance.getAnswers(false)); Collections.sort(conceptAnswers); - + List answers = new ArrayList(); for (ConceptAnswer conceptAnswer : conceptAnswers) { if (conceptAnswer.getAnswerDrug() != null) { @@ -637,10 +590,10 @@ public static Object getAnswers(Concept instance) { answers.add(conceptAnswer.getAnswerConcept()); } } - + return answers; } - + /** * @param instance * @param answerUuids the list of Concepts or Drugs @@ -648,8 +601,8 @@ public static Object getAnswers(Concept instance) { */ @PropertySetter("answers") public static void setAnswers(Concept instance, List answerUuids /*Concept or Drug uuid*/) - throws ResourceDoesNotSupportOperationException { - + throws ResourceDoesNotSupportOperationException { + // remove answers that are not in the new list Iterator iterator = instance.getAnswers(false).iterator(); while (iterator.hasNext()) { @@ -664,7 +617,7 @@ public static void setAnswers(Concept instance, List answerUuids /*Conce instance.removeAnswer(answer); // remove from concept question object } } - + List answerObjects = new ArrayList(answerUuids.size()); for (String uuid : answerUuids) { Concept c = Context.getConceptService().getConceptByUuid(uuid); @@ -677,10 +630,10 @@ public static void setAnswers(Concept instance, List answerUuids /*Conce answerObjects.add(drug); else throw new ResourceDoesNotSupportOperationException("There is no concept or drug with given uuid: " - + uuid); + + uuid); } } - + // add in new answers for (Object obj : answerObjects) { ConceptAnswer answerToAdd = null; @@ -688,13 +641,13 @@ public static void setAnswers(Concept instance, List answerUuids /*Conce answerToAdd = new ConceptAnswer((Concept) obj); else answerToAdd = new ConceptAnswer(((Drug) obj).getConcept(), (Drug) obj); - + answerToAdd.setCreator(Context.getAuthenticatedUser()); answerToAdd.setDateCreated(new Date()); instance.addAnswer(answerToAdd); } } - + /** * @param instance * @param setMembers the list of Concepts @@ -702,15 +655,15 @@ public static void setAnswers(Concept instance, List answerUuids /*Conce @PropertySetter("setMembers") public static void setSetMembers(Concept instance, List setMembers) { instance.getConceptSets().clear(); - + if (setMembers == null || setMembers.isEmpty()) { instance.setSet(false); } else { instance.setSet(true); - + for (Concept setMember : setMembers) { instance.addSetMember(setMember); } } } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java index 58bf17ce0..b34e51399 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.ConceptSource; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -69,26 +65,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("hl7Code", new StringProperty()) - .property("retired", new BooleanProperty()); - } - - @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("hl7Code", new StringProperty()) - .required("name").required("description"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -185,4 +162,4 @@ protected NeedsPaging doSearch(RequestContext context, List(sources, context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java index f1d82939d..ec9253fc9 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java @@ -11,13 +11,10 @@ import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.DrugOrder; import org.openmrs.Order; import org.openmrs.Patient; @@ -135,50 +132,7 @@ public DelegatingResourceDescription getCreatableProperties() { d.removeProperty("orderType"); return d; } - - @Override - public Model getGETModel(Representation rep) { - OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class) - .getResourceBySupportedClass(Order.class); - ModelImpl orderModel = (ModelImpl) orderResource.getGETModel(rep); - orderModel - .property("dose", new DoubleProperty()) - .property("units", new StringProperty()) - .property("frequency", new StringProperty()) - .property("prn", new BooleanProperty()) - .property("complex", new BooleanProperty()) - .property("quantity", new IntegerProperty()); - - if (rep instanceof DefaultRepresentation) { - orderModel - .property("drug", new RefProperty("#/definitions/DrugGetRef")); - } else if (rep instanceof FullRepresentation) { - orderModel - .property("drug", new RefProperty("#/definitions/DrugGet")); - } - return orderModel; - } - - @Override - public Model getCREATEModel(Representation rep) { - OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class) - .getResourceBySupportedClass(Order.class); - ModelImpl orderModel = (ModelImpl) orderResource.getCREATEModel(rep); - orderModel - .property("dose", new DoubleProperty()) - .property("units", new StringProperty()) - .property("frequency", new StringProperty()) - .property("prn", new BooleanProperty()) - .property("complex", new BooleanProperty()) - .property("quantity", new IntegerProperty()) - .property("drug", new RefProperty("#/definitions/DrugCreate")); - - // DrugOrders have a specific hardcoded value for this property - orderModel.getProperties().remove("orderType"); - - return orderModel; - } - + /** * Handles getOrdersByPatient for {@link OrderResource1_8} when type=drugorder * @@ -206,4 +160,4 @@ public static String getDisplay(DrugOrder delegate) { // TODO dates, etc return ret.toString(); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java index f34e6df7f..21eb038c3 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java @@ -9,12 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Drug; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -90,8 +84,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addProperty("maximumDailyDose"); description.addProperty("minimumDailyDose"); description.addProperty("units"); - description.addProperty("concept", Representation.REF); description.addProperty("combination"); + description.addProperty("concept", Representation.REF); description.addProperty("route", Representation.REF); description.addSelfLink(); description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL); @@ -103,73 +97,21 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addProperty("name"); description.addProperty("description"); description.addProperty("retired"); - description.addProperty("dosageForm", Representation.REF); + description.addProperty("dosageForm"); description.addProperty("doseStrength"); description.addProperty("maximumDailyDose"); description.addProperty("minimumDailyDose"); description.addProperty("units"); - description.addProperty("concept", Representation.REF); description.addProperty("combination"); - description.addProperty("route", Representation.REF); + description.addProperty("concept"); + description.addProperty("route"); description.addProperty("auditInfo"); description.addSelfLink(); return description; } - //Let the superclass handle this return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("doseStrength", new DoubleProperty()) - .property("maximumDailyDose", new DoubleProperty()) - .property("minimumDailyDose", new DoubleProperty()) - .property("units", new StringProperty()) - .property("combination", new BooleanProperty()._default(false)); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("dosageForm", new RefProperty("#/definitions/ConceptGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("route", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("dosageForm", new RefProperty("#/definitions/ConceptGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("route", new RefProperty("#/definitions/ConceptGet")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("combination", new BooleanProperty()._default(false)) - .property("concept", new StringProperty()) - .property("doseStrength", new DoubleProperty()) - .property("maximumDailyDose", new DoubleProperty()) - .property("minimumDailyDose", new DoubleProperty()) - .property("units", new StringProperty()) - .property("dosageForm", new StringProperty()) - .property("route", new StringProperty()) - - .required("combination").required("concept"); - if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("dosageForm", new RefProperty("#/definitions/ConceptCreate")) - .property("route", new RefProperty("#/definitions/ConceptCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); //FIXME no updatableProperties() - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource#getCreatableProperties() */ @@ -222,4 +164,4 @@ protected PageableResult doSearch(RequestContext ctx) { boolean hasMore = countOfDrugs > startIndex + limit; return new AlreadyPaged(ctx, drugs, hasMore, Long.valueOf(countOfDrugs)); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterResource1_8.java index d28dcce52..2c7ea1fc1 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterResource1_8.java @@ -9,13 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Encounter; import org.openmrs.Obs; import org.openmrs.Order; @@ -49,7 +42,7 @@ */ @Resource(name = RestConstants.VERSION_1 + "/encounter", supportedClass = Encounter.class, supportedOpenmrsVersions = "1.8.*") public class EncounterResource1_8 extends DataDelegatingCrudResource { - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ @@ -90,57 +83,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("encounterDatetime", new DateProperty()) - .property("provider", new StringProperty()) //FIXME - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("patient", new RefProperty("#/definitions/PatientGetRef")) //FIXME - .property("location", new RefProperty("#/definitions/LocationGetRef")) //FIXME - .property("form", new RefProperty("#/definitions/FormGetRef")) //FIXME - .property("encounterType", new RefProperty("#/definitions/EncountertypeGetRef")) //FIXME - .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsGetRef"))) //FIXME - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderGetRef"))); //FIXME - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("patient", new RefProperty("#/definitions/PatientGet")) //FIXME - .property("location", new RefProperty("#/definitions/LocationGet")) //FIXME - .property("form", new RefProperty("#/definitions/FormGet")) //FIXME - .property("encounterType", new RefProperty("#/definitions/EncountertypeGet")) //FIXME - .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsGet"))) //FIXME - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderGet"))); //FIXME - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("patient", new RefProperty("#/definitions/PatientCreate")) - .property("encounterType", new RefProperty("#/definitions/EncountertypeCreate")) - .property("encounterDatetime", new DateProperty()) - .property("location", new RefProperty("#/definitions/LocationCreate")) - .property("form", new RefProperty("#/definitions/FormCreate")) - .property("provider", new StringProperty()) - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderCreate"))) - .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsCreate"))) - - .required("patient").required("encounterType"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() * Should create an encounter type @@ -148,20 +91,20 @@ public Model getUPDATEModel(Representation rep) { @Override public DelegatingResourceDescription getCreatableProperties() { DelegatingResourceDescription description = new DelegatingResourceDescription(); - + description.addProperty("encounterDatetime"); // has a default value set, hence not required here description.addRequiredProperty("patient"); description.addRequiredProperty("encounterType"); - + description.addProperty("location"); description.addProperty("form"); description.addProperty("provider"); description.addProperty("orders"); description.addProperty("obs"); - + return description; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate() */ @@ -174,7 +117,7 @@ public Encounter newDelegate() { enc.setOrders(new LinkedHashSet()); return enc; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(org.openmrs.Encounter) */ @@ -182,7 +125,7 @@ public Encounter newDelegate() { public Encounter save(Encounter enc) { return Context.getEncounterService().saveEncounter(enc); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String) */ @@ -190,7 +133,7 @@ public Encounter save(Encounter enc) { public Encounter getByUniqueId(String uuid) { return Context.getEncounterService().getEncounterByUuid(uuid); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(org.openmrs.Encounter, * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext) @@ -203,7 +146,7 @@ public void delete(Encounter enc, String reason, RequestContext context) throws } Context.getEncounterService().voidEncounter(enc, reason); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#undelete(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) @@ -215,7 +158,7 @@ protected Encounter undelete(Encounter enc, RequestContext context) throws Respo } return enc; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(org.openmrs.Encounter, * org.openmrs.module.webservices.rest.web.RequestContext) @@ -228,7 +171,7 @@ public void purge(Encounter enc, RequestContext context) throws ResponseExceptio } Context.getEncounterService().purgeEncounter(enc); } - + /** * @param encounter * @return encounter type and date @@ -238,10 +181,10 @@ public String getDisplayString(Encounter encounter) { String ret = encounter.getEncounterType() == null ? "?" : encounter.getEncounterType().getName(); ret += " "; ret += encounter.getEncounterDatetime() == null ? "?" : Context.getDateFormat().format( - encounter.getEncounterDatetime()); + encounter.getEncounterDatetime()); return ret; } - + /** * @param instance * @return all non-voided top-level obs from the given encounter @@ -250,25 +193,25 @@ public String getDisplayString(Encounter encounter) { public static Object getObsAtTopLevel(Encounter instance) { return instance.getObsAtTopLevel(false); } - + @PropertySetter("obs") public static void setObs(Encounter instance, Set obs) { instance.getAllObs(true).clear(); for (Obs o : obs) instance.addObs(o); } - + @PropertySetter("orders") public static void setOrders(Encounter instance, Set orders) { for (Order o : orders) instance.addOrder(o); } - + /** * Gets encounters for the given patient (paged according to context if necessary) only if a * patient parameter exists in the request set on the {@link RequestContext} otherwise searches * for encounters that match the specified query - * + * * @param context * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @@ -277,15 +220,15 @@ protected PageableResult doSearch(RequestContext context) { String patientUuid = context.getRequest().getParameter("patient"); if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( - Patient.class)).getByUniqueId(patientUuid); + Patient.class)).getByUniqueId(patientUuid); if (patient == null) return new EmptySearchResult(); List encs = Context.getEncounterService().getEncountersByPatient(patient); return new NeedsPaging(encs, context); } - + return new ServiceSearcher(EncounterService.class, "getEncounters", "getCountOfEncounters").search( - context.getParameter("q"), context); + context.getParameter("q"), context); } - + } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java index 952889804..6620530f5 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java @@ -9,14 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; import org.openmrs.EncounterType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; -import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource; @@ -42,13 +39,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .required("description"); - } - + /** * @see DelegatingCrudResource#newDelegate() */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java index 61e70b452..ac69f2c33 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java @@ -12,10 +12,6 @@ import java.util.ArrayList; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Field; import org.openmrs.FieldAnswer; import org.openmrs.api.context.Context; @@ -79,39 +75,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("field", new RefProperty("#/definitions/FieldGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("field", new RefProperty("#/definitions/FieldGet")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("concept", new StringProperty().example("uuid")) - .property("field", new StringProperty().example("uuid")) - .required("field").required("concept"); - if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("field", new RefProperty("#/definitions/FieldCreate")); - } - return model; - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource#getCreatableProperties() */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java index 7eb26f5c2..ac39ccbc9 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Field; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -35,46 +30,7 @@ */ @Resource(name = RestConstants.VERSION_1 + "/field", supportedClass = Field.class, supportedOpenmrsVersions = { "1.8.* - 9.*" }) public class FieldResource1_8 extends MetadataDelegatingCrudResource { - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("tableName", new StringProperty()) - .property("attributeName", new StringProperty()) - .property("defaultValue", new StringProperty()) - .property("selectMultiple", new BooleanProperty()._default(false)); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("fieldType", new RefProperty("#/definitions/FieldtypeGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("fieldType", new RefProperty("#/definitions/FieldtypeGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("fieldType", new RefProperty("#/definitions/FieldtypeCreate")) - .property("selectMultiple", new BooleanProperty()._default(false)) - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("tableName", new StringProperty()) - .property("attributeName", new StringProperty()) - .property("defaultValue", new StringProperty()) - - .required("fieldType").required("selectMultiple"); - } - - @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl(); //FIXME missing props - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java index ba62a0174..0fc710915 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; import org.openmrs.FieldType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -31,21 +28,7 @@ @Resource(name = RestConstants.VERSION_1 + "/fieldtype", supportedClass = FieldType.class, supportedOpenmrsVersions = { "1.8.* - 9.*" }) public class FieldTypeResource1_8 extends MetadataDelegatingCrudResource { - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("isSet", new BooleanProperty()._default(false)); - } - return modelImpl; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java index 4b7ddfece..299ea227b 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java @@ -12,13 +12,6 @@ import java.util.ArrayList; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.FloatProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Form; import org.openmrs.FormField; import org.openmrs.api.context.Context; @@ -41,65 +34,7 @@ @SubResource(parent = FormResource1_8.class, path = "formfield", supportedClass = FormField.class, supportedOpenmrsVersions = { "1.8.* - 9.*" }) public class FormFieldResource1_8 extends DelegatingSubResource { - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("fieldNumber", new IntegerProperty()) - .property("fieldPart", new StringProperty()) - .property("pageNumber", new IntegerProperty()) - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("required", new BooleanProperty()._default(false)) - .property("sortWeight", new FloatProperty()) - .property("retired", new BooleanProperty()); //FIXME - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("parent", new RefProperty("#/definitions/FormFormfieldGetRef")) - .property("form", new RefProperty("#/definitions/FormGetRef")) - .property("field", new RefProperty("#/definitions/FieldGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("parent", new RefProperty("#/definitions/FormFormfieldGet")) - .property("form", new RefProperty("#/definitions/FormGet")) - .property("field", new RefProperty("#/definitions/FieldGet")); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() //FIXME validate if correct - .property("form", new StringProperty().example("uuid")) - .property("field", new StringProperty().example("uuid")) - .property("required", new BooleanProperty()._default(false)) - .property("parent", new StringProperty().example("uuid")) - .property("fieldNumber", new IntegerProperty()) - .property("fieldPart", new StringProperty()) - .property("pageNumber", new IntegerProperty()) - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("sortWeight", new BooleanProperty()._default(false)) - - .required("form").required("field").required("required"); - if (rep instanceof FullRepresentation) { - model - .property("form", new RefProperty("#/definitions/FormCreate")) - .property("field", new RefProperty("#/definitions/FieldCreate")) - .property("parent", new RefProperty("#/definitions/FormFormfieldCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormResource1_8.java index 8f1e9894f..12ef0bcdd 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormResource1_8.java @@ -9,17 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; -import org.openmrs.EncounterType; -import org.openmrs.Field; import org.openmrs.Form; -import org.openmrs.FormField; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -97,58 +87,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("version", new StringProperty()) - .property("build", new IntegerProperty()) - .property("published", new BooleanProperty()._default(false)) - .property("retired", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("encounterType", new RefProperty("#/definitions/EncountertypeGetRef")) - .property("formFields", new ArrayProperty(new RefProperty("#/definitions/FormFormfieldGetRef"))); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("encounterType", new RefProperty("#/definitions/EncountertypeGet")) - .property("formFields", new ArrayProperty(new RefProperty("#/definitions/FormFormfieldGet"))); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("version", new StringProperty()) - .property("encounterType", new StringProperty()) - .property("build", new IntegerProperty()) - .property("published", new BooleanProperty()._default(false)) - .property("formFields", new ArrayProperty(new StringProperty())) - .property("xslt", new StringProperty()) - .property("template", new StringProperty()) - - .required("version"); - if (rep instanceof FullRepresentation) { - model - .property("encounterType", new RefProperty("#/definitions/EncountertypeCreate")) - .property("formFields", new ArrayProperty(new RefProperty("#/definitions/FormFormfieldCreate"))); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7MessageResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7MessageResource1_8.java index 999810ac9..3dc44b98e 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7MessageResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7MessageResource1_8.java @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -94,34 +89,7 @@ public DelegatingResourceDescription getCreatableProperties() { description.addRequiredProperty("hl7"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("messageState", new IntegerProperty()); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("source", new RefProperty("#/definitions/Hl7sourceGet")) - .property("sourceKey", new StringProperty()) - .property("data", new StringProperty()) - .property("messageState", new IntegerProperty()); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("hl7", new StringProperty()) //FIXME TYPE - .required("hl7"); - } - + /** * It needs to be overwritten to allow for hidden properties: source, sourceKey and data. They * are automatically extracted from the hl7 property and populated in diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7SourceResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7SourceResource1_8.java index 78eecfd92..b0d252738 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7SourceResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7SourceResource1_8.java @@ -9,8 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; import org.openmrs.api.context.Context; import org.openmrs.hl7.HL7Source; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -56,19 +54,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - - .required("description"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationResource1_8.java index 6a9bbb860..5be475d30 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationResource1_8.java @@ -13,11 +13,6 @@ import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openmrs.Location; @@ -142,66 +137,7 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("address1", new StringProperty()) - .property("address2", new StringProperty()) - .property("cityVillage", new StringProperty()) - .property("stateProvince", new StringProperty()) - .property("country", new StringProperty()) - .property("postalCode", new StringProperty()) - .property("latitude", new StringProperty()) - .property("longitude", new StringProperty()) - .property("countyDistrict", new StringProperty()) - .property("address3", new StringProperty()) - .property("address4", new StringProperty()) - .property("address5", new StringProperty()) - .property("address6", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("tags", new ArrayProperty(new RefProperty("#/definitions/LocationtagGetRef"))) - .property("parentLocation", new RefProperty("#/definitions/LocationGetRef")) - .property("childLocations", new ArrayProperty(new RefProperty("#/definitions/LocationGetRef"))); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("tags", new ArrayProperty(new RefProperty("#/definitions/LocationtagGet"))) - .property("parentLocation", new RefProperty("#/definitions/LocationGet")) - .property("childLocations", new ArrayProperty(new RefProperty("#/definitions/LocationGet"))); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("address1", new StringProperty()) - .property("address2", new StringProperty()) - .property("cityVillage", new StringProperty()) - .property("stateProvince", new StringProperty()) - .property("country", new StringProperty()) - .property("postalCode", new StringProperty()) - .property("latitude", new StringProperty()) - .property("longitude", new StringProperty()) - .property("countyDistrict", new StringProperty()) - .property("address3", new StringProperty()) - .property("address4", new StringProperty()) - .property("address5", new StringProperty()) - .property("address6", new StringProperty()) - .property("tags", new ArrayProperty(new StringProperty())) - .property("parentLocation", new StringProperty()) - .property("childLocations", new ArrayProperty(new StringProperty())); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see DelegatingCrudResource#newDelegate() */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationTagResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationTagResource1_8.java index 9199ba24c..db373a386 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationTagResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationTagResource1_8.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.LocationTag; import org.openmrs.api.LocationService; import org.openmrs.api.context.Context; @@ -92,14 +88,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("retired", new BooleanProperty()) - .property("retiredReason", new StringProperty()); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleActionResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleActionResource1_8.java index d67ab5ff4..14b1d9b83 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleActionResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleActionResource1_8.java @@ -9,19 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.openmrs.api.APIException; import org.openmrs.module.Module; import org.openmrs.module.ModuleException; import org.openmrs.module.ModuleUtil; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.helper.ModuleAction; import org.openmrs.module.webservices.helper.ModuleFactoryWrapper; import org.openmrs.module.webservices.helper.ModuleAction.Action; @@ -41,7 +34,6 @@ import org.springframework.util.ResourceUtils; import javax.servlet.ServletContext; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; @@ -296,24 +288,7 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe description.addRequiredProperty("action", "action"); return description; } - - @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("modules", new ArrayProperty(new RefProperty("#/definitions/ModuleGetRef"))) - .property("action", new EnumProperty(ModuleAction.Action.class)); - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("modules", new ArrayProperty(new StringProperty().example("moduleId"))) - .property("allModules", new BooleanProperty()) - .property("action", new EnumProperty(ModuleAction.Action.class)) - .property("installUri", new StringProperty()) - .required("action"); - } - + /** * Converter does not handle getters starting with 'is' instead of 'get' */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleResource1_8.java index e4d5ecc25..f7fc69fad 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleResource1_8.java @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.io.FileUtils; import org.openmrs.module.Module; import org.openmrs.module.ModuleException; @@ -106,36 +101,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("started", new BooleanProperty()) //FIXME check type - .property("startupErrorMessage", new StringProperty()); //FIXME add-link: action - } - if (rep instanceof FullRepresentation) { - model - .property("packageName", new StringProperty()) - .property("author", new StringProperty()) - .property("version", new StringProperty()) - .property("requireOpenmrsVersion", new StringProperty()) - .property("awareOfModules", new ArrayProperty(new StringProperty())) //FIXME check type - .property("requiredModules", new ArrayProperty(new StringProperty())); - } else if (rep instanceof RefRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - } - return model; - } - - /** + + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingReadableResource#doGetAll(RequestContext) */ @Override 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 9e4970296..d015a6ca5 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 @@ -57,15 +57,6 @@ import org.openmrs.obs.ComplexData; import org.springframework.web.multipart.MultipartFile; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.DateTimeProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * {@link Resource} for Obs, supporting standard CRUD operations */ @@ -181,57 +172,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model.property("uuid", new StringProperty()).property("display", new StringProperty()) - .property("obsDatetime", new DateProperty()).property("accessionNumber", new StringProperty()) - .property("comment", new StringProperty()).property("voided", new BooleanProperty()) - .property("value", new StringProperty()).property("valueModifier", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - model.property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("person", new RefProperty("#/definitions/PersonGetRef")) - .property("obsGroup", new RefProperty("#/definitions/ObsGetRef")) - .property("groupMembers", new ArrayProperty(new RefProperty("#/definitions/ObsGetRef"))) - .property("valueCodedName", new RefProperty("#/definitions/ConceptNameGetRef")) - .property("location", new RefProperty("#/definitions/LocationGetRef")) - .property("order", new RefProperty("#/definitions/OrderGetRef")) - .property("encounter", new RefProperty("#/definitions/EncounterGetRef")); - } else if (rep instanceof FullRepresentation) { - model.property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("person", new RefProperty("#/definitions/PersonGet")) - .property("obsGroup", new RefProperty("#/definitions/ObsGet")) - .property("groupMembers", new ArrayProperty(new RefProperty("#/definitions/ObsGet"))) - .property("valueCodedName", new RefProperty("#/definitions/ConceptNameGet")) - .property("location", new RefProperty("#/definitions/LocationGet")) - .property("order", new RefProperty("#/definitions/OrderGet")) - .property("encounter", new RefProperty("#/definitions/EncounterGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl().property("person", new StringProperty().example("uuid")) - .property("obsDatetime", new DateTimeProperty()).property("concept", new StringProperty().example("uuid")) - .property("location", new StringProperty()).property("order", new StringProperty()) - .property("encounter", new StringProperty()).property("accessionNumber", new StringProperty()) - .property("groupMembers", new ArrayProperty(new StringProperty())) - .property("valueCodedName", new StringProperty()).property("comment", new StringProperty()) - .property("voided", new BooleanProperty()).property("value", new StringProperty()) - .property("valueModifier", new StringProperty()) - - .required("person").required("obsDatetime").required("concept"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/OrderResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/OrderResource1_8.java index e087cb560..d2ee25c18 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/OrderResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/OrderResource1_8.java @@ -11,12 +11,6 @@ import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Order; import org.openmrs.Patient; import org.openmrs.api.OrderService.ORDER_STATUS; @@ -208,81 +202,7 @@ public DelegatingResourceDescription getCreatableProperties() { d.addProperty("accessionNumber"); return d; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("instructions", new StringProperty()) - .property("startDate", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("accessionNumber", new StringProperty()) - .property("discontinuedDate", new DateProperty()) - .property("discontinuedReasonNonCoded", new StringProperty()) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("orderType", new RefProperty("#/definitions/OrdertypeGetRef")) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("encounter", new RefProperty("#/definitions/EncounterGetRef")) - .property("orderer", new RefProperty("#/definitions/UserGetRef")) - .property("discontinuedBy", new RefProperty("#/definitions/UserGetRef")) - .property("discontinuedReason", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("orderType", new RefProperty("#/definitions/OrdertypeGet")) - .property("patient", new RefProperty("#/definitions/PatientGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("encounter", new RefProperty("#/definitions/EncounterGet")) - .property("orderer", new RefProperty("#/definitions/UserGet")) - .property("discontinuedBy", new RefProperty("#/definitions/UserGet")) - .property("discontinuedReason", new RefProperty("#/definitions/ConceptGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("orderType", new StringProperty().example("uuid")) - .property("patient", new StringProperty().example("uuid")) - .property("concept", new StringProperty().example("uuid")) - .property("instructions", new StringProperty()) - .property("startDate", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("encounter", new StringProperty().example("uuid")) - .property("orderer", new StringProperty().example("uuid")) - .property("discontinuedBy", new StringProperty().example("uuid")) - .property("discontinuedDate", new DateProperty()) - .property("discontinuedReason", new RefProperty("#/definitions/ConceptCreate")) - .property("discontinuedReasonNonCoded", new StringProperty()) - .property("accessionNumber", new StringProperty()) - - .required("orderType").required("patient").required("concept"); - if (rep instanceof FullRepresentation) { - model - .property("orderType", new RefProperty("#/definitions/OrdertypeCreate")) - .property("patient", new RefProperty("#/definitions/PatientCreate")) - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("encounter", new RefProperty("#/definitions/EncounterCreate")) - .property("orderer", new RefProperty("#/definitions/UserCreate")) - .property("discontinuedBy", new RefProperty("#/definitions/UserCreate")) - .property("discontinuedReason", new RefProperty("#/definitions/ConceptCreate")); - } - //FIXME missing prop: type - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props - } - + /** * Gets orders by given patient (paged according to context if necessary) only if a patient * parameter exists in the request set on the {@link RequestContext} otherwise diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java index 34f24c837..3d840f2b9 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java @@ -32,12 +32,6 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * Sub-resource for patient identifiers */ @@ -134,52 +128,7 @@ public void setLocation(PatientIdentifier instance, Location location) { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("identifier", new StringProperty()) - .property("preferred", new BooleanProperty()._default(false)) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("identifierType", new RefProperty("#/definitions/PatientidentifiertypeGetRef")) - .property("location", new RefProperty("#/definitions/LocationGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("identifierType", new RefProperty("#/definitions/PatientidentifiertypeGet")) - .property("location", new RefProperty("#/definitions/LocationGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("identifier", new StringProperty()) - .property("identifierType", new StringProperty().example("uuid")) - .property("location", new StringProperty().example("uuid")) - .property("preferred", new BooleanProperty()._default(false)) - - .required("identifier").required("identifierType"); - if (rep instanceof FullRepresentation) { - model - .property("identifierType", new RefProperty("#/definitions/PatientidentifiertypeCreate")) - .property("location", new RefProperty("#/definitions/LocationCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + private PatientService service() { return Context.getPatientService(); } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierTypeResource1_8.java index 209f47396..30d040861 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierTypeResource1_8.java @@ -9,14 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.PatientIdentifierType; import org.openmrs.api.PatientService; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -114,40 +109,7 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("format", new StringProperty()) - .property("formatDescription", new StringProperty()) - .property("required", new BooleanProperty()) - .property("checkDigit", new BooleanProperty()) - .property("validator", new StringProperty()) - .property("locationBehavior", new EnumProperty(PatientIdentifierType.LocationBehavior.class)) - .property("uniquenessBehavior", new StringProperty()); //FIXME check type - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("format", new StringProperty()) - .property("formatDescription", new StringProperty()) - .property("required", new BooleanProperty()) - .property("checkDigit", new BooleanProperty()) - .property("validator", new StringProperty()) - .property("locationBehavior", new EnumProperty(PatientIdentifierType.LocationBehavior.class)) - .property("uniquenessBehavior", new StringProperty()); //FIXME check type - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java index 19178907f..c0777bb78 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java @@ -9,12 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Patient; import org.openmrs.PatientIdentifier; import org.openmrs.Person; @@ -142,51 +136,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - //FIXME check uuid, display in ref rep - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("identifiers", new ArrayProperty(new RefProperty("#/definitions/PatientIdentifierGetRef"))) - .property("preferred", new BooleanProperty()._default(false)) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("person", new StringProperty().example("uuid")) - .property("identifiers", new ArrayProperty(new RefProperty("#/definitions/PatientIdentifierCreate"))) - - .required("person").required("identifiers"); - if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("person", new RefProperty("#/definitions/PersonGet")) - - .required("person"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -367,4 +317,4 @@ public Patient getPatientForUpdate(String uuid, Map propertiesTo return patient; } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientStateResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientStateResource1_8.java index b865ce818..9b45999bd 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientStateResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientStateResource1_8.java @@ -9,13 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.PatientProgram; import org.openmrs.PatientState; import org.openmrs.ProgramWorkflow; @@ -172,45 +165,5 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe updatableProperties.addProperty("voided"); return updatableProperties; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof RefRepresentation || rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("state", new RefProperty("#/definitions/WorkflowStateGet")); - } else if (rep instanceof RefRepresentation) { - model - .property("state", new RefProperty("#/definitions/WorkflowStateGetRef")) - .property("patientProgram", new ObjectProperty()); //FIXME type - } else if (rep instanceof FullRepresentation) { - model - .property("state", new RefProperty("#/definitions/WorkflowStateGetRef")) - .property("patientProgram", new ObjectProperty()); //FIXME type - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("state", new RefProperty("#/definitions/WorkflowStateCreate")) - - .required("state"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("voided", new BooleanProperty()); - } + } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAddressResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAddressResource1_8.java index b47bc1f90..455d714dc 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAddressResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAddressResource1_8.java @@ -9,11 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Person; import org.openmrs.PersonAddress; import org.openmrs.api.context.Context; @@ -139,62 +139,7 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("preferred", new BooleanProperty()._default(false)) - .property("address1", new StringProperty()) - .property("address2", new StringProperty()) - .property("cityVillage", new StringProperty()) - .property("stateProvince", new StringProperty()) - .property("country", new StringProperty()) - .property("postalCode", new StringProperty()) - .property("countyDistrict", new StringProperty()) - .property("address3", new StringProperty()) - .property("address4", new StringProperty()) - .property("address5", new StringProperty()) - .property("address6", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("latitude", new StringProperty()) - .property("longitude", new StringProperty()) - .property("voided", new BooleanProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("preferred", new BooleanProperty()._default(false)) - .property("address1", new StringProperty()) - .property("address2", new StringProperty()) - .property("cityVillage", new StringProperty()) - .property("stateProvince", new StringProperty()) - .property("country", new StringProperty()) - .property("postalCode", new StringProperty()) - .property("countyDistrict", new StringProperty()) - .property("address3", new StringProperty()) - .property("address4", new StringProperty()) - .property("address5", new StringProperty()) - .property("address6", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("latitude", new StringProperty()) - .property("longitude", new StringProperty()); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeResource1_8.java index 45a7ed6ed..8057a2d45 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeResource1_8.java @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Attributable; import org.openmrs.Location; import org.openmrs.Person; @@ -151,49 +146,7 @@ public void setValue(PersonAttribute personAttribute, String value) { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("value", new StringProperty()) - .property("attributeType", new RefProperty("#/definitions/PersonattributetypeGetRef")) - .property("voided", new BooleanProperty()); - } else if (rep instanceof FullRepresentation) { - model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("value", new StringProperty()) - .property("attributeType", new RefProperty("#/definitions/PersonattributetypeGetRef")) - .property("voided", new BooleanProperty()) - .property("hydratedObject", new StringProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("attributeType", new StringProperty().example("uuid")) - .property("value", new StringProperty()) - .property("hydratedObject", new StringProperty().example("uuid")) - - .required("attributeType"); - if (rep instanceof FullRepresentation) { - model - .property("attributeType", new RefProperty("#/definitions/PersonattributetypeCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeTypeResource1_8.java index b630f9aa0..b744510d8 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeTypeResource1_8.java @@ -9,13 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Concept; import org.openmrs.PersonAttributeType; import org.openmrs.api.PersonService; @@ -112,45 +105,7 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("format", new StringProperty()) - .property("foreignKey", new IntegerProperty()) - .property("sortWeight", new DoubleProperty()) - .property("searchable", new BooleanProperty()._default(false)); - } - if (rep instanceof DefaultRepresentation) { - model - .property("editPrivilege", new RefProperty("#/definitions/PrivilegeGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("editPrivilege", new RefProperty("#/definitions/PrivilegeGet")) - .property("concept", new StringProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("format", new StringProperty().example("java.lang.String")) - .property("foreignKey", new IntegerProperty()) - .property("sortWeight", new DoubleProperty()) - .property("searchable", new BooleanProperty()._default(false)) - .property("editPrivilege", new RefProperty("#/definitions/PrivilegeCreate")) - - .required("description"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonNameResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonNameResource1_8.java index 171c10cd7..f9dc12f83 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonNameResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonNameResource1_8.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Person; import org.openmrs.PersonName; import org.openmrs.api.context.Context; @@ -104,52 +100,7 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("givenName", new StringProperty()) - .property("middleName", new StringProperty()) - .property("familyName", new StringProperty()) - .property("familyName2", new StringProperty()) - .property("voided", new BooleanProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("preferred", new BooleanProperty()) - .property("prefix", new StringProperty()) - .property("familyNamePrefix", new StringProperty()) - .property("familyNameSuffix", new StringProperty()) - .property("degree", new StringProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("givenName", new StringProperty()) - .property("middleName", new StringProperty()) - .property("familyName", new StringProperty()) - .property("familyName2", new StringProperty()) - .property("preferred", new BooleanProperty()._default(false)) - .property("prefix", new StringProperty()) - .property("familyNamePrefix", new StringProperty()) - .property("familyNameSuffix", new StringProperty()) - .property("degree", new StringProperty()) - - .required("givenName").required("familyName"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonResource1_8.java index 15de940cc..c01c0d79d 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonResource1_8.java @@ -14,15 +14,6 @@ import java.util.List; import java.util.Set; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.DateTimeProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Person; import org.openmrs.PersonAddress; import org.openmrs.PersonAttribute; @@ -141,74 +132,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.addProperty("deathDate"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("gender", new StringProperty()._enum("M")._enum("F")) - .property("age", new IntegerProperty()) - .property("birthdate", new DateTimeProperty()) - .property("birthdateEstimated", new BooleanProperty()) - .property("dead", new BooleanProperty()) - .property("deathDate", new DateProperty()) - .property("causeOfDeath", new StringProperty()) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/PersonAttributeGetRef"))) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("preferredName", new RefProperty("#/definitions/PersonNameGetRef")) - .property("preferredAddress", new RefProperty("#/definitions/PersonAddressGetRef")); - - } else if (rep instanceof FullRepresentation) { - model - .property("preferredName", new RefProperty("#/definitions/PersonNameGet")) - .property("preferredAddress", new RefProperty("#/definitions/PersonAddressGet")) - .property("names", new ArrayProperty(new RefProperty("#/definitions/PersonNameGet"))) - .property("addresses", new ArrayProperty(new RefProperty("#/definitions/PersonAddressGet"))); - } - return model; - } - - @Override - public Model getCREATEModel(Representation representation) { - ModelImpl model = new ModelImpl() - .property("names", new ArrayProperty(new RefProperty("#/definitions/PersonNameCreate"))) - .property("gender", new StringProperty()._enum("M")._enum("F")) - .property("age", new IntegerProperty()) - .property("birthdate", new DateProperty()) - .property("birthdateEstimated", new BooleanProperty()._default(false)) - .property("dead", new BooleanProperty()._default(false)) - .property("deathDate", new DateProperty()) - .property("causeOfDeath", new StringProperty()) - .property("addresses", new ArrayProperty(new RefProperty("#/definitions/PersonAddressCreate"))) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/PersonAttributeCreate"))); - - model.setRequired(Arrays.asList("names", "gender")); - return model; - } - - @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("dead", new BooleanProperty()) - .property("causeOfDeath", new StringProperty()) - .property("deathDate", new DateProperty()) - .property("age", new IntegerProperty()) - .property("gender", new StringProperty()._enum("M")._enum("F")) - .property("birthdate", new DateProperty()) - .property("birthdateEstimated", new BooleanProperty()._default(false)) - .property("preferredName", new StringProperty().example("uuid")) - .property("preferredAddress", new StringProperty().example("uuid")) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/PersonAttributeCreate"))) - - .required("dead").required("causeOfDeath"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getPropertiesToExposeAsSubResources() */ @@ -564,4 +488,4 @@ public SimpleObject getAuditInfo(Person person) throws Exception { ret.put("dateCreated", ConversionUtil.convertToRepresentation(person.getPersonDateCreated(), Representation.DEFAULT)); return ret; } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PrivilegeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PrivilegeResource1_8.java index 5ca45144b..26b6059ba 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PrivilegeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PrivilegeResource1_8.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.StringUtils; import org.openmrs.Privilege; import org.openmrs.api.context.Context; @@ -92,14 +89,8 @@ public DelegatingResourceDescription getUpdatableProperties() { return description; } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("description", new StringProperty()); - } - - /** + + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @Override @@ -111,7 +102,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - + /** * @param delegate * @return diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProblemResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProblemResource1_8.java index 19de11f5d..8d1883b1f 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProblemResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProblemResource1_8.java @@ -9,15 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.RefProperty; import org.openmrs.Patient; import org.openmrs.activelist.Problem; -import org.openmrs.activelist.ProblemModifier; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; @@ -37,28 +31,8 @@ */ @Resource(name = RestConstants.VERSION_1 + "/problem", supportedClass = Problem.class, supportedOpenmrsVersions = { "1.8.*" }) public class ProblemResource1_8 extends BaseActiveListItemResource1_8 { - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("modifier", new EnumProperty(ProblemModifier.class)) - .property("sortWeight", new DoubleProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("problem", new RefProperty("#/definitions/ConceptGetRef")); - - } else if (rep instanceof FullRepresentation) { - model - .property("problem", new RefProperty("#/definitions/ConceptGet")); - - } - return model; - } - - /** + + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ @Override @@ -91,17 +65,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("problem", new RefProperty("#/definitions/ConceptCreate")) - .property("modifier", new EnumProperty(ProblemModifier.class)) - .property("sortWeight", new DoubleProperty()) - - .required("problem"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramEnrollmentResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramEnrollmentResource1_8.java index 67dcb2dc7..839f16674 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramEnrollmentResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramEnrollmentResource1_8.java @@ -9,12 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Patient; import org.openmrs.PatientProgram; import org.openmrs.api.PatientService; @@ -125,60 +119,7 @@ public DelegatingResourceDescription getCreatableProperties() { d.addProperty("voided"); return d; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("dateEnrolled", new DateProperty()) - .property("dateCompleted", new DateProperty()) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("program", new RefProperty("#/definitions/ProgramGetRef")) - .property("location", new RefProperty("#/definitions/LocationGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientGet")) - .property("program", new RefProperty("#/definitions/ProgramGet")) - .property("location", new RefProperty("#/definitions/LocationGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("patient", new StringProperty().example("uuid")) - .property("program", new StringProperty().example("uuid")) - .property("dateEnrolled", new DateProperty()) - .property("dateCompleted", new DateProperty()) - .property("location", new StringProperty().example("uuid")) - .property("voided", new BooleanProperty()) - - .required("patient").required("program").required("dateEnrolled"); - if (rep instanceof FullRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientCreate")) - .property("program", new RefProperty("#/definitions/ProgramCreate")) - .property("location", new RefProperty("#/definitions/LocationCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("dateEnrolled", new DateProperty()) - .property("dateCompleted", new DateProperty()); //FIXME missing props - - } - + /** * Gets all the programs (excluding voided) of the given patient * diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramResource1_8.java index 144760495..27831b1b8 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramResource1_8.java @@ -9,12 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Program; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -116,44 +110,7 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("retired"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("allWorkflows", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))); - } else if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("allWorkflows", new ArrayProperty(new RefProperty("#/definitions/WorkflowGet"))); - } else if (rep instanceof RefRepresentation) { - model - .property("allWorkflows", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("concept", new StringProperty().example("uuid")) - .property("retired", new BooleanProperty()) - - .required("concept").required("description"); - if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props - } - + @Override protected PageableResult doSearch(RequestContext context) { String query = context.getParameter("q"); diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowResource1_8.java index 9bc4b8834..32c91b4fa 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowResource1_8.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.RefProperty; import org.openmrs.Program; import org.openmrs.ProgramWorkflow; import org.openmrs.ProgramWorkflowState; @@ -70,28 +66,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("states", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGetRef"))); - } else if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("states", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGet"))); - } else if (rep instanceof RefRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("states", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGet"))); - //FIXME should remove 'description'? - } - return model; - } - - @PropertyGetter("states") + + @PropertyGetter("states") public Set getUnretiredStates(ProgramWorkflow instance) { return instance.getStates(false); } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowStateResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowStateResource1_8.java index ce4ec8840..68bcc1e20 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowStateResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowStateResource1_8.java @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Program; import org.openmrs.ProgramWorkflow; import org.openmrs.ProgramWorkflowState; @@ -121,35 +116,6 @@ 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()) - .property("description", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("description", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGet")); - } else if (rep instanceof RefRepresentation) { - model - .property("uuid", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props - } @Override public DelegatingResourceDescription getCreatableProperties() { diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationShipTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationShipTypeResource1_8.java index 8180de756..4e3929644 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationShipTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationShipTypeResource1_8.java @@ -10,10 +10,6 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import org.apache.commons.lang.StringUtils; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.RelationshipType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -130,37 +126,7 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("description"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("aIsToB", new StringProperty()) - .property("bIsToA", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("weight", new IntegerProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("aIsToB", new StringProperty()) - .property("bIsToA", new StringProperty()) - .property("weight", new IntegerProperty()) - - .required("aIsToB").required("bIsToA"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationshipResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationshipResource1_8.java index a004176ba..5e694e2ca 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationshipResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationshipResource1_8.java @@ -9,14 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.Person; import org.openmrs.Relationship; +import org.openmrs.RelationshipType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -31,6 +29,8 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; + /** * {@link org.openmrs.module.webservices.rest.web.annotation.Resource} for Provider, supporting * standard CRUD operations @@ -159,53 +159,5 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.addProperty("voided"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("personA", new RefProperty("#/definitions/PersonGetRef")) - .property("relationshipType", new RefProperty("#/definitions/RelationshiptypeGetRef")) - .property("personB", new RefProperty("#/definitions/PersonGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("personA", new RefProperty("#/definitions/PersonGet")) - .property("relationshipType", new RefProperty("#/definitions/RelationshiptypeGet")) - .property("personB", new RefProperty("#/definitions/PersonGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("personA", new StringProperty().example("uuid")) - .property("relationshipType", new StringProperty().example("uuid")) - .property("personB", new StringProperty().example("uuid")) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - - .required("personA").required("relationshipType").required("personB"); - if (rep instanceof FullRepresentation) { - model - .property("personA", new RefProperty("#/definitions/PersonCreate")) - - .property("relationshipType", new RefProperty("#/definitions/RelationshiptypeCreate")) - .property("personB", new RefProperty("#/definitions/PersonCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("voided", new BooleanProperty()); //FIXME missing properties - } + } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RoleResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RoleResource1_8.java index bacd9c032..034aa780e 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RoleResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RoleResource1_8.java @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.StringUtils; import org.openmrs.Privilege; import org.openmrs.Role; @@ -124,39 +119,7 @@ public DelegatingResourceDescription getUpdatableProperties() { return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeGetRef"))) - .property("inheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleGetRef"))); - } - if (rep instanceof FullRepresentation) { - model - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeGet"))) - .property("inheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleGet"))) - .property("allInheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleGet"))); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeCreate"))) - .property("inheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleCreate"))); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("description", new StringProperty()) - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeCreate"))) - .property("inheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleCreate"))); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ServerLogResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ServerLogResource1_8.java index 0cf9916db..20bc37330 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ServerLogResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ServerLogResource1_8.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.MapProperty; import org.openmrs.module.webservices.helper.ServerLogActionWrapper; import org.openmrs.module.webservices.helper.ServerLogActionWrapper1_8; import org.openmrs.module.webservices.rest.SimpleObject; @@ -43,14 +40,8 @@ public SimpleObject getAll(RequestContext context) throws ResponseException { rest.put("serverLog", serverLogActionWrapper.getServerLogs()); return rest; } - - @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("serverLog", new MapProperty()); - } - - @Override + + @Override public ServerLogActionWrapper getByUniqueId(String uniqueId) { throw new UnsupportedOperationException("Serverlog doesn't support to this action"); } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java index c1f750a4b..c919e7bcd 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java @@ -9,13 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.api.APIException; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.helper.TaskAction; import org.openmrs.module.webservices.helper.TaskServiceWrapper; import org.openmrs.module.webservices.rest.SimpleObject; @@ -196,17 +190,7 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe description.addRequiredProperty("action", "action"); return description; } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl(); - model.property("tasks", new ArrayProperty(new StringProperty())); - model.property("allTasks", new BooleanProperty()); - model.property("action", new EnumProperty(TaskAction.Action.class)); - model.required("action"); - return model; - } - + /** * Converter does not handle getters starting with 'is' instead of 'get' */ @@ -214,5 +198,4 @@ public Model getCREATEModel(Representation rep) { public Boolean isAllModules(TaskAction action) { return action.isAllTasks(); } - } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskDefinitionResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskDefinitionResource1_8.java index 596ff1b1b..f15872f89 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskDefinitionResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskDefinitionResource1_8.java @@ -102,7 +102,7 @@ public DelegatingResourceDescription getCreatableProperties() { description.addRequiredProperty("properties"); return description; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(java.lang.Object) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java index 9cf656933..e18847a77 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java @@ -40,14 +40,6 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.module.webservices.rest.web.v1_0.wrapper.openmrs1_8.UserAndPassword1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.MapProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * {@link Resource} for User, supporting standard CRUD operations */ @@ -134,49 +126,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getGETModel(Representation rep) { - //FIXME check valid supportedClass - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("username", new StringProperty()) - .property("systemId", new StringProperty()) - .property("userProperties", new MapProperty()); //FIXME type - } - if (rep instanceof DefaultRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGetRef")) - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeGetRef"))) - .property("roles", new ArrayProperty(new RefProperty("#/definitions/RoleGetRef"))); - } else if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGet")) - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeGet"))) - .property("roles", new ArrayProperty(new RefProperty("#/definitions/RoleGet"))) - .property("allRoles", new ArrayProperty(new RefProperty("#/definitions/RoleGet"))) - .property("proficientLocales", new ArrayProperty(new ObjectProperty())) - .property("secretQuestion", new StringProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("username", new StringProperty()) - .property("password", new StringProperty()) - .property("person", new RefProperty("#/definitions/PersonCreate")) - .property("systemId", new StringProperty()) - .property("userProperties", new MapProperty()) //FIXME type - .property("roles", new ArrayProperty(new RefProperty("#/definitions/RoleCreate"))) - .property("proficientLocales", new ArrayProperty(new ObjectProperty())) - .property("secretQuestion", new StringProperty()) - - .required("username").required("password").required("person"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate() */ @@ -425,4 +375,4 @@ protected NeedsPaging doGetAll(RequestContext context) { } return new NeedsPaging(users, context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/HivDrugOrderSubclassHandler.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/HivDrugOrderSubclassHandler.java index 0a555964c..ced0d5273 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/HivDrugOrderSubclassHandler.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/HivDrugOrderSubclassHandler.java @@ -9,11 +9,10 @@ */ package org.openmrs.module.webservices.rest.web; -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 io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Order; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; @@ -29,6 +28,8 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.util.OpenmrsConstants; +import java.util.Arrays; + /** * This is a contrived example for testing purposes */ @@ -86,41 +87,7 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return d; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = new ModelImpl(); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("startDate", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("standardRegimenCode", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("patient", new StringProperty().example("uuid")) - .property("concept", new StringProperty().example("uuid")) - .property("startDate", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("standardRegimenCode", new StringProperty()) - .property("instructions", new StringProperty()) - - .required("patient").required("concept"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getAllByType(org.openmrs.module.webservices.rest.web.RequestContext) */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeCrudResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeCrudResource1_9.java index d9f0b6ab1..c34c0f3c1 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeCrudResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeCrudResource1_9.java @@ -12,10 +12,6 @@ import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.StringUtils; import org.openmrs.attribute.Attribute; import org.openmrs.customdatatype.CustomDatatype; @@ -107,30 +103,7 @@ public DelegatingResourceDescription getCreatableProperties() { description.addRequiredProperty("value"); return description; } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("attributeType", new StringProperty().example("uuid")) - .property("value", new StringProperty()) - - .required("attributeType").required("value"); - } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("attributeType", new StringProperty()) //FIXME type - .property("value", new StringProperty()) //FIXME type - .property("voided", new BooleanProperty()); - } - return model; - } - + /** * Gets the display string for an attribute. * diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeTypeCrudResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeTypeCrudResource1_9.java index 0fd108aba..fe2de5b37 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeTypeCrudResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeTypeCrudResource1_9.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.attribute.AttributeType; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; @@ -28,39 +24,7 @@ * @param */ public abstract class BaseAttributeTypeCrudResource1_9> extends MetadataDelegatingCrudResource { - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("datatypeClassname", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("datatypeConfig", new StringProperty()) - .property("handlerConfig", new StringProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("datatypeClassname", new StringProperty()) - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("datatypeConfig", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()) - .property("handlerConfig", new StringProperty()) - - .required("datatypeClassname"); - - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java index 420153e67..fd58497c8 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; import org.apache.commons.lang.StringUtils; import org.openmrs.ConceptMap; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -55,34 +52,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermGetRef")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermGet")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGet")); - } - model.getProperties().remove("source"); //FIXME check - model.getProperties().remove("sourceCode"); - model.getProperties().remove("comment"); - return model; - } - - @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermCreate")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeCreate")) - - .required("conceptReferenceTerm").required("conceptMapType"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapTypeResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapTypeResource1_9.java index 5a200a342..fd2490d32 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapTypeResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapTypeResource1_9.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; import org.openmrs.ConceptMapType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -81,23 +78,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("isHidden", new BooleanProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("isHidden", new BooleanProperty()); - } - + /** * @see DelegatingCrudResource#newDelegate() */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermMapResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermMapResource1_9.java index 91f23b973..e976407ac 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermMapResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermMapResource1_9.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; import org.openmrs.ConceptReferenceTerm; import org.openmrs.ConceptReferenceTermMap; import org.openmrs.api.context.Context; @@ -86,39 +83,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("termA", new RefProperty("#/definitions/ConceptreferencetermGetRef")) - .property("termB", new RefProperty("#/definitions/ConceptreferencetermGetRef")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("termA", new RefProperty("#/definitions/ConceptreferencetermGet")) - .property("termB", new RefProperty("#/definitions/ConceptreferencetermGet")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("termA", new RefProperty("#/definitions/ConceptreferencetermCreate")) - .property("termB", new RefProperty("#/definitions/ConceptreferencetermCreate")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeCreate")) - - .required("termA").required("termB").required("conceptMapType"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props - } - + /** * Gets the display string for a concept map. * 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 c188c85a0..148f7932e 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 @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -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; @@ -92,40 +87,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - 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("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 RefProperty("#/definitions/ConceptsourceCreate")) - .property("version", new StringProperty()) - - .required("code").required("conceptSource"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource#getDisplayString(org.openmrs.OpenmrsMetadata) */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSearchResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSearchResource1_9.java index d824a86a3..5919bcd62 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSearchResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSearchResource1_9.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.ConceptClass; import org.openmrs.ConceptName; import org.openmrs.ConceptSearchResult; @@ -71,29 +67,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("display", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("conceptName", new RefProperty("#/definitions/ConceptNameGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("conceptName", new RefProperty("#/definitions/ConceptNameGetRef")) - .property("word", new StringProperty()) - .property("transientWeight", new StringProperty()); - } - return model; - } - - /** + + /** * @see */ @PropertyGetter("display") diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptStopwordResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptStopwordResource1_9.java index b44987aac..51cef6865 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptStopwordResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptStopwordResource1_9.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.StringUtils; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -83,30 +80,7 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("locale"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("value", new StringProperty()) - .property("locale", new StringProperty().example("en")); //FIXME type - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("value", new StringProperty()) - .property("locale", new StringProperty().example("en")) - - .required("value"); - } - + /** * @see DelegatingCrudResource#getByUniqueId(java.lang.String) */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeHandlerResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeHandlerResource1_9.java index 4675653e9..8faf021fe 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeHandlerResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeHandlerResource1_9.java @@ -9,14 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.SubResource; -import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; -import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.api.PageableResult; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; @@ -39,20 +34,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("handlerClassname", new StringProperty()) - .property("display", new StringProperty()); //FIXME delegate property name - } - return model; - } - - @Override + + @Override public CustomDatatypeHandlerRepresentation newDelegate() { return new CustomDatatypeHandlerRepresentation(); } diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeResource1_9.java index 7762a01b4..75859aff3 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeResource1_9.java @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.api.APIAuthenticationException; import org.openmrs.api.context.Context; import org.openmrs.customdatatype.CustomDatatype; @@ -102,27 +97,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("datatypeClassname", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("handlers", new ArrayProperty(new RefProperty("#/definitions/CustomdatatypeHandlersGetRef"))); - } else if (rep instanceof FullRepresentation) { - model - .property("handlers", new ArrayProperty(new RefProperty("#/definitions/CustomdatatypeHandlersGet"))); - } - return model; - } - - @Override + + @Override protected PageableResult doGetAll(RequestContext context) throws ResponseException { List datatypes = getAllCustomDatatypes(); diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterProviderResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterProviderResource1_9.java index c52c5ddfe..6caed8759 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterProviderResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterProviderResource1_9.java @@ -9,11 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Encounter; import org.openmrs.EncounterProvider; import org.openmrs.EncounterRole; @@ -89,48 +84,7 @@ public DelegatingResourceDescription getUpdatableProperties() { description.addProperty("voidReason"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("provider", new RefProperty("#/definitions/ProviderGetRef")) - .property("encounterRole", new RefProperty("#/definitions/EncounterroleGetRef")) - .property("voided", new BooleanProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("provider", new RefProperty("#/definitions/ProviderGet")) - .property("encounterRole", new RefProperty("#/definitions/EncounterroleGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("provider", new StringProperty().example("uuid")) - .property("encounterRole", new StringProperty().example("uuid")) - .property("encounter", new StringProperty()); //FIXME remove if not needed - if (rep instanceof FullRepresentation) { - model - .property("provider", new RefProperty("#/definitions/ProviderCreate")) - .property("encounter", new RefProperty("#/definitions/EncounterCreate")) - .property("encounterRole", new RefProperty("#/definitions/EncounterroleCreate")); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("encounterRole", new StringProperty()) - .property("voided", new BooleanProperty()) - .property("voidReason", new StringProperty()); - } - + @Override public Encounter getParent(EncounterProvider instance) { return instance.getEncounter(); diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java index 4d8ad24ae..35d956e67 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java @@ -9,13 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; import org.openmrs.EncounterRole; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; -import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource; @@ -41,13 +39,8 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - - /** + + /** * @see DelegatingCrudResource#newDelegate() */ @Override diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResourceResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResourceResource1_9.java index 83f6978eb..c579a04f4 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResourceResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResourceResource1_9.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.StringUtils; import org.openmrs.Form; import org.openmrs.FormResource; @@ -140,44 +136,7 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("name", new StringProperty()) - .property("valueReference", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - modelImpl - .property("dataType", new StringProperty()) - .property("handler", new StringProperty()) - .property("handlerConfig", new StringProperty()); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("form", new StringProperty()) - .property("name", new StringProperty()) - .property("dataType", new StringProperty()) - .property("handler", new StringProperty()) - .property("handlerConfig", new StringProperty()) - .property("value", new StringProperty()) - .property("valueReference", new StringProperty()); - if (rep instanceof FullRepresentation) { - model - .property("form", new RefProperty("#/definitions/FormCreate")); - } - return model; - } - + @Override protected void delete(FormResource delegate, String reason, RequestContext context) throws ResponseException { purge(delegate, context); diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ProviderResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ProviderResource1_9.java index 58a1bdcc8..9cf9e66fb 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ProviderResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ProviderResource1_9.java @@ -9,12 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Provider; import org.openmrs.ProviderAttribute; import org.openmrs.api.context.Context; @@ -112,46 +106,7 @@ public static void setAttributes(Provider provider, Set attri public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGetRef")) - .property("identifier", new StringProperty()) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/ProviderAttributeGetRef"))) - .property("preferredHandlerClassname", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGet")) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/ProviderAttributeGet"))); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("person", new StringProperty().example("uuid")) - .property("identifier", new StringProperty()) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/ProviderAttributeCreate"))) - .property("retired", new BooleanProperty()) - - .required("person").required("identifier"); - if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonCreate")); - } - return model; - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate() */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java index 895cc3699..d0a7a9402 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java @@ -34,10 +34,6 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; - /** * {@link Resource} for {@link GlobalProperty}, supporting standard CRUD operations */ @@ -110,49 +106,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.removeProperty("property"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("property", new StringProperty()) - .property("value", new StringProperty()) - .property("description", new StringProperty()) - .property("display", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("datatypeClassname", new StringProperty()) - .property("datatypeConfig", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()) - .property("handlerConfig", new StringProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("property", new StringProperty()) - .property("description", new StringProperty()) - .property("datatypeClassname", new StringProperty()) - .property("datatypeConfig", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()) - .property("handlerConfig", new StringProperty()) - .property("value", new StringProperty()) - - .required("property"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - Model model = getCREATEModel(rep); - model.getProperties().remove("property"); - return model; - } - + /** * @see DelegatingCrudResource#newDelegate() */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/VisitResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/VisitResource1_9.java index de53a35c2..743bdf9ac 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/VisitResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/VisitResource1_9.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Set; import java.util.Iterator; + import org.openmrs.Location; import org.openmrs.Patient; import org.openmrs.Encounter; @@ -45,14 +46,6 @@ import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.LocationResource1_8; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * {@link Resource} for {@link Visit}, supporting standard CRUD operations */ @@ -165,63 +158,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.removeProperty("patient"); return description; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl.property("uuid", new StringProperty()).property("display", new StringProperty()) - .property("startDatetime", new DateProperty()).property("stopDatetime", new DateProperty()) - .property("attributes", new ArrayProperty(new StringProperty())) //FIXME type - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl.property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("visitType", new RefProperty("#/definitions/VisittypeGetRef")) - .property("indication", new RefProperty("#/definitions/ConceptGetRef")) - .property("location", new RefProperty("#/definitions/LocationGetRef")) - .property("encounters", new ArrayProperty(new RefProperty("#/definitions/EncounterGetRef"))); - } else if (rep instanceof FullRepresentation) { - modelImpl.property("patient", new RefProperty("#/definitions/PatientGet")) - .property("visitType", new RefProperty("#/definitions/VisittypeGet")) - .property("indication", new RefProperty("#/definitions/ConceptGet")) - .property("location", new RefProperty("#/definitions/LocationGet")) - .property("encounters", new ArrayProperty(new RefProperty("#/definitions/EncounterGet"))); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl().property("patient", new StringProperty().example("uuid")) - .property("visitType", new StringProperty().example("uuid")).property("startDatetime", new DateProperty()) - .property("location", new StringProperty().example("uuid")).property("indication", new StringProperty()) - .property("stopDatetime", new DateProperty()) - .property("encounters", new ArrayProperty(new StringProperty().example("uuid"))) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/VisitAttributeCreate"))) - - .required("patient").required("visitType"); - if (rep instanceof FullRepresentation) { - model.property("patient", new RefProperty("#/definitions/PatientCreate")) - .property("visitType", new RefProperty("#/definitions/VisittypeCreate")) - .property("location", new RefProperty("#/definitions/LocationCreate")) - .property("indication", new RefProperty("#/definitions/ConceptCreate")) - .property("encounters", new ArrayProperty(new RefProperty("#/definitions/EncounterCreate"))); - } - return model; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl().property("visitType", new RefProperty("#/definitions/VisittypeCreate")) - .property("startDatetime", new DateProperty()) - .property("location", new RefProperty("#/definitions/LocationCreate")) - .property("indication", new RefProperty("#/definitions/ConceptCreate")) - .property("stopDatetime", new DateProperty()) - .property("encounters", new ArrayProperty(new RefProperty("#/definitions/EncounterCreate"))) - .property("attributes", new ArrayProperty(new StringProperty())); //FIXME type - } - + /** * @see DelegatingCrudResource#newDelegate() */ diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/test/GenericChildResource.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/test/GenericChildResource.java index c2e53d682..a39df972b 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/test/GenericChildResource.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/test/GenericChildResource.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.test; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -42,25 +39,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - - @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("value", new StringProperty()); - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("value", new StringProperty()); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); - } - + @Override public GenericChild newDelegate() { return new GenericChild(); diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs2_0/AllergyReactionConverter2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs2_0/AllergyReactionConverter2_0.java index f6c6be42e..48002092e 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs2_0/AllergyReactionConverter2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs2_0/AllergyReactionConverter2_0.java @@ -33,7 +33,7 @@ public class AllergyReactionConverter2_0 extends BaseDelegatingConverter getLinks(AdministrationSectionLinks instance) return instance.getLinks(); } - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property(MODULE_TITLE, new StringProperty()) - .property(LINKS, new ArrayProperty(new ObjectProperty())); - } - - return model; - } - - @Override + @Override public NeedsPaging doGetAll(RequestContext context) throws ResponseException { return new NeedsPaging<>(getAllAdministrationLinks(), context); } diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertRecipientResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertRecipientResource2_0.java index 6990bb361..8940debc4 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertRecipientResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertRecipientResource2_0.java @@ -9,12 +9,6 @@ */ 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.BooleanProperty; -import io.swagger.models.properties.DateTimeProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.StringUtils; import org.openmrs.User; import org.openmrs.api.context.Context; @@ -99,44 +93,6 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return description; } - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property(UUID, new StringProperty()) - .property(DISPLAY, new StringProperty()); - - if (rep instanceof DefaultRepresentation) { - modelImpl - .property(RECIPIENT, new RefProperty("#/definitions/UserGetRef")) - .property(ALERT_READ, new BooleanProperty()) - .property(DATE_CHANGED, new DateTimeProperty()); - } - if (rep instanceof FullRepresentation) { - modelImpl - .property(RECIPIENT, new RefProperty("#/definitions/UserGet")) - .property(ALERT_READ, new BooleanProperty()) - .property(DATE_CHANGED, new DateTimeProperty()); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl modelImpl = new ModelImpl() - .property(RECIPIENT, new StringProperty().example("uuid")); - - if (rep instanceof FullRepresentation) { - modelImpl - .property(RECIPIENT, new RefProperty("#/definitions/UserCreate")); - } - return modelImpl; - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - @Override public AlertRecipient newDelegate() { return new AlertRecipient(); diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertResource2_0.java index 6107cc925..39e95342d 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertResource2_0.java @@ -9,16 +9,6 @@ */ 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.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.DateTimeProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -148,54 +138,6 @@ public List getPropertiesToExposeAsSubResources() { return Collections.singletonList(RECIPIENTS); } - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property(ALERT_ID, new IntegerProperty()); - - if (rep instanceof DefaultRepresentation) { - modelImpl - .property(TEXT, new StringProperty()) - .property(SATISFIED_BY_ANY, new BooleanProperty()) - .property(ALERT_READ, new BooleanProperty()) - .property(DATE_TO_EXPIRE, new DateProperty()) - .property(RECIPIENTS, new ArrayProperty(new RefProperty("#/definitions/AlertRecipientGetRef"))); - } - if (rep instanceof FullRepresentation) { - modelImpl - .property(TEXT, new StringProperty()) - .property(SATISFIED_BY_ANY, new BooleanProperty()) - .property(ALERT_READ, new BooleanProperty()) - .property(DATE_TO_EXPIRE, new DateProperty()) - .property(CREATOR, new ObjectProperty()) - .property(DATE_CREATED, new DateTimeProperty()) - .property(CHANGED_BY, new ObjectProperty()) - .property(DATE_CHANGED, new DateTimeProperty()) - .property(RECIPIENTS, new ArrayProperty(new RefProperty("#/definitions/AlertRecipientGetRef"))); - } - return modelImpl; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property(TEXT, new StringProperty()) - .property(RECIPIENTS, new ArrayProperty(new RefProperty("#/definitions/AlertRecipientCreate"))) - .property(SATISFIED_BY_ANY, new BooleanProperty()) - .property(DATE_TO_EXPIRE, new DateProperty()); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property(TEXT, new StringProperty()) - .property(RECIPIENTS, new ArrayProperty(new RefProperty("#/definitions/AlertRecipientCreate"))) - .property(SATISFIED_BY_ANY, new BooleanProperty()) - .property(DATE_TO_EXPIRE, new DateProperty()); - } - @Override public DelegatingResourceDescription getCreatableProperties() throws ResourceDoesNotSupportOperationException { DelegatingResourceDescription description = new DelegatingResourceDescription(); 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 2f7bf47db..7722fb8ff 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,11 +9,6 @@ */ 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; @@ -112,50 +107,7 @@ 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") + @PropertyGetter("occurrences") public Integer getOccurrencesProperty(ConceptProposal proposal) { Map> proposalsMap = getProposalsMapByOriginalText(false); return proposalsMap.get(proposal.getOriginalText()).size(); @@ -176,15 +128,6 @@ 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(); @@ -196,17 +139,6 @@ 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 13d6398f0..4ca167494 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 @@ -9,10 +9,6 @@ */ 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.ArrayProperty; -import io.swagger.models.properties.RefProperty; import org.openmrs.ConceptStateConversion; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -87,50 +83,6 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return description; } - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGetRef"))); - } else if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGetRef"))); - } else if (rep instanceof RefRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGetRef"))); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl(); - if (rep instanceof DefaultRepresentation) { - model - .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/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/ConceptCreate")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreate"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreate"))); - } - return model; - } - @Override public ConceptStateConversion newDelegate() { return new ConceptStateConversion(); diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/DatabaseChangeResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/DatabaseChangeResource2_0.java index 4bf7fb11e..e829cc772 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/DatabaseChangeResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/DatabaseChangeResource2_0.java @@ -9,12 +9,6 @@ */ 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.StringProperty; -import liquibase.changelog.ChangeSet; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; @@ -115,34 +109,7 @@ public static String getDisplay(DatabaseUpdater.OpenMRSChangeSet instance) { return instance.getAuthor() + " " + instance.getDescription(); } - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property(UUID, new StringProperty()) - .property(DISPLAY, new StringProperty()) - .property(AUTHOR, new StringProperty()) - .property(DESCRIPTION, new StringProperty()) - .property(RUN_STATUS, new EnumProperty(ChangeSet.RunStatus.class)); - } else if (rep instanceof FullRepresentation) { - model - .property(UUID, new StringProperty()) - .property(DISPLAY, new StringProperty()) - .property(AUTHOR, new StringProperty()) - .property(DESCRIPTION, new StringProperty()) - .property(RUN_STATUS, new EnumProperty(ChangeSet.RunStatus.class)) - .property(COMMENTS, new StringProperty()) - .property(RAN_DATE, new DateProperty()); - } else if (rep instanceof RefRepresentation) { - model - .property(UUID, new StringProperty()) - .property(DISPLAY, new StringProperty()); - } - return model; - } - - @Override + @Override public DatabaseUpdater.OpenMRSChangeSet newDelegate() { return null; } diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/PatientAllergyResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/PatientAllergyResource2_0.java index 4d70a749f..686017a06 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/PatientAllergyResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/PatientAllergyResource2_0.java @@ -12,12 +12,6 @@ import java.util.ArrayList; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Allergy; import org.openmrs.Allergies; import org.openmrs.AllergyReaction; @@ -95,48 +89,7 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("allergen", new ObjectProperty()) //FIXME type - .property("severity", new RefProperty("#/definitions/ConceptGetRef")) - .property("comment", new StringProperty()) - .property("reactions", new ArrayProperty(new RefProperty("#/definitions/ConceptGetRef"))) - .property("patient", new RefProperty("#/definitions/PatientGetRef")); - } - if (rep instanceof FullRepresentation) { - model - .property("severity", new RefProperty("#/definitions/ConceptGet")) - .property("reactions", new ArrayProperty(new RefProperty("#/definitions/ConceptGet"))) - .property("patient", new RefProperty("#/definitions/PatientGet")); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("allergen", new ObjectProperty()) //FIXME type - .property("severity", new ObjectProperty() - .property("uuid", new StringProperty())) - .property("comment", new StringProperty()) - .property("reactions", new ArrayProperty(new ObjectProperty() - .property("allergy", new ObjectProperty().property("uuid", new StringProperty())) - .property("reaction", new ObjectProperty().property("uuid", new StringProperty())))) - - .required("allergen"); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#getParent(java.lang.Object) */ diff --git a/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java b/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java index 29377bcc9..8588f4b84 100644 --- a/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java +++ b/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java @@ -9,12 +9,20 @@ */ package org.openmrs.module.unrelatedtest.rest.resource; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.module.unrelatedtest.UnrelatedGenericChild; import org.openmrs.module.webservices.rest.doc.SwaggerSpecificationCreatorTest; +import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; import org.openmrs.module.webservices.rest.web.representation.Representation; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; +import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; +import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.module.webservices.rest.web.v1_0.test.GenericChild; import org.openmrs.module.webservices.rest.web.v1_0.test.GenericChildResource; /** @@ -25,33 +33,33 @@ @Resource(name = RestConstants.VERSION_1 + "/unrelated", supportedClass = UnrelatedGenericChild.class, supportedOpenmrsVersions = { "1.9.* - 9.*" }) public class UnrelatedGenericChildResource extends GenericChildResource { - public static boolean getGETCalled = false; - - public static boolean getCREATECalled = false; - - public static boolean getUPDATECalled = false; - + public static boolean getRepresentationDescription = false; + + public static boolean getCreatableProperties = false; + + public static boolean getUpdatableProperties = false; + /******************************* * TEST METHOD IMPLEMENTATIONS * These methods are the ones we want to test against. There - * implementaion is unimportant, they just set flags so we can assert the methods were called + * implementation is unimportant, they just set flags so we can assert the methods were called * correctly by the reflector. */ - + @Override - public Model getGETModel(Representation rep) { - getGETCalled = true; - return super.getGETModel(rep); + public DelegatingResourceDescription getRepresentationDescription(Representation rep) { + getRepresentationDescription = true; + return new DelegatingResourceDescription(); } - + @Override - public Model getCREATEModel(Representation rep) { - getCREATECalled = true; - return super.getCREATEModel(rep); + public DelegatingResourceDescription getCreatableProperties() { + getCreatableProperties = true; + return new DelegatingResourceDescription(); } - + @Override - public Model getUPDATEModel(Representation rep) { - getUPDATECalled = true; - return super.getUPDATEModel(rep); + public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { + getUpdatableProperties = true; + return new DelegatingResourceDescription(); } } diff --git a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/doc/SwaggerSpecificationCreatorTest.java b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/doc/SwaggerSpecificationCreatorTest.java index 8d95d79d8..8b177996d 100644 --- a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/doc/SwaggerSpecificationCreatorTest.java +++ b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/doc/SwaggerSpecificationCreatorTest.java @@ -9,19 +9,18 @@ */ package org.openmrs.module.webservices.rest.doc; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.converter.ModelConverterContextImpl; -import io.swagger.converter.ModelConverters; -import io.swagger.jackson.ModelResolver; -import io.swagger.models.Info; -import io.swagger.models.Model; -import io.swagger.models.Operation; -import io.swagger.models.Path; -import io.swagger.models.Scheme; -import io.swagger.models.Swagger; -import io.swagger.models.auth.BasicAuthDefinition; -import io.swagger.models.parameters.Parameter; -import io.swagger.util.Json; +import io.swagger.v3.core.converter.ModelConverters; +import io.swagger.v3.core.util.Json; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; import org.dbunit.database.DatabaseConnection; import org.junit.Assert; import org.junit.Before; @@ -30,9 +29,10 @@ import org.openmrs.Patient; import org.openmrs.api.context.Context; import org.openmrs.module.unrelatedtest.rest.resource.UnrelatedGenericChildResource; +import org.openmrs.module.webservices.docs.swagger.SwaggerConstants; import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator; -import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.api.RestService; +import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0.UserResource2_0; import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; import java.lang.reflect.Field; @@ -49,256 +49,296 @@ import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertNotNull; import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertEquals; public class SwaggerSpecificationCreatorTest extends BaseModuleWebContextSensitiveTest { - - @Test - public void mainTest() { - String str = new SwaggerSpecificationCreator().getJSON(); - assertNotNull(str); - } - - @Test - public void hasSearchHandler() { - SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(); - - assertTrue(creator.hasSearchHandler("attribute", "location")); - - assertFalse(creator.hasSearchHandler("workflow", null)); - assertFalse(creator.hasSearchHandler("description", "concept")); - } - - @Test - public void cacheTest() { - if (SwaggerSpecificationCreator.isCached()) { - SwaggerSpecificationCreator.clearCache(); - } - assertFalse(SwaggerSpecificationCreator.isCached()); - new SwaggerSpecificationCreator().getJSON(); - assertTrue(SwaggerSpecificationCreator.isCached()); - } - - @Test - public void modelResolveTest() { - final ModelResolver modelResolver = new ModelResolver(new ObjectMapper()); - final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver); - final Model model = context.resolve(Patient.class); - assertNotNull(model); - } - - @Test - public void swaggerSerializeTest() { - final Info info = new Info().version("1.0.0").title("Swagger WebServices REST"); - - Swagger swagger = new Swagger().info(info).securityDefinition("basicAuth", new BasicAuthDefinition()) - .scheme(Scheme.HTTP).consumes("application/json").produces("application/json"); - - final Model patientModel = ModelConverters.getInstance().read(Patient.class).get("Patient"); - swagger.addDefinition("Patient", patientModel); - - final String swaggerJson = Json.pretty(swagger); - assertNotNull(swaggerJson); - } - - Map beforeCounts; - - public Map getRowCounts() throws Exception { - Map ret = new HashMap(); - - Connection con = this.getConnection(); - DatabaseMetaData metaData = con.getMetaData(); - DatabaseConnection dbcon = new DatabaseConnection(con); - - ResultSet rs = metaData.getTables(null, "PUBLIC", "%", null); - while (rs.next()) { - String tableName = rs.getString(3); - - ret.put(tableName, dbcon.getRowCount(tableName)); - } - - return ret; - } - - @Before - public void init() throws Exception { - // init REST - Context.getService(RestService.class).initialize(); - - Context.getAdministrationService().saveGlobalProperty( - new GlobalProperty(RestConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME, "true")); - - // ensure GP is written to database before we count the rows - Context.flushSession(); - - beforeCounts = getRowCounts(); - } - - @Test - public void checkNoDatabaseChanges() throws Exception { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - - Map afterCounts = getRowCounts(); - - Assert.assertEquals("Ensure no tables are created or destroyed", beforeCounts.size(), afterCounts.size()); - Assert.assertTrue("Ensure that no data was added or removed from any tables", - ensureCountsEqual(beforeCounts, afterCounts)); - } - - private boolean ensureCountsEqual(Map beforeCounts, Map afterCounts) { - for (String key : beforeCounts.keySet()) { - if (beforeCounts.get(key) != afterCounts.get(key)) { - System.err.println("The " + key + " table has a different number of rows (" + beforeCounts.get(key) - + " before, " + afterCounts.get(key) + " after)."); - - return false; - } - } - - return true; - } - - // makes sure that every operation has a unique operationId - @Test - public void checkOperationIdsSet() { - List operationIds = new ArrayList(); - - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - Swagger spec = ssc.getSwagger(); - - for (Path p : spec.getPaths().values()) { - for (Operation o : p.getOperations()) { - Assert.assertFalse("Ensure each operation has a unique ID", operationIds.contains(o.getOperationId())); - operationIds.add(o.getOperationId()); - } - } - } - - // makes sure that every GET operation has the "v" parameter - @Test - public void checkRepresentationParamExists() { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - Swagger spec = ssc.getSwagger(); - - for (Path p : spec.getPaths().values()) { - if (p.getGet() != null) { - Assert.assertTrue("Ensure each GET operation has the 'v' query parameter", - operationHasRepresentationParam(p.getGet())); - } - } - } - - private boolean operationHasRepresentationParam(Operation o) { - boolean ret = false; - - for (Parameter p : o.getParameters()) { - if (p.getName().equals("v")) { - ret = !ret; - } - } - - return ret; - } - - // make sure each operation that supports paging has the limit and startIndex parameters - @Test - public void checkPagingParamsExist() { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - Swagger spec = ssc.getSwagger(); - - for (Path p : spec.getPaths().values()) { - for (Operation o : p.getOperations()) { - if (o.getOperationId().matches("^getAll[A-Z].*")) { - Assert.assertTrue("Ensure each operation that supports paging has both paging parameters", - operationHasPagingParams(o)); - } - } - } - } - - private boolean operationHasPagingParams(Operation o) { - boolean limit = false, startIndex = false; - - for (Parameter p : o.getParameters()) { - if (p.getName().equals("limit")) { - limit = !limit; - } else if (p.getName().equals("startIndex")) { - startIndex = !startIndex; - } - } - - return limit && startIndex; - } - - @Test - public void addPathsWorksForCoreModels() throws NoSuchMethodException, InvocationTargetException, - IllegalAccessException, NoSuchFieldException { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - - // reflect the swagger propperty and initSwagger method so we can setup for the main test - Field swagger = ssc.getClass().getDeclaredField("swagger"); - swagger.setAccessible(true); - swagger.set(ssc, new Swagger()); - - Method initSwagger = ssc.getClass().getDeclaredMethod("initSwagger"); - initSwagger.setAccessible(true); - initSwagger.invoke(ssc); - - // make the paths method accessible - Method addPaths = ssc.getClass().getDeclaredMethod("addPaths"); - addPaths.setAccessible(true); - - addPaths.invoke(ssc); - } - - /** - * Some subresource appear to only support creation, not fetching or updating. References to the - * Get/Update definitions were still being included in the response options, despite not - * existing. Ensure that these references are not included in the resulting JSON to prevent - * swagger reference errors. See ticket: RESTWS-720 - */ - @Test - public void createOnlySubresourceDefinitions() { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - String json = ssc.getJSON(); - - // A simple search will tell us if the problem definitions exist - assertFalse(json.contains("SystemsettingSubdetailsGet")); - assertFalse(json.contains("SystemsettingSubdetailsUpdate")); - assertTrue(json.contains("SystemsettingSubdetailsCreate")); - } - - /** - * Ensure that resources not directly related to the webservices.rest package are successfully - * defined in the swagger documentation. - */ - @Test - public void testUnrelatedResourceDefinitions() { - // ensure the statics are false first - UnrelatedGenericChildResource.getGETCalled = false; - UnrelatedGenericChildResource.getCREATECalled = false; - UnrelatedGenericChildResource.getUPDATECalled = false; - - // make sure to reset the cache for multiple tests in the same run - if (SwaggerSpecificationCreator.isCached()) { - SwaggerSpecificationCreator.clearCache(); - } - - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - - // check our custom methods were called - assertTrue(UnrelatedGenericChildResource.getGETCalled); - assertTrue(UnrelatedGenericChildResource.getCREATECalled); - assertTrue(UnrelatedGenericChildResource.getUPDATECalled); - - // assert the definition is now in the swagger object - Swagger swagger = ssc.getSwagger(); - assertTrue(swagger.getDefinitions().containsKey("UnrelatedGet")); - assertTrue(swagger.getDefinitions().containsKey("UnrelatedUpdate")); - assertTrue(swagger.getDefinitions().containsKey("UnrelatedCreate")); - } + + @Test + public void mainTest() { + String str = new SwaggerSpecificationCreator().getJSON(); + assertNotNull(str); + } + + @Test + public void hasSearchHandler() { + SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(); + + assertTrue(creator.hasSearchHandler("attribute", "location")); + + assertFalse(creator.hasSearchHandler("workflow", null)); + assertFalse(creator.hasSearchHandler("description", "concept")); + } + + @Test + public void cacheTest() { + if (SwaggerSpecificationCreator.isCached()) { + SwaggerSpecificationCreator.clearCache(); + } + assertFalse(SwaggerSpecificationCreator.isCached()); + new SwaggerSpecificationCreator().getJSON(); + assertTrue(SwaggerSpecificationCreator.isCached()); + } + + @Test + public void modelResolveTest() { + final Schema schema = ModelConverters.getInstance().readAllAsResolvedSchema(Patient.class).schema; + assertNotNull(schema); + } + + @Test + public void swaggerSerializeTest() { + final Info info = new Info().version("1.0.0").title("OpenMRS API Docs"); + + OpenAPI openAPI = new OpenAPI() + .info(info) + .addSecurityItem(new SecurityRequirement().addList("basicAuth")) + .components(new Components().addSecuritySchemes("basicAuth", + new SecurityScheme() + .type(SecurityScheme.Type.HTTP) + .scheme("basic"))); + + final Schema patientSchema = ModelConverters.getInstance().readAllAsResolvedSchema(Patient.class).schema; + openAPI.getComponents().addSchemas("Patient", patientSchema); + + final String swaggerJson = Json.pretty(openAPI); + assertNotNull(swaggerJson); + } + + Map beforeCounts; + + public Map getRowCounts() throws Exception { + Map ret = new HashMap(); + + Connection con = this.getConnection(); + DatabaseMetaData metaData = con.getMetaData(); + DatabaseConnection dbcon = new DatabaseConnection(con); + + ResultSet rs = metaData.getTables(null, "PUBLIC", "%", null); + while (rs.next()) { + String tableName = rs.getString(3); + + ret.put(tableName, dbcon.getRowCount(tableName)); + } + + return ret; + } + + @Before + public void init() throws Exception { + // init REST + Context.getService(RestService.class).initialize(); + + Context.getAdministrationService().saveGlobalProperty( + new GlobalProperty(SwaggerConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME, "true")); + + // ensure GP is written to database before we count the rows + Context.flushSession(); + + beforeCounts = getRowCounts(); + } + + @Test + public void checkNoDatabaseChanges() throws Exception { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + ssc.getJSON(); + + Map afterCounts = getRowCounts(); + + assertEquals("Ensure no tables are created or destroyed", beforeCounts.size(), afterCounts.size()); + Assert.assertTrue("Ensure that no data was added or removed from any tables", + ensureCountsEqual(beforeCounts, afterCounts)); + } + + private boolean ensureCountsEqual(Map beforeCounts, Map afterCounts) { + for (String key : beforeCounts.keySet()) { + if (beforeCounts.get(key) != afterCounts.get(key)) { + System.err.println("The " + key + " table has a different number of rows (" + beforeCounts.get(key) + + " before, " + afterCounts.get(key) + " after)."); + + return false; + } + } + + return true; + } + + // makes sure that every operation has a unique operationId + @Test + public void checkOperationIdsSet() { + List operationIds = new ArrayList(); + + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + ssc.getJSON(); + OpenAPI spec = ssc.getOpenAPI(); + + for (PathItem p : spec.getPaths().values()) { + for (Operation o : p.readOperations()) { + Assert.assertFalse("Ensure each operation has a unique ID", operationIds.contains(o.getOperationId())); + operationIds.add(o.getOperationId()); + } + } + } + + // makes sure that every GET operation has the "v" parameter + @Test + public void checkRepresentationParamExists() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + ssc.getJSON(); + OpenAPI spec = ssc.getOpenAPI(); + + Assert.assertNotNull("SwaggerSpecificationCreator should not be null", ssc); + Assert.assertNotNull("OpenAPI spec should not be null", spec); + Assert.assertNotNull("Paths in OpenAPI spec should not be null", spec.getPaths()); + + spec.getPaths().forEach((path, pathItem) -> { + Operation getOperation = pathItem.getGet(); + if (getOperation != null) { + Assert.assertTrue( + String.format("GET operation at path %s must have 'v' query parameter", path), + operationHasRepresentationParam(getOperation) + ); + } + }); + } + + private boolean operationHasRepresentationParam(Operation operation) { + if (operation.getParameters() == null) { + return false; + } + + return operation.getParameters().stream() + .anyMatch(param -> "v".equals(param.getName())); + } + + // make sure each operation that supports paging has the limit and startIndex parameters + @Test + public void checkPagingParamsExist() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + ssc.getJSON(); + OpenAPI openAPI = ssc.getOpenAPI(); + + openAPI.getPaths().forEach((path, pathItem) -> { + pathItem.readOperationsMap().forEach((httpMethod, operation) -> { + if (operation.getOperationId().matches("^getAll[A-Z].*")) { + Assert.assertTrue("Ensure each operation that supports paging has both paging parameters", + operationHasPagingParams(operation)); + } + }); + }); + } + + private boolean operationHasPagingParams(Operation o) { + boolean limit = false, startIndex = false; + + for (Parameter p : o.getParameters()) { + if (p.getName().equals("limit")) { + limit = true; + } else if (p.getName().equals("startIndex")) { + startIndex = true; + } + } + + return limit && startIndex; + } + + @Test + public void addPathsWorksForCoreModels() throws NoSuchMethodException, InvocationTargetException, + IllegalAccessException, NoSuchFieldException { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + + // reflect the openAPI property and initOpenAPI method so we can setup for the main test + Field openAPIField = ssc.getClass().getDeclaredField("openAPI"); + openAPIField.setAccessible(true); + openAPIField.set(ssc, new OpenAPI()); + + Method initOpenAPI = ssc.getClass().getDeclaredMethod("initOpenAPI"); + initOpenAPI.setAccessible(true); + initOpenAPI.invoke(ssc); + + // make the paths method accessible + Method addPaths = ssc.getClass().getDeclaredMethod("addPaths"); + addPaths.setAccessible(true); + + addPaths.invoke(ssc); + } + + /** + * Some subresource appear to only support creation, not fetching or updating. References to the + * Get/Update definitions were still being included in the response options, despite not + * existing. Ensure that these references are not included in the resulting JSON to prevent + * swagger reference errors. See ticket: RESTWS-720 + */ + @Test + public void createOnlySubresourceDefinitions() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + String json = ssc.getJSON(); + + // A simple search will tell us if the problem definitions exist + assertFalse(json.contains("SystemsettingSubdetailsGet")); + assertFalse(json.contains("SystemsettingSubdetailsUpdate")); + assertTrue(json.contains("SystemsettingSubdetailsCreate")); + } + + @Test + public void determineSchemaForProperty_shouldReturnNotKnownForNonExistentProperty() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + UserResource2_0 resourceHandler = new UserResource2_0(); + + Schema unknownResult = ssc.determineSchemaForProperty(resourceHandler, "nonExistent", "Get"); + assertNotNull(unknownResult); + assertTrue(unknownResult instanceof StringSchema); + assertEquals("unknown", unknownResult.getDescription()); + } + + @Test + public void determineSchemaForProperty_shouldInferSchemaForGivenDatePropertyForSubResource() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + UserResource2_0 resourceHandler = new UserResource2_0(); + + Schema dose = ssc.determineSchemaForProperty(resourceHandler, "dose", "Get"); + assertNotNull(dose); + assertTrue(dose instanceof StringSchema); + } + + @Test + public void determineSchemaForProperty_shouldInferSchemaForGivenPropertyForResourceHandlerWhichDoesNotDirectlyDeclareAParameterizedSuperclass() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + UserResource2_0 testResource2_1 = new UserResource2_0(); + + Schema dose = ssc.determineSchemaForProperty(testResource2_1, "secretQuestion", "Get"); + assertNotNull(dose); + assertEquals("unknown", dose.getDescription()); + } + + /** + * Ensure that resources not directly related to the webservices.rest package are successfully + * defined in the swagger documentation. + */ + @Test + public void testUnrelatedResourceDefinitions() { + // ensure the statics are false first + UnrelatedGenericChildResource.getCreatableProperties = false; + UnrelatedGenericChildResource.getRepresentationDescription = false; + UnrelatedGenericChildResource.getUpdatableProperties = false; + + // make sure to reset the cache for multiple tests in the same run + if (SwaggerSpecificationCreator.isCached()) { + SwaggerSpecificationCreator.clearCache(); + } + + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + ssc.getJSON(); + +// // check our custom methods were called + assertTrue(UnrelatedGenericChildResource.getRepresentationDescription); + assertTrue(UnrelatedGenericChildResource.getCreatableProperties); + assertTrue(UnrelatedGenericChildResource.getUpdatableProperties); + + // assert the definition is now in the swagger object + OpenAPI openAPI = ssc.getOpenAPI(); + + assertTrue(openAPI.getComponents().getSchemas().containsKey("UnrelatedGet")); + assertTrue(openAPI.getComponents().getSchemas().containsKey("UnrelatedUpdate")); + assertTrue(openAPI.getComponents().getSchemas().containsKey("UnrelatedCreate")); + } } diff --git a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/resource/SubDetailsResource.java b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/resource/SubDetailsResource.java index 26f76a9df..8ecc21841 100644 --- a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/resource/SubDetailsResource.java +++ b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/resource/SubDetailsResource.java @@ -9,9 +9,7 @@ */ package org.openmrs.module.webservices.rest.resource; -import io.swagger.models.Model; import org.openmrs.GlobalProperty; -import org.openmrs.module.webservices.rest.doc.SwaggerSpecificationCreatorTest; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.annotation.SubResource; import org.openmrs.module.webservices.rest.web.representation.Representation; @@ -63,7 +61,12 @@ public void purge(SubDetails delegate, RequestContext context) throws ResponseEx public DelegatingResourceDescription getRepresentationDescription(Representation rep) { return new DelegatingResourceDescription(); } - + + @Override + public DelegatingResourceDescription getCreatableProperties() { + return new DelegatingResourceDescription(); + } + @Override public SubDetails newDelegate() { return new SubDetails(); @@ -73,9 +76,5 @@ public SubDetails newDelegate() { public SubDetails save(SubDetails delegate) { return delegate; } - - @Override - public Model getCREATEModel(Representation rep) { - return super.getGETModel(rep); - } + } diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortMembershipResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortMembershipResource2_1.java index 1cc6999e0..2b5243162 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortMembershipResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortMembershipResource2_1.java @@ -11,10 +11,6 @@ import java.util.ArrayList; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.Cohort; import org.openmrs.CohortMembership; import org.openmrs.Patient; @@ -97,37 +93,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe d.addProperty("endDate"); return d; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("patientUuid", new StringProperty()); - } - //FIXME missing props - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("patientUuid", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()); - } - + @PropertyGetter("display") public String getDisplay(CohortMembership cohortMembership) { return "Patient in cohort (see link with rel=patient)"; diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortResource2_1.java index da424571f..abfc7a631 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortResource2_1.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_1; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; import org.openmrs.Cohort; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -32,16 +29,8 @@ public class CohortResource2_1 extends CohortResource1_8 { public String getResourceVersion() { return RestConstants2_1.RESOURCE_VERSION; } - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - model.getProperties().remove("memberIds"); - model.property("size", new IntegerProperty()); - return model; - } - - @Override + + @Override public DelegatingResourceDescription getRepresentationDescription(Representation rep) { // We do not override the CohortResource1_8 representation, because we want to basically do a clean-slate // representation, rather than make minor tweaks (and require a dev to look at a superclass) diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ConceptSourceResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ConceptSourceResource2_1.java index 16ca83737..624802eae 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ConceptSourceResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ConceptSourceResource2_1.java @@ -9,9 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_1; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.openmrs.ConceptSource; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -28,23 +25,7 @@ @Resource(name = RestConstants.VERSION_1 + "/conceptsource", supportedClass = ConceptSource.class, supportedOpenmrsVersions = { "2.1.* - 9.*" }) public class ConceptSourceResource2_1 extends ConceptSourceResource2_0 { - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uniqueId", new StringProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation representation) { - return ((ModelImpl) super.getCREATEModel(representation)) - .property("uniqueId", new StringProperty()); - } - + /** * @see DelegatingCrudResource#getRepresentationDescription(Representation) */ diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ObsResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ObsResource2_1.java index ec7ba7398..fe82e4904 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ObsResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ObsResource2_1.java @@ -9,10 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_1; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; import org.openmrs.Obs; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; import org.openmrs.module.webservices.rest.web.representation.Representation; @@ -25,21 +22,7 @@ */ @Resource(name = RestConstants.VERSION_1 + "/obs", supportedClass = Obs.class, supportedOpenmrsVersions = { "2.1.* - 9.*" }) public class ObsResource2_1 extends ObsResource1_11 { - - @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("status", new EnumProperty(Obs.Status.class)) - .property("interpretation", new EnumProperty(Obs.Interpretation.class)); - } - - @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("status", new EnumProperty(Obs.Status.class)) - .property("interpretation", new EnumProperty(Obs.Interpretation.class)); - } - + @Override public DelegatingResourceDescription getRepresentationDescription(Representation rep) { DelegatingResourceDescription description = super.getRepresentationDescription(rep); diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/PersonNameResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/PersonNameResource2_1.java index 1907a621e..5bf5f565e 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/PersonNameResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/PersonNameResource2_1.java @@ -9,10 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_1; -import io.swagger.models.Model; import org.openmrs.PersonName; import org.openmrs.module.webservices.rest.web.annotation.SubResource; -import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11.PersonResource1_11; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0.PersonNameResource2_0; @@ -27,11 +25,5 @@ public DelegatingResourceDescription getCreatableProperties() { resourceDescription.getProperties().get("familyName").setRequired(false); return resourceDescription; } - - @Override - public Model getCREATEModel(Representation rep) { - Model model = super.getCREATEModel(rep); - model.getProperties().get("familyName").setRequired(false); - return model; - } + } diff --git a/omod-2.2/pom.xml b/omod-2.2/pom.xml index b9737bc0d..8bbc7c760 100644 --- a/omod-2.2/pom.xml +++ b/omod-2.2/pom.xml @@ -19,6 +19,28 @@ ${project.parent.groupId} ${project.parent.artifactId}-omod-common ${project.parent.version} + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + diff --git a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java index eef3438d4..e2d27d74f 100644 --- a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java +++ b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java @@ -9,10 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.openmrs.Condition; @@ -83,61 +79,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getGETModel(Representation) - */ - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("condition", new StringProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("clinicalStatus", new StringProperty()) - .property("verificationStatus", new StringProperty()) - .property("previousVersion", new StringProperty()) - .property("onsetDate", new StringProperty()) - .property("endDate", new StringProperty()) - .property("additionalDetail", new StringProperty()) - .property("voided", new StringProperty()); - } - return model; - } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getCREATEModel(Representation) - */ - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("condition", new StringProperty()) - .property("patient", new StringProperty().example("uuid")) - .property("clinicalStatus", new StringProperty()) - .property("verificationStatus", new StringProperty()) - .property("previousVersion", new StringProperty()) - .property("onsetDate", new StringProperty()) - .property("endDate", new StringProperty()) - .property("additionalDetail", new StringProperty()); - } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getUPDATEModel(Representation) - */ - @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("condition", new StringProperty()) - .property("clinicalStatus", new StringProperty()) - .property("verificationStatus", new StringProperty()) - .property("previousVersion", new StringProperty()) - .property("onsetDate", new StringProperty()) - .property("endDate", new StringProperty()) - .property("additionalDetail", new StringProperty()) - .property("voided", new StringProperty()); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ diff --git a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java index 4be563061..eec5e03b2 100644 --- a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java +++ b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java @@ -12,11 +12,9 @@ import java.util.Date; import org.apache.commons.lang3.StringUtils; -import org.openmrs.ConditionVerificationStatus; import org.openmrs.Diagnosis; import org.openmrs.Patient; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.ConversionUtil; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -34,12 +32,6 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8; /** @@ -127,27 +119,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getGETModel(Representation) - */ - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("diagnosis", new StringProperty()) - .property("condition", new StringProperty()) - .property("certainty", new EnumProperty(ConditionVerificationStatus.class)) - .property("rank", new IntegerProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("voided", new BooleanProperty()); - } - return model; - } - - /** + + /** * @param diagnosis * @return Diagnosis's name */ @@ -179,23 +152,7 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return description; } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getCREATEModel(Representation) - */ - @Override - public Model getCREATEModel(Representation rep) { - - return new ModelImpl() - .property("diagnosis", new StringProperty()) - .property("encounter", new StringProperty()) - .property("condition", new StringProperty()) - .property("certainty", new StringProperty()) - .property("patient", new StringProperty().example("uuid")) - .property("rank", new IntegerProperty()); - } - /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties() */ @@ -212,20 +169,6 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe return description; } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getUPDATEModel(Representation) - */ - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("diagnosis", new StringProperty()) - .property("condition", new StringProperty()) - .property("encounter", new StringProperty()) - .property("certainty", new EnumProperty(ConditionVerificationStatus.class)) - .property("rank", new IntegerProperty()) - .property("voided", new BooleanProperty()); - } @Override protected PageableResult doSearch(RequestContext context) { diff --git a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2.java b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2.java index 5d2bfe57a..4cd85bc2d 100644 --- a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2.java +++ b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2.java @@ -9,12 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.openmrs.Order; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.annotation.Resource; import org.openmrs.module.webservices.rest.web.annotation.SubResource; @@ -53,13 +49,6 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return delegatingResourceDescription; } - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("fulfillerComment", new StringProperty()) - .property("fulfillerStatus", new EnumProperty(Order.FulfillerStatus.class)); - } - @Override public Order getParent(FulfillerDetails2_2 instance) { return instance.getOrder(); diff --git a/omod-2.3/pom.xml b/omod-2.3/pom.xml index e19cca7c1..c7c6c9a4a 100644 --- a/omod-2.3/pom.xml +++ b/omod-2.3/pom.xml @@ -19,6 +19,28 @@ ${project.parent.groupId} ${project.parent.artifactId}-omod-common ${project.parent.version} + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + diff --git a/omod-2.3/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_3/FulfillerDetailsResource2_3.java b/omod-2.3/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_3/FulfillerDetailsResource2_3.java index c68e39b50..2d27e0efb 100644 --- a/omod-2.3/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_3/FulfillerDetailsResource2_3.java +++ b/omod-2.3/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_3/FulfillerDetailsResource2_3.java @@ -9,12 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_3; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; import org.openmrs.Order; import org.openmrs.api.context.Context; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.annotation.Resource; import org.openmrs.module.webservices.rest.web.annotation.SubResource; @@ -56,14 +52,6 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return delegatingResourceDescription; } - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("fulfillerComment", new StringProperty()) - .property("fulfillerStatus", new EnumProperty(Order.FulfillerStatus.class)) - .property("accessionNumber", new StringProperty()); - } - @Override public Order getParent(FulfillerDetails2_3 instance) { return instance.getOrder(); diff --git a/omod-2.4/pom.xml b/omod-2.4/pom.xml index b43706ab8..1960b5c68 100644 --- a/omod-2.4/pom.xml +++ b/omod-2.4/pom.xml @@ -21,6 +21,28 @@ ${project.parent.groupId} ${project.parent.artifactId}-omod-common ${project.parent.version} + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + diff --git a/omod-2.5/pom.xml b/omod-2.5/pom.xml index f09d777c9..f1a3c155e 100644 --- a/omod-2.5/pom.xml +++ b/omod-2.5/pom.xml @@ -23,6 +23,28 @@ ${project.parent.groupId} ${project.parent.artifactId}-omod-common ${project.parent.version} + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java index 010a4ed5e..1ab45b7fb 100644 --- a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java @@ -9,9 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Diagnosis; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; @@ -67,26 +67,11 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe return description; } - @Override - public Model getGETModel(Representation rep) { - return addNewProperties(super.getGETModel(rep), rep); - } - - @Override - public Model getCREATEModel(Representation rep) { - return addNewProperties(super.getCREATEModel(rep), rep); - } - - @Override - public Model getUPDATEModel(Representation rep) { - return addNewProperties(super.getUPDATEModel(rep), rep); - } - - private Model addNewProperties(Model model, Representation rep) { + private Schema addNewProperties(Schema model, Representation rep) { if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - ((ModelImpl) model) - .property("formFieldNamespace", new StringProperty()) - .property("formFieldPath", new StringProperty()); + ((ObjectSchema) model) + .addProperty("formFieldNamespace", new StringSchema()) + .addProperty("formFieldPath", new StringSchema()); } return model; } diff --git a/omod-common/pom.xml b/omod-common/pom.xml index dac56b313..37f82d3c1 100644 --- a/omod-common/pom.xml +++ b/omod-common/pom.xml @@ -31,19 +31,13 @@ - io.swagger + io.swagger.core.v3 swagger-core - 1.6.2 - - - org.slf4j - slf4j-api - - - javax.validation - validation-api - - + + + + io.swagger.core.v3 + swagger-annotations diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/NullSerializer.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/NullSerializer.java deleted file mode 100644 index d8eb59753..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/NullSerializer.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; - -public class NullSerializer extends JsonSerializer { - - @Override - public void serialize(Object arg0, JsonGenerator arg1, SerializerProvider arg2) throws IOException, - JsonProcessingException { - arg1.writeFieldName(""); - - } - -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Operation.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Operation.java deleted file mode 100644 index 6fb9caa6f..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Operation.java +++ /dev/null @@ -1,182 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -//Describes an operation available on a single path -public class Operation { - - public static String OPERATION_GET_ALL_METHOD = "doGetAll"; - - public static String OPERATION_GET_BY_ID = "getByUniqueId"; - - public static String OPERATION_VOID_RETIRE_METHOD = "delete"; - - public static String OPERATION_DELETE_METHOD = "purge"; - - public static String OPERATION_CREATE_METHOD = "create"; - - public static String OPERATION_UPDATE_METHOD = "save"; - - @JsonIgnore - private String name; - - //A verbose explanation of the operation behavior - private String description; - - //A short summary of what the operation does - private String summary; - - //A list of MIME types the operation can produce - private List produces; - - /*A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.*/ - private List tags; - - //A list of parameters that are applicable for this operation - private List parameters; - - //The list of possible responses as they are returned from executing this operation. - private Map responses; - - //Custom field added for specifying if the operation is a search handler - private String isSearchHandler = "false"; - - //Unique identifier for the operation - private String operationId; - - public Operation() { - - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the produces - */ - public List getProduces() { - return produces; - } - - /** - * @param produces the produces to set - */ - public void setProduces(List produces) { - this.produces = produces; - } - - /** - * @return the parameters - */ - public List getParameters() { - return parameters; - } - - /** - * @param parameters the parameters to set - */ - public void setParameters(List parameters) { - this.parameters = parameters; - } - - /** - * @return the responses - */ - public Map getResponses() { - return responses; - } - - /** - * @param responses the responses to set - */ - public void setResponses(Map responses) { - this.responses = responses; - } - - /** - * @return the tags - */ - public List getTags() { - return tags; - } - - /** - * @param tags the tags to set - */ - public void setTags(List tags) { - this.tags = tags; - } - - /** - * @return the isSearchHandler - */ - public String getIsSearchHandler() { - return isSearchHandler; - } - - /** - * @param isSearchHandler the isSearchHandler to set - */ - public void setIsSearchHandler(String isSearchHandler) { - this.isSearchHandler = isSearchHandler; - } - - /** - * @return the summary - */ - public String getSummary() { - return summary; - } - - /** - * @param summary the summary to set - */ - public void setSummary(String summary) { - this.summary = summary; - } - - public String getOperationId() { - return operationId; - } - - public void setOperationId(String operationId) { - this.operationId = operationId; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Parameter.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Parameter.java deleted file mode 100644 index a3857e776..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Parameter.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonSetter; -import org.codehaus.jackson.annotate.JsonProperty; - -import java.util.ArrayList; -import java.util.List; - -/** - * The contents of this file are subject to the OpenMRS Public License Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the - * License at http://license.openmrs.org Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the - * specific language governing rights and limitations under the License. Copyright (C) OpenMRS, LLC. - * All Rights Reserved. - */ - -/*Describes a single operation parameter.*/ -public class Parameter { - - /* The name of the parameter. Parameter names are case sensitive.*/ - private String name; - - /* he location of the parameter. Possible values are "query", "header", "path", "formData" or "body".*/ - private String in; - - /*A brief description of the parameter. This could contain examples of use.*/ - private String description; - - /*Determines whether this parameter is mandatory*/ - private Boolean required; - - private String type; - - @JsonProperty("enum") - private List enumeration; - - private Schema schema; - - public Parameter() { - type = "string"; // default to string - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the in - */ - public String getIn() { - return in; - } - - /** - * @param in the in to set - */ - public void setIn(String in) { - this.in = in; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the required - */ - public Boolean getRequired() { - return required; - } - - /** - * @param required the required to set - */ - public void setRequired(Boolean required) { - this.required = required; - } - - /** - * @return the type - */ - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - @JsonGetter("enum") - public List getEnumeration() { - return this.enumeration; - } - - @JsonSetter("enum") - public void setEnumeration(List enumeration) { - this.enumeration = enumeration; - } - - public void addEnumerationItem(String enumerationItem) { - if (enumeration == null) - enumeration = new ArrayList(); - - if (!this.enumeration.contains(enumerationItem)) { - this.enumeration.add(enumerationItem); - } - } - - public Schema getSchema() { - return schema; - } - - public void setSchema(Schema schema) { - this.schema = schema; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Path.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Path.java deleted file mode 100644 index 21664efe5..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Path.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; - -//Holds the relative path to the individual endpoints. The path is appended to the basePath in order to construct the full URL -public class Path { - - //Describes the operations available on a single path - private Map operations; - - public Path() { - - } - - /** - * @return the operation - */ - @JsonAnyGetter - public Map getOperations() { - return operations; - } - - /** - * @param operation the operation to set - */ - public void setOperations(Map operations) { - this.operations = operations; - } - -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Response.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Response.java deleted file mode 100644 index f9b7274dd..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Response.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -/* An object to hold responses to be reused across operations */ -public class Response { - - private String description; - - private Schema schema; - - public Response() { - - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the schema - */ - public Schema getSchema() { - return schema; - } - - /** - * @param schema the schema to set - */ - public void setSchema(Schema schema) { - this.schema = schema; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Schema.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Schema.java deleted file mode 100644 index e0678969c..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Schema.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -/** - * The contents of this file are subject to the OpenMRS Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://license.openmrs.org - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * Copyright (C) OpenMRS, LLC. All Rights Reserved. - */ - -import com.fasterxml.jackson.annotation.JsonProperty; - -/*The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays.*/ -public class Schema { - - private String ref; - - public Schema() { - - } - - /** - * @return the ref - */ - @JsonProperty("$ref") - public String getRef() { - return ref; - } - - /** - * @param ref the ref to set - */ - public void setRef(String ref) { - this.ref = ref; - } - -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SecurityDefinitions.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SecurityDefinitions.java deleted file mode 100644 index ed95852d9..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SecurityDefinitions.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -public class SecurityDefinitions { - - private SecurityScheme basic_auth; - - public SecurityDefinitions() { - } - - public SecurityScheme getBasicAuth() { - return basic_auth; - } - - public void setBasicAuth(SecurityScheme basic_auth) { - this.basic_auth = basic_auth; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Paths.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerConstants.java similarity index 54% rename from omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Paths.java rename to omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerConstants.java index 68389f8e6..8f2b626ce 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Paths.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerConstants.java @@ -9,32 +9,19 @@ */ package org.openmrs.module.webservices.docs.swagger; -import java.util.Map; +import static org.openmrs.module.webservices.rest.web.RestConstants.MODULE_ID; -import com.fasterxml.jackson.annotation.JsonAnyGetter; - -//List of Available Paths. -public class Paths { - - private Map paths; +/** + * Constants used when generating the Swagger specification + */ +public class SwaggerConstants { - public Paths() { - - } + public static String SWAGGER_IMPOSSIBLE_UNIQUE_ID = "a--b"; + + public static String SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME = MODULE_ID + ".quietDocs"; - /** - * @return the paths - */ - @JsonAnyGetter - public Map getPaths() { - return paths; - } + public static final boolean SWAGGER_LOGS_ON = true; - /** - * @param paths the paths to set - */ - public void setPaths(Map paths) { - this.paths = paths; - } + public static final boolean SWAGGER_LOGS_OFF = false; } diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecification.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecification.java deleted file mode 100644 index d22a91420..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecification.java +++ /dev/null @@ -1,194 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.util.List; - -/* The class describes the RESTful API in accordance with the Swagger specification and is represented as JSON objects and conform to the JSON standards */ -public class SwaggerSpecification { - - //Specifies the Swagger Specification version being used - private String swagger = "2.0"; - - // Provides metadata about the API - private Info info; - - //The host (name or ip) serving the API - private String host; - - //The base path on which the API is served - private String basePath; - - //Allows adding meta data to a single tag that is used by the Operation Object. - private List tags; - - //The transfer protocol of the API - private List schemes; - - //A list of MIME types the APIs can consume - private List consumes; - - //A list of MIME types the APIs can produce - private List produces; - - //The available paths and operations for the API. - private Paths paths; - - //The security definitions - private SecurityDefinitions securityDefinitions; - - //An object to hold data types produced and consumed by operations. - private Definitions definitions; - - public SwaggerSpecification() { - - } - - /** - * @return the info - */ - public Info getInfo() { - return info; - } - - /** - * @param info the info to set - */ - public void setInfo(Info info) { - this.info = info; - } - - /** - * @return the host - */ - public String getHost() { - return host; - } - - /** - * @param host the host to set - */ - public void setHost(String host) { - this.host = host; - } - - /** - * @return the basePath - */ - public String getBasePath() { - return basePath; - } - - /** - * @param basePath the basePath to set - */ - public void setBasePath(String basePath) { - this.basePath = basePath; - } - - /** - * @return the schemes - */ - public List getSchemes() { - return schemes; - } - - /** - * @param schemes the schemes to set - */ - public void setSchemes(List schemes) { - this.schemes = schemes; - } - - /** - * @return the consumes - */ - public List getConsumes() { - return consumes; - } - - /** - * @param consumes the consumes to set - */ - public void setConsumes(List consumes) { - this.consumes = consumes; - } - - /** - * @return the produces - */ - public List getProduces() { - return produces; - } - - /** - * @param produces the produces to set - */ - public void setProduces(List produces) { - this.produces = produces; - } - - /** - * @return the paths - */ - public Paths getPaths() { - return paths; - } - - /** - * @param paths the paths to set - */ - public void setPaths(Paths paths) { - this.paths = paths; - } - - public SecurityDefinitions getSecurityDefinitions() { - return securityDefinitions; - } - - public void setSecurityDefinitions(SecurityDefinitions securityDefinitions) { - this.securityDefinitions = securityDefinitions; - } - - /** - * @return the definitions - */ - public Definitions getDefinitions() { - return definitions; - } - - /** - * @param definitions the definitions to set - */ - public void setDefinitions(Definitions definitions) { - this.definitions = definitions; - } - - /** - * @return the swagger - */ - public String getSwagger() { - return swagger; - } - - /** - * @return the tags - */ - public List getTags() { - return tags; - } - - /** - * @param tags the tags to set - */ - public void setTags(List tags) { - this.tags = tags; - } -} 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 d0232bf2f..ef5deb926 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 @@ -9,30 +9,34 @@ */ package org.openmrs.module.webservices.docs.swagger; -import io.swagger.models.Contact; -import io.swagger.models.ExternalDocs; -import io.swagger.models.Info; -import io.swagger.models.License; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.Operation; -import io.swagger.models.Path; -import io.swagger.models.RefModel; -import io.swagger.models.Response; -import io.swagger.models.Scheme; -import io.swagger.models.SecurityRequirement; -import io.swagger.models.Swagger; -import io.swagger.models.auth.BasicAuthDefinition; -import io.swagger.models.parameters.BodyParameter; -import io.swagger.models.parameters.Parameter; -import io.swagger.models.parameters.PathParameter; -import io.swagger.models.parameters.QueryParameter; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.Property; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; -import io.swagger.util.Json; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.Content; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.MediaType; +import io.swagger.v3.core.util.Json; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.UUIDSchema; +import io.swagger.v3.oas.models.parameters.QueryParameter; +import io.swagger.v3.oas.models.servers.Server; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.responses.ApiResponse; +import io.swagger.v3.oas.models.responses.ApiResponses; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.ExternalDocumentation; +import io.swagger.v3.oas.models.Paths; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Level; import org.apache.log4j.LogManager; @@ -42,7 +46,6 @@ import org.openmrs.module.Module; import org.openmrs.module.ModuleFactory; import org.openmrs.module.webservices.docs.SearchHandlerDoc; -import org.openmrs.module.webservices.docs.SearchQueryDoc; import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -54,6 +57,7 @@ import org.openmrs.module.webservices.rest.web.resource.api.SearchParameter; import org.openmrs.module.webservices.rest.web.resource.api.SearchQuery; import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubclassHandler; import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; @@ -62,6 +66,7 @@ import java.io.OutputStream; import java.io.PrintStream; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -72,10 +77,18 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; + +import static org.openmrs.module.webservices.rest.util.ReflectionUtil.getGenericType; +import static org.openmrs.module.webservices.rest.web.representation.Representation.DEFAULT; +import static org.openmrs.module.webservices.rest.web.representation.Representation.FULL; +import static org.openmrs.module.webservices.rest.web.representation.Representation.REF; public class SwaggerSpecificationCreator { - private static Swagger swagger; + private static OpenAPI openAPI; + + private static String cachedJson; private String host; @@ -91,9 +104,11 @@ public class SwaggerSpecificationCreator { PrintStream originalOut; - private QueryParameter subclassTypeParameter = new QueryParameter().name("t") + private Parameter subclassTypeParameter = new Parameter() + .name("t") + .in("query") .description("The type of Subclass Resource to return") - .type("string"); + .schema(new StringSchema()); Map originalLevels = new HashMap(); @@ -122,58 +137,75 @@ public SwaggerSpecificationCreator scheme(Scheme scheme) { return this; } + @io.swagger.v3.oas.annotations.media.Schema (description = "Scheme type for API communication") + public enum Scheme { + @io.swagger.v3.oas.annotations.media.Schema (description = "Hypertext Transfer Protocol") + HTTP, + + @io.swagger.v3.oas.annotations.media.Schema (description = "Hypertext Transfer Protocol Secure") + HTTPS, + + @io.swagger.v3.oas.annotations.media.Schema (description = "WebSocket Protocol") + WS, + + @io.swagger.v3.oas.annotations.media.Schema(description = "WebSocket Secure Protocol") + WSS + } + /** * Regenerate the swagger spec from scratch */ private void BuildJSON() { - synchronized (this) { - log.info("Initiating Swagger specification creation"); - toggleLogs(RestConstants.SWAGGER_LOGS_OFF); - try { - initSwagger(); - addPaths(); - addDefaultDefinitions(); - // addSubclassOperations(); //FIXME uncomment after fixing the method - } - catch (Exception e) { - log.error("Error while creating Swagger specification", e); - } - finally { - toggleLogs(RestConstants.SWAGGER_LOGS_ON); - log.info("Swagger specification creation complete"); - } + log.info("Initiating Swagger specification creation"); + toggleLogs(SwaggerConstants.SWAGGER_LOGS_OFF); + try { + initOpenAPI(); + addPaths(); + addDefaultDefinitions(); + // addSubclassOperations(); //FIXME uncomment after fixing the method + } + catch (Exception e) { + log.error("Error while creating Swagger specification", e); + } + finally { + toggleLogs(SwaggerConstants.SWAGGER_LOGS_ON); } } public String getJSON() { - if (isCached()) { + if (isCached() && cachedJson != null) { log.info("Returning a cached copy of Swagger specification"); - initSwagger(); - } else { - swagger = new Swagger(); - BuildJSON(); + return cachedJson; } - return createJSON(); + + openAPI = new OpenAPI(); + BuildJSON(); + cachedJson = createJSON(); // Cache the JSON string + return cachedJson; } 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))))))); + Components components = openAPI.getComponents(); + components.addSchemas("FetchAll", new ObjectSchema() + .addProperty("results", new ArraySchema() + .items(new ObjectSchema() + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("links", new ArraySchema() + .items(new ObjectSchema() + .addProperty("rel", new StringSchema().example("self")) + .addProperty("uri", new StringSchema().format("uri"))))))); + + openAPI.setComponents(components); } + @SuppressWarnings("unchecked") private void toggleLogs(boolean targetState) { - if (Context.getAdministrationService().getGlobalProperty(RestConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME) + if (Context.getAdministrationService().getGlobalProperty(SwaggerConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME) .equals("true")) { - if (targetState == RestConstants.SWAGGER_LOGS_OFF) { + if (targetState == SwaggerConstants.SWAGGER_LOGS_OFF) { // turn off the log4j loggers List loggers = Collections. list(LogManager.getCurrentLoggers()); loggers.add(LogManager.getRootLogger()); @@ -198,7 +230,7 @@ public void write(int b) { // noop } })); - } else if (targetState == RestConstants.SWAGGER_LOGS_ON) { + } else if (targetState == SwaggerConstants.SWAGGER_LOGS_ON) { List loggers = Collections. list(LogManager.getCurrentLoggers()); loggers.add(LogManager.getRootLogger()); for (Logger logger : loggers) { @@ -211,7 +243,7 @@ public void write(int b) { } } - private void initSwagger() { + private void initOpenAPI() { final Info info = new Info() .version(OpenmrsConstants.OPENMRS_VERSION_SHORT) .title("OpenMRS API Docs") @@ -219,18 +251,17 @@ private void initSwagger() { .contact(new Contact().name("OpenMRS").url("http://openmrs.org")) .license(new License().name("MPL-2.0 w/ HD").url("http://openmrs.org/license")); - swagger + openAPI = new OpenAPI() + .openapi("3.0.0") .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() + .addServersItem(new Server().url(this.host + this.basePath)) + .components(new Components().addSecuritySchemes("basic_auth", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))) + .addSecurityItem(new SecurityRequirement().addList("basic_auth")) + .externalDocs(new ExternalDocumentation() .description("Find more info on REST Module Wiki") .url("https://wiki.openmrs.org/x/xoAaAQ")); + + openAPI.setPaths(new Paths()); } private List getModuleVersions() { @@ -253,7 +284,7 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } break; @@ -264,7 +295,7 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } break; @@ -275,7 +306,7 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID); + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID); } break; @@ -320,7 +351,7 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso } else { try { // to avoid saving data to the database, we pass a null SimpleObject - method.invoke(resourceHandler, null, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, + method.invoke(resourceHandler, null, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } catch (InvocationTargetException e) { @@ -344,7 +375,7 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resourceHandler), new RequestContext()); } @@ -356,8 +387,8 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, - RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resourceHandler), + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, + SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resourceHandler), new RequestContext()); } @@ -369,7 +400,7 @@ RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resource if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, "", + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, "", new RequestContext()); } @@ -381,8 +412,8 @@ RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resource if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, - RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, "", new RequestContext()); + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, + SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, "", new RequestContext()); } break; case purge: @@ -392,7 +423,7 @@ RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resource if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } break; @@ -403,8 +434,8 @@ RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, buildPOSTUpdateSimpleObject(resource if (method == null) { return false; } else { - method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, - RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); + method.invoke(resourceHandler, SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, + SwaggerConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext()); } } return true; @@ -439,13 +470,11 @@ private SimpleObject buildPOSTUpdateSimpleObject(DelegatingResourceHandler re return simpleObject; } - private Path buildFetchAllPath(Path path, + private PathItem buildFetchAllPath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - - Operation getOperation = null; + io.swagger.v3.oas.models.Operation getOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.get, resourceHandler)) { - getOperation = createOperation(resourceHandler, "get", resourceName, null, OperationEnum.get); } @@ -463,10 +492,10 @@ private Path buildFetchAllPath(Path path, return path; } - private Path buildGetWithUUIDPath(Path path, + private PathItem buildGetWithUUIDPath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - Operation getOperation = null; + io.swagger.v3.oas.models.Operation getOperation = null; if (testOperationImplemented(OperationEnum.getWithUUID, resourceHandler)) { if (resourceParentName == null) { @@ -479,15 +508,14 @@ private Path buildGetWithUUIDPath(Path path, } if (getOperation != null) { - path.get(getOperation); + path.setGet(getOperation); } return path; } - private Path buildCreatePath(Path path, + private PathItem buildCreatePath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - - Operation postCreateOperation = null; + io.swagger.v3.oas.models.Operation postCreateOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.postCreate, resourceHandler)) { @@ -502,15 +530,15 @@ private Path buildCreatePath(Path path, } if (postCreateOperation != null) { - path.post(postCreateOperation); + path.setPost(postCreateOperation); } return path; } - private Path buildUpdatePath(Path path, + private PathItem buildUpdatePath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - Operation postUpdateOperation = null; + io.swagger.v3.oas.models.Operation postUpdateOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.postUpdate, resourceHandler)) { @@ -525,15 +553,15 @@ private Path buildUpdatePath(Path path, } if (postUpdateOperation != null) { - path.post(postUpdateOperation); + path.setPost(postUpdateOperation); } return path; } - private Path buildDeletePath(Path path, + private PathItem buildDeletePath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - Operation deleteOperation = null; + io.swagger.v3.oas.models.Operation deleteOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.delete, resourceHandler)) { @@ -548,26 +576,26 @@ private Path buildDeletePath(Path path, } if (deleteOperation != null) { - path.delete(deleteOperation); + path.setDelete(deleteOperation); } return path; } - private Path buildPurgePath(Path path, DelegatingResourceHandler resourceHandler, + private PathItem buildPurgePath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { if (path.getDelete() != null) { // just add optional purge parameter - Operation deleteOperation = path.getDelete(); + io.swagger.v3.oas.models.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); + Parameter purgeParam = new Parameter().name("purge").in("query").schema(new StringSchema()); + deleteOperation.addParametersItem(purgeParam); } else { // create standalone purge operation with required - Operation purgeOperation = null; + io.swagger.v3.oas.models.Operation purgeOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.purge, resourceHandler)) { @@ -582,21 +610,22 @@ private Path buildPurgePath(Path path, DelegatingResourceHandler resourceHand } if (purgeOperation != null) { - path.delete(purgeOperation); + path.setDelete(purgeOperation); } } return path; } - private void addIndividualPath(String resourceParentName, String resourceName, Path path, + private void addIndividualPath(String resourceParentName, String resourceName, PathItem path, String pathSuffix) { - if (!path.getOperations().isEmpty()) { - if (resourceParentName == null) { - swagger.path("/" + resourceName + pathSuffix, path); - } else { - swagger.path("/" + resourceParentName + "/{parent-uuid}/" + resourceName + pathSuffix, path); - } + if (path.getGet() != null || path.getPost() != null || path.getDelete() != null) { + String fullPath = resourceParentName == null ? + "/" + resourceName + pathSuffix : + "/" + resourceParentName + "/{parent-uuid}/" + resourceName + pathSuffix; + + log.debug("Adding path: " + fullPath); + openAPI.getPaths().addPathItem(fullPath, path); } } @@ -622,7 +651,7 @@ private String buildSearchParameterDependencyString(Set depende } private void addSearchOperations(DelegatingResourceHandler resourceHandler, String resourceName, - String resourceParentName, Path getAllPath) { + String resourceParentName, PathItem getAllPath) { if (resourceName == null) { return; } @@ -631,17 +660,27 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S boolean wasNew = false; if (hasSearchHandler || hasDoSearch) { - Operation operation; + io.swagger.v3.oas.models.Operation operation; // query parameter - Parameter q = new QueryParameter().name("q") + Parameter q = new Parameter() + .name("q") + .in("query") .description("The search query") - .type("string"); + .schema(new StringSchema()); - if (getAllPath.getOperations().isEmpty() || getAllPath.getGet() == null) { + if (getAllPath.getGet() == null) { // create search-only operation - operation = new Operation(); - operation.tag(resourceParentName == null ? resourceName : resourceParentName); - operation.produces("application/json").produces("application/xml"); + operation = new io.swagger.v3.oas.models.Operation(); + operation.addTagsItem(resourceParentName == null ? resourceName : resourceParentName); + + // Set the responses using the proper method + ApiResponses responses = new ApiResponses(); + responses.addApiResponse("200", new ApiResponse() + .description(resourceName + " response") + .content(new Content() + .addMediaType("application/json", + new MediaType().schema(new Schema().$ref("#/components/schemas/FetchAll"))))); + operation.setResponses(responses); // if the path has no operations, add a note that at least one search parameter must be specified operation.setSummary("Search for " + resourceName); @@ -650,8 +689,8 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S // 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")); + .schema(new StringSchema() + ._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 @@ -660,12 +699,9 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S } operation.setParameters(buildPagingParameters()); - operation.parameter(v).parameter(q); - operation.addResponse("200", new Response() - .description(resourceName + " response") - .schema(new RefProperty("#/definitions/FetchAll"))); + operation.addParametersItem(v).addParametersItem(q); if (((BaseDelegatingResource) resourceHandler).hasTypesDefined()) { - operation.parameter(subclassTypeParameter); + operation.addParametersItem(subclassTypeParameter); } // since the path has no existing get operations then it is considered new wasNew = true; @@ -673,7 +709,7 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S operation = getAllPath.getGet(); operation.setSummary("Fetch all non-retired " + resourceName + " resources or perform search"); operation.setDescription("All search parameters are optional"); - operation.parameter(q); + operation.addParametersItem(q); } Map parameterMap = new HashMap(); @@ -691,13 +727,13 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S for (SearchQuery searchQuery : searchHandler.getSearchConfig().getSearchQueries()) { // parameters with no dependencies for (SearchParameter requiredParameter : searchQuery.getRequiredParameters()) { - Parameter p = new QueryParameter().type("string"); + Parameter p = new Parameter().in("query").schema(new StringSchema()); p.setName(requiredParameter.getName()); parameterMap.put(requiredParameter.getName(), p); } // parameters with dependencies for (SearchParameter optionalParameter : searchQuery.getOptionalParameters()) { - Parameter p = new QueryParameter().type("string"); + Parameter p = new Parameter().in("query").schema(new StringSchema()); p.setName(optionalParameter.getName()); p.setDescription(buildSearchParameterDependencyString(searchQuery.getRequiredParameters())); parameterMap.put(optionalParameter.getName(), p); @@ -708,7 +744,7 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S } for (Parameter p : parameterMap.values()) { - operation.parameter(p); + operation.addParametersItem(p); } operation.setOperationId("getAll" + getOperationTitle(resourceHandler, true)); @@ -719,177 +755,130 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S } private void addPaths() { + log.debug("Starting addPaths method"); + + if (openAPI.getPaths() == null) { + log.debug("Paths object is null, initializing it"); + openAPI.setPaths(new Paths()); + } + // get all registered resource handlers List> resourceHandlers = Context.getService(RestService.class).getResourceHandlers(); + System.out.println("Number of resource handlers: " + resourceHandlers.size()); + log.debug("Number of resource handlers: " + resourceHandlers.size()); + sortResourceHandlers(resourceHandlers); // generate swagger JSON for each handler for (DelegatingResourceHandler resourceHandler : resourceHandlers) { + try { + // get name and parent if it's a subresource + Resource annotation = resourceHandler.getClass().getAnnotation(Resource.class); - // get name and parent if it's a subresource - Resource annotation = resourceHandler.getClass().getAnnotation(Resource.class); - - String resourceParentName = null; - String resourceName = null; + 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 (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); + if (subResourceAnnotation != null) { + Resource parentResourceAnnotation = subResourceAnnotation.parent().getAnnotation(Resource.class); - resourceName = subResourceAnnotation.path(); - resourceParentName = parentResourceAnnotation.name().substring( - parentResourceAnnotation.name().indexOf('/') + 1); + resourceName = subResourceAnnotation.path(); + resourceParentName = parentResourceAnnotation.name().substring( + 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); - addIndividualPath(resourceParentName, resourceName, rootPathGetAll, ""); - - ///////////////////////// - // GET search // - ///////////////////////// - addSearchOperations(resourceHandler, resourceName, resourceParentName, rootPathGetAll); - - ///////////////////////// - // POST create // - ///////////////////////// - Path rootPathPostCreate = buildCreatePath(rootPathGetAll, resourceHandler, resourceName, - resourceParentName); - addIndividualPath(resourceParentName, resourceName, rootPathPostCreate, ""); - - ///////////////////////// - // GET with UUID // - ///////////////////////// - Path uuidPathGetAll = buildGetWithUUIDPath(uuidPath, resourceHandler, resourceName, - resourceParentName); - addIndividualPath(resourceParentName, resourceName, uuidPathGetAll, "/{uuid}"); - - ///////////////////////// - // POST update // - ///////////////////////// - Path uuidPathPostUpdate = buildUpdatePath(uuidPathGetAll, resourceHandler, resourceName, - resourceParentName); - addIndividualPath(resourceParentName, resourceName, uuidPathPostUpdate, "/{uuid}"); - - ///////////////////////// - // DELETE // - ///////////////////////// - Path uuidPathDelete = buildDeletePath(uuidPathPostUpdate, resourceHandler, resourceName, - resourceParentName); - - ///////////////////////// - // DELETE (purge) // - ///////////////////////// - Path uuidPathPurge = buildPurgePath(uuidPathDelete, resourceHandler, resourceName, - 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(); + log.debug("Processing resource: " + resourceName + (resourceParentName != null ? " (parent: " + resourceParentName + ")" : "")); - // 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()) { - if (properties.get(prop.getKey()) == null) { - properties.put(prop.getKey(), prop.getValue()); + // subclass operations are handled separately in another method + if (resourceHandler instanceof DelegatingSubclassHandler) { + log.debug("Skipping subclass handler for: " + resourceName); + continue; } - } - // 3. update description - post.setDescription("Certain properties may be required depending on type"); - } - } - - @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; + // set up paths + PathItem rootPath = new PathItem(); + PathItem uuidPath = new PathItem(); + + ///////////////////////// + // GET all // + ///////////////////////// + PathItem rootPathGetAll = buildFetchAllPath(rootPath, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, rootPathGetAll, ""); + + ///////////////////////// + // GET search // + ///////////////////////// + addSearchOperations(resourceHandler, resourceName, resourceParentName, rootPathGetAll); + + ///////////////////////// + // POST create // + ///////////////////////// + PathItem rootPathPostCreate = buildCreatePath(rootPathGetAll, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, rootPathPostCreate, ""); + + ///////////////////////// + // GET with UUID // + ///////////////////////// + PathItem uuidPathGetAll = buildGetWithUUIDPath(uuidPath, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, uuidPathGetAll, "/{uuid}"); + + ///////////////////////// + // POST update // + ///////////////////////// + PathItem uuidPathPostUpdate = buildUpdatePath(uuidPathGetAll, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, uuidPathPostUpdate, "/{uuid}"); + + ///////////////////////// + // DELETE // + ///////////////////////// + PathItem uuidPathDelete = buildDeletePath(uuidPathPostUpdate, resourceHandler, resourceName, + resourceParentName); + + ///////////////////////// + // DELETE (purge) // + ///////////////////////// + PathItem uuidPathPurge = buildPurgePath(uuidPathDelete, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, uuidPathPurge, "/{uuid}"); + + // After building all paths for a resource, log the number of operations + log.debug("Added " + (rootPath.readOperations().size() + uuidPath.readOperations().size()) + " operations for resource: " + resourceName); + } catch (Exception e) { + log.error("Error processing resource handler: " + resourceHandler.getClass().getName(), e); } } - return parameters; + + // After processing all resources, log the total number of paths + log.debug("Finished addPaths method. Total paths: " + (openAPI.getPaths() != null ? openAPI.getPaths().size() : 0)); } private String createJSON() { - return Json.pretty(swagger); + return Json.pretty(openAPI); } private Parameter buildRequiredUUIDParameter(String name, String desc) { - return new PathParameter().name(name).description(desc).type("string"); + return new Parameter().name(name).description(desc).schema(new StringSchema()).in("path").required(true); } private List buildPagingParameters() { List params = new ArrayList(); - Parameter limit = new QueryParameter().name("limit") - .description("The number of results to return").type("integer"); + Parameter limit = new Parameter().name("limit") + .description("The number of results to return").schema(new IntegerSchema()).in("query"); - Parameter startIndex = new QueryParameter().name("startIndex") - .description("The offset at which to start").type("integer"); + Parameter startIndex = new Parameter().name("startIndex") + .description("The offset at which to start").schema(new IntegerSchema()).in("query"); params.add(limit); params.add(startIndex); @@ -899,22 +888,19 @@ private List buildPagingParameters() { private Parameter buildPOSTBodyParameter(String resourceName, String resourceParentName, OperationEnum operationEnum) { - BodyParameter bodyParameter = new BodyParameter(); - bodyParameter.setRequired(true); + Parameter bodyParameter = new Parameter().name("resource").description("Resource to create").in("body").required(true); switch (operationEnum) { case postCreate: case postSubresource: - bodyParameter.setName("resource"); bodyParameter.setDescription("Resource to create"); break; case postUpdate: case postUpdateSubresouce: - bodyParameter.setName("resource"); bodyParameter.setDescription("Resource properties to update"); } - bodyParameter.schema(new RefModel(getSchemaRef(resourceName, resourceParentName, operationEnum))); + bodyParameter.setSchema(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, operationEnum))); return bodyParameter; } @@ -959,7 +945,7 @@ private String getSchemaName(String resourceName, String resourceParentName, Ope } private String getSchemaRef(String resourceName, String resourceParentName, OperationEnum operationEnum) { - return "#/definitions/" + getSchemaName(resourceName, resourceParentName, operationEnum); + return "#/components/schemas/" + getSchemaName(resourceName, resourceParentName, operationEnum); } private String getOperationTitle(DelegatingResourceHandler resourceHandler, Boolean pluralize) { @@ -990,193 +976,239 @@ private String getOperationTitle(DelegatingResourceHandler resourceHandler, B return ret.toString(); } + /** + * Creates and adds schema definitions to the OpenAPI components for a given resource and operation. + * + * @param operationEnum The type of operation (GET, CREATE, UPDATE) + * @param resourceName The name of the resource + * @param resourceParentName The name of the parent resource (if applicable, can be null) + * @param resourceHandler The DelegatingResourceHandler for the resource + * + * @throws IllegalArgumentException if operationEnum, resourceName, or resourceHandler is null + *

+ * This method performs the following tasks: + * 1. Generates a schema name based on the resource and operation type + * 2. Retrieves or creates the Components object from the OpenAPI specification + * 3. Based on the operation type (Get, Create, or Update): + * - Generates the appropriate schema(s) using the OpenMRSOpenAPIGenerator + * - Adds the schema(s) to the Components object with the generated name + *

+ * For GET operations, it adds schemas for DEFAULT, REF, and FULL representations. + * For CREATE operations, it adds schemas for DEFAULT and FULL representations. + * For UPDATE operations, it adds a schema for the DEFAULT representation. + * + * The method ensures that only non-null schemas are added to the components. + */ private void createDefinition(OperationEnum operationEnum, String resourceName, String resourceParentName, DelegatingResourceHandler resourceHandler) { + if (operationEnum == null || resourceName == null || resourceHandler == null) { + throw new IllegalArgumentException("Operation, resource name, and resource handler must not be null"); + } 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); - modelFull = resourceHandler.getGETModel(Representation.FULL); - } else if (definitionName.endsWith("Create")) { - model = resourceHandler.getCREATEModel(Representation.DEFAULT); - modelFull = resourceHandler.getCREATEModel(Representation.FULL); - } else if (definitionName.endsWith("Update")) { - model = resourceHandler.getUPDATEModel(Representation.DEFAULT); + System.out.println("definition-name:" + definitionName); + Components components = openAPI.getComponents(); + if (components == null) { + components = new Components(); + openAPI.setComponents(components); } - if (model != null) { - swagger.addDefinition(definitionName, model); - } - if (modelRef != null) { - swagger.addDefinition(definitionName + "Ref", modelRef); - } - if (modelFull != null) { - swagger.addDefinition(definitionName + "Full", modelFull); + if (definitionName.endsWith("Get")) { + Schema getSchema = generateGETSchema(resourceHandler, Representation.DEFAULT); + Schema getRefSchema = generateGETSchema(resourceHandler, Representation.REF); + Schema getFullSchema = generateGETSchema(resourceHandler, Representation.FULL); + + if (getSchema != null) { + components.addSchemas(definitionName, getSchema); + } + if (getRefSchema != null) { + components.addSchemas(definitionName + "Ref", getRefSchema); + } + if (getFullSchema != null) { + components.addSchemas(definitionName + "Full", getFullSchema); + } + } else if (definitionName.endsWith("Create")) { + Schema createSchema = generateCREATESchema(resourceHandler, Representation.DEFAULT); + Schema createFullSchema = generateCREATESchema(resourceHandler, FULL); + + if (createSchema != null) { + components.addSchemas(definitionName, createSchema); + } + if (createFullSchema != null) { + components.addSchemas(definitionName + "Full", createFullSchema); + } + } else if (definitionName.endsWith("Update")) { + Schema updateSchema = generateUPDATESchema(resourceHandler, Representation.DEFAULT); + if (updateSchema != null) { + components.addSchemas(definitionName, updateSchema); + } } } /** - * @param resourceHandler - * @param operationName get, post, delete - * @param resourceName - * @param resourceParentName - * @param representation - * @param operationEnum - * @return + * Creates an OpenAPI Operation object for a given resource and operation type. + * + * @param resourceHandler The DelegatingResourceHandler for the resource + * @param operationName The name of the operation (e.g., "get", "post") + * @param resourceName The name of the resource + * @param resourceParentName The name of the parent resource (if applicable, null otherwise) + * @param operationEnum The type of operation (from OperationEnum) + * @return An OpenAPI Operation object describing the API endpoint */ private Operation createOperation(DelegatingResourceHandler resourceHandler, String operationName, String resourceName, String resourceParentName, OperationEnum operationEnum) { Operation operation = new Operation() - .tag(resourceParentName == null ? resourceName : resourceParentName) - .consumes("application/json").produces("application/json"); + .addTagsItem(resourceParentName == null ? resourceName : resourceParentName); // create definition - if (operationName.equals("post") || operationName.equals("get") ) { + if (operationName.equals("post") || operationName.equals("get")) { createDefinition(operationEnum, resourceName, resourceParentName, resourceHandler); } // create all possible responses + ApiResponses responses = new ApiResponses(); + // 200 response (Successful operation) - Response response200 = new Response().description(resourceName + " response"); + ApiResponse response200 = new ApiResponse().description(resourceName + " response"); // 201 response (Successfully created) - Response response201 = new Response().description(resourceName + " response"); + ApiResponse response201 = new ApiResponse().description(resourceName + " response"); // 204 delete success - Response response204 = new Response().description("Delete successful"); + ApiResponse response204 = new ApiResponse().description("Delete successful"); // 401 response (User not logged in) - Response response401 = new Response().description("User not logged in"); + ApiResponse response401 = new ApiResponse().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"); + ApiResponse response404 = new ApiResponse().description("Resource with given uuid doesn't exist"); // create all possible query params // representations query parameter - Parameter v = new QueryParameter().name("v") + 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")); + .schema(new StringSchema()._enum(Arrays.asList("ref", "default", "full", "custom"))); - if (operationEnum == OperationEnum.get) { + switch (operationEnum) { + case get: + operation.summary("Fetch all non-retired") + .operationId("getAll" + getOperationTitle(resourceHandler, true)); + response200.content(new Content().addMediaType("application/json", + new MediaType().schema(new ArraySchema().items(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))))); + responses.addApiResponse("200", response200); + + operation.parameters(buildPagingParameters()); + operation.addParametersItem(v); + if (((BaseDelegatingResource) resourceHandler).hasTypesDefined()) { + operation.addParametersItem(subclassTypeParameter); + } + break; - 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))))); - - operation.setParameters(buildPagingParameters()); - operation.parameter(v); - if (((BaseDelegatingResource) resourceHandler).hasTypesDefined()) { - operation.parameter(subclassTypeParameter); - } + case getWithUUID: + operation.summary("Fetch by uuid") + .operationId("get" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(v); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to filter by")); + response200.content(new Content().addMediaType("application/json", + new MediaType().schema(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, OperationEnum.get))))); + responses.addApiResponse("200", response200); + responses.addApiResponse("404", response404); + break; - } else if (operationEnum == OperationEnum.getWithUUID) { + case postCreate: + operation.summary("Create with properties in request") + .operationId("create" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postCreate)); + responses.addApiResponse("201", response201); + break; - 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)))); - operation.addResponse("404", response404); + case postUpdate: + operation.summary("Edit with given uuid, only modifying properties in request") + .operationId("update" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid of resource to update")); + operation.addParametersItem(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdate)); + responses.addApiResponse("201", response201); + break; - } else if (operationEnum == OperationEnum.postCreate) { + case getSubresource: + operation.summary("Fetch all non-retired " + resourceName + " subresources") + .operationId("getAll" + getOperationTitle(resourceHandler, true)); + operation.parameters(buildPagingParameters()); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(v); + response200.content(new Content().addMediaType("application/json", + new MediaType().schema(new ObjectSchema() + .addProperty("results", new ArraySchema() + .items(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, OperationEnum.get))))))); + responses.addApiResponse("200", response200); + break; + + case postSubresource: + operation.summary("Create " + resourceName + " subresource with properties in request") + .operationId("create" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postSubresource)); + responses.addApiResponse("201", response201); + break; + + case postUpdateSubresouce: + operation.summary("edit " + resourceName + " subresource with given uuid, only modifying properties in request") + .operationId("update" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid of resource to update")); + operation.addParametersItem(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdateSubresouce)); + responses.addApiResponse("201", response201); + break; - operation.setSummary("Create with properties in request"); - operation.setOperationId("create" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postCreate)); - operation.addResponse("201", response201); + case getSubresourceWithUUID: + operation.summary("Fetch " + resourceName + " subresources by uuid") + .operationId("get" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to filter by")); + operation.addParametersItem(v); + response200.content(new Content().addMediaType("application/json", + new MediaType().schema(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, OperationEnum.getSubresourceWithUUID))))); + responses.addApiResponse("200", response200); + responses.addApiResponse("404", response404); + break; - } else if (operationEnum == OperationEnum.postUpdate) { + case delete: + operation.summary("Delete resource by uuid") + .operationId("delete" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to delete")); + responses.addApiResponse("204", response204); + responses.addApiResponse("404", response404); + break; - 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); + case deleteSubresource: + operation.summary("Delete " + resourceName + " subresource by uuid") + .operationId("delete" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to delete")); + responses.addApiResponse("204", response204); + responses.addApiResponse("404", response404); + break; - } else if (operationEnum == OperationEnum.getSubresource) { + case purge: + operation.summary("Purge resource by uuid") + .operationId("purge" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to delete")); + responses.addApiResponse("204", response204); + break; - 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)))))); - - } 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"); - 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)); - operation.addResponse("201", response201); - - } else if (operationEnum == OperationEnum.getSubresourceWithUUID) { - operation.setSummary("Fetch " + resourceName + " subresources by uuid"); - operation.setOperationId("get" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to filter by")); - operation.parameter(v); - operation.addResponse("200", response200.schema(new RefProperty(getSchemaRef(resourceName, resourceParentName, - 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)); - operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); - 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); + case purgeSubresource: + operation.summary("Purge " + resourceName + " subresource by uuid") + .operationId("purge" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to delete")); + responses.addApiResponse("204", response204); + break; } - operation.response(401, response401); + responses.addApiResponse("401", response401); + operation.responses(responses); return operation; } @@ -1222,19 +1254,281 @@ public String getBaseUrl() { return baseUrl; } - public Swagger getSwagger() { - return swagger; + public OpenAPI getOpenAPI() { + if (openAPI == null) { + log.debug("OpenAPI object is null, creating new specification"); + BuildJSON(); + } + return openAPI; } /** - * @return true if and only if swagger is not null, and its paths are also set. + * @return true if and only if openAPI is not null, and its paths are also set. */ public static boolean isCached() { - return swagger != null && swagger.getPaths() != null; + return openAPI != null && + openAPI.getPaths() != null && + !openAPI.getPaths().isEmpty(); } public static void clearCache() { - swagger = null; + openAPI = null; + cachedJson = null; + } + + /** + * Generates the schema for GET operations. + * + * @param resourceHandler the resource handler for the resource + * @param representation the representation type (DEFAULT, REF, FULL) + * @return the generated schema + * @throws IllegalArgumentException if the representation is unsupported + */ + public Schema generateGETSchema(DelegatingResourceHandler resourceHandler, Representation representation) { + ObjectSchema schema = new ObjectSchema(); + + if (representation.equals(DEFAULT)) { + schema = addDefaultProperties(resourceHandler); + } else if (representation.equals(REF)) { + schema = addRefProperties(resourceHandler); + } else if (representation.equals(FULL)) { + schema = addFullProperties(resourceHandler); + } else { + throw new IllegalArgumentException("Unsupported representation: " + representation); + } + + return schema; + } + + /** + * Generates the schema for CREATE operations. + * + * @param resourceHandler the resource handler for the resource + * @param representation the representation type (DEFAULT, FULL) + * @return the generated schema + * @throws IllegalArgumentException if the representation is unsupported + */ + public Schema generateCREATESchema(DelegatingResourceHandler resourceHandler, Representation representation) { + ObjectSchema schema = new ObjectSchema(); + + if (representation.equals(DEFAULT)) { + schema = addCreatableProperties(resourceHandler, "Create"); + } else if (representation.equals(FULL)) { + schema = addCreatableProperties(resourceHandler, "CreateFull"); + } else { + throw new IllegalArgumentException("Unsupported representation: " + representation); + } + + return schema; + } + + /** + * Generates the schema for UPDATE operations. + * + * @param resourceHandler the resource handler for the resource + * @param representation the representation type (DEFAULT) + * @return the generated schema + * @throws IllegalArgumentException if the representation is unsupported + */ + public Schema generateUPDATESchema(DelegatingResourceHandler resourceHandler, Representation representation) { + ObjectSchema schema = new ObjectSchema(); + + if (representation.equals(DEFAULT)) { + schema = addUpdatableProperties(resourceHandler); + } else { + throw new IllegalArgumentException("Unsupported representation: " + representation); + } + + return schema; + } + + /** + * Adds default properties to the schema based on the resource handler's DEFAULT representation. + * + * @param resourceHandler the resource handler for the resource + * @return the updated schema with default properties + */ + private ObjectSchema addDefaultProperties(DelegatingResourceHandler resourceHandler) { + ObjectSchema schema = new ObjectSchema(); + schema.addProperty("uuid", new UUIDSchema().description("Unique identifier of the resource")); + schema.addProperty("display", new StringSchema().description("Display name of the resource")); + + DelegatingResourceDescription description = resourceHandler.getRepresentationDescription(DEFAULT); + if (description != null) { + for (String property : description.getProperties().keySet()) { + schema.addProperty(property, determineSchemaForProperty(resourceHandler, property, "Get")); + } + } + + return schema; + } + + /** + * Adds reference properties to the schema based on the resource handler's REF representation. + * + * @param resourceHandler the resource handler for the resource + * @return the updated schema with reference properties + */ + private ObjectSchema addRefProperties(DelegatingResourceHandler resourceHandler) { + ObjectSchema schema = new ObjectSchema(); + schema.addProperty("uuid", new UUIDSchema().description("Unique identifier of the resource")); + schema.addProperty("display", new StringSchema().description("Display name of the resource")); + + DelegatingResourceDescription description = resourceHandler.getRepresentationDescription(REF); + if (description != null) { + for (String property : description.getProperties().keySet()) { + schema.addProperty(property, determineSchemaForProperty(resourceHandler, property, "GetRef")); + } + } + + return schema; + } + + /** + * Adds full properties to the schema based on the resource handler's FULL representation. + * + * @param resourceHandler the resource handler for the resource + * @return the updated schema with full properties + */ + private ObjectSchema addFullProperties(DelegatingResourceHandler resourceHandler) { + ObjectSchema schema = new ObjectSchema(); + + DelegatingResourceDescription description = resourceHandler.getRepresentationDescription(FULL); + if (description != null) { + for (String property : description.getProperties().keySet()) { + schema.addProperty(property, determineSchemaForProperty(resourceHandler, property, "GetFull")); + } + } + + return schema; + } + + /** + * Adds creatable properties to the schema based on the resource handler's creatable properties. + * + * @param resourceHandler the resource handler for the resource + * @return the updated schema with creatable properties + */ + private ObjectSchema addCreatableProperties(DelegatingResourceHandler resourceHandler, String operationType) { + ObjectSchema schema = new ObjectSchema(); + + DelegatingResourceDescription description = resourceHandler.getCreatableProperties(); + if (description != null) { + for (String property : description.getProperties().keySet()) { + schema.addProperty(property, determineSchemaForProperty(resourceHandler, property, operationType)); + } + } + + return schema; + } + + /** + * Adds updatable properties to the schema based on the resource handler's updatable properties. + * + * @param resourceHandler the resource handler for the resource + * @return the updated schema with updatable properties + */ + private ObjectSchema addUpdatableProperties(DelegatingResourceHandler resourceHandler) { + ObjectSchema schema = new ObjectSchema(); + + DelegatingResourceDescription description = resourceHandler.getUpdatableProperties(); + if (description != null) { + for (String property : description.getProperties().keySet()) { + schema.addProperty(property, determineSchemaForProperty(resourceHandler, property, "Update")); + } + } + + return schema; + } + + /** + * determines the schema for a property based on the resource handler and property name. + * + * @param resourceHandler the resource handler for the resource + * @param propertyName the name of the property + * @return the schema for the property + */ + public Schema determineSchemaForProperty(DelegatingResourceHandler resourceHandler, String propertyName, String operationType) { + Class genericType = getGenericType(resourceHandler.getClass()); + if (genericType == null) { + //FIXME: need to handle cases where resource handler doesn't extend directly + // but instead extend another resource-handler e.g public class UserResource2_0 extends UserResource1_8 + throw new IllegalArgumentException("No generic type for resource handler"); + } + + try { + Field field = genericType.getDeclaredField(propertyName); + Class fieldType = field.getType(); + return createSchemaForType(fieldType, operationType, field); + } catch (NoSuchFieldException e) { + return new StringSchema().description("unknown"); + } + } + + /** + *

+ * This method maps Java types to their corresponding OpenAPI schema types. For example, it converts + * Java primitives and common types (like {@link String}, {@link Integer}, and {@link UUID}) into + * their OpenAPI equivalents (e.g., {@code StringSchema}, {@code IntegerSchema}). It also handles + * arrays, dates, and custom OpenMRS resource types by referencing specific schema definitions in + * OpenAPI components. + *

+ * If the provided class is a custom OpenMRS data object (e.g., `Concept`, `Patient`), the method + * generates a reference schema (`$ref`) pointing to the corresponding OpenAPI component, using + * the class name and the specified operation type (e.g., `ConceptCreate` or `ConceptGet`). + * + * @param type the Java class type to generate the schema for + * (e.g., {@link String}, {@link Integer}, {@link Boolean}, custom OpenMRS objects) + * @param operationType the type of operation (e.g., "Create", "Get", "Update") + * used to distinguish schema variants for different API operations + * @param field + * @return a {@link Schema} object representing the OpenAPI schema for the provided type + * @throws IllegalArgumentException if an unsupported type is encountered + *

+ * Example: + * - For {@link String}, returns a {@code StringSchema}. + * - For {@link UUID}, returns a {@code UUIDSchema}. + * - For `Concept` with operationType="Create", returns a schema with + * {@code $ref: "#/components/schemas/ConceptCreate"}. + */ + @SuppressWarnings("unchecked") + private Schema createSchemaForType(Class type, String operationType, Field field) { + if (String.class.equals(type)) { + return new StringSchema(); + } else if (Integer.class.equals(type) || int.class.equals(type)) { + return new IntegerSchema(); + } else if (Boolean.class.equals(type) || boolean.class.equals(type)) { + return new BooleanSchema(); + } else if (UUID.class.equals(type)) { + return new UUIDSchema(); + } else if (java.util.Date.class.equals(type)) { + return new DateSchema(); + } else if (Double.class.equals(type)) { + return new NumberSchema().format("double"); + } else if (Object.class.equals(type)) { + return new ObjectSchema(); + } else if (Set.class.equals(type)) { + return new ArraySchema().items(new Schema().$ref("#/components/schemas/" + field.getName() + operationType)); + } + + // Handle references to other OpenMRS data objects e.g PatientResource references Person i.e #/components/schemas/PersonGet + else if (isOpenMRSResource(type)) { + return new Schema().$ref("#/components/schemas/" + field.getName() + operationType); + } else if (isOpenMRSResource(type) && type.isEnum()) { + return new Schema().type("string")._enum(Arrays.asList(type)); + } else { + return new ObjectSchema(); + } + } + + /** + * Checks whether a class is an OpenMRS resource (e.g., references an OpenMRS data object). + * + * @param type the class to check + * @return true if the class represents an OpenMRS resource, false otherwise + */ + private boolean isOpenMRSResource(Class type) { + return type.getPackage().getName().startsWith("org.openmrs"); } -} +} \ No newline at end of file diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/core/property/EnumProperty.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/core/property/EnumProperty.java deleted file mode 100644 index 35348dee1..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/core/property/EnumProperty.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger.core.property; - -import io.swagger.models.properties.StringProperty; - -import java.util.Arrays; -import java.util.List; - -public class EnumProperty extends StringProperty { - - public EnumProperty(Class> e) { - _enum(getEnumsAsList(e)); - } - - private List getEnumsAsList(Class> e) { - return Arrays.asList(getEnums(e)); - } - - private String[] getEnums(Class> e) { - return Arrays.toString(e.getEnumConstants()) - .replaceAll("^.|.$", "").split(", "); - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/util/ReflectionUtil.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/util/ReflectionUtil.java index 4c6eced5b..b8265ec68 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/util/ReflectionUtil.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/util/ReflectionUtil.java @@ -147,5 +147,51 @@ public static Method findMethod(Class clazz, String name) { throw new RuntimeException("No suitable method \"" + name + "\" in " + clazz); return ret; } - + + /** + * Extracts the generic type parameter from a specified class or its superclasses + * that implement a parameterized interface or extend a parameterized class. + *

+ * This method works by checking the current class for parameterized interfaces + * or superclasses. If the current class does not have a generic type, the method + * traverses up the class hierarchy until it finds one or reaches the top of the hierarchy. + *

+ * @param resourceHandlerClass the class implementing or extending a parameterized type + * @return the Class representing the generic type, or null if it cannot be determined + */ + public static Class getGenericType(Class resourceHandlerClass) { + Class currentClass = resourceHandlerClass; + + while (currentClass != null) { + // If the current class implements a parameterized interface, extract the generic type + Type[] genericInterfaces = currentClass.getGenericInterfaces(); + for (Type genericInterface : genericInterfaces) { + if (genericInterface instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) genericInterface; + Type[] typeArguments = parameterizedType.getActualTypeArguments(); + + if (typeArguments.length > 0 && typeArguments[0] instanceof Class) { + return (Class) typeArguments[0]; + } + } + } + + // If the current class has a parameterized superclass, extract the generic type + Type genericSuperclass = currentClass.getGenericSuperclass(); + if (genericSuperclass instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass; + Type[] typeArguments = parameterizedType.getActualTypeArguments(); + + if (typeArguments.length > 0 && typeArguments[0] instanceof Class) { + return (Class) typeArguments[0]; + } + } + + currentClass = currentClass.getSuperclass(); + } + + return null; + } + + } diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/DynamicBeanConfiguration.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/DynamicBeanConfiguration.java index 346716cf9..2b2cf2d93 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/DynamicBeanConfiguration.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/DynamicBeanConfiguration.java @@ -13,9 +13,7 @@ import java.util.Arrays; import java.util.List; -import org.openmrs.api.APIException; import org.openmrs.api.context.Context; -import org.openmrs.api.context.ServiceContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestConstants.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestConstants.java index e2a204ae7..99f2a978e 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestConstants.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/RestConstants.java @@ -190,17 +190,6 @@ public class RestConstants { SPECIAL_REQUEST_PARAMETERS.add(REQUEST_PROPERTY_FOR_SEARCH_ID); SPECIAL_REQUEST_PARAMETERS.add(REQUEST_PROPERTY_FOR_TYPE); } - - /** - * Constants used when generating the Swagger specification - */ - public static String SWAGGER_IMPOSSIBLE_UNIQUE_ID = "a--b"; - - public static String SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME = MODULE_ID + ".quietDocs"; - - public static boolean SWAGGER_LOGS_ON = true; - - public static boolean SWAGGER_LOGS_OFF = false; /** * Constants used for the Server Log REST Service privilege checking diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingConverter.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingConverter.java index 2f510d606..2a7e03252 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingConverter.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingConverter.java @@ -43,7 +43,7 @@ public abstract class BaseDelegatingConverter implements Converter, Delega /** * Gets the {@link DelegatingResourceDescription} for the given representation for this * resource, if it exists - * + * * @param rep * @return */ diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java index 179b0327a..7841f947b 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java @@ -42,8 +42,6 @@ import org.openmrs.module.webservices.rest.web.annotation.SubClassHandler; import org.openmrs.module.webservices.rest.web.api.RestService; import org.openmrs.module.webservices.rest.web.representation.CustomRepresentation; -import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; -import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; import org.openmrs.module.webservices.rest.web.representation.NamedRepresentation; import org.openmrs.module.webservices.rest.web.representation.RefRepresentation; import org.openmrs.module.webservices.rest.web.representation.Representation; @@ -56,53 +54,19 @@ import org.openmrs.util.OpenmrsConstants; import org.openmrs.util.OpenmrsUtil; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.StringProperty; - /** * A base implementation of a resource or sub-resource that delegates operations to a wrapped * object. Implementations generally should extend either {@link DelegatingCrudResource} or * {@link DelegatingSubResource} rather than this class directly. - * + * * @param the class we're delegating to */ public abstract class BaseDelegatingResource extends BaseDelegatingConverter implements Converter, Resource, DelegatingResourceHandler { - + private final Log log = LogFactory.getLog(getClass()); - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = new ModelImpl(); - if (rep instanceof DefaultRepresentation) { - model - .property("links", new ArrayProperty() - .items(new ObjectProperty() - .property("rel", new StringProperty().example("self|full")) - .property("uri", new StringProperty(StringProperty.Format.URI)))); - - } else if (rep instanceof FullRepresentation) { - model - .property("auditInfo", new StringProperty()) - .property("links", new ArrayProperty() - .items(new ObjectProperty() - .property("rel", new StringProperty()).example("self") - .property("uri", new StringProperty(StringProperty.Format.URI)))); - - } else if (rep instanceof RefRepresentation) { - model - .property("links", new ArrayProperty() - .items(new ObjectProperty() - .property("rel", new StringProperty().example("self")) - .property("uri", new StringProperty(StringProperty.Format.URI)))); - } - return model; - } - - protected Set propertiesIgnoredWhenUpdating = new HashSet(); - + + protected Set propertiesIgnoredWhenUpdating = new HashSet(); + /** * Properties that should silently be ignored if you try to get them. Implementations should * generally configure this property with a list of properties that were added to their @@ -111,13 +75,13 @@ public Model getGETModel(Representation rep) { * wasn't added to PatientIdentifierType until OpenMRS 1.9. delegate class */ protected Set allowedMissingProperties = new HashSet(); - + /** * If this resource represents a class hierarchy (rather than a single class), this will hold * handlers for each subclass */ protected volatile List> subclassHandlers; - + /** * Default constructor will set propertiesIgnoredWhenUpdating to include "display", "links", and * "resourceVersion" @@ -128,18 +92,18 @@ protected BaseDelegatingResource() { propertiesIgnoredWhenUpdating.add("auditInfo"); propertiesIgnoredWhenUpdating.add(RestConstants.PROPERTY_FOR_RESOURCE_VERSION); } - + /** * All our resources support letting modules register subclass handlers. If any are registered, * then the resource represents a class hierarchy, e.g. requiring a "type" parameter when * creating a new instance. - * + * * @return whether there are any subclass handlers registered with this resource */ public boolean hasTypesDefined() { return subclassHandlers != null && subclassHandlers.size() > 0; } - + /** * This will be automatically called with the first call to {@link #getSubclassHandler(Class)} * or {@link #getSubclassHandler(String)}. It finds all subclass handlers intended for this @@ -148,21 +112,21 @@ public boolean hasTypesDefined() { @SuppressWarnings({ "unchecked", "rawtypes" }) public void init() { List> tmpSubclassHandlers = new ArrayList>(); - + List handlers = Context.getRegisteredComponents(DelegatingSubclassHandler.class); for (DelegatingSubclassHandler handler : handlers) { - + Class handlerClass = handler.getClass(); Class forDelegateClass = ReflectionUtil.getParameterizedTypeFromInterface(handlerClass, - DelegatingSubclassHandler.class, 0); + DelegatingSubclassHandler.class, 0); if (forDelegateClass == null) { throw new IllegalStateException( - "Could not determine type information. Make sure that " - + handlerClass.getName() - + " explicitly says implements DelegatingSubclassHandler<...>. It is not sufficient to just extend a base class that implements this."); + "Could not determine type information. Make sure that " + + handlerClass.getName() + + " explicitly says implements DelegatingSubclassHandler<...>. It is not sufficient to just extend a base class that implements this."); } Resource resourceForHandler = Context.getService(RestService.class) - .getResourceBySupportedClass(forDelegateClass); + .getResourceBySupportedClass(forDelegateClass); if (getClass().equals(resourceForHandler.getClass())) { SubClassHandler annotation = handlerClass.getAnnotation(SubClassHandler.class); if (annotation != null) { @@ -175,18 +139,18 @@ public void init() { } } else { log.warn("SubclassHandler " - + handlerClass.getName() - + " does not have a @SubClassHandler annotation. This can cause conflicts in resolving handlers for your subclass."); + + handlerClass.getName() + + " does not have a @SubClassHandler annotation. This can cause conflicts in resolving handlers for your subclass."); } } } - + subclassHandlers = tmpSubclassHandlers; } - + /** * Registers the given subclass handler. - * + * * @param handler */ public void registerSubclassHandler(DelegatingSubclassHandler handler) { @@ -201,7 +165,7 @@ public void registerSubclassHandler(DelegatingSubclassHandler ha } subclassHandlers.add(handler); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getResourceVersion() */ @@ -209,22 +173,22 @@ public void registerSubclassHandler(DelegatingSubclassHandler ha public String getResourceVersion() { return RestConstants.PROPERTY_FOR_RESOURCE_VERSION_DEFAULT_VALUE; } - + /** * @return the value of the {@link org.openmrs.module.webservices.rest.web.annotation.Resource} * annotation on the concrete subclass */ protected String getResourceName() { org.openmrs.module.webservices.rest.web.annotation.Resource ann = getClass().getAnnotation( - org.openmrs.module.webservices.rest.web.annotation.Resource.class); + org.openmrs.module.webservices.rest.web.annotation.Resource.class); if (ann == null) throw new RuntimeException("There is no " + Resource.class + " annotation on " + getClass()); if (StringUtils.isEmpty(ann.name())) throw new RuntimeException(Resource.class.getSimpleName() + " annotation on " + getClass() - + " must specify a name"); + + " must specify a name"); return ann.name(); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#newInstance(java.lang.String) */ @@ -233,67 +197,67 @@ public T newInstance(String type) { if (hasTypesDefined()) { if (type == null) throw new IllegalArgumentException(getClass().getSimpleName() + " requires a '" - + RestConstants.PROPERTY_FOR_TYPE + "' property to create a new object"); + + RestConstants.PROPERTY_FOR_TYPE + "' property to create a new object"); DelegatingResourceHandler handler = getResourceHandler(type); return handler.newDelegate(); } else { return newDelegate(); } } - + /** * Gets the delegate object with the given unique id. Implementations may decide whether * "unique id" means a uuid, or if they also want to retrieve delegates based on a unique * human-readable property. - * + * * @param uniqueId * @return the delegate for the given uniqueId */ @Override public abstract T getByUniqueId(String uniqueId); - + /** * Void or retire delegate, whichever action is appropriate for the resource type. Subclasses * need to override this method, which is called internally by * {@link #delete(String, String, RequestContext)}. - * + * * @param delegate * @param reason * @param context * @throws ResponseException */ protected abstract void delete(T delegate, String reason, RequestContext context) throws ResponseException; - + /** * Unvoid or unretire delegate, whichever action is appropriate for the resource type. * Subclasses need to override this method, which is called internally by * {@link #undelete(String, RequestContext)}. - * + * * @param delegate * @param context * @throws ResponseException * @return Object */ protected T undelete(T delegate, RequestContext context) throws ResponseException { - //Default implementation of this method if not overriden by sub-class is to raise an + //Default implementation of this method if not overriden by sub-class is to raise an //exception stating "undelete action not yet supported for this resource" throw new ResourceDoesNotSupportOperationException("undelete action not yet supported for this resource"); } - + /** * Purge delegate from persistent storage. Subclasses need to override this method, which is * called internally by {@link #purge(String, RequestContext)}. - * + * * @param delegate * @param context * @throws ResponseException */ @Override public abstract void purge(T delegate, RequestContext context) throws ResponseException; - + /** * Gets a description of resource's properties which can be set on creation. - * + * * @return the description * @throws ResponseException */ @@ -301,18 +265,13 @@ protected T undelete(T delegate, RequestContext context) throws ResponseExceptio public DelegatingResourceDescription getCreatableProperties() throws ResourceDoesNotSupportOperationException { throw new ResourceDoesNotSupportOperationException(); } - - @Override - public Model getCREATEModel(Representation rep) { - return null; - } - + /** * Gets a description of resource's properties which can be edited. *

* By default delegates to {@link #getCreatableProperties()} and removes sub-resources returned * by {@link #getPropertiesToExposeAsSubResources()}. - * + * * @return the description * @throws ResponseException */ @@ -324,29 +283,20 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } return description; } - - @Override - public Model getUPDATEModel(Representation rep) { - ModelImpl model = (ModelImpl) getCREATEModel(rep); - for (String property : getPropertiesToExposeAsSubResources()) { - model.getProperties().remove(property); - } - return model; - } - + /** * Implementations should override this method if they support sub-resources - * + * * @return a list of properties available as sub-resources or an empty list */ public List getPropertiesToExposeAsSubResources() { return Collections.emptyList(); } - + /** * Implementations should override this method if T is not uniquely identified by a "uuid" * property. - * + * * @param delegate * @return the uuid property of delegate */ @@ -358,11 +308,11 @@ protected String getUniqueId(T delegate) { throw new RuntimeException("Cannot find String uuid property on " + delegate.getClass(), null); } } - + /** * Creates an object of the given representation, pulling values from fields and methods as * specified by a subclass - * + * * @param representation * @return * Should return valid RefRepresentation @@ -373,20 +323,20 @@ protected String getUniqueId(T delegate) { public SimpleObject asRepresentation(T delegate, Representation representation) throws ConversionException { if (delegate == null) throw new NullPointerException(); - + DelegatingResourceHandler handler = getResourceHandler(delegate); - + // first call getRepresentationDescription() DelegatingResourceDescription repDescription = handler.getRepresentationDescription(representation); if (repDescription != null) { SimpleObject simple = convertDelegateToRepresentation(delegate, repDescription); - + maybeDecorateWithType(simple, delegate); decorateWithResourceVersion(simple, representation); - + return simple; } - + // otherwise look for a method annotated to handle this representation Method meth = findAnnotatedMethodForRepresentation(handler.getClass(), representation); if (meth != null) { @@ -397,30 +347,30 @@ public SimpleObject asRepresentation(T delegate, Representation representation) simple = (SimpleObject) meth.invoke(handler, delegate); else simple = (SimpleObject) meth.invoke(handler, delegate, representation); - + maybeDecorateWithType(simple, delegate); decorateWithResourceVersion(simple, representation); - + return simple; } catch (Exception ex) { throw new ConversionException(null, ex); } } - + // finally if it is a custom representation and not supported by any other handler if (representation instanceof CustomRepresentation) { repDescription = ConversionUtil.getCustomRepresentationDescription((CustomRepresentation) representation); return convertDelegateToRepresentation(delegate, repDescription); } - + throw new ConversionException("Don't know how to get " + getClass().getSimpleName() + "(" + delegate.getClass() - + ") as " + representation.getRepresentation(), null); + + ") as " + representation.getRepresentation(), null); } - + /** * Sets resourceVersion to {@link #getResourceVersion()} for representations other than REF. - * + * * @param simple the simplified representation which will be decorated with the resource version * @param representation the type of representation */ @@ -429,10 +379,10 @@ private void decorateWithResourceVersion(SimpleObject simple, Representation rep simple.put(RestConstants.PROPERTY_FOR_RESOURCE_VERSION, getResourceVersion()); } } - + /** * If this resource supports subclasses, then we add a type property to the input, and return it - * + * * @param simple simplified representation which will be decorated with the user-friendly type * name * @param delegate the object that simple represents @@ -441,11 +391,11 @@ private void maybeDecorateWithType(SimpleObject simple, T delegate) { if (hasTypesDefined()) simple.add(RestConstants.PROPERTY_FOR_TYPE, getTypeName(delegate)); } - + /** * If this resources supports subclasses, this method gets the user-friendly type name for the * given subclass - * + * * @param subclass * @return */ @@ -463,14 +413,14 @@ protected String getTypeName(Class subclass) { } return null; } - + /** * @see #getTypeName(Class) */ protected String getTypeName(T delegate) { return getTypeName((Class) delegate.getClass()); } - + /** * @param type user-friendly type name * @return the actual java class for this type @@ -482,7 +432,7 @@ protected Class getActualSubclass(String type) { // otherwise we need to return our own declared class return ReflectionUtil.getParameterizedTypeFromInterface(getClass(), DelegatingResourceHandler.class, 0); } - + /** * @param type user-friendly type name * @return a subclass handler if any is suitable for type, or this resource itself if it is @@ -497,9 +447,9 @@ protected DelegatingResourceHandler getResourceHandler(String type) if (getResourceName().endsWith(type)) return this; throw new IllegalArgumentException("type=" + type + " is not handled by this resource (" + getClass() - + ") or any subclass"); + + ") or any subclass"); } - + /** * Delegates to @see {@link #getResourceHandler(Class)} */ @@ -511,7 +461,7 @@ protected DelegatingResourceHandler getResourceHandler(T delegate) return null; return getResourceHandler((Class) delegate.getClass()); } - + /** * @param clazz * @return a subclass handler if any is suitable for the given class, or this resource itself if @@ -525,7 +475,7 @@ protected DelegatingResourceHandler getResourceHandler(Class getResourceHandler(Class getResourceHandler(Class getResourceHandler(Class getResourceHandler(ClassShould allow setting a null value */ public void setConvertedProperties(T delegate, Map propertyMap, - DelegatingResourceDescription description, boolean mustIncludeRequiredProperties) throws ConversionException { + DelegatingResourceDescription description, boolean mustIncludeRequiredProperties) throws ConversionException { Map allowedProperties = new LinkedHashMap(description.getProperties()); - + Map propertiesToSet = new HashMap(propertyMap); propertiesToSet.keySet().removeAll(propertiesIgnoredWhenUpdating); - + // Apply properties in the order specified in the resource description (necessary e.g. so the obs resource // can apply "concept" before "value"); we have already excluded unchanged and ignored properties. // Because some resources (e.g. any AttributeResource) require some properties to be set before others can @@ -599,14 +549,14 @@ public void setConvertedProperties(T delegate, Map propertyMap, propertiesToSet.remove(property); continue; } - + setProperty(delegate, property, propertiesToSet.get(property)); } } - + // If any non-settable properties remain after the above logic, fail Collection notAllowedProperties = CollectionUtils.subtract(propertiesToSet.keySet(), - allowedProperties.keySet()); + allowedProperties.keySet()); // Do allow posting back an unchanged value to an unchangeable property for (Iterator iterator = notAllowedProperties.iterator(); iterator.hasNext();) { String property = iterator.next(); @@ -618,9 +568,9 @@ public void setConvertedProperties(T delegate, Map propertyMap, } if (!notAllowedProperties.isEmpty()) { throw new ConversionException("Some properties are not allowed to be set: " - + StringUtils.join(notAllowedProperties, ", ")); + + StringUtils.join(notAllowedProperties, ", ")); } - + if (mustIncludeRequiredProperties) { Set missingProperties = new HashSet(); for (Entry prop : allowedProperties.entrySet()) { @@ -630,11 +580,11 @@ public void setConvertedProperties(T delegate, Map propertyMap, } if (!missingProperties.isEmpty()) { throw new ConversionException("Some required properties are missing: " - + StringUtils.join(missingProperties, ", ")); + + StringUtils.join(missingProperties, ", ")); } } } - + private boolean unchangedValue(Object oldValue, Object newValue) { if (newValue instanceof Map && oldValue != null && !(oldValue instanceof Map)) { newValue = ConversionUtil.convert(newValue, oldValue.getClass()); @@ -644,11 +594,11 @@ private boolean unchangedValue(Object oldValue, Object newValue) { } return OpenmrsUtil.nullSafeEquals(oldValue, newValue); } - + /** * Finds a method on clazz or a superclass that is annotated with {@link RepHandler} and is * suitable for rep - * + * * @param clazz * @param rep * @return @@ -664,7 +614,7 @@ private Method findAnnotatedMethodForRepresentation(Class clazz, Representati } return null; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#getProperty(java.lang.Object, * java.lang.String) @@ -673,13 +623,13 @@ private Method findAnnotatedMethodForRepresentation(Class clazz, Representati public Object getProperty(T instance, String propertyName) throws ConversionException { try { DelegatingResourceHandler handler = getResourceHandler(instance); - + // try to find a @PropertyGetter-annotated method Method annotatedGetter = ReflectionUtil.findPropertyGetterMethod(handler, propertyName); if (annotatedGetter != null) { return annotatedGetter.invoke(handler, instance); } - + return PropertyUtils.getProperty(instance, propertyName); } catch (Exception ex) { @@ -689,7 +639,7 @@ public Object getProperty(T instance, String propertyName) throws ConversionExce throw new ConversionException(propertyName + " on " + instance.getClass(), ex); } } - + /** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#setProperty(java.lang.Object, * java.lang.String, java.lang.Object) @@ -701,7 +651,7 @@ public void setProperty(Object instance, String propertyName, Object value) thro } try { DelegatingResourceHandler handler; - + try { handler = getResourceHandler((T) instance); } @@ -710,7 +660,7 @@ public void setProperty(Object instance, String propertyName, Object value) thro // but I'm putting in here just in case handler = this; } - + // try to find a @PropertySetter-annotated method Method annotatedSetter = ReflectionUtil.findPropertySetterMethod(handler, propertyName); if (annotatedSetter != null) { @@ -719,25 +669,25 @@ public void setProperty(Object instance, String propertyName, Object value) thro annotatedSetter.invoke(handler, instance, value); return; } - + // we need the generic type of this property, not just the class Method setter = PropertyUtils.getPropertyDescriptor(instance, propertyName).getWriteMethod(); - + // Convert the value to the specified type value = ConversionUtil.convert(value, setter.getGenericParameterTypes()[0], instance); - + setPropertyWhichMayBeAHibernateCollection(instance, propertyName, value); } catch (Exception ex) { throw new ConversionException(propertyName + " on " + instance.getClass(), ex); } } - + /** * Removes any elements from the passed-in collection that aren't of the given type. This is a * convenience method for subclass-aware resources that want to limit query results to a given * type. - * + * * @param collection * @param type a user-friendly type name */ @@ -748,11 +698,11 @@ protected void filterByType(Collection collection, String type) { i.remove(); } } - + /** * Convenience method that looks for a specific method on the subclass handler for the given * type - * + * * @param type user-friendly type name * @param methodName * @param argumentTypes @@ -769,11 +719,11 @@ protected Method findSubclassHandlerMethod(String type, String methodName, Class return null; } } - + /** * Convenience method that finds a specific method on the subclass handler for the given type, * and invokes it - * + * * @param type user-friendly type name * @param methodName * @param arguments @@ -802,7 +752,7 @@ protected Object findAndInvokeSubclassHandlerMethod(String type, String methodNa throw new RuntimeException(ex); } } - + /** * @param delegate * @return the URI for the given delegate object @@ -812,15 +762,15 @@ protected Object findAndInvokeSubclassHandlerMethod(String type, String methodNa public String getUri(Object delegate) { if (delegate == null) return ""; - + org.openmrs.module.webservices.rest.web.annotation.Resource res = getClass().getAnnotation( - org.openmrs.module.webservices.rest.web.annotation.Resource.class); + org.openmrs.module.webservices.rest.web.annotation.Resource.class); if (res != null) { return RestConstants.URI_PREFIX + res.name() + "/" + getUniqueId((T) delegate); } throw new RuntimeException(getClass() + " needs a @Resource or @SubResource annotation"); } - + /** * @see org.openmrs.module.webservices.rest.util.ReflectionUtil#findMethod(Class,String) * @deprecated It is always best to annotate the method with @PropertyGetter instead of finding @@ -831,10 +781,10 @@ public String getUri(Object delegate) { protected Method findMethod(String name) { return ReflectionUtil.findMethod(getClass(), name); } - + /** * Gets the audit information of a resource. - * + * * @param resource the resource. * @return a {@link SimpleObject} with the audit information. */ @@ -842,10 +792,9 @@ protected Method findMethod(String name) { public SimpleObject getAuditInfo(Object resource) { return ConversionUtil.getAuditInfo(resource); } - + @Override public T newDelegate(SimpleObject object) { return newDelegate(); } - } diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingSubclassHandler.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingSubclassHandler.java index c7796267a..68d7d016c 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingSubclassHandler.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingSubclassHandler.java @@ -9,7 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.resource.impl; -import io.swagger.models.Model; import org.openmrs.OpenmrsData; import org.openmrs.OpenmrsMetadata; import org.openmrs.api.context.Context; @@ -22,7 +21,6 @@ import org.openmrs.module.webservices.rest.web.annotation.RepHandler; import org.openmrs.module.webservices.rest.web.api.RestService; import org.openmrs.module.webservices.rest.web.representation.RefRepresentation; -import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.api.Resource; import org.openmrs.module.webservices.rest.web.response.ConversionException; import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; @@ -76,13 +74,8 @@ public Class getSubclassHandled() { public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { return getCreatableProperties(); } - - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - - /** + + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) */ @SuppressWarnings("unchecked") diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingResourceHandler.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingResourceHandler.java index 23aa4f01d..932e2c48f 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingResourceHandler.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingResourceHandler.java @@ -9,7 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.resource.impl; -import io.swagger.models.Model; import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.representation.Representation; @@ -23,8 +22,8 @@ * @param the class of the delegate this resource handles */ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor { - - /** + + /** * Indicates a version of the supported resource. * * @return the resource version @@ -34,7 +33,7 @@ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor /** * Instantiates a new instance of the handled delegate * - * @return + * @return T */ T newDelegate(); @@ -45,7 +44,7 @@ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor * to {@link #newDelegate()}. * * @param object - * @return + * @return T */ T newDelegate(SimpleObject object); @@ -68,7 +67,7 @@ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor /** * Gets the {@link DelegatingResourceDescription} for the given representation for this * resource, if it exists - * + * * @param rep * @return */ @@ -89,39 +88,5 @@ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor * @throws ResponseException if this resource does not support the operation */ DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException; - - /** - * Returns a {@link Model} object representing GET representation schema for the resource. - * - * @param rep representation type under which the resource {@link Model} should be fetched. It - * can take {@link Representation#DEFAULT}, {@link Representation#REF}, or - * {@link Representation#FULL} - * @return a {@link Model} object or null in case if such model does not exist or not - * documented. - */ - Model getGETModel(Representation rep); - - /** - * Returns a {@link Model} object representing CREATE representation schema for the resource. - * The returned model object will hold properties (and example values) required to create the - * underlying resource. - * - * @param rep representation type under which the resource {@link Model} should be fetched. It - * can take {@link Representation#DEFAULT}, or {@link Representation#FULL} - * @return a {@link Model} object or null in case if such model does not exist or not - * documented. - */ - Model getCREATEModel(Representation rep); - - /** - * Returns a {@link Model} object representing UPDATE representation schema for the resource. - * The returned model object will hold properties (and example values) required to update the - * underlying resource. - * - * @param rep representation type under which the resource {@link Model} should be fetched. It - * can take {@link Representation#DEFAULT}, or {@link Representation#FULL} - * @return a {@link Model} object or null in case if such model does not exist or not - * documented. - */ - Model getUPDATEModel(Representation rep); + } diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java index bf4defa25..a6d503c53 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java @@ -11,10 +11,6 @@ import java.util.Date; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; import org.apache.commons.lang.StringUtils; import org.openmrs.OpenmrsMetadata; import org.openmrs.api.context.Context; @@ -37,29 +33,7 @@ * @param */ public abstract class MetadataDelegatingCrudResource extends DelegatingCrudResource { - - @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - if (rep instanceof FullRepresentation) { - model - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("retired", new BooleanProperty()); - } - return model; - } - - @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .required("name"); - } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingConverter#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ diff --git a/omod-common/src/test/java/org/mockingbird/test/rest/resource/CatSubclassHandler_1_9.java b/omod-common/src/test/java/org/mockingbird/test/rest/resource/CatSubclassHandler_1_9.java index 8ce4ad0ba..8a5277c9f 100644 --- a/omod-common/src/test/java/org/mockingbird/test/rest/resource/CatSubclassHandler_1_9.java +++ b/omod-common/src/test/java/org/mockingbird/test/rest/resource/CatSubclassHandler_1_9.java @@ -9,7 +9,7 @@ */ package org.mockingbird.test.rest.resource; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.mockingbird.test.Animal; import org.mockingbird.test.Cat; import org.openmrs.module.webservices.rest.SimpleObject; @@ -89,19 +89,5 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { return null; } - - @Override - public Model getGETModel(Representation representation) { - return null; - } - - @Override - public Model getCREATEModel(Representation representation) { - return null; - } - - @Override - public Model getUPDATEModel(Representation representation) { - return null; - } + } diff --git a/omod-common/src/test/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResourceTest.java b/omod-common/src/test/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResourceTest.java index 7ff2fce86..df0e8067b 100644 --- a/omod-common/src/test/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResourceTest.java +++ b/omod-common/src/test/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResourceTest.java @@ -9,7 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.resource.impl; -import io.swagger.models.Model; import org.junit.Test; import org.openmrs.Location; import org.openmrs.api.context.ServiceContext; @@ -101,21 +100,7 @@ public void purge(Location delegate, RequestContext context) throws ResponseExce public DelegatingResourceDescription getRepresentationDescription(Representation rep) { return null; } - - @Override - public Model getGETModel(Representation representation) { - return null; - } - - @Override - public Model getCREATEModel(Representation representation) { - return null; - } - - @Override - public Model getUPDATEModel(Representation representation) { - return null; - } + } } diff --git a/omod/src/main/java/org/openmrs/module/webservices/rest/web/controller/SwaggerSpecificationController.java b/omod/src/main/java/org/openmrs/module/webservices/rest/web/controller/SwaggerSpecificationController.java index af6c74777..17f3db3e6 100644 --- a/omod/src/main/java/org/openmrs/module/webservices/rest/web/controller/SwaggerSpecificationController.java +++ b/omod/src/main/java/org/openmrs/module/webservices/rest/web/controller/SwaggerSpecificationController.java @@ -9,8 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.controller; -import com.google.common.net.HttpHeaders; -import io.swagger.models.Scheme; import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -24,22 +22,25 @@ public class SwaggerSpecificationController { @RequestMapping(method = RequestMethod.GET) - public @ResponseBody - String getSwaggerSpecification(HttpServletRequest request) throws Exception { + @SuppressWarnings("unused") + public @ResponseBody String getOpenAPISpecification(HttpServletRequest request) throws Exception { - String host = request.getHeader(HttpHeaders.HOST); + String host = request.getServerName(); + int port = request.getServerPort(); + String contextPath = request.getContextPath(); - String scheme = request.getHeader(HttpHeaders.X_FORWARDED_PROTO); + String scheme = request.getHeader("X-Forwarded-Proto"); if (scheme == null) { scheme = request.getScheme(); } - return new SwaggerSpecificationCreator() - .host(host) - .basePath(request.getContextPath() + "/ws/rest/v1") - .scheme(Scheme.forValue(scheme)) - - .getJSON(); + String baseUrl = scheme + "://" + host + (port == 80 || port == 443 ? "" : ":" + port) + contextPath; + + SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(); + creator.host(baseUrl) + .basePath("/ws/rest/v1"); + + return creator.getJSON(); } } diff --git a/omod/src/main/webapp/apiDocs.jsp b/omod/src/main/webapp/apiDocs.jsp index 011bc8a30..0209d8f17 100644 --- a/omod/src/main/webapp/apiDocs.jsp +++ b/omod/src/main/webapp/apiDocs.jsp @@ -8,7 +8,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -72,15 +72,15 @@

- - + +