Skip to content

Commit 22be424

Browse files
committed
RESTWS-963: Refactor the mechanism for making Swagger aware of resource handlers and adopt a more automated approach
1 parent 9786f8d commit 22be424

File tree

109 files changed

+158
-3849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+158
-3849
lines changed

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
import java.util.List;
1414
import java.util.regex.Pattern;
1515

16-
import io.swagger.models.Model;
17-
import io.swagger.models.ModelImpl;
1816
import org.openmrs.CareSetting;
1917
import org.openmrs.api.context.Context;
20-
import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty;
2118
import org.openmrs.module.webservices.rest.web.RequestContext;
2219
import org.openmrs.module.webservices.rest.web.RestConstants;
2320
import org.openmrs.module.webservices.rest.web.annotation.Resource;
@@ -69,17 +66,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
6966
public DelegatingResourceDescription getCreatableProperties() {
7067
throw new ResourceDoesNotSupportOperationException();
7168
}
72-
73-
@Override
74-
public Model getGETModel(Representation rep) {
75-
ModelImpl model = (ModelImpl) super.getGETModel(rep);
76-
if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) {
77-
model
78-
.property("careSettingType", new EnumProperty(CareSetting.CareSettingType.class));
79-
}
80-
return model;
81-
}
82-
69+
8370
/**
8471
* @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate()
8572
*/

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
2525
import org.openmrs.module.webservices.rest.web.response.ResponseException;
2626

27-
import io.swagger.models.Model;
28-
import io.swagger.models.ModelImpl;
29-
import io.swagger.models.properties.RefProperty;
30-
import io.swagger.models.properties.StringProperty;
31-
3227
import org.openmrs.module.webservices.rest.web.RequestContext;
3328
import org.openmrs.module.webservices.rest.web.RestConstants;
3429

@@ -117,27 +112,5 @@ public DelegatingResourceDescription getCreatableProperties() {
117112
description.addProperty("drug");
118113
return description;
119114
}
120-
121-
public Model getGETModel(Representation rep) {
122-
ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep);
123-
if (rep instanceof DefaultRepresentation) {
124-
modelImpl.property("display", new StringProperty()).property("uuid", new StringProperty())
125-
.property("drug", new RefProperty("#/definitions/DrugGetRef"))
126-
.property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermGetRef"))
127-
.property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGetRef"));
128-
} else if (rep instanceof FullRepresentation) {
129-
modelImpl.property("display", new StringProperty()).property("uuid", new StringProperty())
130-
.property("auditInfo", new StringProperty()).property("drug", new RefProperty("#/definitions/DrugGet"))
131-
.property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermGet"))
132-
.property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGet"));
133-
}
134-
return modelImpl;
135-
}
136-
137-
@Override
138-
public Model getCREATEModel(Representation rep) {
139-
return new ModelImpl().property("conceptReferenceTerm", new StringProperty().example("uuid"))
140-
.property("conceptMapType", new StringProperty().example("uuid"))
141-
.property("drug", new StringProperty().example("uuid"));
142-
}
115+
143116
}

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
1919
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.DrugResource1_8;
2020

21-
import io.swagger.models.Model;
22-
import io.swagger.models.ModelImpl;
23-
import io.swagger.models.properties.RefProperty;
24-
2521
/**
2622
* {@link org.openmrs.module.webservices.rest.web.annotation.Resource} for {@link org.openmrs.Drug},
2723
* supporting standard CRUD operations
@@ -59,22 +55,5 @@ public DelegatingResourceDescription getCreatableProperties() {
5955

6056
return description;
6157
}
62-
63-
public Model getGETModel(Representation rep) {
64-
ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep);
65-
if (rep instanceof DefaultRepresentation) {
66-
modelImpl
67-
.property("drugReferenceMaps", new RefProperty("#/definitions/DrugreferencemapGetRef"));
68-
} else if (rep instanceof FullRepresentation) {
69-
modelImpl
70-
.property("drugReferenceMaps", new RefProperty("#/definitions/DrugreferencemapGet"));
71-
}
72-
return modelImpl;
73-
}
74-
75-
@Override
76-
public Model getCREATEModel(Representation rep) {
77-
return new ModelImpl()
78-
.property("drugReferenceMaps", new RefProperty("#/definitions/DrugreferencemapCreate"));
79-
}
58+
8059
}

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99
*/
1010
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10;
1111

12-
import io.swagger.models.Model;
13-
import io.swagger.models.ModelImpl;
14-
import io.swagger.models.properties.DateProperty;
15-
import io.swagger.models.properties.RefProperty;
16-
import io.swagger.models.properties.StringProperty;
1712
import org.apache.commons.lang.StringUtils;
1813
import org.openmrs.CareSetting;
1914
import org.openmrs.Order;
2015
import org.openmrs.OrderType;
2116
import org.openmrs.Patient;
2217
import org.openmrs.api.context.Context;
23-
import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty;
2418
import org.openmrs.module.webservices.rest.web.ConversionUtil;
2519
import org.openmrs.module.webservices.rest.web.RequestContext;
2620
import org.openmrs.module.webservices.rest.web.RestConstants;
@@ -31,7 +25,6 @@
3125
import org.openmrs.module.webservices.rest.web.representation.Representation;
3226
import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
3327
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
34-
import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult;
3528
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
3629
import org.openmrs.module.webservices.rest.web.response.InvalidSearchException;
3730
import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException;
@@ -114,45 +107,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
114107
return null;
115108
}
116109
}
117-
118-
@Override
119-
public Model getCREATEModel(Representation rep) {
120-
ModelImpl model = new ModelImpl()
121-
.property("encounter", new StringProperty().example("uuid"))
122-
.property("orderType", new StringProperty().example("uuid"))
123-
.property("action", new EnumProperty(Order.Action.class))
124-
.property("accessionNumber", new StringProperty())
125-
.property("dateActivated", new DateProperty())
126-
.property("scheduledDate", new DateProperty())
127-
.property("patient", new StringProperty().example("uuid"))
128-
.property("concept", new StringProperty().example("uuid"))
129-
.property("careSetting", new StringProperty().example("uuid"))
130-
.property("dateStopped", new DateProperty())
131-
.property("autoExpireDate", new DateProperty())
132-
.property("orderer", new StringProperty().example("uuid"))
133-
.property("previousOrder", new StringProperty().example("uuid"))
134-
.property("urgency", new EnumProperty(Order.Urgency.class))
135-
.property("orderReason", new StringProperty().example("uuid"))
136-
.property("orderReasonNonCoded", new StringProperty())
137-
.property("instructions", new StringProperty())
138-
.property("commentToFulfiller", new StringProperty())
139-
140-
.required("orderType").required("patient").required("concept");
141-
if (rep instanceof FullRepresentation) {
142-
model
143-
.property("encounter", new RefProperty("#/definitions/EncounterCreate"))
144-
.property("patient", new RefProperty("#/definitions/PatientCreate"))
145-
.property("concept", new RefProperty("#/definitions/ConceptCreate"))
146-
.property("orderer", new RefProperty("#/definitions/UserCreate"))
147-
.property("previousOrder", new RefProperty("#/definitions/OrderCreate"))
148-
.property("orderReason", new RefProperty("#/definitions/ConceptCreate"))
149-
.property("orderReasonNonCoded", new StringProperty())
150-
.property("instructions", new StringProperty())
151-
.property("commentToFulfiller", new StringProperty());
152-
}
153-
return model;
154-
}
155-
110+
156111
/**
157112
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties()
158113
*/

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
import java.util.List;
1414
import java.util.regex.Pattern;
1515

16-
import io.swagger.models.Model;
17-
import io.swagger.models.ModelImpl;
18-
import io.swagger.models.properties.ArrayProperty;
19-
import io.swagger.models.properties.RefProperty;
20-
import io.swagger.models.properties.StringProperty;
2116
import org.openmrs.OrderType;
2217
import org.openmrs.api.context.Context;
2318
import org.openmrs.module.webservices.rest.web.RequestContext;
@@ -151,33 +146,5 @@ public DelegatingResourceDescription getCreatableProperties() {
151146
d.addProperty("conceptClasses");
152147
return d;
153148
}
154-
155-
@Override
156-
public Model getGETModel(Representation rep) {
157-
ModelImpl model = (ModelImpl) super.getGETModel(rep);
158-
if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) {
159-
model
160-
.property("javaClassName", new StringProperty());
161-
}
162-
if (rep instanceof DefaultRepresentation) {
163-
model
164-
.property("conceptClasses", new ArrayProperty(new RefProperty("#/definitions/ConceptclassGetRef")))
165-
.property("parent", new RefProperty("#/definitions/OrdertypeGetRef"));
166-
} else if (rep instanceof FullRepresentation) {
167-
model
168-
.property("conceptClasses", new ArrayProperty(new RefProperty("#/definitions/ConceptclassGet")))
169-
.property("parent", new RefProperty("#/definitions/OrdertypeGet"));
170-
}
171-
return model;
172-
}
173-
174-
@Override
175-
public Model getCREATEModel(Representation rep) {
176-
return ((ModelImpl) super.getCREATEModel(rep))
177-
.property("javaClassName", new StringProperty())
178-
.property("parent", new StringProperty().example("uuid")) //FIXME type
179-
.property("conceptClasses", new ArrayProperty(new StringProperty().example("uuid")))
180-
181-
.required("javaClassName");
182-
}
149+
183150
}

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe
5959
description.addProperty("birthtime");
6060
return description;
6161
}
62-
@Override
63-
public Model getGETModel(Representation rep) {
64-
return addNewProperties(super.getGETModel(rep), rep);
65-
}
66-
67-
@Override
68-
public Model getCREATEModel(Representation rep) {
69-
return addNewProperties(super.getCREATEModel(rep), rep);
70-
}
71-
72-
@Override
73-
public Model getUPDATEModel(Representation rep) {
74-
return addNewProperties(super.getUPDATEModel(rep), rep);
75-
}
76-
62+
7763
private Model addNewProperties(Model model, Representation rep) {
7864

7965
return model;

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
*/
1010
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10;
1111

12-
import io.swagger.models.Model;
13-
import io.swagger.models.ModelImpl;
14-
import io.swagger.models.properties.ArrayProperty;
15-
import io.swagger.models.properties.BooleanProperty;
16-
import io.swagger.models.properties.DateProperty;
17-
import io.swagger.models.properties.RefProperty;
1812
import org.openmrs.PatientProgram;
1913
import org.openmrs.PatientState;
2014
import org.openmrs.api.context.Context;
@@ -98,28 +92,7 @@ public DelegatingResourceDescription getCreatableProperties() {
9892
d.addProperty("voided");
9993
return d;
10094
}
101-
102-
@Override
103-
public Model getCREATEModel(Representation rep) {
104-
return ((ModelImpl) super.getCREATEModel(rep))
105-
.property("states", new ArrayProperty(new RefProperty("#/definitions/ProgramenrollmentStateCreate")))
106-
.property("outcome", new RefProperty("#/definitions/ConceptCreate"));
107-
}
108-
109-
@Override
110-
public Model getUPDATEModel(Representation rep) {
111-
return new ModelImpl() //FIXME use super.
112-
.property("dateEnrolled", new DateProperty())
113-
.property("states", new ArrayProperty(new RefProperty("#/definitions/ProgramenrollmentStateCreate")))
114-
.property("outcome", new RefProperty("#/definitions/ConceptCreate"))
115-
.property("location", new RefProperty("#/definitions/LocationCreate"))
116-
.property("voided", new BooleanProperty())
117-
.property("dateCompleted", new DateProperty())
118-
119-
.required("dateEnrolled");
120-
121-
}
122-
95+
12396
@Override
12497
public DelegatingResourceDescription getUpdatableProperties() {
12598
DelegatingResourceDescription d = new DelegatingResourceDescription();

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
*/
1010
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10;
1111

12-
import io.swagger.models.Model;
13-
import io.swagger.models.ModelImpl;
14-
import io.swagger.models.properties.RefProperty;
15-
import io.swagger.models.properties.StringProperty;
1612
import org.openmrs.Program;
1713
import org.openmrs.module.webservices.rest.web.RestConstants;
1814
import org.openmrs.module.webservices.rest.web.annotation.Resource;
@@ -63,18 +59,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
6359
}
6460
return null;
6561
}
66-
67-
@Override
68-
public Model getCREATEModel(Representation rep) {
69-
ModelImpl model = ((ModelImpl) super.getCREATEModel(rep))
70-
.property("outcomesConcept", new StringProperty().example("uuid"));
71-
if (rep instanceof FullRepresentation) {
72-
model
73-
.property("outcomesConcept", new RefProperty("#/definitions/ConceptCreate"));
74-
}
75-
return model;
76-
}
77-
62+
7863
@Override
7964
public DelegatingResourceDescription getCreatableProperties() {
8065
DelegatingResourceDescription description = new DelegatingResourceDescription();

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.openmrs.TestOrder;
2020
import org.openmrs.api.OrderService;
2121
import org.openmrs.api.context.Context;
22-
import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty;
2322
import org.openmrs.module.webservices.rest.web.ConversionUtil;
2423
import org.openmrs.module.webservices.rest.web.RequestContext;
2524
import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter;
@@ -35,12 +34,6 @@
3534
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
3635
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
3736

38-
import io.swagger.models.Model;
39-
import io.swagger.models.ModelImpl;
40-
import io.swagger.models.properties.IntegerProperty;
41-
import io.swagger.models.properties.RefProperty;
42-
import io.swagger.models.properties.StringProperty;
43-
4437
/**
4538
* Exposes the {@link org.openmrs.TestOrder} subclass as a type in
4639
* {@link org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.OrderResource1_8}
@@ -128,49 +121,7 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe
128121
//this actually throws a ResourceDoesNotSupportOperationException
129122
return orderResource.getUpdatableProperties();
130123
}
131-
132-
@Override
133-
public Model getGETModel(Representation rep) {
134-
OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class)
135-
.getResourceBySupportedClass(Order.class);
136-
ModelImpl orderModel = (ModelImpl) orderResource.getGETModel(rep);
137-
orderModel
138-
.property("laterality", new EnumProperty(TestOrder.Laterality.class))
139-
.property("clinicalHistory", new StringProperty())
140-
.property("numberOfRepeats", new IntegerProperty());
141-
142-
if (rep instanceof DefaultRepresentation) {
143-
orderModel
144-
.property("specimenSource", new RefProperty("#/definitions/ConceptGetRef"))
145-
.property("frequency", new RefProperty("#/definitions/OrderfrequencyGetRef"));
146-
} else if (rep instanceof FullRepresentation) {
147-
orderModel
148-
.property("specimenSource", new RefProperty("#/definitions/ConceptGet"))
149-
.property("frequency", new RefProperty("#/definitions/OrderfrequencyGet"));
150-
}
151-
return orderModel;
152-
}
153-
154-
@Override
155-
public Model getCREATEModel(Representation rep) {
156-
OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class)
157-
.getResourceBySupportedClass(Order.class);
158-
ModelImpl orderModel = (ModelImpl) orderResource.getCREATEModel(rep);
159-
return orderModel
160-
.property("specimenSource", new StringProperty().example("uuid"))
161-
.property("laterality", new EnumProperty(TestOrder.Laterality.class))
162-
.property("clinicalHistory", new StringProperty())
163-
.property("frequency", new StringProperty().example("uuid"))
164-
.property("numberOfRepeats", new IntegerProperty());
165-
}
166-
167-
@Override
168-
public Model getUPDATEModel(Representation rep) {
169-
OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class)
170-
.getResourceBySupportedClass(Order.class);
171-
return orderResource.getUPDATEModel(rep);
172-
}
173-
124+
174125
public PageableResult getActiveOrders(Patient patient, RequestContext context) {
175126
String careSettingUuid = context.getRequest().getParameter("careSetting");
176127
String asOfDateString = context.getRequest().getParameter("asOfDate");

0 commit comments

Comments
 (0)