Skip to content

Commit

Permalink
RESTWS-957: Fix Swagger errors displayed on the openmrs swagger api d…
Browse files Browse the repository at this point in the history
…ocs page (#67)
  • Loading branch information
mherman22 authored Oct 7, 2024
1 parent d832598 commit e62127e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@ public static enum ContentFamily {
* PRIVILEGES
*/
public static final String CREATE_ATTACHMENTS = "Create Attachments";

public static final String VIEW_ATTACHMENTS = "View Attachments";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
import java.util.Arrays;
import java.util.List;

import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.ByteArrayProperty;
import io.swagger.models.properties.DateProperty;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.BooleanUtils;
Expand All @@ -30,6 +36,7 @@
import org.openmrs.module.attachments.ComplexObsSaver;
import org.openmrs.module.attachments.obs.Attachment;
import org.openmrs.module.attachments.obs.ValueComplex;
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 @@ -178,9 +185,28 @@ public Object upload(MultipartFile file, RequestContext context) throws Response
public DelegatingResourceDescription getCreatableProperties() {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("comment");
description.addProperty("dateTime");
description.addProperty("filename");
description.addProperty("bytesMimeType");
description.addProperty("bytesContentFamily");
description.addProperty("complexData");
return description;
}

@Override
public Model getCREATEModel(Representation rep) {
return new ModelImpl().property("comment", new StringProperty()).property("dateTime", new DateProperty())
.property("filename", new StringProperty()).property("bytesMimeType", new StringProperty())

.property("bytesContentFamily", new EnumProperty(AttachmentsConstants.ContentFamily.class))
.property("complexData", new StringProperty(StringProperty.Format.URI));
}

@Override
public Model getUPDATEModel(Representation rep) {
return getCREATEModel(rep);
}

@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
Expand All @@ -194,6 +220,15 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
return description;
}

@Override
public Model getGETModel(Representation rep) {
ModelImpl model = (ModelImpl) super.getGETModel(rep);
return model.property("uuid", new StringProperty()).property("dateTime", new DateProperty())
.property("filename", new StringProperty()).property("comment", new StringProperty())
.property("bytesMimeType", new StringProperty())
.property("bytesContentFamily", new EnumProperty(AttachmentsConstants.ContentFamily.class));
}

/**
* Voids the encounter if it contains no non-voided obs.
*
Expand Down

0 comments on commit e62127e

Please sign in to comment.