Skip to content

Commit

Permalink
Merge 5a45e99 into 023de3c
Browse files Browse the repository at this point in the history
  • Loading branch information
BartlomiejRasztabiga committed Nov 29, 2017
2 parents 023de3c + 5a45e99 commit 8ef8228
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.openmrs.Order;
import org.openmrs.Patient;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator;
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 Down Expand Up @@ -112,8 +112,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
public Model getCREATEModel(Representation rep) {
ModelImpl model = new ModelImpl()
.property("encounter", new StringProperty().example("uuid"))
.property("action", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(Order.Action.class)))
.property("action", new EnumProperty(Order.Action.class))
.property("accessionNumber", new StringProperty())
.property("dateActivated", new DateProperty())
.property("scheduledDate", new DateProperty())
Expand All @@ -124,8 +123,7 @@ public Model getCREATEModel(Representation rep) {
.property("autoExpireDate", new DateProperty())
.property("orderer", new StringProperty().example("uuid"))
.property("previousOrder", new StringProperty().example("uuid"))
.property("urgency", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(Order.Urgency.class)))
.property("urgency", new EnumProperty(Order.Urgency.class))
.property("orderReason", new StringProperty().example("uuid"))
.property("orderReasonNonCoded", new StringProperty())
.property("instructions", new StringProperty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.openmrs.activelist.AllergySeverity;
import org.openmrs.activelist.AllergyType;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator;
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;
Expand Down Expand Up @@ -66,11 +66,9 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
@Override
public Model getGETModel(Representation rep) {
ModelImpl model = ((ModelImpl) super.getGETModel(rep))
.property("allergyType", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(AllergyType.class)))
.property("allergyType", new EnumProperty(AllergyType.class))
.property("reaction", new RefProperty("#/definitions/ConceptGetRef"))
.property("severity", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(AllergySeverity.class)))
.property("severity", new EnumProperty(AllergySeverity.class))
.property("allergen", new RefProperty("#/definitions/ConceptGetRef"));
if (rep instanceof FullRepresentation) {
model
Expand All @@ -83,12 +81,10 @@ public Model getGETModel(Representation rep) {
@Override
public Model getCREATEModel(Representation rep) {
return ((ModelImpl) super.getCREATEModel(rep))
.property("allergyType", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(AllergyType.class)))
.property("allergyType", new EnumProperty(AllergyType.class))
.property("reaction", new ObjectProperty()
.property("uuid", new StringProperty()))
.property("severity", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(AllergySeverity.class)))
.property("severity", new EnumProperty(AllergySeverity.class))
.property("allergen", new StringProperty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.openmrs.ConceptName;
import org.openmrs.api.ConceptNameType;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator;
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;
Expand Down Expand Up @@ -80,8 +80,7 @@ public Model getGETModel(Representation rep) {
.property("name", new StringProperty())
.property("locale", new StringProperty().example("en"))
.property("localePreferred", new BooleanProperty())
.property("conceptNameType", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(ConceptNameType.class)));
.property("conceptNameType", new EnumProperty(ConceptNameType.class));
}
return model;
}
Expand All @@ -92,8 +91,7 @@ public Model getCREATEModel(Representation rep) {
.property("name", new StringProperty())
.property("locale", new StringProperty().example("en"))
.property("localePreferred", new BooleanProperty()._default(false))
.property("conceptNameType", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(ConceptNameType.class)))
.property("conceptNameType", new EnumProperty(ConceptNameType.class))
.required("name").required("locale");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.swagger.models.properties.StringProperty;
import org.openmrs.module.Module;
import org.openmrs.module.ModuleException;
import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator;
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.rest.SimpleObject;
Expand Down Expand Up @@ -239,18 +239,16 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe
public Model getGETModel(Representation rep) {
return ((ModelImpl) super.getGETModel(rep))
.property("modules", new ArrayProperty(new RefProperty("#/definitions/ModuleGetRef")))
.property("action", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(ModuleAction.Action.class)));
.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 StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(ModuleAction.Action.class)))

.property("action", new EnumProperty(ModuleAction.Action.class))

.required("action");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.openmrs.PatientIdentifierType;
import org.openmrs.api.PatientService;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator;
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 @@ -125,8 +125,7 @@ public Model getGETModel(Representation rep) {
.property("required", new BooleanProperty())
.property("checkDigit", new BooleanProperty())
.property("validator", new StringProperty())
.property("locationBehavior", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(PatientIdentifierType.LocationBehavior.class)))
.property("locationBehavior", new EnumProperty(PatientIdentifierType.LocationBehavior.class))
.property("uniquenessBehavior", new StringProperty()); //FIXME check type
}
return model;
Expand All @@ -140,8 +139,7 @@ public Model getCREATEModel(Representation rep) {
.property("required", new BooleanProperty())
.property("checkDigit", new BooleanProperty())
.property("validator", new StringProperty())
.property("locationBehavior", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(PatientIdentifierType.LocationBehavior.class)))
.property("locationBehavior", new EnumProperty(PatientIdentifierType.LocationBehavior.class))
.property("uniquenessBehavior", new StringProperty()); //FIXME check type
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.openmrs.activelist.Problem;
import org.openmrs.activelist.ProblemModifier;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator;
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;
Expand All @@ -44,8 +44,7 @@ public Model getGETModel(Representation rep) {
ModelImpl model = (ModelImpl) super.getGETModel(rep);
if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) {
model
.property("modifier", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(ProblemModifier.class)))
.property("modifier", new EnumProperty(ProblemModifier.class))
.property("sortWeight", new DoubleProperty());
}
if (rep instanceof DefaultRepresentation) {
Expand Down Expand Up @@ -98,8 +97,7 @@ public DelegatingResourceDescription getCreatableProperties() {
public Model getCREATEModel(Representation rep) {
return ((ModelImpl) super.getCREATEModel(rep))
.property("problem", new RefProperty("#/definitions/ConceptCreate"))
.property("modifier", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(ProblemModifier.class)))
.property("modifier", new EnumProperty(ProblemModifier.class))
.property("sortWeight", new DoubleProperty())

.required("problem");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.StringProperty;
import org.openmrs.Obs;
import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator;
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;
Expand All @@ -30,19 +30,15 @@ public class ObsResource2_1 extends ObsResource1_11 {
@Override
public Model getGETModel(Representation rep) {
return ((ModelImpl) super.getGETModel(rep))
.property("status", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(Obs.Status.class)))
.property("interpretation", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(Obs.Interpretation.class)));
.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 StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(Obs.Status.class)))
.property("interpretation", new StringProperty()
._enum(SwaggerSpecificationCreator.getEnumsAsList(Obs.Interpretation.class)));
.property("status", new EnumProperty(Obs.Status.class))
.property("interpretation", new EnumProperty(Obs.Interpretation.class));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,15 +1233,5 @@ public static boolean isCached() {
public static void clearCache() {
swagger = null;
}

//FIXME: move to separate util calls
// see: https://stackoverflow.com/q/13783295/3647002
public static String[] getEnums(Class<? extends Enum<?>> e) {
return Arrays.toString(e.getEnumConstants())
.replaceAll("^.|.$", "").split(", ");
}

public static List<String> getEnumsAsList(Class<? extends Enum<?>> e) {
return Arrays.asList(getEnums(e));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@
package org.openmrs.module.webservices.docs.swagger.core.property;

import io.swagger.models.properties.StringProperty;
import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator;

import java.util.Arrays;
import java.util.List;

public class EnumProperty extends StringProperty {

public EnumProperty(Class<? extends Enum<?>> e) {
_enum(SwaggerSpecificationCreator.getEnumsAsList(e));
_enum(getEnumsAsList(e));
}

private List<String> getEnumsAsList(Class<? extends Enum<?>> e) {
return Arrays.asList(getEnums(e));
}

private String[] getEnums(Class<? extends Enum<?>> e) {
return Arrays.toString(e.getEnumConstants())
.replaceAll("^.|.$", "").split(", ");
}
}

0 comments on commit 8ef8228

Please sign in to comment.