From 8c145fc245e8d4287da0cc3cf15fe32113d338de Mon Sep 17 00:00:00 2001 From: mherman22 Date: Tue, 1 Oct 2024 16:55:48 +0300 Subject: [PATCH 1/2] RESTWS-957: Fix Swagger errors displayed on the openmrs swagger api docs page --- .../attachments/AttachmentsConstants.java | 1 + .../attachments/rest/AttachmentResource.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/api/src/main/java/org/openmrs/module/attachments/AttachmentsConstants.java b/api/src/main/java/org/openmrs/module/attachments/AttachmentsConstants.java index c9af5b2..50449b8 100644 --- a/api/src/main/java/org/openmrs/module/attachments/AttachmentsConstants.java +++ b/api/src/main/java/org/openmrs/module/attachments/AttachmentsConstants.java @@ -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"; } diff --git a/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java b/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java index 67d069e..743fb50 100644 --- a/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java +++ b/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java @@ -12,6 +12,11 @@ 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.StringProperty; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.BooleanUtils; @@ -181,6 +186,16 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } + @Override + public Model getCREATEModel(Representation rep) { + return new ModelImpl().property("comment", new StringProperty()); + } + + @Override + public Model getUPDATEModel(Representation rep) { + return getCREATEModel(rep); + } + @Override public DelegatingResourceDescription getRepresentationDescription(Representation rep) { DelegatingResourceDescription description = new DelegatingResourceDescription(); @@ -194,6 +209,14 @@ 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 ByteArrayProperty()).property("bytesContentFamily", new ByteArrayProperty()); + } + /** * Voids the encounter if it contains no non-voided obs. * From 880ed2dfe3322ed0eb00dd18f79c03ea4939c847 Mon Sep 17 00:00:00 2001 From: mherman22 Date: Fri, 4 Oct 2024 17:49:58 +0300 Subject: [PATCH 2/2] add more properties to the models --- .../attachments/rest/AttachmentResource.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java b/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java index 743fb50..3097b3f 100644 --- a/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java +++ b/omod/src/main/java/org/openmrs/module/attachments/rest/AttachmentResource.java @@ -16,6 +16,7 @@ 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; @@ -35,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; @@ -183,12 +185,21 @@ 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()); + 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 @@ -214,7 +225,8 @@ 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 ByteArrayProperty()).property("bytesContentFamily", new ByteArrayProperty()); + .property("bytesMimeType", new StringProperty()) + .property("bytesContentFamily", new EnumProperty(AttachmentsConstants.ContentFamily.class)); } /**