Skip to content

Commit

Permalink
Refactor the mechanism for making Swagger aware of resource handlers …
Browse files Browse the repository at this point in the history
…and adopt a more automated approach
  • Loading branch information
mherman22 committed Dec 2, 2024
1 parent 9786f8d commit 7a4fbe0
Show file tree
Hide file tree
Showing 109 changed files with 158 additions and 3,849 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,17 +66,7 @@ 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()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,7 @@ 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) {

return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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;
Expand All @@ -35,12 +34,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}
Expand Down Expand Up @@ -128,49 +121,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");
Expand Down
Loading

0 comments on commit 7a4fbe0

Please sign in to comment.