From 0601289098d822a4b5ff14049f578c5f41f29a05 Mon Sep 17 00:00:00 2001 From: mherman22 Date: Mon, 14 Oct 2024 12:19:01 +0300 Subject: [PATCH 01/15] RESTWS-958: Ensure the REST Module Api Docs are upgraded to use Swagger 2.2.23 --- .../openmrs1_10/CareSettingResource1_10.java | 20 +- .../DrugReferenceMapResource1_10.java | 58 +- .../openmrs1_10/DrugResource1_10.java | 36 +- .../openmrs1_10/OrderResource1_10.java | 80 +- .../openmrs1_10/OrderTypeResource1_10.java | 52 +- .../openmrs1_10/PersonResource1_10.java | 18 +- .../ProgramEnrollmentResource1_10.java | 46 +- .../openmrs1_10/ProgramResource1_10.java | 20 +- .../TestOrderSubclassHandler1_10.java | 60 +- .../DrugIngredientResource1_11.java | 55 +- .../resource/openmrs1_11/ObsResource1_11.java | 22 +- .../openmrs1_11/PersonResource1_11.java | 24 +- .../openmrs1_12/OrderGroupResource1_12.java | 85 +- .../OrderSetMemberResource1_12.java | 76 +- .../openmrs1_12/OrderSetResource1_12.java | 53 +- .../openmrs1_8/AllergyResource1_8.java | 57 +- .../BaseActiveListItemResource1_8.java | 97 +-- .../openmrs1_8/CohortMemberResource1_8.java | 52 +- .../openmrs1_8/CohortResource1_8.java | 62 +- .../openmrs1_8/ConceptClassResource1_8.java | 16 +- .../ConceptDatatypeResource1_8.java | 30 +- .../ConceptDescriptionResource1_8.java | 54 +- .../openmrs1_8/ConceptMapResource1_8.java | 50 +- .../openmrs1_8/ConceptNameResource1_8.java | 74 +- .../openmrs1_8/ConceptResource1_8.java | 335 ++++---- .../openmrs1_8/ConceptSourceResource1_8.java | 46 +- .../DrugOrderSubclassHandler1_8.java | 72 +- .../resource/openmrs1_8/DrugResource1_8.java | 107 +-- .../openmrs1_8/EncounterResource1_8.java | 140 ++-- .../openmrs1_8/EncounterTypeResource1_8.java | 12 +- .../openmrs1_8/FieldAnswerResource1_8.java | 48 +- .../resource/openmrs1_8/FieldResource1_8.java | 60 +- .../openmrs1_8/FieldTypeResource1_8.java | 16 +- .../openmrs1_8/FormFieldResource1_8.java | 89 +- .../resource/openmrs1_8/FormResource1_8.java | 105 +-- .../openmrs1_8/HL7MessageResource1_8.java | 57 +- .../openmrs1_8/HL7SourceResource1_8.java | 16 +- .../openmrs1_8/LocationResource1_8.java | 118 +-- .../openmrs1_8/LocationTagResource1_8.java | 16 +- .../openmrs1_8/ModuleActionResource1_8.java | 38 +- .../openmrs1_8/ModuleResource1_8.java | 42 +- .../resource/openmrs1_8/ObsResource1_8.java | 91 ++- .../resource/openmrs1_8/OrderResource1_8.java | 118 +-- .../PatientIdentifierResource1_8.java | 57 +- .../PatientIdentifierTypeResource1_8.java | 51 +- .../openmrs1_8/PatientResource1_8.java | 81 +- .../openmrs1_8/PatientStateResource1_8.java | 56 +- .../openmrs1_8/PersonAddressResource1_8.java | 93 +-- .../PersonAttributeResource1_8.java | 58 +- .../PersonAttributeTypeResource1_8.java | 57 +- .../openmrs1_8/PersonNameResource1_8.java | 66 +- .../openmrs1_8/PersonResource1_8.java | 134 ++-- .../openmrs1_8/PrivilegeResource1_8.java | 16 +- .../openmrs1_8/ProblemResource1_8.java | 47 +- .../ProgramEnrollmentResource1_8.java | 74 +- .../openmrs1_8/ProgramResource1_8.java | 44 +- .../ProgramWorkflowResource1_8.java | 25 +- .../ProgramWorkflowStateResource1_8.java | 47 +- .../RelationShipTypeResource1_8.java | 34 +- .../openmrs1_8/RelationshipResource1_8.java | 66 +- .../resource/openmrs1_8/RoleResource1_8.java | 41 +- .../openmrs1_8/ServerLogResource1_8.java | 11 +- .../openmrs1_8/TaskActionResource1_8.java | 42 +- .../openmrs1_8/TaskDefinitionResource1_8.java | 54 +- .../resource/openmrs1_8/UserResource1_8.java | 81 +- .../rest/web/HivDrugOrderSubclassHandler.java | 63 +- .../BaseAttributeCrudResource1_9.java | 33 +- .../BaseAttributeTypeCrudResource1_9.java | 44 +- .../openmrs1_9/ConceptMapResource1_9.java | 55 +- .../openmrs1_9/ConceptMapTypeResource1_9.java | 18 +- .../ConceptReferenceTermMapResource1_9.java | 57 +- .../ConceptReferenceTermResource1_9.java | 56 +- .../openmrs1_9/ConceptSearchResource1_9.java | 43 +- .../ConceptStopwordResource1_9.java | 47 +- .../CustomDatatypeHandlerResource1_9.java | 23 +- .../openmrs1_9/CustomDatatypeResource1_9.java | 41 +- .../EncounterProviderResource1_9.java | 75 +- .../openmrs1_9/EncounterRoleResource1_9.java | 10 +- .../openmrs1_9/FormResourceResource1_9.java | 69 +- .../openmrs1_9/ProviderResource1_9.java | 79 +- .../openmrs1_9/SystemSettingResource1_9.java | 79 +- .../resource/openmrs1_9/VisitResource1_9.java | 122 +-- .../web/v1_0/test/GenericChildResource.java | 31 +- .../AdministrationLinksResource2_0.java | 17 +- .../openmrs2_0/AlertRecipientResource2_0.java | 64 +- .../resource/openmrs2_0/AlertResource2_0.java | 92 +-- .../ConceptProposalResource2_0.java | 128 +-- .../ConceptStateConversionResource2_0.java | 64 +- .../openmrs2_0/DatabaseChangeResource2_0.java | 55 +- .../openmrs2_0/PatientAllergyResource2_0.java | 80 +- .../UnrelatedGenericChildResource.java | 21 +- .../doc/SwaggerSpecificationCreatorTest.java | 543 +++++++------ .../rest/resource/SubDetailsResource.java | 9 +- .../CohortMembershipResource2_1.java | 52 +- .../openmrs2_1/CohortResource2_1.java | 19 +- .../openmrs2_1/ConceptSourceResource2_1.java | 29 +- .../resource/openmrs2_1/ObsResource2_1.java | 36 +- .../openmrs2_1/PersonNameResource2_1.java | 11 +- .../openmrs2_2/ConditionResource2_2.java | 91 ++- .../openmrs2_2/DiagnosisResource2_2.java | 90 +-- .../FulfillerDetailsResource2_2.java | 18 +- .../FulfillerDetailsResource2_3.java | 22 +- .../openmrs2_5/DiagnosisResource2_5.java | 26 +- omod-common/pom.xml | 10 +- .../docs/swagger/NullSerializer.java | 28 - .../webservices/docs/swagger/Operation.java | 182 ----- .../webservices/docs/swagger/Parameter.java | 147 ---- .../module/webservices/docs/swagger/Path.java | 41 - .../webservices/docs/swagger/Paths.java | 40 - .../webservices/docs/swagger/Response.java | 50 -- .../webservices/docs/swagger/Schema.java | 52 -- .../docs/swagger/SecurityDefinitions.java | 26 - .../docs/swagger/SwaggerSpecification.java | 194 ----- .../swagger/SwaggerSpecificationCreator.java | 758 +++++++++--------- .../swagger/core/property/EnumProperty.java | 31 - .../resource/impl/BaseDelegatingResource.java | 282 ++++--- .../impl/BaseDelegatingSubclassHandler.java | 6 +- .../impl/DelegatingResourceHandler.java | 34 +- .../impl/MetadataDelegatingCrudResource.java | 45 +- .../rest/resource/CatSubclassHandler_1_9.java | 14 +- .../MetadataDelegatingCrudResourceTest.java | 14 +- .../SwaggerSpecificationController.java | 25 +- omod/src/main/webapp/apiDocs.jsp | 13 +- 123 files changed, 3927 insertions(+), 4435 deletions(-) delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/NullSerializer.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Operation.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Parameter.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Path.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Paths.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Response.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Schema.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SecurityDefinitions.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecification.java delete mode 100644 omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/core/property/EnumProperty.java diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java index 7aa1da2c0..03b7c75ae 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/CareSettingResource1_10.java @@ -9,15 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; +import io.swagger.v3.oas.models.media.Schema; 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; @@ -71,13 +70,16 @@ public DelegatingResourceDescription getCreatableProperties() { } @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)); + @SuppressWarnings("unchecked") + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("careSettingType", new Schema() + .type("string") + ._enum(Arrays.asList(CareSetting.CareSettingType.values()))); } - return model; + return schema; } /** diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java index b40c3fab0..be0c28b4a 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugReferenceMapResource1_10.java @@ -9,6 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.ConceptMapType; +import org.openmrs.ConceptReferenceTerm; +import org.openmrs.Drug; import org.openmrs.DrugReferenceMap; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; @@ -24,11 +30,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; @@ -117,27 +118,36 @@ 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")); + + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + schema + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("drug", new Schema().$ref("#/components/schemas/DrugGetRef")) + .addProperty("conceptReferenceTerm", new Schema().$ref("#/components/schemas/ConceptreferencetermGetRef")) + .addProperty("conceptMapType", new Schema().$ref("#/components/schemas/ConceptmaptypeGetRef")); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("auditInfo", new StringSchema()) + .addProperty("drug", new Schema().$ref("#/components/schemas/DrugGet")) + .addProperty("conceptReferenceTerm", new Schema().$ref("#/components/schemas/ConceptreferencetermGet")) + .addProperty("conceptMapType", new Schema().$ref("#/components/schemas/ConceptmaptypeGet")); + } } - return modelImpl; + return schema; } - + @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")); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("conceptReferenceTerm", new StringSchema().example("uuid")) + .addProperty("conceptMapType", new StringSchema().example("uuid")) + .addProperty("drug", new StringSchema().example("uuid")); } } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java index 820e8298e..1f42c6cf3 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/DrugResource1_10.java @@ -9,7 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.Drug; +import org.openmrs.DrugReferenceMap; 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.DefaultRepresentation; @@ -18,10 +21,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 @@ -59,22 +58,23 @@ 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")); + + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + if (rep instanceof DefaultRepresentation) { + schema.addProperty("drugReferenceMaps", new Schema().$ref("#/components/schemas/DrugreferencemapGetRef")); + } else if (rep instanceof FullRepresentation) { + schema.addProperty("drugReferenceMaps", new Schema().$ref("#/components/schemas/DrugreferencemapGet")); + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("drugReferenceMaps", new RefProperty("#/definitions/DrugreferencemapCreate")); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("drugReferenceMaps", new Schema().$ref("#/components/schemas/DrugreferencemapCreate")); } } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java index 98b8c0f76..e9f94ff4c 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java @@ -9,18 +9,19 @@ */ 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 io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.CareSetting; +import org.openmrs.Concept; +import org.openmrs.Encounter; import org.openmrs.Order; import org.openmrs.OrderType; import org.openmrs.Patient; +import org.openmrs.User; 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; @@ -31,7 +32,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; @@ -41,6 +41,7 @@ import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -116,41 +117,40 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @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"); + public Schema getCREATESchema(Representation rep) { + Schema schema = new ObjectSchema() + .addProperty("encounter", new StringSchema().example("uuid")) + .addProperty("orderType", new StringSchema().example("uuid")) + .addProperty("action", new Schema()._enum(Arrays.asList(Order.Action.values()))) + .addProperty("accessionNumber", new StringSchema()) + .addProperty("dateActivated", new DateTimeSchema()) + .addProperty("scheduledDate", new DateTimeSchema()) + .addProperty("patient", new StringSchema().example("uuid")) + .addProperty("concept", new StringSchema().example("uuid")) + .addProperty("careSetting", new StringSchema().example("uuid")) + .addProperty("dateStopped", new DateTimeSchema()) + .addProperty("autoExpireDate", new DateTimeSchema()) + .addProperty("orderer", new StringSchema().example("uuid")) + .addProperty("previousOrder", new StringSchema().example("uuid")) + .addProperty("urgency", new Schema()._enum(Arrays.asList(Order.Urgency.values()))) + .addProperty("orderReason", new StringSchema().example("uuid")) + .addProperty("orderReasonNonCoded", new StringSchema()) + .addProperty("instructions", new StringSchema()) + .addProperty("commentToFulfiller", new StringSchema()); + schema.setRequired(Arrays.asList("orderType", "patient", "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()); + schema + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterCreate")) + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientCreate")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("orderer", new Schema().$ref("#/components/schemas/UserCreate")) + .addProperty("previousOrder", new Schema().$ref("#/components/schemas/OrderCreate")) + .addProperty("orderReason", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("orderReasonNonCoded", new StringSchema()) + .addProperty("instructions", new StringSchema()) + .addProperty("commentToFulfiller", new StringSchema()); } - return model; + return schema; } /** diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java index e0eb1037e..499a4f75e 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderTypeResource1_10.java @@ -9,15 +9,16 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; +import java.util.Collections; import java.util.Iterator; 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 io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.ConceptClass; import org.openmrs.OrderType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -153,31 +154,36 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("javaClassName", new StringProperty()); + schema + .addProperty("javaClassName", new StringSchema()); } if (rep instanceof DefaultRepresentation) { - model - .property("conceptClasses", new ArrayProperty(new RefProperty("#/definitions/ConceptclassGetRef"))) - .property("parent", new RefProperty("#/definitions/OrdertypeGetRef")); + schema + .addProperty("conceptClasses", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptclassGetRef"))) + .addProperty("parent", new Schema().$ref("#/components/schemas/OrdertypeGetRef")); } else if (rep instanceof FullRepresentation) { - model - .property("conceptClasses", new ArrayProperty(new RefProperty("#/definitions/ConceptclassGet"))) - .property("parent", new RefProperty("#/definitions/OrdertypeGet")); + schema + .addProperty("conceptClasses", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptclassGetFull"))) + .addProperty("parent", new Schema().$ref("#/components/schemas/OrdertypeGetFull")); } - return model; + return schema; } @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"); + public Schema getCREATESchema(Representation rep) { + Schema schema = super.getCREATESchema(rep); + if (schema instanceof ObjectSchema) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("javaClassName", new StringSchema()) + .addProperty("parent", new StringSchema().example("uuid")) + .addProperty("conceptClasses", new ArraySchema().items(new StringSchema().example("uuid"))); + + objectSchema.setRequired(Collections.singletonList("javaClassName")); + } + return schema; } } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java index e605ecdf1..fbc830529 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java @@ -9,7 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.Person; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -59,23 +59,23 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.addProperty("birthtime"); return description; } + @Override - public Model getGETModel(Representation rep) { - return addNewProperties(super.getGETModel(rep), rep); + public Schema getGETSchema(Representation rep) { + return addNewProperties(super.getGETSchema(rep), rep); } @Override - public Model getCREATEModel(Representation rep) { - return addNewProperties(super.getCREATEModel(rep), rep); + public Schema getCREATESchema(Representation rep) { + return addNewProperties(super.getCREATESchema(rep), rep); } @Override - public Model getUPDATEModel(Representation rep) { - return addNewProperties(super.getUPDATEModel(rep), rep); + public Schema getUPDATESchema(Representation rep) { + return addNewProperties(super.getUPDATESchema(rep), rep); } - private Model addNewProperties(Model model, Representation rep) { - + private Schema addNewProperties(Schema model, Representation rep) { return model; } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java index 3fad6b60f..5e88f70d2 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramEnrollmentResource1_10.java @@ -9,12 +9,13 @@ */ 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 io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import org.openmrs.Concept; +import org.openmrs.Location; import org.openmrs.PatientProgram; import org.openmrs.PatientState; import org.openmrs.api.context.Context; @@ -100,23 +101,28 @@ public DelegatingResourceDescription getCreatableProperties() { } @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")); + public Schema getCREATESchema(Representation rep) { + Schema schema = super.getCREATESchema(rep); + if (schema != null) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("states", new ArraySchema().items(new Schema().$ref("#/components/schemas/ProgramenrollmentStateCreate"))) + .addProperty("outcome", new Schema().$ref("#/components/schemas/ConceptCreate")); + } + return schema; } @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"); + @SuppressWarnings("unchecked") + public Schema getUPDATESchema(Representation rep) { + return super.getUPDATESchema(rep) + .addProperty("dateEnrolled", new DateTimeSchema()) + .addProperty("states", new ArraySchema().items(new Schema().$ref("#/components/schemas/ProgramenrollmentStateCreate"))) + .addProperty("outcome", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationCreate")) + .addProperty("voided", new BooleanSchema()) + .addProperty("dateCompleted", new DateTimeSchema()) + .required(Collections.singletonList("dateEnrolled")); } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java index 123d687bc..e34eefe3a 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/ProgramResource1_10.java @@ -9,10 +9,10 @@ */ 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 io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Concept; import org.openmrs.Program; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -65,14 +65,13 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("outcomesConcept", new StringProperty().example("uuid")); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = (ObjectSchema) super.getCREATESchema(rep) + .addProperty("outcomesConcept", new StringSchema().example("uuid")); if (rep instanceof FullRepresentation) { - model - .property("outcomesConcept", new RefProperty("#/definitions/ConceptCreate")); + schema.addProperty("outcomesConcept", new Schema().$ref("#/components/schemas/ConceptCreate")); } - return model; + return schema; } @Override @@ -86,5 +85,4 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("retired"); return description; } - } diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java index a42d475fb..1fd90d24e 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/TestOrderSubclassHandler1_10.java @@ -9,17 +9,23 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; +import java.util.Arrays; import java.util.List; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.CareSetting; +import org.openmrs.Concept; import org.openmrs.Order; +import org.openmrs.OrderFrequency; import org.openmrs.OrderType; import org.openmrs.Patient; 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; @@ -35,12 +41,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} @@ -130,45 +130,45 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } @Override - public Model getGETModel(Representation rep) { + public Schema getGETSchema(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()); + ObjectSchema orderSchema = (ObjectSchema) orderResource.getGETSchema(rep); + orderSchema + .addProperty("laterality", new Schema()._enum(Arrays.asList(TestOrder.Laterality.values()))) + .addProperty("clinicalHistory", new StringSchema()) + .addProperty("numberOfRepeats", new IntegerSchema()); if (rep instanceof DefaultRepresentation) { - orderModel - .property("specimenSource", new RefProperty("#/definitions/ConceptGetRef")) - .property("frequency", new RefProperty("#/definitions/OrderfrequencyGetRef")); + orderSchema + .addProperty("specimenSource", new Schema().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("frequency", new Schema().$ref("#/components/schemas/OrderfrequencyGetRef")); } else if (rep instanceof FullRepresentation) { - orderModel - .property("specimenSource", new RefProperty("#/definitions/ConceptGet")) - .property("frequency", new RefProperty("#/definitions/OrderfrequencyGet")); + orderSchema + .addProperty("specimenSource", new Schema().$ref("#/components/schemas/ConceptGetFull")) + .addProperty("frequency", new Schema().$ref("#/components/schemas/OrderfrequencyGetFull")); } - return orderModel; + return orderSchema; } @Override - public Model getCREATEModel(Representation rep) { + public Schema getCREATESchema(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()); + ObjectSchema orderSchema = (ObjectSchema) orderResource.getCREATESchema(rep); + return orderSchema + .addProperty("specimenSource", new StringSchema().example("uuid")) + .addProperty("laterality", new Schema()._enum(Arrays.asList(TestOrder.Laterality.values()))) + .addProperty("clinicalHistory", new StringSchema()) + .addProperty("frequency", new StringSchema().example("uuid")) + .addProperty("numberOfRepeats", new IntegerSchema()); } @Override - public Model getUPDATEModel(Representation rep) { + public Schema getUPDATESchema(Representation rep) { OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class) .getResourceBySupportedClass(Order.class); - return orderResource.getUPDATEModel(rep); + return orderResource.getUPDATESchema(rep); } public PageableResult getActiveOrders(Patient patient, RequestContext context) { diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/DrugIngredientResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/DrugIngredientResource1_11.java index 15dbb8976..63fd359d4 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/DrugIngredientResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/DrugIngredientResource1_11.java @@ -10,13 +10,14 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Concept; import org.openmrs.Drug; import org.openmrs.DrugIngredient; import org.openmrs.api.context.Context; @@ -86,39 +87,39 @@ public DelegatingResourceDescription getUpdatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema schema = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("strength", new DoubleProperty()); + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("strength", new NumberSchema().format("double")); } if (rep instanceof DefaultRepresentation) { - modelImpl - .property("ingredient", new RefProperty("#/definitions/ConceptGetRef")) - .property("units", new RefProperty("#/definitions/ConceptGetRef")); + schema + .addProperty("ingredient", new Schema().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("units", new Schema().$ref("#/components/schemas/ConceptGetRef")); } else if (rep instanceof FullRepresentation) { - modelImpl - .property("ingredient", new RefProperty("#/definitions/ConceptGet")) - .property("units", new RefProperty("#/definitions/ConceptGet")); + schema + .addProperty("ingredient", new Schema().$ref("#/components/schemas/ConceptGetFull")) + .addProperty("units", new Schema().$ref("#/components/schemas/ConceptGetFull")); } - return modelImpl; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("ingredient", new StringProperty().example("uuid")) - .property("strength", new DoubleProperty()) - .property("units", new StringProperty().example("uuid")) - - .required("ingredient"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("ingredient", new Schema().$ref("#/components/schemas/ConceptCreate").example("uuid")) + .addProperty("strength", new NumberSchema().format("double")) + .addProperty("units", new Schema().$ref("#/components/schemas/ConceptCreate").example("uuid")) + .required(Collections.singletonList("ingredient")); } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java index 14626f497..138f5c6cc 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java @@ -9,9 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.BooleanUtils; import org.openmrs.Concept; import org.openmrs.ConceptNumeric; @@ -43,17 +43,17 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("formFieldPath", new StringProperty()) - .property("formFieldNamespace", new StringProperty()); + public Schema getGETSchema(Representation rep) { + return ((ObjectSchema) super.getGETSchema(rep)) + .addProperty("formFieldPath", new StringSchema()) + .addProperty("formFieldNamespace", new StringSchema()); } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("formFieldPath", new StringProperty()) - .property("formFieldNamespace", new StringProperty()); + public Schema getCREATESchema(Representation rep) { + return ((ObjectSchema) super.getCREATESchema(rep)) + .addProperty("formFieldPath", new StringSchema()) + .addProperty("formFieldNamespace", new StringSchema()); } /** diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java index 5a272b267..ecc8ca1c8 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/PersonResource1_11.java @@ -9,9 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.Person; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -64,24 +63,23 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } @Override - public Model getGETModel(Representation rep) { - return addNewProperties(super.getGETModel(rep), rep); + public Schema getGETSchema(Representation rep) { + return addNewProperties(super.getGETSchema(rep), rep); } - + @Override - public Model getCREATEModel(Representation rep) { - return addNewProperties(super.getCREATEModel(rep), rep); + public Schema getCREATESchema(Representation rep) { + return addNewProperties(super.getCREATESchema(rep), rep); } @Override - public Model getUPDATEModel(Representation rep) { - return addNewProperties(super.getUPDATEModel(rep), rep); + public Schema getUPDATESchema(Representation rep) { + return addNewProperties(super.getUPDATESchema(rep), rep); } - private Model addNewProperties(Model model, Representation rep) { + private Schema addNewProperties(Schema model, Representation rep) { if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - ((ModelImpl) model) - .property("deathdateEstimated", new BooleanProperty()._default(false)); + model.addProperty("deathdateEstimated", new BooleanSchema()._default(false)); } return model; } diff --git a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java index e54ac146d..8686c6eb1 100644 --- a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java +++ b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderGroupResource1_12.java @@ -9,8 +9,15 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_12; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Encounter; import org.openmrs.Order; import org.openmrs.OrderGroup; +import org.openmrs.OrderSet; import org.openmrs.Patient; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -27,13 +34,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.ArrayProperty; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - @Resource(name = RestConstants.VERSION_1 + "/ordergroup", supportedClass = OrderGroup.class, supportedOpenmrsVersions = { "1.12.* - 9.*" }) public class OrderGroupResource1_12 extends DataDelegatingCrudResource { @@ -127,44 +127,51 @@ public DelegatingResourceDescription getUpdatableProperties() { description.addProperty("orders"); return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - modelImpl.property("uuid", new StringProperty()).property("display", new StringProperty()) - .property("voided", new BooleanProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("encounter", new RefProperty("#/definitions/EncounterGetRef")) - .property("orders", new RefProperty("#/definitions/OrderGetRef")) - .property("orderSet", new RefProperty("#/definitions/OrdersetGetRef")); - - } else if (rep instanceof FullRepresentation) { - modelImpl.property("uuid", new StringProperty()).property("display", new StringProperty()) - .property("voided", new BooleanProperty()).property("auditInfo", new BooleanProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("encounter", new RefProperty("#/definitions/EncounterGetRef")) - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderGetRef"))) - .property("orderSet", new RefProperty("#/definitions/OrdersetGetRef")); - } else if (rep instanceof RefRepresentation) { - modelImpl.property("display", new StringProperty()).property("uuid", new StringProperty()); - + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof Schema) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("voided", new BooleanSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetRef")) + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterGetRef")) + .addProperty("orders", new Schema().$ref("#/components/schemas/OrderGetRef")) + .addProperty("orderSet", new Schema().$ref("#/components/schemas/OrdersetGetRef")); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("auditInfo", new BooleanSchema()) + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetRef")) + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterGetRef")) + .addProperty("orders", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrderGetRef"))) + .addProperty("orderSet", new Schema().$ref("#/components/schemas/OrdersetGetRef")); + } else if (rep instanceof RefRepresentation) { + schema + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()); + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl().property("patient", new StringProperty().example("uuid")) - .property("encounter", new StringProperty().example("uuid")) - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderCreate"))) - .property("orderSet", new StringProperty().example("uuid")); + public Schema getCREATESchema(Representation representation) { + return new ObjectSchema() + .addProperty("patient", new StringSchema().example("uuid")) + .addProperty("encounter", new StringSchema().example("uuid")) + .addProperty("orders", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrderCreate"))) + .addProperty("orderSet", new StringSchema().example("uuid")); } - + @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl().property("orders", - new ArrayProperty(new RefProperty("#/definitions/OrderCreate"))); + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("orders", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrderCreate"))); } @PropertyGetter("display") diff --git a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java index 9ae07a777..e8a70771c 100644 --- a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java +++ b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetMemberResource1_12.java @@ -12,8 +12,14 @@ import java.util.ArrayList; import java.util.List; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Concept; import org.openmrs.OrderSet; import org.openmrs.OrderSetMember; +import org.openmrs.OrderType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -30,13 +36,6 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * {@link Resource} for OrderSetMembers, supporting standard CRUD operations */ @@ -103,43 +102,44 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("orderTemplate", new StringProperty()) - .property("orderTemplateType", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("orderType", new RefProperty("#/definitions/OrdertypeGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("orderType", new RefProperty("#/definitions/OrdertypeGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("retired", new BooleanSchema()) + .addProperty("orderTemplate", new StringSchema()) + .addProperty("orderTemplateType", new StringSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("orderType", new Schema().$ref("#/components/schemas/OrdertypeGetRef")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetRef")); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("orderType", new Schema().$ref("#/components/schemas/OrdertypeGet")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")); + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("orderType", new ObjectProperty() - .property("uuid", new StringProperty())) - .property("orderTemplate", new StringProperty()) - .property("concept", new StringProperty().example("uuid")) - .property("retired", new BooleanProperty()); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("orderType", new ObjectSchema() + .addProperty("uuid", new StringSchema())) + .addProperty("orderTemplate", new StringSchema()) + .addProperty("concept", new StringSchema().example("uuid")) + .addProperty("retired", new BooleanSchema()); } - + @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } @Override diff --git a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetResource1_12.java b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetResource1_12.java index 41176c265..36665f865 100644 --- a/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetResource1_12.java +++ b/omod-1.12/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_12/OrderSetResource1_12.java @@ -9,16 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_12; -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.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openmrs.OrderSet; import org.openmrs.OrderSetMember; 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.PropertySetter; @@ -32,6 +30,7 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; import java.util.List; @Resource(name = RestConstants.VERSION_1 + "/orderset", supportedClass = OrderSet.class, supportedOpenmrsVersions = { @@ -107,31 +106,31 @@ public DelegatingResourceDescription getCreatableProperties() { d.addProperty("orderSetMembers"); return d; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("operator", new EnumProperty(OrderSet.Operator.class)); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("orderSetMembers", new ArrayProperty(new RefProperty( - "#/definitions/OrdersetOrdersetmemberGetRef"))); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("orderSetMembers", new ArrayProperty( - new RefProperty("#/definitions/OrdersetOrdersetmemberGet"))); + @SuppressWarnings("unchecked") + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("operator", new Schema().type("string")._enum(Arrays.asList(OrderSet.Operator.values()))); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("orderSetMembers", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrdersetOrdersetmemberGetRef"))); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("orderSetMembers", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrdersetOrdersetmemberGet"))); + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("operator", new EnumProperty(OrderSet.Operator.class)) - .property("orderSetMembers", - new ArrayProperty(new RefProperty("#/definitions/OrdersetOrdersetmemberCreate"))); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation representation) { + return new ObjectSchema() + .addProperty("operator", new Schema().type("string")._enum(Arrays.asList(OrderSet.Operator.values()))) + .addProperty("orderSetMembers", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrdersetOrdersetmemberCreate"))); } } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/AllergyResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/AllergyResource1_8.java index 9892c90e4..095c56b24 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/AllergyResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/AllergyResource1_8.java @@ -9,17 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; import org.openmrs.Patient; import org.openmrs.activelist.Allergy; import org.openmrs.activelist.AllergySeverity; import org.openmrs.activelist.AllergyType; 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.PropertyGetter; @@ -34,6 +31,8 @@ import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; +import java.util.Arrays; + /** * {@link Resource} for Allergy, supporting standard CRUD operations */ @@ -64,28 +63,34 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)) - .property("allergyType", new EnumProperty(AllergyType.class)) - .property("reaction", new RefProperty("#/definitions/ConceptGetRef")) - .property("severity", new EnumProperty(AllergySeverity.class)) - .property("allergen", new RefProperty("#/definitions/ConceptGetRef")); - if (rep instanceof FullRepresentation) { - model - .property("reaction", new RefProperty("#/definitions/ConceptGet")) - .property("allergen", new RefProperty("#/definitions/ConceptGet")); + @SuppressWarnings("unchecked") + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof ObjectSchema) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("allergyType", new Schema().type("string")._enum(Arrays.asList(AllergyType.values()))) + .addProperty("reaction", new Schema().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("severity", new Schema().type("string")._enum(Arrays.asList(AllergySeverity.values()))) + .addProperty("allergen", new Schema().$ref("#/components/schemas/ConceptGetRef")); + if (rep instanceof FullRepresentation) { + objectSchema + .addProperty("reaction", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("allergen", new Schema().$ref("#/components/schemas/ConceptGet")); + } } - return model; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("allergyType", new EnumProperty(AllergyType.class)) - .property("reaction", new ObjectProperty() - .property("uuid", new StringProperty())) - .property("severity", new EnumProperty(AllergySeverity.class)) - .property("allergen", new StringProperty()); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("allergyType", new Schema().type("string")._enum(Arrays.asList(AllergyType.values()))) + .addProperty("reaction", new ObjectSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("severity", new Schema().type("string")._enum(Arrays.asList(AllergySeverity.values()))) + .addProperty("allergen", new StringSchema()); } /** @@ -127,7 +132,7 @@ public String getDisplayString(Allergy allergy) { /** * Annotated setter for allergen * - * @param allergen + * @param allergy * @param value */ @PropertySetter("allergen") @@ -158,4 +163,4 @@ protected PageableResult doSearch(RequestContext context) { return super.doSearch(context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java index 9ef1b74c0..e54fa8d97 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/BaseActiveListItemResource1_8.java @@ -9,12 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import org.openmrs.Obs; +import org.openmrs.Person; import org.openmrs.activelist.ActiveListItem; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -26,6 +28,8 @@ import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; + /** * Subclass of {@link DataDelegatingCrudResource} with helper methods specific to * {@link ActiveListItem} @@ -33,22 +37,49 @@ public abstract class BaseActiveListItemResource1_8 extends DataDelegatingCrudResource { @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("person", new StringProperty()) - .property("startDate", new DateProperty()) - .property("comments", new StringProperty()) - .property("startObs", new StringProperty()) - .property("stopObs", new StringProperty()) - - .required("person").required("startDate"); + public Schema getGETSchema(Representation rep) { + Schema schema = new ObjectSchema() + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("startDate", new DateTimeSchema()) + .addProperty("endDate", new DateTimeSchema()) + .addProperty("comments", new StringSchema()) + .addProperty("voided", new BooleanSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGet")) + .addProperty("activeListType", new StringSchema()) + .addProperty("startObs", new Schema().$ref("#/components/schemas/ObsGet")) + .addProperty("stopObs", new Schema().$ref("#/components/schemas/ObsGetRef")); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGetRef")) + .addProperty("activeListType", new StringSchema()) + .addProperty("startObs", new Schema().$ref("#/components/schemas/ObsGetRef")) + .addProperty("stopObs", new Schema().$ref("#/components/schemas/ObsGetRef")); + } + return schema; + } + + @Override + public Schema getCREATESchema(Representation rep) { + Schema schema = new ObjectSchema() + .addProperty("person", new StringSchema()) + .addProperty("startDate", new DateSchema()) + .addProperty("comments", new StringSchema()) + .addProperty("startObs", new StringSchema()) + .addProperty("stopObs", new StringSchema()); + + schema.setRequired(Arrays.asList("person", "startDate")); + if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonCreate")) - .property("startObs", new RefProperty("#/definitions/ObsCreate")) - .property("stopObs", new RefProperty("#/definitions/ObsCreate")); + schema.addProperty("person", new Schema().$ref("#/components/schemas/PersonCreate")); + schema.addProperty("startObs", new Schema().$ref("#/components/schemas/ObsCreate")); + schema.addProperty("stopObs", new Schema().$ref("#/components/schemas/ObsCreate")); } - return model; + + return schema; } /** @@ -90,30 +121,6 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("comments", new StringProperty()) - .property("voided", new BooleanProperty()); - if (rep instanceof DefaultRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGet")) - .property("activeListType", new StringProperty()) //FIXME type - .property("startObs", new RefProperty("#/definitions/ObsGet")) - .property("stopObs", new RefProperty("#/definitions/ObsGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGetRef")) - .property("activeListType", new StringProperty()) //FIXME type - .property("startObs", new RefProperty("#/definitions/ObsGetRef")) - .property("stopObs", new RefProperty("#/definitions/ObsGetRef")); - } - return model; - } - /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -174,4 +181,4 @@ public void purge(T delegate, RequestContext context) throws ResponseException { //delegate.setComments("Stopped from a REST web service call"); //Context.getActiveListService().removeActiveListItem(delegate, null); -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java index e062d1db3..940d82880 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortMemberResource1_8.java @@ -10,12 +10,13 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Cohort; import org.openmrs.Patient; import org.openmrs.api.context.Context; @@ -119,38 +120,31 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = new Schema(); if (rep instanceof RefRepresentation) { - modelImpl - .property("display", new StringProperty()); - } else if (rep instanceof DefaultRepresentation) { - modelImpl - .property("display", new StringProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("display", new StringProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")); + schema + .addProperty("display", new StringSchema()); + } else if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { + schema + .addProperty("display", new StringSchema()) + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetRef")); } - return modelImpl; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("patient", new StringProperty().example("uuid")) - .required("patient"); - if (rep instanceof FullRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientCreate")); - } - return model; + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema.addProperty("patient", new StringSchema().example("uuid")); + schema.setRequired(Collections.singletonList("patient")); + return schema; } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** @@ -279,4 +273,4 @@ public String getDisplayString(CohortMember1_8 member) { return member.getPatient().getPatientIdentifier().getIdentifier() + " - " + member.getPatient().getPersonName().getFullName(); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java index ff12bc660..83a80ebd2 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/CohortResource1_8.java @@ -9,13 +9,16 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; +import java.util.Arrays; +import java.util.Collections; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.BooleanSchema; import org.openmrs.Cohort; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -91,35 +94,40 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("voided", new StringProperty()) - .property("memberIds", new ArrayProperty(new IntegerProperty())); //FIXME + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("voided", new BooleanSchema()) + .addProperty("memberIds", new ArraySchema().items(new IntegerSchema())); } - return model; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("memberIds", new ArrayProperty(new IntegerProperty())) //FIXME - .required("name").required("description").required("memberIds"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("memberIds", new ArraySchema().items(new IntegerSchema())); + schema.setRequired(Arrays.asList("name", "description", "memberIds")); + return schema; } @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .required("name").required("description"); + public Schema getUPDATESchema(Representation representation) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()); + schema.setRequired(Arrays.asList("name", "description")); + return schema; } /** @@ -204,4 +212,4 @@ protected NeedsPaging doSearch(RequestContext context) { return new NeedsPaging(cohorts, context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java index e4a8e25a0..30960311b 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptClassResource1_8.java @@ -9,7 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.ConceptClass; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -67,11 +67,6 @@ public void purge(ConceptClass conceptClass, RequestContext context) throws Resp Context.getConceptService().purgeConceptClass(conceptClass); } - @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); - } - /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @@ -80,5 +75,12 @@ protected NeedsPaging doGetAll(RequestContext context) { return new NeedsPaging(Context.getConceptService().getAllConceptClasses(context.getIncludeAll()), context); } - + + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource#getCREATESchema(Representation) (Representation) + */ + @Override + public Schema getGETSchema(Representation rep) { + return getCREATESchema(rep); + } } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java index 0de73cceb..937cba458 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDatatypeResource1_8.java @@ -9,10 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.BooleanSchema; import org.openmrs.ConceptDatatype; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.SimpleObject; @@ -67,18 +66,19 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("hl7Abbreviation", new StringProperty()) - .property("retired", new BooleanProperty()); + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("hl7Abbreviation", new StringSchema()) + .addProperty("retired", new BooleanSchema()); } - return model; + return schema; } /** @@ -146,4 +146,4 @@ protected NeedsPaging doGetAll(RequestContext context) { context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDescriptionResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDescriptionResource1_8.java index d5465bd38..928389a1f 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDescriptionResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptDescriptionResource1_8.java @@ -10,11 +10,12 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; import org.openmrs.Concept; import org.openmrs.ConceptDescription; import org.openmrs.api.context.Context; @@ -67,34 +68,37 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = new ObjectSchema(); if (rep instanceof RefRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()); } else if (rep instanceof DefaultRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("description", new StringProperty()) - .property("locale", new StringProperty()); + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("locale", new StringSchema()); } else if (rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("description", new StringProperty()) - .property("locale", new StringProperty()); + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("locale", new StringSchema()); } - return modelImpl; + return schema; } @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("description", new StringProperty()) - .property("locale", new StringProperty().example("fr")) - .required("description").required("locale"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("description", new StringSchema()) + .addProperty("locale", new StringSchema().example("fr")); + schema.setRequired(Arrays.asList("description", "locale")); + return schema; } /** @@ -212,4 +216,4 @@ public String getLocaleAsString(ConceptDescription instance) { return instance.getLocale().toString(); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptMapResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptMapResource1_8.java index 798d54364..3dd0234e3 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptMapResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptMapResource1_8.java @@ -10,11 +10,12 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; import org.openmrs.Concept; import org.openmrs.ConceptMap; import org.openmrs.api.context.Context; @@ -65,31 +66,34 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = new ObjectSchema(); if (rep instanceof DefaultRepresentation) { - modelImpl - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("source", new StringProperty()) //FIXME - .property("sourceCode", new StringProperty()); + schema + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("source", new Schema().$ref("#/components/schemas/ConceptSourceGetRef")) + .addProperty("sourceCode", new StringSchema()); } else if (rep instanceof FullRepresentation) { - modelImpl - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("source", new StringProperty()) //FIXME - .property("sourceCode", new StringProperty()) - .property("comment", new StringProperty()); + schema + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("source", new Schema().$ref("#/components/schemas/ConceptSourceGet")) + .addProperty("sourceCode", new StringSchema()) + .addProperty("comment", new StringSchema()); } - return modelImpl; + return schema; } @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("source", new StringProperty()) - .property("sourceCode", new StringProperty()) - .required("source").required("sourceCode"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("source", new StringSchema()) + .addProperty("sourceCode", new StringSchema()); + schema.setRequired(Arrays.asList("source", "sourceCode")); + return schema; } /** @@ -188,4 +192,4 @@ public void purge(ConceptMap delegate, RequestContext context) throws ResponseEx delegate.getConcept().removeConceptMapping(delegate); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptNameResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptNameResource1_8.java index 8088f9f54..14da3e1d2 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptNameResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptNameResource1_8.java @@ -10,18 +10,19 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; import org.openmrs.Concept; import org.openmrs.ConceptName; import org.openmrs.api.ConceptNameType; 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.PropertyGetter; @@ -29,6 +30,7 @@ import org.openmrs.module.webservices.rest.web.annotation.SubResource; import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; +import org.openmrs.module.webservices.rest.web.representation.RefRepresentation; import org.openmrs.module.webservices.rest.web.representation.Representation; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource; @@ -44,7 +46,13 @@ public class ConceptNameResource1_8 extends DelegatingSubResource getGETSchema(Representation rep) { + Schema schema = new Schema(); + if (rep instanceof RefRepresentation) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()); + } else if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("name", new StringSchema()) + .addProperty("locale", new StringSchema().example("en")) + .addProperty("localePreferred", new BooleanSchema()) + .addProperty("conceptNameType", new Schema()._enum(Arrays.asList(ConceptNameType.values()))); } - return model; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("locale", new StringProperty().example("en")) - .property("localePreferred", new BooleanProperty()._default(false)) - .property("conceptNameType", new EnumProperty(ConceptNameType.class)) - .required("name").required("locale"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("name", new StringSchema()) + .addProperty("locale", new StringSchema().example("en")) + .addProperty("localePreferred", new BooleanSchema()._default(false)) + .addProperty("conceptNameType", new Schema()._enum(Arrays.asList(ConceptNameType.values()))); + schema.setRequired(Arrays.asList("name", "locale")); + return schema; } @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("name", new StringProperty()); //FIXME missing props + public Schema getUPDATESchema(Representation representation) { + return new Schema() + .addProperty("name", new StringSchema()); } /** @@ -230,4 +244,4 @@ public String getLocaleAsString(ConceptName instance) { return instance.getLocale().toString(); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptResource1_8.java index 9c2042dc9..c34bbf39d 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptResource1_8.java @@ -9,13 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.Concept; import org.openmrs.ConceptAnswer; @@ -69,9 +67,9 @@ /** * {@link Resource} for {@link Concept}, supporting standard CRUD operations */ -@Resource(name = RestConstants.VERSION_1 + "/concept", order = 2, supportedClass = Concept.class, supportedOpenmrsVersions = "1.8.*") +@Resource(name = RestConstants.VERSION_1 + "/concept", supportedClass = Concept.class, supportedOpenmrsVersions = "1.8.*") public class ConceptResource1_8 extends DelegatingCrudResource { - + public ConceptResource1_8() { //RESTWS-439 //Concept numeric fields @@ -86,7 +84,7 @@ public ConceptResource1_8() { allowedMissingProperties.add("allowDecimal"); allowedMissingProperties.add("displayPrecision"); } - + @RepHandler(RefRepresentation.class) public SimpleObject asRef(Concept delegate) throws ConversionException { DelegatingResourceDescription description = new DelegatingResourceDescription(); @@ -98,38 +96,38 @@ public SimpleObject asRef(Concept delegate) throws ConversionException { description.addSelfLink(); return convertDelegateToRepresentation(delegate, description); } - + @RepHandler(FullRepresentation.class) public SimpleObject asFull(Concept delegate) throws ConversionException { DelegatingResourceDescription description = fullRepresentationDescription(delegate); return convertDelegateToRepresentation(delegate, description); } - + @RepHandler(value = NamedRepresentation.class, name = "fullchildren") public SimpleObject asFullChildren(Concept delegate) throws ConversionException { Set path = new HashSet(); path.add(delegate.getUuid()); assertNoCycles(delegate, path); - + return asFullChildrenInternal(delegate); } - + protected void assertNoCycles(Concept delegate, Set path) throws ConversionException { for (Concept member : delegate.getSetMembers()) { if (path.add(member.getUuid())) { assertNoCycles(member, path); } else { throw new ConversionException("Cycles in children are not supported. Concept with uuid " - + delegate.getUuid() + " repeats in a set."); + + delegate.getUuid() + " repeats in a set."); } path.remove(member.getUuid()); } } - + /** * It is used internally for the fullchildren representation. Contrary to the fullchildren * handler it does not check for cycles. - * + * * @param delegate * @return * @throws ConversionException @@ -143,14 +141,14 @@ public SimpleObject asFullChildrenInternal(Concept delegate) throws ConversionEx description.addProperty("answers", Representation.FULL); return convertDelegateToRepresentation(delegate, description); } - + @Override public List getAvailableRepresentations() { List availableRepresentations = super.getAvailableRepresentations(); availableRepresentations.add(new NamedRepresentation("fullchildren")); return availableRepresentations; } - + protected DelegatingResourceDescription fullRepresentationDescription(Concept delegate) { DelegatingResourceDescription description = new DelegatingResourceDescription(); description.addProperty("uuid"); @@ -161,12 +159,12 @@ protected DelegatingResourceDescription fullRepresentationDescription(Concept de description.addProperty("set"); description.addProperty("version"); description.addProperty("retired"); - + description.addProperty("names", Representation.DEFAULT); description.addProperty("descriptions", Representation.DEFAULT); - + description.addProperty("mappings", Representation.DEFAULT); - + description.addProperty("answers", Representation.DEFAULT); description.addProperty("setMembers", Representation.DEFAULT); description.addProperty("auditInfo"); @@ -183,7 +181,7 @@ protected DelegatingResourceDescription fullRepresentationDescription(Concept de } return description; } - + /** * @see DelegatingCrudResource#getRepresentationDescription(Representation) */ @@ -199,89 +197,114 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addProperty("set"); description.addProperty("version"); description.addProperty("retired"); - + description.addProperty("names", Representation.REF); description.addProperty("descriptions", Representation.REF); - + description.addProperty("mappings", Representation.REF); - + description.addProperty("answers", Representation.REF); description.addProperty("setMembers", Representation.REF); //description.addProperty("conceptMappings", Representation.REF); add as subresource - + description.addSelfLink(); description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL); return description; } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("name", new RefProperty("#/definitions/ConceptNameGet")) - .property("datatype", new RefProperty("#/definitions/ConceptdatatypeGetRef")) - .property("conceptClass", new RefProperty("#/definitions/ConceptclassGetRef")) - .property("set", new BooleanProperty()) - .property("version", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameGetRef"))) //FIXME - .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionGetRef"))) //FIXME - .property("mappings", new ArrayProperty(new RefProperty("#/definitions/ConceptMappingGetRef"))) //FIXME - .property("answers", new ArrayProperty(new ObjectProperty())) //FIXME - .property("setMembers", new ArrayProperty(new ObjectProperty())); //FIXME + + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = new Schema(); + if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("name", new Schema().$ref("#/components/schemas/ConceptNameGet")) + .addProperty("datatype", new Schema().$ref("#/components/schemas/ConceptdatatypeGetRef")) + .addProperty("conceptClass", new Schema().$ref("#/components/schemas/ConceptclassGetRef")) + .addProperty("set", new BooleanSchema()) + .addProperty("version", new StringSchema()) + .addProperty("retired", new BooleanSchema()) + .addProperty("names", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptNameGetRef"))) + .addProperty("descriptions", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptDescriptionGetRef"))) + .addProperty("mappings", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptMappingGetRef"))) + .addProperty("answers", new ArraySchema().items(new Schema())) + .addProperty("setMembers", new ArraySchema().items(new Schema())); } - return modelImpl; + return schema; } - + +// @Override +// public Schema getCREATESchema(Representation rep) { +// return new ObjectSchema() +// .addProperty("names", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptNameCreate"))) +// .addProperty("datatype", new StringSchema().example("uuid")) +// .addProperty("set", new BooleanSchema()) +// .addProperty("version", new StringSchema()) +// .addProperty("answers", new ArraySchema().items(new StringSchema().example("uuid"))) +// .addProperty("setMembers", new ArraySchema().items(new StringSchema().example("uuid"))) +// +// //ConceptNumeric properties +// .addProperty("hiNormal", new StringSchema()) +// .addProperty("hiAbsolute", new StringSchema()) +// .addProperty("hiCritical", new StringSchema()) +// .addProperty("lowNormal", new StringSchema()) +// .addProperty("lowAbsolute", new StringSchema()) +// .addProperty("lowCritical", new StringSchema()) +// .addProperty("units", new StringSchema()) +// .addProperty("allowDecimal", new StringSchema()) +// .addProperty("displayPrecision", new StringSchema()) +// +// .required("names").required("datatype").required("conceptClass"); +// } + @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameCreate"))) - .property("datatype", new StringProperty().example("uuid")) - .property("set", new BooleanProperty()) - .property("version", new StringProperty()) - .property("answers", new ArrayProperty(new StringProperty().example("uuid"))) - .property("setMembers", new ArrayProperty(new StringProperty().example("uuid"))) - - //ConceptNumeric properties - .property("hiNormal", new StringProperty()) - .property("hiAbsolute", new StringProperty()) - .property("hiCritical", new StringProperty()) - .property("lowNormal", new StringProperty()) - .property("lowAbsolute", new StringProperty()) - .property("lowCritical", new StringProperty()) - .property("units", new StringProperty()) - .property("allowDecimal", new StringProperty()) - .property("displayPrecision", new StringProperty()) - - .required("names").required("datatype").required("conceptClass"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("names", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptNameCreate"))) + .addProperty("datatype", new StringSchema().example("uuid")) + .addProperty("set", new BooleanSchema()) + .addProperty("version", new StringSchema()) + .addProperty("answers", new ArraySchema().items(new StringSchema().example("uuid"))) + .addProperty("setMembers", new ArraySchema().items(new StringSchema().example("uuid"))) + + //ConceptNumeric properties + .addProperty("hiNormal", new StringSchema()) + .addProperty("hiAbsolute", new StringSchema()) + .addProperty("hiCritical", new StringSchema()) + .addProperty("lowNormal", new StringSchema()) + .addProperty("lowAbsolute", new StringSchema()) + .addProperty("lowCritical", new StringSchema()) + .addProperty("units", new StringSchema()) + .addProperty("allowDecimal", new StringSchema()) + .addProperty("displayPrecision", new StringSchema()); + schema.setRequired(Arrays.asList("name", "datatype", "conceptClass")); if (rep instanceof DefaultRepresentation) { - model - .property("conceptClass", new StringProperty()) - .property("descriptions", new ArrayProperty(new StringProperty())) - .property("mappings", new ArrayProperty(new StringProperty())); + schema + .addProperty("conceptClass", new StringSchema()) + .addProperty("descriptions", new ArraySchema().items(new StringSchema())) + .addProperty("mappings", new ArraySchema().items(new StringSchema())); } else if (rep instanceof FullRepresentation) { - model - .property("conceptClass", new RefProperty("#/definitions/ConceptclassCreate")) - .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionCreate"))) - .property("mappings", new ArrayProperty(new RefProperty("#/definitions/ConceptMappingCreate"))); + schema + .addProperty("conceptClass", new Schema().$ref("#/components/schemas/ConceptclassCreate")) + .addProperty("descriptions", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptDescriptionCreate"))) + .addProperty("mappings", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptMappingCreate"))); } - return model; + return schema; } - + @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("name", new RefProperty("#/definitions/ConceptNameCreate")) - .property("names", new ArrayProperty(new RefProperty("#/definitions/ConceptNameCreate"))) - .property("descriptions", new ArrayProperty(new RefProperty("#/definitions/ConceptDescriptionCreate"))); + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("name", new Schema().$ref("#/components/schemas/ConceptNameCreate")) + .addProperty("names", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptNameCreate"))) + .addProperty("descriptions", new ArraySchema().items(new Schema().$ref("#/components/schemas/ConceptDescriptionCreate"))); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -291,14 +314,14 @@ public DelegatingResourceDescription getCreatableProperties() { description.addRequiredProperty("names"); description.addRequiredProperty("datatype"); description.addRequiredProperty("conceptClass"); - + description.addProperty("descriptions"); description.addProperty("set"); description.addProperty("version"); description.addProperty("mappings"); description.addProperty("answers"); description.addProperty("setMembers"); - + //ConceptNumeric properties description.addProperty("hiNormal"); description.addProperty("hiAbsolute"); @@ -311,21 +334,21 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("displayPrecision"); return description; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties() */ @Override public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { DelegatingResourceDescription description = super.getUpdatableProperties(); - + description.addProperty("name"); description.addProperty("names"); description.addProperty("descriptions"); - + return description; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getPropertiesToExposeAsSubResources() */ @@ -333,10 +356,10 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe public List getPropertiesToExposeAsSubResources() { return Arrays.asList("names", "descriptions", "conceptMappings"); } - + /** * Sets the name property to be the fully specified name of the Concept in the current locale - * + * * @param instance * @param name */ @@ -345,12 +368,12 @@ public static void setFullySpecifiedName(Concept instance, String name) { ConceptName fullySpecifiedName = new ConceptName(name, Context.getLocale()); instance.setFullySpecifiedName(fullySpecifiedName); } - + /** * It's needed, because of ConversionException: Don't know how to handle collection class: * interface java.util.Collection If request to update Concept updates ConceptName, adequate * resource takes care of it, so this method just adds new and removes deleted names. - * + * * @param instance * @param names * @throws NoSuchMethodException @@ -359,43 +382,43 @@ public static void setFullySpecifiedName(Concept instance, String name) { */ @PropertySetter("names") public static void setNames(Concept instance, List names) throws IllegalAccessException, - InvocationTargetException, NoSuchMethodException { - + InvocationTargetException, NoSuchMethodException { + new HibernateCollectionHelper( - instance) { - + instance) { + @Override public int compare(ConceptName left, ConceptName right) { if (Objects.equals(left.getUuid(), right.getUuid())) { return 0; } boolean areEqual = (Objects.equals(left.getName(), right.getName()) - && Objects.equals(left.getConceptNameType(), right.getConceptNameType()) && Objects.equals( - left.getLocale(), right.getLocale())); + && Objects.equals(left.getConceptNameType(), right.getConceptNameType()) && Objects.equals( + left.getLocale(), right.getLocale())); return areEqual ? 0 : 1; } - + @Override public Collection getAll() { return instance.getNames(); } - + @Override public void add(ConceptName item) { instance.addName(item); } - + @Override public void remove(ConceptName item) { instance.removeName(item); } }.set(names); } - + /** * It's needed, because of ConversionException: Don't know how to handle collection class: * interface java.util.Collection - * + * * @param instance * @param descriptions * @throws NoSuchMethodException @@ -404,42 +427,42 @@ public void remove(ConceptName item) { */ @PropertySetter("descriptions") public static void setDescriptions(Concept instance, List descriptions) - throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { - + throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { + new HibernateCollectionHelper( - instance) { - + instance) { + @Override public int compare(ConceptDescription left, ConceptDescription right) { if (Objects.equals(left.getUuid(), right.getUuid())) { return 0; } boolean areEqual = (Objects.equals(left.getDescription(), right.getDescription()) && Objects.equals( - left.getLocale(), right.getLocale())); + left.getLocale(), right.getLocale())); return areEqual ? 0 : 1; } - + @Override public Collection getAll() { return instance.getDescriptions(); } - + @Override public void add(ConceptDescription item) { instance.addDescription(item); } - + @Override public void remove(ConceptDescription item) { instance.removeDescription(item); } }.set(descriptions); } - + /** * It's needed, because of ConversionException: Don't know how to handle collection class: * interface java.util.Collection - * + * * @param instance * @param mappings */ @@ -450,15 +473,15 @@ public static void setMappings(Concept instance, List mappings) { instance.addConceptMapping(map); } } - + @PropertyGetter("mappings") public static List getMappings(Concept instance) { return new ArrayList(instance.getConceptMappings()); } - + /** * Gets the display name of the Concept delegate - * + * * @param instance the delegate instance to get the display name off */ @PropertyGetter("display") @@ -475,17 +498,17 @@ public String getDisplayString(Concept instance) { } } } - + /** * {@link #newDelegate(SimpleObject)} is used instead to support ConceptNumeric - * + * * @see DelegatingCrudResource#newDelegate() */ @Override public Concept newDelegate() { throw new ResourceDoesNotSupportOperationException("Should use newDelegate(SimpleObject) instead"); } - + @Override public Concept newDelegate(SimpleObject object) { String datatypeUuid = (String) object.get("datatype"); @@ -495,7 +518,7 @@ public Concept newDelegate(SimpleObject object) { return new Concept(); } } - + /** * @see DelegatingCrudResource#save(java.lang.Object) */ @@ -503,17 +526,17 @@ public Concept newDelegate(SimpleObject object) { public Concept save(Concept c) { return Context.getConceptService().saveConcept(c); } - + /** * Fetches a concept by uuid - * + * * @see DelegatingCrudResource#getByUniqueId(java.lang.String) */ @Override public Concept getByUniqueId(String uuid) { return Context.getConceptService().getConceptByUuid(uuid); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) @@ -524,10 +547,10 @@ public void purge(Concept concept, RequestContext context) throws ResponseExcept return; Context.getConceptService().purgeConcept(concept); } - + /** * This does not include retired concepts - * + * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override @@ -535,7 +558,7 @@ protected NeedsPaging doGetAll(RequestContext context) { List allConcepts = Context.getConceptService().getAllConcepts(null, true, context.getIncludeAll()); return new NeedsPaging(allConcepts, context); } - + /** * Concept searches support the following additional query parameters: *
    @@ -544,7 +567,7 @@ protected NeedsPaging doGetAll(RequestContext context) { *
  • memberOf=(uuid): restricts to concepts that are set members of the given concept set's * uuid
  • *
- * + * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(RequestContext) */ @Override @@ -553,7 +576,7 @@ protected PageableResult doSearch(RequestContext context) { Integer startIndex = null; Integer limit = null; boolean canPage = true; - + // Collect information for answerTo and memberOf query parameters String answerToUuid = context.getRequest().getParameter("answerTo"); String memberOfUuid = context.getRequest().getParameter("memberOf"); @@ -567,27 +590,27 @@ protected PageableResult doSearch(RequestContext context) { log.error("Unexpected exception while retrieving answerTo Concept with UUID " + answerToUuid, ex); } } - + if (StringUtils.isNotBlank(memberOfUuid)) { Concept memberOf = service.getConceptByUuid(memberOfUuid); memberOfList = service.getConceptsByConceptSet(memberOf); canPage = false; // ConceptService does not support memberOf searches, so paging must be deferred. } - + // Only set startIndex and limit if we can return paged results if (canPage) { startIndex = context.getStartIndex(); limit = context.getLimit(); } - + List searchResults; - + // get the user's locales...and then convert that from a set to a list List locales = new ArrayList(LocaleUtility.getLocalesInOrder()); - + searchResults = service.getConcepts(context.getParameter("q"), locales, context.getIncludeAll(), null, null, null, - null, answerTo, startIndex, limit); - + null, answerTo, startIndex, limit); + // convert search results into list of concepts List results = new ArrayList(searchResults.size()); for (ConceptSearchResult csr : searchResults) { @@ -595,21 +618,21 @@ protected PageableResult doSearch(RequestContext context) { if (memberOfList == null || memberOfList.contains(csr.getConcept())) results.add(csr.getConcept()); } - + PageableResult result = null; if (canPage) { Integer count = service.getCountOfConcepts(context.getParameter("q"), locales, false, - Collections. emptyList(), Collections. emptyList(), - Collections. emptyList(), Collections. emptyList(), answerTo); + Collections. emptyList(), Collections. emptyList(), + Collections. emptyList(), Collections. emptyList(), answerTo); boolean hasMore = count > startIndex + limit; result = new AlreadyPaged(context, results, hasMore, Long.valueOf(count)); } else { result = new NeedsPaging(results, context); } - + return result; } - + @Override protected void delete(Concept c, String reason, RequestContext context) throws ResponseException { if (c.isRetired()) { @@ -618,7 +641,7 @@ protected void delete(Concept c, String reason, RequestContext context) throws R } Context.getConceptService().retireConcept(c, reason); } - + /** * @param instance * @return the list of Concepts or Drugs @@ -628,7 +651,7 @@ public static Object getAnswers(Concept instance) { List conceptAnswers = new ArrayList(); conceptAnswers.addAll(instance.getAnswers(false)); Collections.sort(conceptAnswers); - + List answers = new ArrayList(); for (ConceptAnswer conceptAnswer : conceptAnswers) { if (conceptAnswer.getAnswerDrug() != null) { @@ -637,10 +660,10 @@ public static Object getAnswers(Concept instance) { answers.add(conceptAnswer.getAnswerConcept()); } } - + return answers; } - + /** * @param instance * @param answerUuids the list of Concepts or Drugs @@ -648,8 +671,8 @@ public static Object getAnswers(Concept instance) { */ @PropertySetter("answers") public static void setAnswers(Concept instance, List answerUuids /*Concept or Drug uuid*/) - throws ResourceDoesNotSupportOperationException { - + throws ResourceDoesNotSupportOperationException { + // remove answers that are not in the new list Iterator iterator = instance.getAnswers(false).iterator(); while (iterator.hasNext()) { @@ -664,7 +687,7 @@ public static void setAnswers(Concept instance, List answerUuids /*Conce instance.removeAnswer(answer); // remove from concept question object } } - + List answerObjects = new ArrayList(answerUuids.size()); for (String uuid : answerUuids) { Concept c = Context.getConceptService().getConceptByUuid(uuid); @@ -677,10 +700,10 @@ public static void setAnswers(Concept instance, List answerUuids /*Conce answerObjects.add(drug); else throw new ResourceDoesNotSupportOperationException("There is no concept or drug with given uuid: " - + uuid); + + uuid); } } - + // add in new answers for (Object obj : answerObjects) { ConceptAnswer answerToAdd = null; @@ -688,13 +711,13 @@ public static void setAnswers(Concept instance, List answerUuids /*Conce answerToAdd = new ConceptAnswer((Concept) obj); else answerToAdd = new ConceptAnswer(((Drug) obj).getConcept(), (Drug) obj); - + answerToAdd.setCreator(Context.getAuthenticatedUser()); answerToAdd.setDateCreated(new Date()); instance.addAnswer(answerToAdd); } } - + /** * @param instance * @param setMembers the list of Concepts @@ -702,15 +725,15 @@ public static void setAnswers(Concept instance, List answerUuids /*Conce @PropertySetter("setMembers") public static void setSetMembers(Concept instance, List setMembers) { instance.getConceptSets().clear(); - + if (setMembers == null || setMembers.isEmpty()) { instance.setSet(false); } else { instance.setSet(true); - + for (Concept setMember : setMembers) { instance.addSetMember(setMember); } } } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java index 58bf17ce0..ce958ad57 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ConceptSourceResource1_8.java @@ -9,10 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.BooleanSchema; import org.openmrs.ConceptSource; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -28,6 +28,7 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; @@ -70,23 +71,30 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return null; } - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("hl7Code", new StringProperty()) - .property("retired", new BooleanProperty()); + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("hl7Code", new StringSchema()) + .addProperty("retired", new BooleanSchema()); + } + return schema; } @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("hl7Code", new StringProperty()) - .required("name").required("description"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("hl7Code", new StringSchema()); + schema.setRequired(Arrays.asList("name", "description")); + return schema; } /** @@ -185,4 +193,4 @@ protected NeedsPaging doSearch(RequestContext context, List(sources, context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java index f1d82939d..94cd1aaf6 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugOrderSubclassHandler1_8.java @@ -11,13 +11,10 @@ import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.DrugOrder; import org.openmrs.Order; import org.openmrs.Patient; @@ -137,48 +134,53 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { + public Schema getGETSchema(Representation rep) { OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(Order.class); - ModelImpl orderModel = (ModelImpl) orderResource.getGETModel(rep); - orderModel - .property("dose", new DoubleProperty()) - .property("units", new StringProperty()) - .property("frequency", new StringProperty()) - .property("prn", new BooleanProperty()) - .property("complex", new BooleanProperty()) - .property("quantity", new IntegerProperty()); + Schema orderSchema = orderResource.getGETSchema(rep); + orderSchema + .addProperty("dose", new NumberSchema().format("double")) + .addProperty("units", new StringSchema()) + .addProperty("frequency", new StringSchema()) + .addProperty("prn", new BooleanSchema()) + .addProperty("complex", new BooleanSchema()) + .addProperty("quantity", new NumberSchema().format("integer")); if (rep instanceof DefaultRepresentation) { - orderModel - .property("drug", new RefProperty("#/definitions/DrugGetRef")); + orderSchema + .addProperty("drug", new Schema().$ref("#/components/schemas/DrugGetRef")); } else if (rep instanceof FullRepresentation) { - orderModel - .property("drug", new RefProperty("#/definitions/DrugGet")); + orderSchema + .addProperty("drug", new Schema().$ref("#/components/schemas/DrugGet")); } - return orderModel; + return orderSchema; } @Override - public Model getCREATEModel(Representation rep) { + public Schema getCREATESchema(Representation rep) { OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(Order.class); - ModelImpl orderModel = (ModelImpl) orderResource.getCREATEModel(rep); - orderModel - .property("dose", new DoubleProperty()) - .property("units", new StringProperty()) - .property("frequency", new StringProperty()) - .property("prn", new BooleanProperty()) - .property("complex", new BooleanProperty()) - .property("quantity", new IntegerProperty()) - .property("drug", new RefProperty("#/definitions/DrugCreate")); + Schema orderSchema = orderResource.getCREATESchema(rep); + orderSchema + .addProperty("dose", new NumberSchema().format("double")) + .addProperty("units", new StringSchema()) + .addProperty("frequency", new StringSchema()) + .addProperty("prn", new BooleanSchema()) + .addProperty("complex", new BooleanSchema()) + .addProperty("quantity", new NumberSchema().format("integer")) + .addProperty("drug", new Schema().$ref("#/components/schemas/DrugCreate")); // DrugOrders have a specific hardcoded value for this property - orderModel.getProperties().remove("orderType"); + orderSchema.getProperties().remove("orderType"); - return orderModel; + return orderSchema; } - + + @Override + public Schema getUPDATESchema(Representation rep) { + return null; + } + /** * Handles getOrdersByPatient for {@link OrderResource1_8} when type=drugorder * @@ -206,4 +208,4 @@ public static String getDisplay(DrugOrder delegate) { // TODO dates, etc return ret.toString(); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java index f34e6df7f..25bf2cd72 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/DrugResource1_8.java @@ -9,12 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Drug; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -30,6 +28,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; import java.util.List; /** @@ -90,8 +89,8 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addProperty("maximumDailyDose"); description.addProperty("minimumDailyDose"); description.addProperty("units"); - description.addProperty("concept", Representation.REF); description.addProperty("combination"); + description.addProperty("concept", Representation.REF); description.addProperty("route", Representation.REF); description.addSelfLink(); description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL); @@ -103,71 +102,77 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addProperty("name"); description.addProperty("description"); description.addProperty("retired"); - description.addProperty("dosageForm", Representation.REF); + description.addProperty("dosageForm"); description.addProperty("doseStrength"); description.addProperty("maximumDailyDose"); description.addProperty("minimumDailyDose"); description.addProperty("units"); - description.addProperty("concept", Representation.REF); description.addProperty("combination"); - description.addProperty("route", Representation.REF); + description.addProperty("concept"); + description.addProperty("route"); description.addProperty("auditInfo"); description.addSelfLink(); return description; } - //Let the superclass handle this return null; } - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + @Override + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("doseStrength", new DoubleProperty()) - .property("maximumDailyDose", new DoubleProperty()) - .property("minimumDailyDose", new DoubleProperty()) - .property("units", new StringProperty()) - .property("combination", new BooleanProperty()._default(false)); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("dosageForm", new RefProperty("#/definitions/ConceptGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("route", new RefProperty("#/definitions/ConceptGetRef")); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("dosageForm", new RefProperty("#/definitions/ConceptGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("route", new RefProperty("#/definitions/ConceptGet")); + schema + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("retired", new BooleanSchema()) + .addProperty("doseStrength", new NumberSchema()) + .addProperty("maximumDailyDose", new NumberSchema()) + .addProperty("minimumDailyDose", new NumberSchema()) + .addProperty("units", new StringSchema()) + .addProperty("combination", new BooleanSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("dosageForm", new Schema().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("route", new Schema().$ref("#/components/schemas/ConceptGetRef")); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("dosageForm", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("route", new Schema().$ref("#/components/schemas/ConceptGet")); + } } - return modelImpl; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("combination", new BooleanProperty()._default(false)) - .property("concept", new StringProperty()) - .property("doseStrength", new DoubleProperty()) - .property("maximumDailyDose", new DoubleProperty()) - .property("minimumDailyDose", new DoubleProperty()) - .property("units", new StringProperty()) - .property("dosageForm", new StringProperty()) - .property("route", new StringProperty()) - - .required("combination").required("concept"); + public Schema getCREATESchema(Representation rep) { + Schema schema = super.getCREATESchema(rep); + schema + .addProperty("combination", new BooleanSchema()._default(false)) + .addProperty("concept", new StringSchema()) + .addProperty("doseStrength", new NumberSchema()) + .addProperty("maximumDailyDose", new NumberSchema()) + .addProperty("minimumDailyDose", new NumberSchema()) + .addProperty("units", new StringSchema()) + .addProperty("dosageForm", new StringSchema()) + .addProperty("route", new StringSchema()); + schema.setRequired(Arrays.asList("combination", "concept")); if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("dosageForm", new RefProperty("#/definitions/ConceptCreate")) - .property("route", new RefProperty("#/definitions/ConceptCreate")); + schema + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("dosageForm", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("route", new Schema().$ref("#/components/schemas/ConceptCreate")); } - return model; + return schema; } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); //FIXME no updatableProperties() + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); //FIXME no updatableProperties() } /** @@ -222,4 +227,4 @@ protected PageableResult doSearch(RequestContext ctx) { boolean hasMore = countOfDrugs > startIndex + limit; return new AlreadyPaged(ctx, drugs, hasMore, Long.valueOf(countOfDrugs)); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterResource1_8.java index d28dcce52..bfc273723 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterResource1_8.java @@ -9,14 +9,16 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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 io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Encounter; +import org.openmrs.EncounterType; +import org.openmrs.Form; +import org.openmrs.Location; import org.openmrs.Obs; import org.openmrs.Order; import org.openmrs.Patient; @@ -39,6 +41,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.ServiceSearcher; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; import java.util.Date; import java.util.LinkedHashSet; import java.util.List; @@ -49,7 +52,7 @@ */ @Resource(name = RestConstants.VERSION_1 + "/encounter", supportedClass = Encounter.class, supportedOpenmrsVersions = "1.8.*") public class EncounterResource1_8 extends DataDelegatingCrudResource { - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ @@ -90,57 +93,56 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("encounterDatetime", new DateProperty()) - .property("provider", new StringProperty()) //FIXME - .property("voided", new BooleanProperty()); + schema.addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("encounterDatetime", new DateTimeSchema()) + .addProperty("provider", new StringSchema()) //FIXME + .addProperty("voided", new BooleanSchema()); } if (rep instanceof DefaultRepresentation) { - modelImpl - .property("patient", new RefProperty("#/definitions/PatientGetRef")) //FIXME - .property("location", new RefProperty("#/definitions/LocationGetRef")) //FIXME - .property("form", new RefProperty("#/definitions/FormGetRef")) //FIXME - .property("encounterType", new RefProperty("#/definitions/EncountertypeGetRef")) //FIXME - .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsGetRef"))) //FIXME - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderGetRef"))); //FIXME + schema.addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetRef")) //FIXME + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGetRef")) //FIXME + .addProperty("form", new Schema
().$ref("#/components/schemas/FormGetRef")) //FIXME + .addProperty("encounterType", new Schema().$ref("#/components/schemas/EncountertypeGetRef")) //FIXME + .addProperty("obs", new ArraySchema().items(new Schema().$ref("#/components/schemas/ObsGetRef"))) //FIXME + .addProperty("orders", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrderGetRef"))); //FIXME } else if (rep instanceof FullRepresentation) { - modelImpl - .property("patient", new RefProperty("#/definitions/PatientGet")) //FIXME - .property("location", new RefProperty("#/definitions/LocationGet")) //FIXME - .property("form", new RefProperty("#/definitions/FormGet")) //FIXME - .property("encounterType", new RefProperty("#/definitions/EncountertypeGet")) //FIXME - .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsGet"))) //FIXME - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderGet"))); //FIXME + schema.addProperty("patient", new Schema().$ref("#/components/schemas/PatientGet")) //FIXME + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGet")) //FIXME + .addProperty("form", new Schema().$ref("#/components/schemas/FormGet")) //FIXME + .addProperty("encounterType", new Schema().$ref("#/components/schemas/EncountertypeGet")) //FIXME + .addProperty("obs", new ArraySchema().items(new Schema().$ref("#/components/schemas/ObsGet"))) //FIXME + .addProperty("orders", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrderGet"))); //FIXME } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("patient", new RefProperty("#/definitions/PatientCreate")) - .property("encounterType", new RefProperty("#/definitions/EncountertypeCreate")) - .property("encounterDatetime", new DateProperty()) - .property("location", new RefProperty("#/definitions/LocationCreate")) - .property("form", new RefProperty("#/definitions/FormCreate")) - .property("provider", new StringProperty()) - .property("orders", new ArrayProperty(new RefProperty("#/definitions/OrderCreate"))) - .property("obs", new ArrayProperty(new RefProperty("#/definitions/ObsCreate"))) - - .required("patient").required("encounterType"); + public Schema getCREATESchema(Representation rep) { + Schema schema = new ObjectSchema() + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientCreate")) + .addProperty("encounterType", new Schema().$ref("#/components/schemas/EncountertypeCreate")) + .addProperty("encounterDatetime", new DateTimeSchema()) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationCreate")) + .addProperty("form", new Schema().$ref("#/components/schemas/FormCreate")) + .addProperty("provider", new StringSchema()) + .addProperty("orders", new ArraySchema().items(new Schema().$ref("#/components/schemas/OrderCreate"))) + .addProperty("obs", new ArraySchema().items(new Schema().$ref("#/components/schemas/ObsCreate"))); + + schema.setRequired(Arrays.asList("patient", "encounterType")); + + return schema; } - + @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() * Should create an encounter type @@ -148,20 +150,20 @@ public Model getUPDATEModel(Representation rep) { @Override public DelegatingResourceDescription getCreatableProperties() { DelegatingResourceDescription description = new DelegatingResourceDescription(); - + description.addProperty("encounterDatetime"); // has a default value set, hence not required here description.addRequiredProperty("patient"); description.addRequiredProperty("encounterType"); - + description.addProperty("location"); description.addProperty("form"); description.addProperty("provider"); description.addProperty("orders"); description.addProperty("obs"); - + return description; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#newDelegate() */ @@ -174,7 +176,7 @@ public Encounter newDelegate() { enc.setOrders(new LinkedHashSet()); return enc; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(org.openmrs.Encounter) */ @@ -182,7 +184,7 @@ public Encounter newDelegate() { public Encounter save(Encounter enc) { return Context.getEncounterService().saveEncounter(enc); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(java.lang.String) */ @@ -190,7 +192,7 @@ public Encounter save(Encounter enc) { public Encounter getByUniqueId(String uuid) { return Context.getEncounterService().getEncounterByUuid(uuid); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(org.openmrs.Encounter, * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext) @@ -203,7 +205,7 @@ public void delete(Encounter enc, String reason, RequestContext context) throws } Context.getEncounterService().voidEncounter(enc, reason); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#undelete(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) @@ -215,7 +217,7 @@ protected Encounter undelete(Encounter enc, RequestContext context) throws Respo } return enc; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#purge(org.openmrs.Encounter, * org.openmrs.module.webservices.rest.web.RequestContext) @@ -228,7 +230,7 @@ public void purge(Encounter enc, RequestContext context) throws ResponseExceptio } Context.getEncounterService().purgeEncounter(enc); } - + /** * @param encounter * @return encounter type and date @@ -238,10 +240,10 @@ public String getDisplayString(Encounter encounter) { String ret = encounter.getEncounterType() == null ? "?" : encounter.getEncounterType().getName(); ret += " "; ret += encounter.getEncounterDatetime() == null ? "?" : Context.getDateFormat().format( - encounter.getEncounterDatetime()); + encounter.getEncounterDatetime()); return ret; } - + /** * @param instance * @return all non-voided top-level obs from the given encounter @@ -250,25 +252,25 @@ public String getDisplayString(Encounter encounter) { public static Object getObsAtTopLevel(Encounter instance) { return instance.getObsAtTopLevel(false); } - + @PropertySetter("obs") public static void setObs(Encounter instance, Set obs) { instance.getAllObs(true).clear(); for (Obs o : obs) instance.addObs(o); } - + @PropertySetter("orders") public static void setOrders(Encounter instance, Set orders) { for (Order o : orders) instance.addOrder(o); } - + /** * Gets encounters for the given patient (paged according to context if necessary) only if a * patient parameter exists in the request set on the {@link RequestContext} otherwise searches * for encounters that match the specified query - * + * * @param context * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @@ -277,15 +279,15 @@ protected PageableResult doSearch(RequestContext context) { String patientUuid = context.getRequest().getParameter("patient"); if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( - Patient.class)).getByUniqueId(patientUuid); + Patient.class)).getByUniqueId(patientUuid); if (patient == null) return new EmptySearchResult(); List encs = Context.getEncounterService().getEncountersByPatient(patient); return new NeedsPaging(encs, context); } - + return new ServiceSearcher(EncounterService.class, "getEncounters", "getCountOfEncounters").search( - context.getParameter("q"), context); + context.getParameter("q"), context); } - + } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java index 952889804..93de5f3f4 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/EncounterTypeResource1_8.java @@ -9,8 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.EncounterType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -23,6 +23,8 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Collections; + /** * {@link Resource} for {@link EncounterType}, supporting standard CRUD operations */ @@ -44,9 +46,9 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .required("description"); + public Schema getCREATESchema(Representation rep) { + return ((ObjectSchema) super.getCREATESchema(rep)) + .required(Collections.singletonList("description")); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java index 61e70b452..e886086f3 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldAnswerResource1_8.java @@ -10,12 +10,14 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.UUIDSchema; +import org.openmrs.Concept; import org.openmrs.Field; import org.openmrs.FieldAnswer; import org.openmrs.api.context.Context; @@ -79,35 +81,37 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + + @Override + public Schema getGETSchema(Representation rep) { + ObjectSchema modelImpl = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation) { modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("field", new RefProperty("#/definitions/FieldGetRef")); + .addProperty("uuid", new UUIDSchema()) + .addProperty("display", new StringSchema()) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("field", new Schema().$ref("#/components/schemas/FieldGetRef")); } else if (rep instanceof FullRepresentation) { modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("field", new RefProperty("#/definitions/FieldGet")); + .addProperty("uuid", new UUIDSchema()) + .addProperty("display", new StringSchema()) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("field", new Schema().$ref("#/components/schemas/FieldGet")); } return modelImpl; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("concept", new StringProperty().example("uuid")) - .property("field", new StringProperty().example("uuid")) - .required("field").required("concept"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) new ObjectSchema() + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreate").example("uuid")) + .addProperty("field", new Schema().$ref("#/components/schemas/FieldCreate").example("uuid")) + .required(Arrays.asList("field", "concept")); if (rep instanceof FullRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("field", new RefProperty("#/definitions/FieldCreate")); + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreateFull")) + .addProperty("field", new Schema().$ref("#/components/schemas/FieldCreateFull")); } return model; } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java index 7eb26f5c2..de146e572 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldResource1_8.java @@ -9,12 +9,13 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Concept; import org.openmrs.Field; +import org.openmrs.FieldType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -36,45 +37,46 @@ @Resource(name = RestConstants.VERSION_1 + "/field", supportedClass = Field.class, supportedOpenmrsVersions = { "1.8.* - 9.*" }) public class FieldResource1_8 extends MetadataDelegatingCrudResource { - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema modelImpl = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { modelImpl - .property("tableName", new StringProperty()) - .property("attributeName", new StringProperty()) - .property("defaultValue", new StringProperty()) - .property("selectMultiple", new BooleanProperty()._default(false)); + .addProperty("tableName", new StringSchema()) + .addProperty("attributeName", new StringSchema()) + .addProperty("defaultValue", new StringSchema()) + .addProperty("selectMultiple", new BooleanSchema()._default(false)); } if (rep instanceof DefaultRepresentation) { modelImpl - .property("fieldType", new RefProperty("#/definitions/FieldtypeGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); + .addProperty("fieldType", new Schema().$ref("#/components/schemas/FieldtypeGet")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")); } else if (rep instanceof FullRepresentation) { modelImpl - .property("fieldType", new RefProperty("#/definitions/FieldtypeGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")); + .addProperty("fieldType", new Schema().$ref("#/components/schemas/FieldtypeGetFull")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetFull")); } return modelImpl; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("fieldType", new RefProperty("#/definitions/FieldtypeCreate")) - .property("selectMultiple", new BooleanProperty()._default(false)) - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("tableName", new StringProperty()) - .property("attributeName", new StringProperty()) - .property("defaultValue", new StringProperty()) - - .required("fieldType").required("selectMultiple"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = (ObjectSchema) super.getCREATESchema(rep) + .addProperty("fieldType", new Schema().$ref("#/components/schemas/FieldtypeCreate")) + .addProperty("selectMultiple", new BooleanSchema()._default(false)) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("tableName", new StringSchema()) + .addProperty("attributeName", new StringSchema()) + .addProperty("defaultValue", new StringSchema()); + + schema.setRequired(Arrays.asList("fieldType", "selectMultiple")); + return schema; } - + @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl(); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return super.getUPDATESchema(rep); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java index ba62a0174..e4d8ba9bd 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FieldTypeResource1_8.java @@ -9,9 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.FieldType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -32,18 +32,18 @@ "1.8.* - 9.*" }) public class FieldTypeResource1_8 extends MetadataDelegatingCrudResource { - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema modelImpl = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { modelImpl - .property("isSet", new BooleanProperty()._default(false)); + .addProperty("isSet", new BooleanSchema()._default(false)); } return modelImpl; } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema(); //FIXME missing props } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java index 4b7ddfece..1897c0aa6 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormFieldResource1_8.java @@ -10,15 +10,16 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.FloatProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Field; import org.openmrs.Form; import org.openmrs.FormField; import org.openmrs.api.context.Context; @@ -42,62 +43,62 @@ "1.8.* - 9.*" }) public class FormFieldResource1_8 extends DelegatingSubResource { - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema modelImpl = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("fieldNumber", new IntegerProperty()) - .property("fieldPart", new StringProperty()) - .property("pageNumber", new IntegerProperty()) - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("required", new BooleanProperty()._default(false)) - .property("sortWeight", new FloatProperty()) - .property("retired", new BooleanProperty()); //FIXME + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("fieldNumber", new IntegerSchema()) + .addProperty("fieldPart", new StringSchema()) + .addProperty("pageNumber", new IntegerSchema()) + .addProperty("minOccurs", new IntegerSchema()) + .addProperty("maxOccurs", new IntegerSchema()) + .addProperty("required", new BooleanSchema()._default(false)) + .addProperty("sortWeight", new NumberSchema().format("float")) + .addProperty("retired", new BooleanSchema()); } if (rep instanceof DefaultRepresentation) { modelImpl - .property("parent", new RefProperty("#/definitions/FormFormfieldGetRef")) - .property("form", new RefProperty("#/definitions/FormGetRef")) - .property("field", new RefProperty("#/definitions/FieldGetRef")); + .addProperty("form", new Schema().$ref("#/components/schemas/FormGet")) + .addProperty("field", new Schema().$ref("#/components/schemas/FieldGet")) + .addProperty("parent", new Schema().$ref("#/components/schemas/FormFormfieldGet")); } else if (rep instanceof FullRepresentation) { modelImpl - .property("parent", new RefProperty("#/definitions/FormFormfieldGet")) - .property("form", new RefProperty("#/definitions/FormGet")) - .property("field", new RefProperty("#/definitions/FieldGet")); + .addProperty("form", new Schema().$ref("#/components/schemas/FormGetFull")) + .addProperty("field", new Schema().$ref("#/components/schemas/FieldGetFull")) + .addProperty("parent", new Schema().$ref("#/components/schemas/FormFormfieldGetFull")); } return modelImpl; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() //FIXME validate if correct - .property("form", new StringProperty().example("uuid")) - .property("field", new StringProperty().example("uuid")) - .property("required", new BooleanProperty()._default(false)) - .property("parent", new StringProperty().example("uuid")) - .property("fieldNumber", new IntegerProperty()) - .property("fieldPart", new StringProperty()) - .property("pageNumber", new IntegerProperty()) - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("sortWeight", new BooleanProperty()._default(false)) - - .required("form").required("field").required("required"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) new ObjectSchema() + .addProperty("form", new StringSchema().example("uuid")) + .addProperty("field", new StringSchema().example("uuid")) + .addProperty("required", new BooleanSchema()._default(false)) + .addProperty("parent", new StringSchema().example("uuid")) + .addProperty("fieldNumber", new IntegerSchema()) + .addProperty("fieldPart", new StringSchema()) + .addProperty("pageNumber", new IntegerSchema()) + .addProperty("minOccurs", new IntegerSchema()) + .addProperty("maxOccurs", new IntegerSchema()) + .addProperty("sortWeight", new BooleanSchema()._default(false)) + .required(Arrays.asList("form", "field", "required")); if (rep instanceof FullRepresentation) { model - .property("form", new RefProperty("#/definitions/FormCreate")) - .property("field", new RefProperty("#/definitions/FieldCreate")) - .property("parent", new RefProperty("#/definitions/FormFormfieldCreate")); + .addProperty("form", new Schema().$ref("#/components/schemas/FormCreate")) + .addProperty("field", new Schema().$ref("#/components/schemas/FieldCreate")) + .addProperty("parent", new Schema().$ref("#/components/schemas/FormFormfieldCreate")); } return model; } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema(); //FIXME missing props } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormResource1_8.java index 8f1e9894f..4fa7b2d6b 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/FormResource1_8.java @@ -9,15 +9,13 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.EncounterType; -import org.openmrs.Field; import org.openmrs.Form; import org.openmrs.FormField; import org.openmrs.api.context.Context; @@ -97,56 +95,63 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("version", new StringProperty()) - .property("build", new IntegerProperty()) - .property("published", new BooleanProperty()._default(false)) - .property("retired", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("encounterType", new RefProperty("#/definitions/EncountertypeGetRef")) - .property("formFields", new ArrayProperty(new RefProperty("#/definitions/FormFormfieldGetRef"))); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("encounterType", new RefProperty("#/definitions/EncountertypeGet")) - .property("formFields", new ArrayProperty(new RefProperty("#/definitions/FormFormfieldGet"))); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof ObjectSchema && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("version", new StringSchema()) + .addProperty("build", new IntegerSchema()) + .addProperty("published", new BooleanSchema()._default(false)) + .addProperty("retired", new BooleanSchema()); + + if (rep instanceof DefaultRepresentation) { + objectSchema + .addProperty("encounterType", new Schema().$ref("#/components/schemas/EncountertypeGetRef")) + .addProperty("formFields", new ArraySchema().items(new Schema().$ref("#/components/schemas/FormFormfieldGetRef"))); + } else if (rep instanceof FullRepresentation) { + objectSchema + .addProperty("encounterType", new Schema().$ref("#/components/schemas/EncountertypeGetRef")) + .addProperty("formFields", new ArraySchema().items(new Schema().$ref("#/components/schemas/FormFormfieldGetRef")));; + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("version", new StringProperty()) - .property("encounterType", new StringProperty()) - .property("build", new IntegerProperty()) - .property("published", new BooleanProperty()._default(false)) - .property("formFields", new ArrayProperty(new StringProperty())) - .property("xslt", new StringProperty()) - .property("template", new StringProperty()) - - .required("version"); - if (rep instanceof FullRepresentation) { - model - .property("encounterType", new RefProperty("#/definitions/EncountertypeCreate")) - .property("formFields", new ArrayProperty(new RefProperty("#/definitions/FormFormfieldCreate"))); + public Schema getCREATESchema(Representation rep) { + Schema schema = super.getCREATESchema(rep); + if (schema instanceof ObjectSchema) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("version", new StringSchema()) + .addProperty("encounterType", new StringSchema()) + .addProperty("build", new IntegerSchema()) + .addProperty("published", new BooleanSchema()._default(false)) + .addProperty("formFields", new ArraySchema().items(new StringSchema())) + .addProperty("xslt", new StringSchema()) + .addProperty("template", new StringSchema()); + + objectSchema.setRequired(Arrays.asList("version")); + + if (rep instanceof FullRepresentation) { + objectSchema + .addProperty("encounterType", new Schema().$ref("#/components/schemas/EncountertypeCreate")) + .addProperty("formFields", new ArraySchema().items(new Schema().$ref("#/components/schemas/FormFormfieldCreate"))); + } } - return model; + return schema; } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7MessageResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7MessageResource1_8.java index 999810ac9..5fbd5d7cc 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7MessageResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7MessageResource1_8.java @@ -9,12 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.api.context.Context; +import org.openmrs.hl7.HL7Source; 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; @@ -30,6 +30,7 @@ import org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.HL7MessageController1_8; import org.openmrs.module.webservices.rest.web.v1_0.wrapper.openmrs1_8.IncomingHl7Message1_8; +import java.util.Collections; import java.util.Map; /** @@ -94,32 +95,36 @@ public DelegatingResourceDescription getCreatableProperties() { description.addRequiredProperty("hl7"); return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("messageState", new IntegerProperty()); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("source", new RefProperty("#/definitions/Hl7sourceGet")) - .property("sourceKey", new StringProperty()) - .property("data", new StringProperty()) - .property("messageState", new IntegerProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof ObjectSchema) { + ObjectSchema objectSchema = (ObjectSchema) schema; + if (rep instanceof DefaultRepresentation) { + objectSchema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("messageState", new IntegerSchema()); + } else if (rep instanceof FullRepresentation) { + objectSchema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("source", new Schema().$ref("#/components/schemas/Hl7sourceGet")) + .addProperty("sourceKey", new StringSchema()) + .addProperty("data", new StringSchema()) + .addProperty("messageState", new IntegerSchema()); + } } - return modelImpl; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("hl7", new StringProperty()) //FIXME TYPE - .required("hl7"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("hl7", new StringSchema()) //FIXME TYPE + .required(Collections.singletonList("hl7")); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7SourceResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7SourceResource1_8.java index 78eecfd92..2b17e9136 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7SourceResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/HL7SourceResource1_8.java @@ -9,8 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.api.context.Context; import org.openmrs.hl7.HL7Source; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -22,6 +22,8 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Collections; + /** * {@link Resource} for {@link HL7Source}, supporting standard CRUD operations */ @@ -58,15 +60,15 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) + public Schema getCREATESchema(Representation rep) { + return ((ObjectSchema) super.getCREATESchema(rep)) - .required("description"); + .required(Collections.singletonList("description")); } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationResource1_8.java index 6a9bbb860..05ac717ca 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationResource1_8.java @@ -13,11 +13,10 @@ import java.util.Arrays; import java.util.List; -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 io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.openmrs.Location; @@ -142,64 +141,71 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("address1", new StringProperty()) - .property("address2", new StringProperty()) - .property("cityVillage", new StringProperty()) - .property("stateProvince", new StringProperty()) - .property("country", new StringProperty()) - .property("postalCode", new StringProperty()) - .property("latitude", new StringProperty()) - .property("longitude", new StringProperty()) - .property("countyDistrict", new StringProperty()) - .property("address3", new StringProperty()) - .property("address4", new StringProperty()) - .property("address5", new StringProperty()) - .property("address6", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl - .property("tags", new ArrayProperty(new RefProperty("#/definitions/LocationtagGetRef"))) - .property("parentLocation", new RefProperty("#/definitions/LocationGetRef")) - .property("childLocations", new ArrayProperty(new RefProperty("#/definitions/LocationGetRef"))); - } else if (rep instanceof FullRepresentation) { - modelImpl - .property("tags", new ArrayProperty(new RefProperty("#/definitions/LocationtagGet"))) - .property("parentLocation", new RefProperty("#/definitions/LocationGet")) - .property("childLocations", new ArrayProperty(new RefProperty("#/definitions/LocationGet"))); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof ObjectSchema && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("address1", new StringSchema()) + .addProperty("address2", new StringSchema()) + .addProperty("cityVillage", new StringSchema()) + .addProperty("stateProvince", new StringSchema()) + .addProperty("country", new StringSchema()) + .addProperty("postalCode", new StringSchema()) + .addProperty("latitude", new StringSchema()) + .addProperty("longitude", new StringSchema()) + .addProperty("countyDistrict", new StringSchema()) + .addProperty("address3", new StringSchema()) + .addProperty("address4", new StringSchema()) + .addProperty("address5", new StringSchema()) + .addProperty("address6", new StringSchema()); + + if (rep instanceof DefaultRepresentation) { + objectSchema + .addProperty("tags", new ArraySchema().items(new Schema().$ref("#/components/schemas/LocationtagGetRef"))) + .addProperty("parentLocation", new Schema().$ref("#/components/schemas/LocationGetRef")) + .addProperty("childLocations", new ArraySchema().items(new Schema().$ref("#/components/schemas/LocationGetRef"))); + } else if (rep instanceof FullRepresentation) { + objectSchema + .addProperty("tags", new ArraySchema().items(new Schema().$ref("#/components/schemas/LocationtagGet"))) + .addProperty("parentLocation", new Schema().$ref("#/components/schemas/LocationGet")) + .addProperty("childLocations", new ArraySchema().items(new Schema().$ref("#/components/schemas/LocationGet"))); + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("address1", new StringProperty()) - .property("address2", new StringProperty()) - .property("cityVillage", new StringProperty()) - .property("stateProvince", new StringProperty()) - .property("country", new StringProperty()) - .property("postalCode", new StringProperty()) - .property("latitude", new StringProperty()) - .property("longitude", new StringProperty()) - .property("countyDistrict", new StringProperty()) - .property("address3", new StringProperty()) - .property("address4", new StringProperty()) - .property("address5", new StringProperty()) - .property("address6", new StringProperty()) - .property("tags", new ArrayProperty(new StringProperty())) - .property("parentLocation", new StringProperty()) - .property("childLocations", new ArrayProperty(new StringProperty())); + public Schema getCREATESchema(Representation rep) { + Schema schema = super.getCREATESchema(rep); + if (schema instanceof ObjectSchema) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("address1", new StringSchema()) + .addProperty("address2", new StringSchema()) + .addProperty("cityVillage", new StringSchema()) + .addProperty("stateProvince", new StringSchema()) + .addProperty("country", new StringSchema()) + .addProperty("postalCode", new StringSchema()) + .addProperty("latitude", new StringSchema()) + .addProperty("longitude", new StringSchema()) + .addProperty("countyDistrict", new StringSchema()) + .addProperty("address3", new StringSchema()) + .addProperty("address4", new StringSchema()) + .addProperty("address5", new StringSchema()) + .addProperty("address6", new StringSchema()) + .addProperty("tags", new ArraySchema().items(new StringSchema())) + .addProperty("parentLocation", new StringSchema()) + .addProperty("childLocations", new ArraySchema().items(new StringSchema())); + } + return schema; } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationTagResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationTagResource1_8.java index 9199ba24c..db988c46f 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationTagResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/LocationTagResource1_8.java @@ -9,10 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.LocationTag; import org.openmrs.api.LocationService; import org.openmrs.api.context.Context; @@ -94,10 +94,10 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("retired", new BooleanProperty()) - .property("retiredReason", new StringProperty()); + public Schema getCREATESchema(Representation rep) { + return ((ObjectSchema) super.getCREATESchema(rep)) + .addProperty("retired", new BooleanSchema()) + .addProperty("retiredReason", new StringSchema()); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleActionResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleActionResource1_8.java index d67ab5ff4..f660a6be8 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleActionResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleActionResource1_8.java @@ -9,19 +9,17 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.openmrs.api.APIException; import org.openmrs.module.Module; import org.openmrs.module.ModuleException; import org.openmrs.module.ModuleUtil; -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.helper.ModuleAction.Action; @@ -41,12 +39,13 @@ import org.springframework.util.ResourceUtils; import javax.servlet.ServletContext; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; @Resource(name = RestConstants.VERSION_1 + "/moduleaction", supportedClass = ModuleAction.class, supportedOpenmrsVersions = { @@ -298,20 +297,21 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe } @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("modules", new ArrayProperty(new RefProperty("#/definitions/ModuleGetRef"))) - .property("action", new EnumProperty(ModuleAction.Action.class)); + public Schema getGETSchema(Representation rep) { + return ((ObjectSchema) super.getGETSchema(rep)) + .addProperty("modules", new ArraySchema().$ref("#/definitions/ModuleGetRef")) + .addProperty("action", new Schema()._enum(Arrays.asList(ModuleAction.Action.values()))); } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("modules", new ArrayProperty(new StringProperty().example("moduleId"))) - .property("allModules", new BooleanProperty()) - .property("action", new EnumProperty(ModuleAction.Action.class)) - .property("installUri", new StringProperty()) - .required("action"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("modules", new ArraySchema().items(new StringSchema().example("moduleId"))) + .addProperty("allModules", new BooleanSchema()) + .addProperty("action", new Schema()._enum(Arrays.asList(ModuleAction.Action.values()))) + .addProperty("installUri", new StringSchema()) + .required(Collections.singletonList("action")); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleResource1_8.java index e4d5ecc25..c06af7cc2 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ModuleResource1_8.java @@ -9,11 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.io.FileUtils; import org.openmrs.module.Module; import org.openmrs.module.ModuleException; @@ -108,29 +108,29 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("started", new BooleanProperty()) //FIXME check type - .property("startupErrorMessage", new StringProperty()); //FIXME add-link: action + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("started", new BooleanSchema()) //FIXME check type + .addProperty("startupErrorMessage", new StringSchema()); //FIXME add-link: action } if (rep instanceof FullRepresentation) { model - .property("packageName", new StringProperty()) - .property("author", new StringProperty()) - .property("version", new StringProperty()) - .property("requireOpenmrsVersion", new StringProperty()) - .property("awareOfModules", new ArrayProperty(new StringProperty())) //FIXME check type - .property("requiredModules", new ArrayProperty(new StringProperty())); + .addProperty("packageName", new StringSchema()) + .addProperty("author", new StringSchema()) + .addProperty("version", new StringSchema()) + .addProperty("requireOpenmrsVersion", new StringSchema()) + .addProperty("awareOfModules", new ArraySchema().items(new StringSchema())) //FIXME check type + .addProperty("requiredModules", new ArraySchema().items(new StringSchema())); } else if (rep instanceof RefRepresentation) { model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()); } return model; } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java index 9e4970296..70bb22b95 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java @@ -21,14 +21,24 @@ import javax.xml.bind.DatatypeConverter; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.Concept; +import org.openmrs.ConceptName; import org.openmrs.ConceptNumeric; import org.openmrs.Drug; import org.openmrs.Encounter; import org.openmrs.Location; import org.openmrs.Obs; +import org.openmrs.Order; import org.openmrs.Patient; +import org.openmrs.Person; import org.openmrs.api.APIException; import org.openmrs.api.ObsService; import org.openmrs.api.context.Context; @@ -57,15 +67,6 @@ import org.openmrs.obs.ComplexData; import org.springframework.web.multipart.MultipartFile; -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.DateTimeProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * {@link Resource} for Obs, supporting standard CRUD operations */ @@ -183,53 +184,55 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model.property("uuid", new StringProperty()).property("display", new StringProperty()) - .property("obsDatetime", new DateProperty()).property("accessionNumber", new StringProperty()) - .property("comment", new StringProperty()).property("voided", new BooleanProperty()) - .property("value", new StringProperty()).property("valueModifier", new StringProperty()); + model.addProperty("uuid", new StringSchema()).addProperty("display", new StringSchema()) + .addProperty("obsDatetime", new DateSchema()).addProperty("accessionNumber", new StringSchema()) + .addProperty("comment", new StringSchema()).addProperty("voided", new BooleanSchema()) + .addProperty("value", new StringSchema()).addProperty("valueModifier", new StringSchema()); } if (rep instanceof DefaultRepresentation) { - model.property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("person", new RefProperty("#/definitions/PersonGetRef")) - .property("obsGroup", new RefProperty("#/definitions/ObsGetRef")) - .property("groupMembers", new ArrayProperty(new RefProperty("#/definitions/ObsGetRef"))) - .property("valueCodedName", new RefProperty("#/definitions/ConceptNameGetRef")) - .property("location", new RefProperty("#/definitions/LocationGetRef")) - .property("order", new RefProperty("#/definitions/OrderGetRef")) - .property("encounter", new RefProperty("#/definitions/EncounterGetRef")); + model + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGet")) + .addProperty("obsGroup", new Schema().$ref("#/components/schemas/ObsGet")) + .addProperty("groupMembers", new ArraySchema().items(new Schema().$ref("#/components/schemas/ObsGet"))) + .addProperty("valueCodedName", new Schema().$ref("#/components/schemas/ConceptNameGet")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGet")) + .addProperty("order", new Schema().$ref("#/components/schemas/OrderGet")) + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterGet")); } else if (rep instanceof FullRepresentation) { - model.property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("person", new RefProperty("#/definitions/PersonGet")) - .property("obsGroup", new RefProperty("#/definitions/ObsGet")) - .property("groupMembers", new ArrayProperty(new RefProperty("#/definitions/ObsGet"))) - .property("valueCodedName", new RefProperty("#/definitions/ConceptNameGet")) - .property("location", new RefProperty("#/definitions/LocationGet")) - .property("order", new RefProperty("#/definitions/OrderGet")) - .property("encounter", new RefProperty("#/definitions/EncounterGet")); + model + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetFull")) + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGetFull")) + .addProperty("obsGroup", new Schema().$ref("#/components/schemas/ObsGetFull")) + .addProperty("groupMembers", new ArraySchema().items(new Schema().$ref("#/components/schemas/ObsGetFull"))) + .addProperty("valueCodedName", new Schema().$ref("#/components/schemas/ConceptNameGetFull")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGetFull")) + .addProperty("order", new Schema().$ref("#/components/schemas/OrderGetFull")) + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterGetFull")); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl().property("person", new StringProperty().example("uuid")) - .property("obsDatetime", new DateTimeProperty()).property("concept", new StringProperty().example("uuid")) - .property("location", new StringProperty()).property("order", new StringProperty()) - .property("encounter", new StringProperty()).property("accessionNumber", new StringProperty()) - .property("groupMembers", new ArrayProperty(new StringProperty())) - .property("valueCodedName", new StringProperty()).property("comment", new StringProperty()) - .property("voided", new BooleanProperty()).property("value", new StringProperty()) - .property("valueModifier", new StringProperty()) - - .required("person").required("obsDatetime").required("concept"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema().addProperty("person", new StringSchema().example("uuid")) + .addProperty("obsDatetime", new DateTimeSchema()).addProperty("concept", new StringSchema().example("uuid")) + .addProperty("location", new StringSchema()).addProperty("order", new StringSchema()) + .addProperty("encounter", new StringSchema()).addProperty("accessionNumber", new StringSchema()) + .addProperty("groupMembers", new ArraySchema().items(new StringSchema())) + .addProperty("valueCodedName", new StringSchema()).addProperty("comment", new StringSchema()) + .addProperty("voided", new BooleanSchema()).addProperty("value", new StringSchema()) + .addProperty("valueModifier", new StringSchema()) + .required(Arrays.asList("person", "obsDatetime", "concept")); } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/OrderResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/OrderResource1_8.java index e087cb560..a822fe663 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/OrderResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/OrderResource1_8.java @@ -9,16 +9,20 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; +import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Concept; +import org.openmrs.Encounter; import org.openmrs.Order; +import org.openmrs.OrderType; import org.openmrs.Patient; +import org.openmrs.User; import org.openmrs.api.OrderService.ORDER_STATUS; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -210,77 +214,77 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("instructions", new StringProperty()) - .property("startDate", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("accessionNumber", new StringProperty()) - .property("discontinuedDate", new DateProperty()) - .property("discontinuedReasonNonCoded", new StringProperty()) - .property("voided", new BooleanProperty()); + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("instructions", new StringSchema()) + .addProperty("startDate", new DateSchema()) + .addProperty("autoExpireDate", new DateSchema()) + .addProperty("accessionNumber", new StringSchema()) + .addProperty("discontinuedDate", new DateSchema()) + .addProperty("discontinuedReasonNonCoded", new StringSchema()) + .addProperty("voided", new BooleanSchema()); } if (rep instanceof DefaultRepresentation) { model - .property("orderType", new RefProperty("#/definitions/OrdertypeGetRef")) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("encounter", new RefProperty("#/definitions/EncounterGetRef")) - .property("orderer", new RefProperty("#/definitions/UserGetRef")) - .property("discontinuedBy", new RefProperty("#/definitions/UserGetRef")) - .property("discontinuedReason", new RefProperty("#/definitions/ConceptGetRef")); + .addProperty("orderType", new Schema().$ref("#/components/schemas/OrdertypeGet")) + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGet")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterGet")) + .addProperty("orderer", new Schema().$ref("#/components/schemas/UserGet")) + .addProperty("discontinuedBy", new Schema().$ref("#/components/schemas/UserGet")) + .addProperty("discontinuedReason", new Schema().$ref("#/components/schemas.ConceptGet")); } else if (rep instanceof FullRepresentation) { model - .property("orderType", new RefProperty("#/definitions/OrdertypeGet")) - .property("patient", new RefProperty("#/definitions/PatientGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("encounter", new RefProperty("#/definitions/EncounterGet")) - .property("orderer", new RefProperty("#/definitions/UserGet")) - .property("discontinuedBy", new RefProperty("#/definitions/UserGet")) - .property("discontinuedReason", new RefProperty("#/definitions/ConceptGet")); + .addProperty("orderType", new Schema().$ref("#/components/schemas/OrdertypeGetFull")) + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetFull")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetFull")) + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterGetFull")) + .addProperty("orderer", new Schema().$ref("#/components/schemas/UserGetFull")) + .addProperty("discontinuedBy", new Schema().$ref("#/components/schemas/UserGetFull")) + .addProperty("discontinuedReason", new Schema().$ref("#/components/schemas.ConceptGetFull")); } return model; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("orderType", new StringProperty().example("uuid")) - .property("patient", new StringProperty().example("uuid")) - .property("concept", new StringProperty().example("uuid")) - .property("instructions", new StringProperty()) - .property("startDate", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("encounter", new StringProperty().example("uuid")) - .property("orderer", new StringProperty().example("uuid")) - .property("discontinuedBy", new StringProperty().example("uuid")) - .property("discontinuedDate", new DateProperty()) - .property("discontinuedReason", new RefProperty("#/definitions/ConceptCreate")) - .property("discontinuedReasonNonCoded", new StringProperty()) - .property("accessionNumber", new StringProperty()) - - .required("orderType").required("patient").required("concept"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) new ObjectSchema() + .addProperty("orderType", new StringSchema().example("uuid")) + .addProperty("patient", new StringSchema().example("uuid")) + .addProperty("concept", new StringSchema().example("uuid")) + .addProperty("instructions", new StringSchema()) + .addProperty("startDate", new DateSchema()) + .addProperty("autoExpireDate", new DateSchema()) + .addProperty("encounter", new StringSchema().example("uuid")) + .addProperty("orderer", new StringSchema().example("uuid")) + .addProperty("discontinuedBy", new StringSchema().example("uuid")) + .addProperty("discontinuedDate", new DateSchema()) + .addProperty("discontinuedReason", new Schema().$ref("#/components/schemas.ConceptCreate")) + .addProperty("discontinuedReasonNonCoded", new StringSchema()) + .addProperty("accessionNumber", new StringSchema()) + .required(Arrays.asList("orderType", "patient", "concept")); if (rep instanceof FullRepresentation) { model - .property("orderType", new RefProperty("#/definitions/OrdertypeCreate")) - .property("patient", new RefProperty("#/definitions/PatientCreate")) - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("encounter", new RefProperty("#/definitions/EncounterCreate")) - .property("orderer", new RefProperty("#/definitions/UserCreate")) - .property("discontinuedBy", new RefProperty("#/definitions/UserCreate")) - .property("discontinuedReason", new RefProperty("#/definitions/ConceptCreate")); + .addProperty("orderType", new Schema().$ref("#/components/schemas/OrdertypeCreate")) + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientCreate")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterCreate")) + .addProperty("orderer", new Schema().$ref("#/components/schemas/UserCreate")) + .addProperty("discontinuedBy", new Schema().$ref("#/components/schemas/UserCreate")) + .addProperty("discontinuedReason", new Schema().$ref("#/components/schemas.ConceptCreate")); } //FIXME missing prop: type return model; } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema(); //FIXME missing props } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java index 34f24c837..2b65e4deb 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java @@ -10,8 +10,13 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang3.StringUtils; import org.openmrs.Location; import org.openmrs.Patient; @@ -32,12 +37,6 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; - /** * Sub-resource for patient identifiers */ @@ -136,48 +135,48 @@ public DelegatingResourceDescription getUpdatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("identifier", new StringProperty()) - .property("preferred", new BooleanProperty()._default(false)) - .property("voided", new BooleanProperty()); + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("identifier", new StringSchema()) + .addProperty("preferred", new BooleanSchema()._default(false)) + .addProperty("voided", new BooleanSchema()); } if (rep instanceof DefaultRepresentation) { model - .property("identifierType", new RefProperty("#/definitions/PatientidentifiertypeGetRef")) - .property("location", new RefProperty("#/definitions/LocationGetRef")); + .addProperty("identifierType", new Schema().$ref("#/components/schemas/PatientidentifiertypeGet")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGet")); } else if (rep instanceof FullRepresentation) { model - .property("identifierType", new RefProperty("#/definitions/PatientidentifiertypeGet")) - .property("location", new RefProperty("#/definitions/LocationGet")); + .addProperty("identifierType", new Schema().$ref("#/components/schemas/PatientidentifiertypeGetFull")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGetFull")); } return model; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("identifier", new StringProperty()) - .property("identifierType", new StringProperty().example("uuid")) - .property("location", new StringProperty().example("uuid")) - .property("preferred", new BooleanProperty()._default(false)) - - .required("identifier").required("identifierType"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) new ObjectSchema() + .addProperty("identifier", new StringSchema()) + .addProperty("identifierType", new StringSchema().example("uuid")) + .addProperty("location", new StringSchema().example("uuid")) + .addProperty("preferred", new BooleanSchema()._default(false)) + .required(Arrays.asList("identifier", "identifierType")); if (rep instanceof FullRepresentation) { model - .property("identifierType", new RefProperty("#/definitions/PatientidentifiertypeCreate")) - .property("location", new RefProperty("#/definitions/LocationCreate")); + .addProperty("identifierType", new Schema().$ref("#/components/schemas/PatientidentifiertypeCreate")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationCreate")); } return model; } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } private PatientService service() { diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierTypeResource1_8.java index 209f47396..faf998d59 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierTypeResource1_8.java @@ -9,14 +9,13 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.PatientIdentifierType; import org.openmrs.api.PatientService; 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; @@ -28,6 +27,8 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; + /** * Allows standard CRUD for the {@link PatientIdentifierType} domain object */ @@ -116,36 +117,36 @@ public DelegatingResourceDescription getUpdatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("format", new StringProperty()) - .property("formatDescription", new StringProperty()) - .property("required", new BooleanProperty()) - .property("checkDigit", new BooleanProperty()) - .property("validator", new StringProperty()) - .property("locationBehavior", new EnumProperty(PatientIdentifierType.LocationBehavior.class)) - .property("uniquenessBehavior", new StringProperty()); //FIXME check type + .addProperty("format", new StringSchema()) + .addProperty("formatDescription", new StringSchema()) + .addProperty("required", new BooleanSchema()) + .addProperty("checkDigit", new BooleanSchema()) + .addProperty("validator", new StringSchema()) + .addProperty("locationBehavior", new Schema()._enum(Arrays.asList(PatientIdentifierType.LocationBehavior.values()))) + .addProperty("uniquenessBehavior", new StringSchema()); //FIXME check type } return model; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("format", new StringProperty()) - .property("formatDescription", new StringProperty()) - .property("required", new BooleanProperty()) - .property("checkDigit", new BooleanProperty()) - .property("validator", new StringProperty()) - .property("locationBehavior", new EnumProperty(PatientIdentifierType.LocationBehavior.class)) - .property("uniquenessBehavior", new StringProperty()); //FIXME check type + public Schema getCREATESchema(Representation rep) { + return super.getCREATESchema(rep) + .addProperty("format", new StringSchema()) + .addProperty("formatDescription", new StringSchema()) + .addProperty("required", new BooleanSchema()) + .addProperty("checkDigit", new BooleanSchema()) + .addProperty("validator", new StringSchema()) + .addProperty("locationBehavior", new Schema()._enum(Arrays.asList(PatientIdentifierType.LocationBehavior.values()))) + .addProperty("uniquenessBehavior", new StringSchema()); //FIXME check type } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java index 19178907f..a0a0dc6a2 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java @@ -9,12 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; import org.openmrs.Patient; import org.openmrs.PatientIdentifier; import org.openmrs.Person; @@ -42,6 +41,7 @@ import org.openmrs.module.webservices.validation.ValidateUtil; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -144,47 +144,48 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - //FIXME check uuid, display in ref rep - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("identifiers", new ArrayProperty(new RefProperty("#/definitions/PatientIdentifierGetRef"))) - .property("preferred", new BooleanProperty()._default(false)) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGet")); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof ObjectSchema && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("identifiers", new ArraySchema().items(new Schema().$ref("#/components/schemas/PatientIdentifierGetRef"))) + .addProperty("preferred", new BooleanSchema()._default(false)) + .addProperty("voided", new BooleanSchema()); + + if (rep instanceof DefaultRepresentation) { + objectSchema.addProperty("person", new Schema().$ref("#/components/schemas/PersonGetRef")); + } else if (rep instanceof FullRepresentation) { + objectSchema.addProperty("person", new Schema().$ref("#/components/schemas/PersonGet")); + } } - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("person", new StringProperty().example("uuid")) - .property("identifiers", new ArrayProperty(new RefProperty("#/definitions/PatientIdentifierCreate"))) - - .required("person").required("identifiers"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = (ObjectSchema) new ObjectSchema() + .addProperty("person", new StringSchema().example("uuid")) + .addProperty("identifiers", new ArraySchema().items(new Schema().$ref("#/components/schemas/PatientIdentifierCreate"))); + + schema.setRequired(Arrays.asList("person", "identifiers")); + if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonCreate")); + schema.addProperty("person", new Schema().$ref("#/components/schemas/PersonCreate")); } - return model; + return schema; } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("person", new RefProperty("#/definitions/PersonGet")) - - .required("person"); + public Schema getUPDATESchema(Representation rep) { + ObjectSchema schema = (ObjectSchema) new ObjectSchema() + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGet")); + + schema.setRequired(Collections.singletonList("person")); + + return schema; } /** @@ -367,4 +368,4 @@ public Patient getPatientForUpdate(String uuid, Map propertiesTo return patient; } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientStateResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientStateResource1_8.java index b865ce818..1834b5f37 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientStateResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientStateResource1_8.java @@ -9,16 +9,15 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.PatientProgram; import org.openmrs.PatientState; import org.openmrs.ProgramWorkflow; +import org.openmrs.ProgramWorkflowState; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -174,43 +173,42 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof RefRepresentation || rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("uuid", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("voided", new BooleanProperty()); + .addProperty("uuid", new StringSchema()) + .addProperty("startDate", new DateSchema()) + .addProperty("endDate", new DateSchema()) + .addProperty("voided", new BooleanSchema()); } if (rep instanceof DefaultRepresentation) { - model - .property("state", new RefProperty("#/definitions/WorkflowStateGet")); + model.addProperty("state", new Schema().$ref("#/components/schemas/WorkflowStateGet")); } else if (rep instanceof RefRepresentation) { model - .property("state", new RefProperty("#/definitions/WorkflowStateGetRef")) - .property("patientProgram", new ObjectProperty()); //FIXME type + .addProperty("state", new Schema().$ref("#/components/schemas/WorkflowStateGetRef")) + .addProperty("patientProgram", new ObjectSchema()); //FIXME type } else if (rep instanceof FullRepresentation) { model - .property("state", new RefProperty("#/definitions/WorkflowStateGetRef")) - .property("patientProgram", new ObjectProperty()); //FIXME type + .addProperty("state", new Schema().$ref("#/components/schemas/WorkflowStateGetFull")) + .addProperty("patientProgram", new ObjectSchema()); //FIXME type } return model; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("state", new RefProperty("#/definitions/WorkflowStateCreate")) - - .required("state"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("state", new Schema().$ref("#/components/schemas/WorkflowStateCreate")) + .required(Collections.singletonList("state")); } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("voided", new BooleanProperty()); + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("startDate", new DateSchema()) + .addProperty("endDate", new DateSchema()) + .addProperty("voided", new BooleanSchema()); } } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAddressResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAddressResource1_8.java index b47bc1f90..6ad81225c 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAddressResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAddressResource1_8.java @@ -9,11 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.UUIDSchema; import org.openmrs.Person; import org.openmrs.PersonAddress; import org.openmrs.api.context.Context; @@ -141,58 +142,58 @@ public DelegatingResourceDescription getUpdatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) ((ObjectSchema) super.getGETSchema(rep)) + .addProperty("uuid", new UUIDSchema()) + .addProperty("display", new StringSchema()); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("preferred", new BooleanProperty()._default(false)) - .property("address1", new StringProperty()) - .property("address2", new StringProperty()) - .property("cityVillage", new StringProperty()) - .property("stateProvince", new StringProperty()) - .property("country", new StringProperty()) - .property("postalCode", new StringProperty()) - .property("countyDistrict", new StringProperty()) - .property("address3", new StringProperty()) - .property("address4", new StringProperty()) - .property("address5", new StringProperty()) - .property("address6", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("latitude", new StringProperty()) - .property("longitude", new StringProperty()) - .property("voided", new BooleanProperty()); + .addProperty("preferred", new BooleanSchema()._default(false)) + .addProperty("address1", new StringSchema()) + .addProperty("address2", new StringSchema()) + .addProperty("cityVillage", new StringSchema()) + .addProperty("stateProvince", new StringSchema()) + .addProperty("country", new StringSchema()) + .addProperty("postalCode", new StringSchema()) + .addProperty("countyDistrict", new StringSchema()) + .addProperty("address3", new StringSchema()) + .addProperty("address4", new StringSchema()) + .addProperty("address5", new StringSchema()) + .addProperty("address6", new StringSchema()) + .addProperty("startDate", new DateSchema()) + .addProperty("endDate", new DateSchema()) + .addProperty("latitude", new StringSchema()) + .addProperty("longitude", new StringSchema()) + .addProperty("voided", new BooleanSchema()); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("preferred", new BooleanProperty()._default(false)) - .property("address1", new StringProperty()) - .property("address2", new StringProperty()) - .property("cityVillage", new StringProperty()) - .property("stateProvince", new StringProperty()) - .property("country", new StringProperty()) - .property("postalCode", new StringProperty()) - .property("countyDistrict", new StringProperty()) - .property("address3", new StringProperty()) - .property("address4", new StringProperty()) - .property("address5", new StringProperty()) - .property("address6", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("latitude", new StringProperty()) - .property("longitude", new StringProperty()); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("preferred", new BooleanSchema()._default(false)) + .addProperty("address1", new StringSchema()) + .addProperty("address2", new StringSchema()) + .addProperty("cityVillage", new StringSchema()) + .addProperty("stateProvince", new StringSchema()) + .addProperty("country", new StringSchema()) + .addProperty("postalCode", new StringSchema()) + .addProperty("countyDistrict", new StringSchema()) + .addProperty("address3", new StringSchema()) + .addProperty("address4", new StringSchema()) + .addProperty("address5", new StringSchema()) + .addProperty("address6", new StringSchema()) + .addProperty("startDate", new DateSchema()) + .addProperty("endDate", new DateSchema()) + .addProperty("latitude", new StringSchema()) + .addProperty("longitude", new StringSchema()); } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeResource1_8.java index 45a7ed6ed..dcb73dd00 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeResource1_8.java @@ -9,11 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Attributable; import org.openmrs.Location; import org.openmrs.Person; @@ -39,6 +38,8 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.util.OpenmrsClassLoader; +import java.util.Collections; + /** * {@link Resource} for PersonAttributes, supporting standard CRUD operations */ @@ -153,45 +154,44 @@ public DelegatingResourceDescription getUpdatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation) { model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("value", new StringProperty()) - .property("attributeType", new RefProperty("#/definitions/PersonattributetypeGetRef")) - .property("voided", new BooleanProperty()); + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("value", new StringSchema()) + .addProperty("attributeType", new Schema().$ref("#/components/schemas/PersonattributetypeGet")) + .addProperty("voided", new BooleanSchema()); } else if (rep instanceof FullRepresentation) { model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("value", new StringProperty()) - .property("attributeType", new RefProperty("#/definitions/PersonattributetypeGetRef")) - .property("voided", new BooleanProperty()) - .property("hydratedObject", new StringProperty()); + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("value", new StringSchema()) + .addProperty("attributeType", new Schema().$ref("#/components/schemas/PersonattributetypeGetFull")) + .addProperty("voided", new BooleanSchema()) + .addProperty("hydratedObject", new StringSchema()); } return model; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("attributeType", new StringProperty().example("uuid")) - .property("value", new StringProperty()) - .property("hydratedObject", new StringProperty().example("uuid")) - - .required("attributeType"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) new ObjectSchema() + .addProperty("attributeType", new StringSchema().example("uuid")) + .addProperty("value", new StringSchema()) + .addProperty("hydratedObject", new StringSchema().example("uuid")) + .required(Collections.singletonList("attributeType")); if (rep instanceof FullRepresentation) { - model - .property("attributeType", new RefProperty("#/definitions/PersonattributetypeCreate")); + model.addProperty("attributeType", new Schema().$ref("#/components/schemas/PersonattributetypeCreate")); } return model; } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeTypeResource1_8.java index b630f9aa0..ebd349136 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonAttributeTypeResource1_8.java @@ -9,15 +9,15 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Concept; import org.openmrs.PersonAttributeType; +import org.openmrs.Privilege; import org.openmrs.api.PersonService; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.ConversionUtil; @@ -34,6 +34,8 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.util.OpenmrsUtil; +import java.util.Collections; + /** * Allows standard CRUD for the {@link PersonAttributeType} domain object */ @@ -114,41 +116,40 @@ public DelegatingResourceDescription getUpdatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("format", new StringProperty()) - .property("foreignKey", new IntegerProperty()) - .property("sortWeight", new DoubleProperty()) - .property("searchable", new BooleanProperty()._default(false)); + .addProperty("format", new StringSchema()) + .addProperty("foreignKey", new IntegerSchema()) + .addProperty("sortWeight", new NumberSchema().format("double")) + .addProperty("searchable", new BooleanSchema()._default(false)); } if (rep instanceof DefaultRepresentation) { - model - .property("editPrivilege", new RefProperty("#/definitions/PrivilegeGetRef")); + model.addProperty("editPrivilege", new Schema().$ref("#/components/schemas/PrivilegeGet")); } else if (rep instanceof FullRepresentation) { model - .property("editPrivilege", new RefProperty("#/definitions/PrivilegeGet")) - .property("concept", new StringProperty()); + .addProperty("editPrivilege", new Schema().$ref("#/components/schemas/PrivilegeGetFull")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetFull")); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("format", new StringProperty().example("java.lang.String")) - .property("foreignKey", new IntegerProperty()) - .property("sortWeight", new DoubleProperty()) - .property("searchable", new BooleanProperty()._default(false)) - .property("editPrivilege", new RefProperty("#/definitions/PrivilegeCreate")) - - .required("description"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return super.getCREATESchema(rep) + .addProperty("format", new StringSchema().example("java.lang.String")) + .addProperty("foreignKey", new IntegerSchema()) + .addProperty("sortWeight", new NumberSchema().format("double")) + .addProperty("searchable", new BooleanSchema()._default(false)) + .addProperty("editPrivilege", new Schema().$ref("#/components/schemas/PrivilegeGetFull")) + .required(Collections.singletonList("description")); } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonNameResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonNameResource1_8.java index 171c10cd7..beae23223 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonNameResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonNameResource1_8.java @@ -9,10 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Person; import org.openmrs.PersonName; import org.openmrs.api.context.Context; @@ -33,6 +33,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; @@ -106,48 +107,49 @@ public DelegatingResourceDescription getUpdatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("givenName", new StringProperty()) - .property("middleName", new StringProperty()) - .property("familyName", new StringProperty()) - .property("familyName2", new StringProperty()) - .property("voided", new BooleanProperty()); + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("givenName", new StringSchema()) + .addProperty("middleName", new StringSchema()) + .addProperty("familyName", new StringSchema()) + .addProperty("familyName2", new StringSchema()) + .addProperty("voided", new BooleanSchema()); } if (rep instanceof FullRepresentation) { model - .property("preferred", new BooleanProperty()) - .property("prefix", new StringProperty()) - .property("familyNamePrefix", new StringProperty()) - .property("familyNameSuffix", new StringProperty()) - .property("degree", new StringProperty()); + .addProperty("preferred", new BooleanSchema()) + .addProperty("prefix", new StringSchema()) + .addProperty("familyNamePrefix", new StringSchema()) + .addProperty("familyNameSuffix", new StringSchema()) + .addProperty("degree", new StringSchema()); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("givenName", new StringProperty()) - .property("middleName", new StringProperty()) - .property("familyName", new StringProperty()) - .property("familyName2", new StringProperty()) - .property("preferred", new BooleanProperty()._default(false)) - .property("prefix", new StringProperty()) - .property("familyNamePrefix", new StringProperty()) - .property("familyNameSuffix", new StringProperty()) - .property("degree", new StringProperty()) + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("givenName", new StringSchema()) + .addProperty("middleName", new StringSchema()) + .addProperty("familyName", new StringSchema()) + .addProperty("familyName2", new StringSchema()) + .addProperty("preferred", new BooleanSchema()._default(false)) + .addProperty("prefix", new StringSchema()) + .addProperty("familyNamePrefix", new StringSchema()) + .addProperty("familyNameSuffix", new StringSchema()) + .addProperty("degree", new StringSchema()) + .required(Arrays.asList("givenName", "familyName")); - .required("givenName").required("familyName"); } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonResource1_8.java index 15de940cc..1dd631b21 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PersonResource1_8.java @@ -14,15 +14,13 @@ import java.util.List; import java.util.Set; -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.DateTimeProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; import org.openmrs.Person; import org.openmrs.PersonAddress; import org.openmrs.PersonAttribute; @@ -143,70 +141,72 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("gender", new StringProperty()._enum("M")._enum("F")) - .property("age", new IntegerProperty()) - .property("birthdate", new DateTimeProperty()) - .property("birthdateEstimated", new BooleanProperty()) - .property("dead", new BooleanProperty()) - .property("deathDate", new DateProperty()) - .property("causeOfDeath", new StringProperty()) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/PersonAttributeGetRef"))) - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("preferredName", new RefProperty("#/definitions/PersonNameGetRef")) - .property("preferredAddress", new RefProperty("#/definitions/PersonAddressGetRef")); - - } else if (rep instanceof FullRepresentation) { - model - .property("preferredName", new RefProperty("#/definitions/PersonNameGet")) - .property("preferredAddress", new RefProperty("#/definitions/PersonAddressGet")) - .property("names", new ArrayProperty(new RefProperty("#/definitions/PersonNameGet"))) - .property("addresses", new ArrayProperty(new RefProperty("#/definitions/PersonAddressGet"))); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof ObjectSchema && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("gender", new StringSchema()._enum(Arrays.asList("M", "F"))) + .addProperty("age", new IntegerSchema()) + .addProperty("birthdate", new DateTimeSchema()) + .addProperty("birthdateEstimated", new BooleanSchema()) + .addProperty("dead", new BooleanSchema()) + .addProperty("deathDate", new DateTimeSchema()) + .addProperty("causeOfDeath", new StringSchema()) + .addProperty("attributes", new ArraySchema().items(new Schema().$ref("#/components/schemas/PersonAttributeGetRef"))) + .addProperty("voided", new BooleanSchema()); + + if (rep instanceof DefaultRepresentation) { + objectSchema + .addProperty("preferredName", new Schema().$ref("#/components/schemas/PersonNameGetRef")) + .addProperty("preferredAddress", new Schema().$ref("#/components/schemas/PersonAddressGetRef")); + } else if (rep instanceof FullRepresentation) { + objectSchema + .addProperty("preferredName", new Schema().$ref("#/components/schemas/PersonNameGet")) + .addProperty("preferredAddress", new Schema().$ref("#/components/schemas/PersonAddressGet")) + .addProperty("names", new ArraySchema().items(new Schema().$ref("#/components/schemas/PersonNameGet"))) + .addProperty("addresses", new ArraySchema().items(new Schema().$ref("#/components/schemas/PersonAddressGet"))); + } } - return model; + return schema; } @Override - public Model getCREATEModel(Representation representation) { - ModelImpl model = new ModelImpl() - .property("names", new ArrayProperty(new RefProperty("#/definitions/PersonNameCreate"))) - .property("gender", new StringProperty()._enum("M")._enum("F")) - .property("age", new IntegerProperty()) - .property("birthdate", new DateProperty()) - .property("birthdateEstimated", new BooleanProperty()._default(false)) - .property("dead", new BooleanProperty()._default(false)) - .property("deathDate", new DateProperty()) - .property("causeOfDeath", new StringProperty()) - .property("addresses", new ArrayProperty(new RefProperty("#/definitions/PersonAddressCreate"))) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/PersonAttributeCreate"))); - - model.setRequired(Arrays.asList("names", "gender")); - return model; + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("names", new ArraySchema().items(new Schema().$ref("#/components/schemas/PersonNameCreate"))) + .addProperty("gender", new StringSchema()._enum(Arrays.asList("M", "F"))) + .addProperty("age", new IntegerSchema()) + .addProperty("birthdate", new DateTimeSchema()) + .addProperty("birthdateEstimated", new BooleanSchema()._default(false)) + .addProperty("dead", new BooleanSchema()._default(false)) + .addProperty("deathDate", new DateTimeSchema()) + .addProperty("causeOfDeath", new StringSchema()) + .addProperty("addresses", new ArraySchema().items(new Schema().$ref("#/components/schemas/PersonAddressCreate"))) + .addProperty("attributes", new ArraySchema().items(new Schema().$ref("#/components/schemas/PersonAttributeCreate"))); + schema.setRequired(Arrays.asList("names", "gender")); + return schema; } @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("dead", new BooleanProperty()) - .property("causeOfDeath", new StringProperty()) - .property("deathDate", new DateProperty()) - .property("age", new IntegerProperty()) - .property("gender", new StringProperty()._enum("M")._enum("F")) - .property("birthdate", new DateProperty()) - .property("birthdateEstimated", new BooleanProperty()._default(false)) - .property("preferredName", new StringProperty().example("uuid")) - .property("preferredAddress", new StringProperty().example("uuid")) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/PersonAttributeCreate"))) - - .required("dead").required("causeOfDeath"); + public Schema getUPDATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("dead", new BooleanSchema()) + .addProperty("causeOfDeath", new StringSchema()) + .addProperty("deathDate", new DateTimeSchema()) + .addProperty("age", new IntegerSchema()) + .addProperty("gender", new StringSchema()._enum(Arrays.asList("M", "F"))) + .addProperty("birthdate", new DateTimeSchema()) + .addProperty("birthdateEstimated", new BooleanSchema()._default(false)) + .addProperty("preferredName", new StringSchema().example("uuid")) + .addProperty("preferredAddress", new StringSchema().example("uuid")) + .addProperty("attributes", new ArraySchema().items(new Schema().$ref("#/components/schemas/PersonAttributeCreate"))); + schema.setRequired((Arrays.asList("dead", "causeOfDeath"))); + return schema; } /** @@ -564,4 +564,4 @@ public SimpleObject getAuditInfo(Person person) throws Exception { ret.put("dateCreated", ConversionUtil.convertToRepresentation(person.getPersonDateCreated(), Representation.DEFAULT)); return ret; } -} +} \ No newline at end of file diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PrivilegeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PrivilegeResource1_8.java index 5ca45144b..58761fc3c 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PrivilegeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PrivilegeResource1_8.java @@ -9,9 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.Privilege; import org.openmrs.api.context.Context; @@ -92,13 +91,12 @@ public DelegatingResourceDescription getUpdatableProperties() { return description; } - + @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("description", new StringProperty()); + public Schema getUPDATESchema(Representation rep) { + return super.getUPDATESchema(rep).addProperty("description", new StringSchema()); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @@ -111,7 +109,7 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - + /** * @param delegate * @return diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProblemResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProblemResource1_8.java index 19de11f5d..066b55a14 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProblemResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProblemResource1_8.java @@ -9,15 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.DoubleProperty; -import io.swagger.models.properties.RefProperty; +import io.swagger.v3.oas.models.media.NumberSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import org.openmrs.Concept; import org.openmrs.Patient; import org.openmrs.activelist.Problem; import org.openmrs.activelist.ProblemModifier; 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.PropertyGetter; @@ -32,28 +31,28 @@ import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; +import java.util.Arrays; +import java.util.Collections; + /** * {@link Resource} for Problem, supporting standard CRUD operations */ @Resource(name = RestConstants.VERSION_1 + "/problem", supportedClass = Problem.class, supportedOpenmrsVersions = { "1.8.*" }) public class ProblemResource1_8 extends BaseActiveListItemResource1_8 { - + + @SuppressWarnings("unchecked") @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("modifier", new EnumProperty(ProblemModifier.class)) - .property("sortWeight", new DoubleProperty()); + .addProperty("modifier", new Schema().type("string")._enum(Arrays.asList(ProblemModifier.values()))) + .addProperty("sortWeight", new NumberSchema().format("double")); } if (rep instanceof DefaultRepresentation) { - model - .property("problem", new RefProperty("#/definitions/ConceptGetRef")); - + model.addProperty("problem", new Schema().$ref("#/components/schemas/ConceptGet")); } else if (rep instanceof FullRepresentation) { - model - .property("problem", new RefProperty("#/definitions/ConceptGet")); - + model.addProperty("problem", new Schema().$ref("#/components/schemas/ConceptGetFull")); } return model; } @@ -91,15 +90,15 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - + @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("problem", new RefProperty("#/definitions/ConceptCreate")) - .property("modifier", new EnumProperty(ProblemModifier.class)) - .property("sortWeight", new DoubleProperty()) - - .required("problem"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return super.getCREATESchema(rep) + .addProperty("problem", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("modifier", new Schema().type("string")._enum(Arrays.asList(ProblemModifier.values()))) + .addProperty("sortWeight", new NumberSchema().format("double")) + .required(Collections.singletonList("problem")); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramEnrollmentResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramEnrollmentResource1_8.java index 67dcb2dc7..ae314c9b1 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramEnrollmentResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramEnrollmentResource1_8.java @@ -9,14 +9,16 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.UUIDSchema; +import org.openmrs.Location; import org.openmrs.Patient; import org.openmrs.PatientProgram; +import org.openmrs.Program; import org.openmrs.api.PatientService; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -33,6 +35,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; import java.util.List; @Resource(name = RestConstants.VERSION_1 + "/programenrollment", supportedClass = PatientProgram.class, supportedOpenmrsVersions = { "1.8.* - 1.9.*" }, order = 1) @@ -127,55 +130,54 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("dateEnrolled", new DateProperty()) - .property("dateCompleted", new DateProperty()) - .property("voided", new BooleanProperty()); + .addProperty("uuid", new UUIDSchema()) + .addProperty("display", new StringSchema()) + .addProperty("dateEnrolled", new DateSchema()) + .addProperty("dateCompleted", new DateSchema()) + .addProperty("voided", new BooleanSchema()); } if (rep instanceof DefaultRepresentation) { model - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("program", new RefProperty("#/definitions/ProgramGetRef")) - .property("location", new RefProperty("#/definitions/LocationGetRef")); + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGet")) + .addProperty("program", new Schema().$ref("#/components/schemas/ProgramGet")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGet")); } else if (rep instanceof FullRepresentation) { model - .property("patient", new RefProperty("#/definitions/PatientGet")) - .property("program", new RefProperty("#/definitions/ProgramGet")) - .property("location", new RefProperty("#/definitions/LocationGet")); + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetFull")) + .addProperty("program", new Schema().$ref("#/components/schemas/ProgramGetFull")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGetFull")); } return model; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("patient", new StringProperty().example("uuid")) - .property("program", new StringProperty().example("uuid")) - .property("dateEnrolled", new DateProperty()) - .property("dateCompleted", new DateProperty()) - .property("location", new StringProperty().example("uuid")) - .property("voided", new BooleanProperty()) - - .required("patient").required("program").required("dateEnrolled"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) new ObjectSchema() + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientCreate").example("uuid")) + .addProperty("program", new Schema().$ref("#/components/schemas/ProgramCreate").example("uuid")) + .addProperty("dateEnrolled", new DateSchema()) + .addProperty("dateCompleted", new DateSchema()) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationCreate").example("uuid")) + .addProperty("voided", new BooleanSchema()); + model.setRequired(Arrays.asList("patient", "program", "dateEnrolled")); if (rep instanceof FullRepresentation) { model - .property("patient", new RefProperty("#/definitions/PatientCreate")) - .property("program", new RefProperty("#/definitions/ProgramCreate")) - .property("location", new RefProperty("#/definitions/LocationCreate")); + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientCreateFull").example("uuid")) + .addProperty("program", new Schema().$ref("#/components/schemas/ProgramCreateFull").example("uuid")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationCreateFull").example("uuid")); } return model; } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("dateEnrolled", new DateProperty()) - .property("dateCompleted", new DateProperty()); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("dateEnrolled", new DateSchema()) + .addProperty("dateCompleted", new DateSchema()); //FIXME missing props } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramResource1_8.java index 144760495..5198c5b62 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramResource1_8.java @@ -9,13 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import org.openmrs.Concept; import org.openmrs.Program; +import org.openmrs.ProgramWorkflow; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -31,6 +30,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Collections; import java.util.List; @Resource(name = RestConstants.VERSION_1 + "/program", supportedClass = Program.class, supportedOpenmrsVersions = { "1.8.* - 1.9.*" }, order = 1) @@ -118,40 +118,38 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("allWorkflows", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))); + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("allWorkflows", new Schema().$ref("#/components/schemas/WorkflowGet")); } else if (rep instanceof FullRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("allWorkflows", new ArrayProperty(new RefProperty("#/definitions/WorkflowGet"))); + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetFull")) + .addProperty("allWorkflows", new Schema().$ref("#/components/schemas/WorkflowGetFull")); } else if (rep instanceof RefRepresentation) { model - .property("allWorkflows", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))); + .addProperty("allWorkflows", new Schema().$ref("#/components/schemas/WorkflowGetRef")); } return model; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("concept", new StringProperty().example("uuid")) - .property("retired", new BooleanProperty()) - - .required("concept").required("description"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getCREATESchema(rep) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreate").required(Collections.singletonList("concept")).example("uuid")) + .addProperty("retired", new BooleanSchema()); if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptCreate")); + model.addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreateFull").required(Collections.singletonList("concept")).example("uuid")); } return model; } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema(); //FIXME missing props } @Override diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowResource1_8.java index 9bc4b8834..fa8819079 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowResource1_8.java @@ -9,10 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import org.openmrs.Concept; import org.openmrs.Program; import org.openmrs.ProgramWorkflow; import org.openmrs.ProgramWorkflowState; @@ -72,21 +72,20 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("states", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGetRef"))); + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("states", new ArraySchema().items(new Schema().$ref("#/components/schemas/WorkflowStateGet"))); } else if (rep instanceof FullRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("states", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGet"))); + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetFull")) + .addProperty("states", new ArraySchema().items(new Schema().$ref("#/components/schemas/WorkflowStateGetFull"))); } else if (rep instanceof RefRepresentation) { model - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("states", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGet"))); - //FIXME should remove 'description'? + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("states", new ArraySchema().items(new Schema().$ref("#/components/schemas/WorkflowStateGet"))); } return model; } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowStateResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowStateResource1_8.java index ce4ec8840..9875fd3f8 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowStateResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ProgramWorkflowStateResource1_8.java @@ -9,11 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.UUIDSchema; +import org.openmrs.Concept; import org.openmrs.Program; import org.openmrs.ProgramWorkflow; import org.openmrs.ProgramWorkflowState; @@ -33,6 +34,7 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; @SubResource(parent = ProgramWorkflowResource1_8.class, path = "state", supportedClass = ProgramWorkflowState.class, supportedOpenmrsVersions = { @@ -123,32 +125,37 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation) { model - .property("uuid", new StringProperty()) - .property("description", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); + .addProperty("uuid", new UUIDSchema()) + .addProperty("description", new StringSchema()) + .addProperty("retired", new BooleanSchema()) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")); } else if (rep instanceof FullRepresentation) { model - .property("uuid", new StringProperty()) - .property("description", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGet")); + .addProperty("uuid", new UUIDSchema()) + .addProperty("description", new StringSchema()) + .addProperty("retired", new BooleanSchema()) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetFull")); } else if (rep instanceof RefRepresentation) { model - .property("uuid", new StringProperty()) - .property("retired", new BooleanProperty()) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); + .addProperty("uuid", new UUIDSchema()) + .addProperty("retired", new BooleanSchema()) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptCreate").required(Collections.singletonList("concept"))) + .addProperty("initial", new BooleanSchema()) + .addProperty("terminal", new BooleanSchema()); + } @Override diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationShipTypeResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationShipTypeResource1_8.java index 8180de756..c40c5fa6b 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationShipTypeResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationShipTypeResource1_8.java @@ -9,11 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.RelationshipType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -29,6 +29,7 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; @Resource(name = RestConstants.VERSION_1 + "/relationshiptype", supportedClass = RelationshipType.class, supportedOpenmrsVersions = { @@ -132,33 +133,32 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("aIsToB", new StringProperty()) - .property("bIsToA", new StringProperty()); + .addProperty("aIsToB", new StringSchema()) + .addProperty("bIsToA", new StringSchema()); } if (rep instanceof FullRepresentation) { model - .property("weight", new IntegerProperty()); + .addProperty("weight", new IntegerSchema()); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("aIsToB", new StringProperty()) - .property("bIsToA", new StringProperty()) - .property("weight", new IntegerProperty()) + public Schema getCREATESchema(Representation rep) { + return super.getCREATESchema(rep) + .addProperty("aIsToB", new StringSchema().required(Collections.singletonList("aIsToB"))) + .addProperty("bIsToA", new StringSchema().required(Collections.singletonList("bIsToA"))) + .addProperty("weight", new IntegerSchema()); - .required("aIsToB").required("bIsToA"); } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationshipResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationshipResource1_8.java index a004176ba..58eda8dbb 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationshipResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RelationshipResource1_8.java @@ -9,14 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Person; import org.openmrs.Relationship; +import org.openmrs.RelationshipType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -31,6 +31,8 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; + /** * {@link org.openmrs.module.webservices.rest.web.annotation.Resource} for Provider, supporting * standard CRUD operations @@ -161,51 +163,49 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("voided", new BooleanProperty()); + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("voided", new BooleanSchema()); } if (rep instanceof DefaultRepresentation) { model - .property("personA", new RefProperty("#/definitions/PersonGetRef")) - .property("relationshipType", new RefProperty("#/definitions/RelationshiptypeGetRef")) - .property("personB", new RefProperty("#/definitions/PersonGetRef")); + .addProperty("personA", new Schema().$ref("#/components/schemas/PersonGet")) + .addProperty("relationshipType", new Schema().$ref("#/components/schemas/RelationshiptypeGet")) + .addProperty("personB", new Schema().$ref("#/components/schemas/PersonGet")); } else if (rep instanceof FullRepresentation) { model - .property("personA", new RefProperty("#/definitions/PersonGet")) - .property("relationshipType", new RefProperty("#/definitions/RelationshiptypeGet")) - .property("personB", new RefProperty("#/definitions/PersonGet")); + .addProperty("personA", new Schema().$ref("#/components/schemas/PersonGetFull")) + .addProperty("relationshipType", new Schema().$ref("#/components/schemas/RelationshiptypeGetFull")) + .addProperty("personB", new Schema().$ref("#/components/schemas/PersonGetFull")); } return model; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("personA", new StringProperty().example("uuid")) - .property("relationshipType", new StringProperty().example("uuid")) - .property("personB", new StringProperty().example("uuid")) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - - .required("personA").required("relationshipType").required("personB"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) new ObjectSchema() + .addProperty("personA", new Schema().$ref("#/components/schemas/PersonCreate").example("uuid")) + .addProperty("relationshipType", new Schema().$ref("#/components/schemas/RelationshiptypeCreate").example("uuid")) + .addProperty("personB", new Schema().$ref("#/components/schemas/PersonCreate").example("uuid")) + .addProperty("startDate", new DateSchema()) + .addProperty("endDate", new DateSchema()); + model.setRequired(Arrays.asList("personA", "relationshipType", "personB")); if (rep instanceof FullRepresentation) { model - .property("personA", new RefProperty("#/definitions/PersonCreate")) - - .property("relationshipType", new RefProperty("#/definitions/RelationshiptypeCreate")) - .property("personB", new RefProperty("#/definitions/PersonCreate")); + .addProperty("personA", new Schema().$ref("#/components/schemas/PersonCreate").example("uuid")) + .addProperty("relationshipType", new Schema().$ref("#/components/schemas/RelationshiptypeCreate").example("uuid")) + .addProperty("personB", new Schema().$ref("#/components/schemas/PersonCreate").example("uuid")); } return model; } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("voided", new BooleanProperty()); //FIXME missing properties + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("voided", new BooleanSchema()); //FIXME missing properties } } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RoleResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RoleResource1_8.java index bacd9c032..b608b8ce5 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RoleResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/RoleResource1_8.java @@ -9,11 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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 io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.Privilege; import org.openmrs.Role; @@ -126,35 +125,35 @@ public DelegatingResourceDescription getUpdatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation) { model - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeGetRef"))) - .property("inheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleGetRef"))); + .addProperty("privileges", new ArraySchema().items(new Schema().$ref("#/components/schemas/PrivilegeGet"))) + .addProperty("inheritedRoles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleGet"))); } if (rep instanceof FullRepresentation) { model - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeGet"))) - .property("inheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleGet"))) - .property("allInheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleGet"))); + .addProperty("privileges", new ArraySchema().items(new Schema().$ref("#/components/schemas/PrivilegeGetFull"))) + .addProperty("inheritedRoles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleGetFull"))) + .addProperty("allInheritedRoles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleGetFull"))); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeCreate"))) - .property("inheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleCreate"))); + public Schema getCREATESchema(Representation rep) { + return ((ObjectSchema) super.getCREATESchema(rep)) + .addProperty("privileges", new ArraySchema().items(new Schema().$ref("#/components/schemas/PrivilegeCreate"))) + .addProperty("inheritedRoles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleCreate"))); } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("description", new StringProperty()) - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeCreate"))) - .property("inheritedRoles", new ArrayProperty(new RefProperty("#/definitions/RoleCreate"))); + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("description", new StringSchema()) + .addProperty("privileges", new ArraySchema().items(new Schema().$ref("#/components/schemas/PrivilegeCreate"))) + .addProperty("inheritedRoles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleCreate"))); } /** diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ServerLogResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ServerLogResource1_8.java index 0cf9916db..a0de496d0 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ServerLogResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ServerLogResource1_8.java @@ -9,9 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.MapProperty; +import io.swagger.v3.oas.models.media.MapSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.module.webservices.helper.ServerLogActionWrapper; import org.openmrs.module.webservices.helper.ServerLogActionWrapper1_8; import org.openmrs.module.webservices.rest.SimpleObject; @@ -45,9 +44,9 @@ public SimpleObject getAll(RequestContext context) throws ResponseException { } @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("serverLog", new MapProperty()); + public Schema getGETSchema(Representation rep) { + return super.getGETSchema(rep) + .addProperty("serverLog", new MapSchema()); } @Override diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java index c1f750a4b..05103d902 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskActionResource1_8.java @@ -9,13 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; -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.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.api.APIException; -import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty; import org.openmrs.module.webservices.helper.TaskAction; import org.openmrs.module.webservices.helper.TaskServiceWrapper; import org.openmrs.module.webservices.rest.SimpleObject; @@ -35,7 +34,9 @@ import org.openmrs.scheduler.TaskDefinition; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; @Resource(name = RestConstants.VERSION_1 + "/taskaction", supportedClass = TaskAction.class, supportedOpenmrsVersions = { "1.8.* - 9.*" }) @@ -196,15 +197,27 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe description.addRequiredProperty("action", "action"); return description; } - + + @SuppressWarnings("unchecked") @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl(); - model.property("tasks", new ArrayProperty(new StringProperty())); - model.property("allTasks", new BooleanProperty()); - model.property("action", new EnumProperty(TaskAction.Action.class)); - model.required("action"); - return model; + public Schema getGETSchema(Representation rep) { + ObjectSchema schema = (ObjectSchema) super.getGETSchema(rep); + schema.addProperty("tasks", new ArraySchema().items(new StringSchema())); + schema.addProperty("action", new Schema().type("string")._enum(Arrays.asList(TaskAction.Action.values()))) + .required(Collections.singletonList("action")); + return schema; + + } + + @SuppressWarnings("unchecked") + @Override + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema.addProperty("tasks", new ArraySchema().items(new StringSchema())); + schema.addProperty("allTasks", new BooleanSchema()); + schema.addProperty("action", new Schema().type("string")._enum(Arrays.asList(TaskAction.Action.values()))) + .required(Collections.singletonList("action")); + return schema; } /** @@ -214,5 +227,4 @@ public Model getCREATEModel(Representation rep) { public Boolean isAllModules(TaskAction action) { return action.isAllTasks(); } - } diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskDefinitionResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskDefinitionResource1_8.java index 596ff1b1b..356dbb6cb 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskDefinitionResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/TaskDefinitionResource1_8.java @@ -9,6 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.MapSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.UUIDSchema; import org.openmrs.module.webservices.helper.TaskServiceWrapper; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; import org.openmrs.module.webservices.rest.web.representation.RefRepresentation; @@ -25,6 +33,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.response.ResponseException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -102,7 +111,50 @@ public DelegatingResourceDescription getCreatableProperties() { description.addRequiredProperty("properties"); return description; } - + + @Override + public Schema getGETSchema(Representation rep) { + ObjectSchema schema = (ObjectSchema) super.getGETSchema(rep); + if (rep instanceof DefaultRepresentation) { + schema.addProperty("uuid", new UUIDSchema()); + schema.addProperty("name", new StringSchema()); + schema.addProperty("description", new StringSchema()); + schema.addProperty("taskClass", new StringSchema()); + schema.addProperty("startTime", new DateTimeSchema()); + schema.addProperty("started", new BooleanSchema()); + } else if (rep instanceof FullRepresentation) { + schema.addProperty("uuid", new UUIDSchema()); + schema.addProperty("name", new StringSchema()); + schema.addProperty("description", new StringSchema()); + schema.addProperty("taskClass", new StringSchema()); + schema.addProperty("startTime", new DateTimeSchema()); + schema.addProperty("lastExecutionTime", new DateTimeSchema()); + schema.addProperty("repeatInterval", new IntegerSchema().format("long")); + schema.addProperty("startOnStartup", new BooleanSchema()); + schema.addProperty("startTimePattern", new StringSchema()); + schema.addProperty("started", new BooleanSchema()); + schema.addProperty("properties", new MapSchema()); + } else if (rep instanceof RefRepresentation) { + schema.addProperty("uuid", new UUIDSchema()); + schema.addProperty("name", new StringSchema()); + schema.addProperty("description", new StringSchema()); + schema.addProperty("taskClass", new StringSchema()); + } + return schema; + } + + @Override + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + return schema + .addProperty("name", new StringSchema().required(Collections.singletonList("name"))) + .addProperty("description", new StringSchema().required(Collections.singletonList("description"))) + .addProperty("taskClass", new StringSchema().required(Collections.singletonList("taskClass"))) + .addProperty("startTime", new DateTimeSchema().required(Collections.singletonList("startTime"))) + .addProperty("repeatInterval", new IntegerSchema().format("long").required(Collections.singletonList("repeatInterval"))) + .addProperty("properties", new MapSchema().required(Collections.singletonList("properties"))); + } + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(java.lang.Object) */ diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java index 9cf656933..b7f29b747 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/UserResource1_8.java @@ -16,8 +16,11 @@ import java.util.List; import java.util.Set; +import io.swagger.v3.oas.models.media.ObjectSchema; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang.StringUtils; +import org.openmrs.Person; +import org.openmrs.Privilege; import org.openmrs.Role; import org.openmrs.User; import org.openmrs.api.context.Context; @@ -40,13 +43,10 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.module.webservices.rest.web.v1_0.wrapper.openmrs1_8.UserAndPassword1_8; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.MapProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.MapSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; /** * {@link Resource} for User, supporting standard CRUD operations @@ -136,45 +136,46 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - //FIXME check valid supportedClass - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("username", new StringProperty()) - .property("systemId", new StringProperty()) - .property("userProperties", new MapProperty()); //FIXME type + schema + .addProperty("username", new StringSchema()) + .addProperty("systemId", new StringSchema()) + .addProperty("userProperties", new MapSchema().additionalProperties(new StringSchema())); //FIXME type } if (rep instanceof DefaultRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGetRef")) - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeGetRef"))) - .property("roles", new ArrayProperty(new RefProperty("#/definitions/RoleGetRef"))); + schema + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGetRef")) + .addProperty("privileges", new ArraySchema().items(new Schema().$ref("#/components/schemas/PrivilegeGetRef"))) + .addProperty("roles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleGetRef"))); } else if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGet")) - .property("privileges", new ArrayProperty(new RefProperty("#/definitions/PrivilegeGet"))) - .property("roles", new ArrayProperty(new RefProperty("#/definitions/RoleGet"))) - .property("allRoles", new ArrayProperty(new RefProperty("#/definitions/RoleGet"))) - .property("proficientLocales", new ArrayProperty(new ObjectProperty())) - .property("secretQuestion", new StringProperty()); + schema + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGet")) + .addProperty("privileges", new ArraySchema().items(new Schema().$ref("#/components/schemas/PrivilegeGet"))) + .addProperty("roles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleGet"))) + .addProperty("allRoles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleGet"))) + .addProperty("proficientLocales", new ArraySchema().items(new ObjectSchema())) + .addProperty("secretQuestion", new StringSchema()); } - return model; + + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("username", new StringProperty()) - .property("password", new StringProperty()) - .property("person", new RefProperty("#/definitions/PersonCreate")) - .property("systemId", new StringProperty()) - .property("userProperties", new MapProperty()) //FIXME type - .property("roles", new ArrayProperty(new RefProperty("#/definitions/RoleCreate"))) - .property("proficientLocales", new ArrayProperty(new ObjectProperty())) - .property("secretQuestion", new StringProperty()) - - .required("username").required("password").required("person"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + return schema + .addProperty("username", new StringSchema().required(Collections.singletonList("username"))) + .addProperty("password", new StringSchema().required(Collections.singletonList("password"))) + .addProperty("person", new Schema().$ref("#/components/schemas/PersonCreate").required(Collections.singletonList("person"))) + .addProperty("systemId", new StringSchema()) + .addProperty("userProperties", new MapSchema().additionalProperties(new StringSchema())) + .addProperty("proficientLocales", new ArraySchema().items(new ObjectSchema())) + .addProperty("roles", new ArraySchema().items(new Schema().$ref("#/components/schemas/RoleCreate"))) + .addProperty("secretQuestion", new StringSchema()); } /** @@ -425,4 +426,4 @@ protected NeedsPaging doGetAll(RequestContext context) { } return new NeedsPaging(users, context); } -} +} \ No newline at end of file diff --git a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/HivDrugOrderSubclassHandler.java b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/HivDrugOrderSubclassHandler.java index 0a555964c..a13cf5d2b 100644 --- a/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/HivDrugOrderSubclassHandler.java +++ b/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/HivDrugOrderSubclassHandler.java @@ -9,12 +9,13 @@ */ package org.openmrs.module.webservices.rest.web; -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 io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Concept; import org.openmrs.Order; +import org.openmrs.Patient; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; @@ -29,6 +30,8 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.util.OpenmrsConstants; +import java.util.Arrays; + /** * This is a contrived example for testing purposes */ @@ -86,39 +89,39 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return d; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = new ModelImpl(); + public Schema getGETSchema(Representation rep) { + Schema schema = new Schema(); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("startDate", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("standardRegimenCode", new StringProperty()); + schema + .addProperty("startDate", new DateTimeSchema()) + .addProperty("autoExpireDate", new DateTimeSchema()) + .addProperty("standardRegimenCode", new StringSchema()); } if (rep instanceof DefaultRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("concept", new RefProperty("#/definitions/ConceptGetRef")); + schema + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetRef")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetRef")); } else if (rep instanceof FullRepresentation) { - model - .property("patient", new RefProperty("#/definitions/PatientGet")) - .property("concept", new RefProperty("#/definitions/ConceptGet")); + schema + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGet")) + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")); } - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("patient", new StringProperty().example("uuid")) - .property("concept", new StringProperty().example("uuid")) - .property("startDate", new DateProperty()) - .property("autoExpireDate", new DateProperty()) - .property("standardRegimenCode", new StringProperty()) - .property("instructions", new StringProperty()) - - .required("patient").required("concept"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("patient", new StringSchema().example("uuid")) + .addProperty("concept", new StringSchema().example("uuid")) + .addProperty("startDate", new DateTimeSchema()) + .addProperty("autoExpireDate", new DateTimeSchema()) + .addProperty("standardRegimenCode", new StringSchema()) + .addProperty("instructions", new StringSchema()) + .required(Arrays.asList("patient", "concept")); } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeCrudResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeCrudResource1_9.java index d9f0b6ab1..53c67a275 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeCrudResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeCrudResource1_9.java @@ -12,10 +12,9 @@ import java.util.Arrays; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.attribute.Attribute; import org.openmrs.customdatatype.CustomDatatype; @@ -109,24 +108,24 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("attributeType", new StringProperty().example("uuid")) - .property("value", new StringProperty()) - - .required("attributeType").required("value"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new Schema() + .addProperty("attributeType", new StringSchema().example("uuid")) + .addProperty("value", new StringSchema()) + .required(Arrays.asList("attributeType", "value")); } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + Schema model = super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("attributeType", new StringProperty()) //FIXME type - .property("value", new StringProperty()) //FIXME type - .property("voided", new BooleanProperty()); + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("attributeType", new StringSchema()) + .addProperty("value", new StringSchema()) + .addProperty("voided", new BooleanSchema()); } return model; } diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeTypeCrudResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeTypeCrudResource1_9.java index 0fd108aba..638bad18b 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeTypeCrudResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/BaseAttributeTypeCrudResource1_9.java @@ -9,10 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.attribute.AttributeType; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; @@ -21,6 +20,8 @@ import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource; +import java.util.Collections; + /** * Subclass of {@link MetadataDelegatingCrudResource} with helper methods specific to * {@link AttributeType} @@ -30,34 +31,33 @@ public abstract class BaseAttributeTypeCrudResource1_9> extends MetadataDelegatingCrudResource { @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + Schema model = (Schema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("datatypeClassname", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()); + .addProperty("minOccurs", new IntegerSchema()) + .addProperty("maxOccurs", new IntegerSchema()) + .addProperty("datatypeClassname", new StringSchema()) + .addProperty("preferredHandlerClassname", new StringSchema()); } if (rep instanceof FullRepresentation) { model - .property("datatypeConfig", new StringProperty()) - .property("handlerConfig", new StringProperty()); + .addProperty("datatypeConfig", new StringSchema()) + .addProperty("handlerConfig", new StringSchema()); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("datatypeClassname", new StringProperty()) - .property("minOccurs", new IntegerProperty()) - .property("maxOccurs", new IntegerProperty()) - .property("datatypeConfig", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()) - .property("handlerConfig", new StringProperty()) - - .required("datatypeClassname"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return super.getCREATESchema(rep) + .addProperty("datatypeClassname", new StringSchema()) + .addProperty("minOccurs", new IntegerSchema()) + .addProperty("maxOccurs", new IntegerSchema()) + .addProperty("datatypeConfig", new StringSchema()) + .addProperty("preferredHandlerClassname", new StringSchema()) + .addProperty("handlerConfig", new StringSchema()).required(Collections.singletonList("datatypeClassname")); } diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java index 420153e67..47fc3fa22 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapResource1_9.java @@ -9,11 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.apache.commons.lang.StringUtils; import org.openmrs.ConceptMap; +import org.openmrs.ConceptMapType; +import org.openmrs.ConceptReferenceTerm; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -25,6 +26,8 @@ import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.ConceptMapResource1_8; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.ConceptResource1_8; +import java.util.Arrays; + /** * {@link Resource} for {@link ConceptMap}, supporting standard CRUD operations */ @@ -55,32 +58,34 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermGetRef")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermGet")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGet")); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("conceptReferenceTerm", new Schema().$ref("#/components/schemas/ConceptreferencetermGetRef")) + .addProperty("conceptMapType", new Schema().$ref("#/components/schemas/ConceptmaptypeGetRef")); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("conceptReferenceTerm", new Schema().$ref("#/components/schemas/ConceptreferencetermGet")) + .addProperty("conceptMapType", new Schema().$ref("#/components/schemas/ConceptmaptypeGet")); + } + schema.getProperties().remove("source"); //FIXME check + schema.getProperties().remove("sourceCode"); + schema.getProperties().remove("comment"); } - model.getProperties().remove("source"); //FIXME check - model.getProperties().remove("sourceCode"); - model.getProperties().remove("comment"); - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation representation) { - return new ModelImpl() - .property("conceptReferenceTerm", new RefProperty("#/definitions/ConceptreferencetermCreate")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeCreate")) - - .required("conceptReferenceTerm").required("conceptMapType"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation representation) { + return new ObjectSchema() + .addProperty("conceptReferenceTerm", new Schema().$ref("#/components/schemas/ConceptreferencetermCreate")) + .addProperty("conceptMapType", new Schema().$ref("#/components/schemas/ConceptmaptypeCreate")) + .required(Arrays.asList("conceptReferenceTerm", "conceptMapType")); } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapTypeResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapTypeResource1_9.java index 5a200a342..b43c5a42c 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapTypeResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptMapTypeResource1_9.java @@ -9,9 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.ConceptMapType; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -83,19 +83,19 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property("isHidden", new BooleanProperty()); + .addProperty("isHidden", new BooleanSchema()); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("isHidden", new BooleanProperty()); + public Schema getCREATESchema(Representation rep) { + return super.getCREATESchema(rep) + .addProperty("isHidden", new BooleanSchema()); } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermMapResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermMapResource1_9.java index 91f23b973..c486f5baf 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermMapResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermMapResource1_9.java @@ -9,9 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import org.openmrs.ConceptMapType; import org.openmrs.ConceptReferenceTerm; import org.openmrs.ConceptReferenceTermMap; import org.openmrs.api.context.Context; @@ -30,6 +30,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; /** * {@link Resource} for {@link ConceptReferenceTermMap}, supporting standard CRUD operations @@ -86,37 +87,39 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("termA", new RefProperty("#/definitions/ConceptreferencetermGetRef")) - .property("termB", new RefProperty("#/definitions/ConceptreferencetermGetRef")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("termA", new RefProperty("#/definitions/ConceptreferencetermGet")) - .property("termB", new RefProperty("#/definitions/ConceptreferencetermGet")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeGet")); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("termA", new Schema().$ref("#/components/schemas/ConceptreferencetermGetRef")) + .addProperty("termB", new Schema().$ref("#/components/schemas/ConceptreferencetermGetRef")) + .addProperty("conceptMapType", new Schema().$ref("#/components/schemas/ConceptmaptypeGetRef")); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("termA", new Schema().$ref("#/components/schemas/ConceptreferencetermGet")) + .addProperty("termB", new Schema().$ref("#/components/schemas/ConceptreferencetermGet")) + .addProperty("conceptMapType", new Schema().$ref("#/components/schemas/ConceptmaptypeGet")); + } } - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("termA", new RefProperty("#/definitions/ConceptreferencetermCreate")) - .property("termB", new RefProperty("#/definitions/ConceptreferencetermCreate")) - .property("conceptMapType", new RefProperty("#/definitions/ConceptmaptypeCreate")) - - .required("termA").required("termB").required("conceptMapType"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("termA", new Schema().$ref("#/components/schemas/ConceptreferencetermCreate")) + .addProperty("termB", new Schema().$ref("#/components/schemas/ConceptreferencetermCreate")) + .addProperty("conceptMapType", new Schema().$ref("#/components/schemas/ConceptmaptypeCreate")) + .required(Arrays.asList("termA", "termB", "conceptMapType")); } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema(); //FIXME missing props } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermResource1_9.java index c188c85a0..22374c66d 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptReferenceTermResource1_9.java @@ -9,13 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; -import io.swagger.models.properties.UUIDProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang3.StringUtils; import org.openmrs.ConceptReferenceTerm; +import org.openmrs.ConceptSource; import org.openmrs.api.ConceptService; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -34,6 +33,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; import java.util.List; /** @@ -94,38 +94,40 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation) { - model.property("uuid", new UUIDProperty()); - model.property("conceptSource", new RefProperty("#/definitions/ConceptsourceGetRef")); - model.property("code", new StringProperty()); - model.property("version", new StringProperty()); + model + .addProperty("uuid", new Schema().type("string").format("uuid")) + .addProperty("conceptSource", new Schema().$ref("#/components/schemas/ConceptsourceGetRef")) + .addProperty("code", new StringSchema()) + .addProperty("version", new StringSchema()); } else if (rep instanceof FullRepresentation) { - model.property("uuid", new UUIDProperty()); - model.property("conceptSource", new RefProperty("#/definitions/ConceptsourceGetFull")); - model.property("code", new StringProperty()); - model.property("version", new StringProperty()); - model.property("auditInfo", new StringProperty()); + model + .addProperty("uuid", new Schema().type("string").format("uuid")) + .addProperty("conceptSource", new Schema().$ref("#/components/schemas/ConceptsourceGetFull")) + .addProperty("code", new StringSchema()) + .addProperty("version", new StringSchema()) + .addProperty("auditInfo", new StringSchema()); } return model; } @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("code", new StringProperty()) - .property("conceptSource", new RefProperty("#/definitions/ConceptsourceCreate")) - .property("version", new StringProperty()) - - .required("code").required("conceptSource"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return super.getCREATESchema(rep) + .addProperty("code", new StringSchema()) + .addProperty("conceptSource", new Schema().$ref("#/components/schemas/ConceptsourceCreate")) + .addProperty("version", new StringSchema()) + .required(Arrays.asList("code", "conceptSource")); } - + @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); //FIXME missing props + public Schema getUPDATESchema(Representation rep) { + return super.getUPDATESchema(rep); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.MetadataDelegatingCrudResource#getDisplayString(org.openmrs.OpenmrsMetadata) */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSearchResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSearchResource1_9.java index d824a86a3..3d4363ad6 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSearchResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptSearchResource1_9.java @@ -9,10 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Concept; import org.openmrs.ConceptClass; import org.openmrs.ConceptName; import org.openmrs.ConceptSearchResult; @@ -71,26 +70,26 @@ public DelegatingResourceDescription getRepresentationDescription(Representation return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("display", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("conceptName", new RefProperty("#/definitions/ConceptNameGetRef")); - } else if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGet")) - .property("conceptName", new RefProperty("#/definitions/ConceptNameGetRef")) - .property("word", new StringProperty()) - .property("transientWeight", new StringProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema.addProperty("display", new StringSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("conceptName", new Schema().$ref("#/components/schemas/ConceptNameGetRef")); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("concept", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("conceptName", new Schema().$ref("#/components/schemas/ConceptNameGetRef")) + .addProperty("word", new StringSchema()) + .addProperty("transientWeight", new StringSchema()); + } } - return model; + return schema; } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptStopwordResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptStopwordResource1_9.java index b44987aac..96a58526e 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptStopwordResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ConceptStopwordResource1_9.java @@ -9,9 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -27,6 +27,8 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.ConceptStopWord; +import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -83,28 +85,31 @@ public DelegatingResourceDescription getCreatableProperties() { description.addProperty("locale"); return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("value", new StringProperty()) - .property("locale", new StringProperty().example("en")); //FIXME type + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()); + + if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { + schema + .addProperty("value", new StringSchema()) + .addProperty("locale", new StringSchema().example("en")); //FIXME type + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("value", new StringProperty()) - .property("locale", new StringProperty().example("en")) - - .required("value"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("value", new StringSchema()) + .addProperty("locale", new StringSchema().example("en")) + .required(Collections.singletonList("value")); } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeHandlerResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeHandlerResource1_9.java index 4675653e9..f5e06705e 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeHandlerResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeHandlerResource1_9.java @@ -9,9 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.SubResource; @@ -39,17 +38,17 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addLink("full", ".?v=" + RestConstants.REPRESENTATION_FULL); return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("handlerClassname", new StringProperty()) - .property("display", new StringProperty()); //FIXME delegate property name + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("handlerClassname", new StringSchema()) + .addProperty("display", new StringSchema()); //FIXME delegate property name } - return model; + return schema; } @Override diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeResource1_9.java index 7762a01b4..dea82724a 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/CustomDatatypeResource1_9.java @@ -9,11 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -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 io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.api.APIAuthenticationException; import org.openmrs.api.context.Context; import org.openmrs.customdatatype.CustomDatatype; @@ -102,24 +100,25 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("datatypeClassname", new StringProperty()); - } - if (rep instanceof DefaultRepresentation) { - model - .property("handlers", new ArrayProperty(new RefProperty("#/definitions/CustomdatatypeHandlersGetRef"))); - } else if (rep instanceof FullRepresentation) { - model - .property("handlers", new ArrayProperty(new RefProperty("#/definitions/CustomdatatypeHandlersGet"))); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("datatypeClassname", new StringSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("handlers", new ArraySchema().items(new Schema>().$ref("#/components/schemas/CustomdatatypeHandlersGetRef"))); + } else if (rep instanceof FullRepresentation) { + ((Schema) schema) + .addProperty("handlers", new ArraySchema().items(new Schema>().$ref("#/components/schemas/CustomdatatypeHandlersGet"))); + } } - return model; + return schema; } @Override diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterProviderResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterProviderResource1_9.java index c52c5ddfe..8b136ca47 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterProviderResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterProviderResource1_9.java @@ -9,11 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Encounter; import org.openmrs.EncounterProvider; import org.openmrs.EncounterRole; @@ -89,46 +88,48 @@ public DelegatingResourceDescription getUpdatableProperties() { description.addProperty("voidReason"); return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("provider", new RefProperty("#/definitions/ProviderGetRef")) - .property("encounterRole", new RefProperty("#/definitions/EncounterroleGetRef")) - .property("voided", new BooleanProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("provider", new RefProperty("#/definitions/ProviderGet")) - .property("encounterRole", new RefProperty("#/definitions/EncounterroleGet")); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("provider", new Schema().$ref("#/components/schemas/ProviderGetRef")) + .addProperty("encounterRole", new Schema().$ref("#/components/schemas/EncounterroleGetRef")) + .addProperty("voided", new BooleanSchema()); + + if (rep instanceof FullRepresentation) { + ((Schema) schema) + .addProperty("provider", new Schema().$ref("#/components/schemas/ProviderGet")) + .addProperty("encounterRole", new Schema().$ref("#/components/schemas/EncounterroleGet")); + } } - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("provider", new StringProperty().example("uuid")) - .property("encounterRole", new StringProperty().example("uuid")) - .property("encounter", new StringProperty()); //FIXME remove if not needed + public Schema getCREATESchema(Representation rep) { + Schema schema = new ObjectSchema() + .addProperty("provider", new StringSchema().example("uuid")) + .addProperty("encounterRole", new StringSchema().example("uuid")) + .addProperty("encounter", new StringSchema()); //FIXME remove if not needed + if (rep instanceof FullRepresentation) { - model - .property("provider", new RefProperty("#/definitions/ProviderCreate")) - .property("encounter", new RefProperty("#/definitions/EncounterCreate")) - .property("encounterRole", new RefProperty("#/definitions/EncounterroleCreate")); + schema + .addProperty("provider", new Schema().$ref("#/components/schemas/ProviderCreate")) + .addProperty("encounter", new Schema().$ref("#/components/schemas/EncounterCreate")) + .addProperty("encounterRole", new Schema().$ref("#/components/schemas/EncounterroleCreate")); } - return model; + return schema; } - + @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("encounterRole", new StringProperty()) - .property("voided", new BooleanProperty()) - .property("voidReason", new StringProperty()); + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("encounterRole", new StringSchema()) + .addProperty("voided", new BooleanSchema()) + .addProperty("voidReason", new StringSchema()); } @Override diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java index 4d8ad24ae..994faca35 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/EncounterRoleResource1_9.java @@ -9,7 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.EncounterRole; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -41,12 +41,12 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - + @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } - + /** * @see DelegatingCrudResource#newDelegate() */ diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResourceResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResourceResource1_9.java index 83f6978eb..20d0cf627 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResourceResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/FormResourceResource1_9.java @@ -9,10 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.Form; import org.openmrs.FormResource; @@ -140,42 +139,44 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); - - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl - .property("name", new StringProperty()) - .property("valueReference", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - modelImpl - .property("dataType", new StringProperty()) - .property("handler", new StringProperty()) - .property("handlerConfig", new StringProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()); + + if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { + schema + .addProperty("name", new StringSchema()) + .addProperty("valueReference", new StringSchema()); + } + if (rep instanceof FullRepresentation) { + schema + .addProperty("dataType", new StringSchema()) + .addProperty("handler", new StringSchema()) + .addProperty("handlerConfig", new StringSchema()); + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl() - .property("form", new StringProperty()) - .property("name", new StringProperty()) - .property("dataType", new StringProperty()) - .property("handler", new StringProperty()) - .property("handlerConfig", new StringProperty()) - .property("value", new StringProperty()) - .property("valueReference", new StringProperty()); + public Schema getCREATESchema(Representation rep) { + Schema schema = new ObjectSchema() + .addProperty("form", new StringSchema()) + .addProperty("name", new StringSchema()) + .addProperty("dataType", new StringSchema()) + .addProperty("handler", new StringSchema()) + .addProperty("handlerConfig", new StringSchema()) + .addProperty("value", new StringSchema()) + .addProperty("valueReference", new StringSchema()); if (rep instanceof FullRepresentation) { - model - .property("form", new RefProperty("#/definitions/FormCreate")); + schema.addProperty("form", new Schema().$ref("#/components/schemas/FormCreate")); } - return model; + return schema; } @Override diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ProviderResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ProviderResource1_9.java index 58a1bdcc8..5b2ccaec8 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ProviderResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ProviderResource1_9.java @@ -9,12 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; -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.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Person; import org.openmrs.Provider; import org.openmrs.ProviderAttribute; import org.openmrs.api.context.Context; @@ -34,6 +33,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; import java.util.List; import java.util.Set; @@ -112,44 +112,49 @@ public static void setAttributes(Provider provider, Set attri public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGetRef")) - .property("identifier", new StringProperty()) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/ProviderAttributeGetRef"))) - .property("preferredHandlerClassname", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonGet")) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/ProviderAttributeGet"))); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof Schema && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGetRef")) + .addProperty("identifier", new StringSchema()) + .addProperty("attributes", new ArraySchema().items(new Schema().$ref("#/components/schemas/ProviderAttributeGetRef"))) + .addProperty("preferredHandlerClassname", new StringSchema()); + + if (rep instanceof FullRepresentation) { + schema + .addProperty("person", new Schema().$ref("#/components/schemas/PersonGet")) + .addProperty("attributes", new ArraySchema().items(new Schema().$ref("#/components/schemas/ProviderAttributeGet"))); + } } - return model; + return schema; } - + @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } - + @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getCREATEModel(rep)) - .property("person", new StringProperty().example("uuid")) - .property("identifier", new StringProperty()) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/ProviderAttributeCreate"))) - .property("retired", new BooleanProperty()) - - .required("person").required("identifier"); - if (rep instanceof FullRepresentation) { - model - .property("person", new RefProperty("#/definitions/PersonCreate")); + public Schema getCREATESchema(Representation rep) { + Schema schema = super.getCREATESchema(rep); + if (schema instanceof Schema) { + schema + .addProperty("person", new StringSchema().example("uuid")) + .addProperty("identifier", new StringSchema()) + .addProperty("attributes", new ArraySchema().items(new Schema().$ref("#/components/schemas/ProviderAttributeCreate"))) + .addProperty("retired", new BooleanSchema()); + + schema.setRequired(Arrays.asList("person", "identifier")); + + if (rep instanceof FullRepresentation) { + schema + .addProperty("person", new Schema().$ref("#/components/schemas/PersonCreate")); + } } - return model; + return schema; } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java index 895cc3699..3de086e10 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/SystemSettingResource1_9.java @@ -9,8 +9,12 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; +import java.util.Collections; import java.util.List; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.GlobalProperty; import org.openmrs.api.APIException; @@ -34,10 +38,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.StringProperty; - /** * {@link Resource} for {@link GlobalProperty}, supporting standard CRUD operations */ @@ -110,47 +110,48 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.removeProperty("property"); return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("property", new StringProperty()) - .property("value", new StringProperty()) - .property("description", new StringProperty()) - .property("display", new StringProperty()); - } - if (rep instanceof FullRepresentation) { - model - .property("datatypeClassname", new StringProperty()) - .property("datatypeConfig", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()) - .property("handlerConfig", new StringProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof Schema && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("property", new StringSchema()) + .addProperty("value", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("display", new StringSchema()); + + if (rep instanceof FullRepresentation) { + schema + .addProperty("datatypeClassname", new StringSchema()) + .addProperty("datatypeConfig", new StringSchema()) + .addProperty("preferredHandlerClassname", new StringSchema()) + .addProperty("handlerConfig", new StringSchema()); + } } - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("property", new StringProperty()) - .property("description", new StringProperty()) - .property("datatypeClassname", new StringProperty()) - .property("datatypeConfig", new StringProperty()) - .property("preferredHandlerClassname", new StringProperty()) - .property("handlerConfig", new StringProperty()) - .property("value", new StringProperty()) - - .required("property"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("property", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("datatypeClassname", new StringSchema()) + .addProperty("datatypeConfig", new StringSchema()) + .addProperty("preferredHandlerClassname", new StringSchema()) + .addProperty("handlerConfig", new StringSchema()) + .addProperty("value", new StringSchema()) + .required(Collections.singletonList("property")); } - + @Override - public Model getUPDATEModel(Representation rep) { - Model model = getCREATEModel(rep); - model.getProperties().remove("property"); - return model; + public Schema getUPDATESchema(Representation rep) { + Schema schema = getCREATESchema(rep); + ((ObjectSchema) schema).getProperties().remove("property"); + return schema; } /** diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/VisitResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/VisitResource1_9.java index de53a35c2..711c65d7e 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/VisitResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/VisitResource1_9.java @@ -16,6 +16,14 @@ import java.util.List; import java.util.Set; import java.util.Iterator; + +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import org.openmrs.Concept; import org.openmrs.Location; import org.openmrs.Patient; import org.openmrs.Encounter; @@ -45,14 +53,6 @@ import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.LocationResource1_8; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8; -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 io.swagger.models.properties.StringProperty; - /** * {@link Resource} for {@link Visit}, supporting standard CRUD operations */ @@ -165,61 +165,73 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe description.removeProperty("patient"); return description; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - modelImpl.property("uuid", new StringProperty()).property("display", new StringProperty()) - .property("startDatetime", new DateProperty()).property("stopDatetime", new DateProperty()) - .property("attributes", new ArrayProperty(new StringProperty())) //FIXME type - .property("voided", new BooleanProperty()); - } - if (rep instanceof DefaultRepresentation) { - modelImpl.property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("visitType", new RefProperty("#/definitions/VisittypeGetRef")) - .property("indication", new RefProperty("#/definitions/ConceptGetRef")) - .property("location", new RefProperty("#/definitions/LocationGetRef")) - .property("encounters", new ArrayProperty(new RefProperty("#/definitions/EncounterGetRef"))); - } else if (rep instanceof FullRepresentation) { - modelImpl.property("patient", new RefProperty("#/definitions/PatientGet")) - .property("visitType", new RefProperty("#/definitions/VisittypeGet")) - .property("indication", new RefProperty("#/definitions/ConceptGet")) - .property("location", new RefProperty("#/definitions/LocationGet")) - .property("encounters", new ArrayProperty(new RefProperty("#/definitions/EncounterGet"))); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof Schema && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("startDatetime", new DateTimeSchema()) + .addProperty("stopDatetime", new DateTimeSchema()) + .addProperty("attributes", new ArraySchema().items(new StringSchema())) //FIXME type + .addProperty("voided", new BooleanSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetRef")) + .addProperty("visitType", new Schema().$ref("#/components/schemas/VisittypeGetRef")) + .addProperty("indication", new Schema().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGetRef")) + .addProperty("encounters", new ArraySchema().items(new Schema().$ref("#/components/schemas/EncounterGetRef"))); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGet")) + .addProperty("visitType", new Schema().$ref("#/components/schemas/VisittypeGet")) + .addProperty("indication", new Schema().$ref("#/components/schemas/ConceptGet")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationGet")) + .addProperty("encounters", new ArraySchema().items(new Schema().$ref("#/components/schemas/EncounterGet"))); + } } - return modelImpl; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl().property("patient", new StringProperty().example("uuid")) - .property("visitType", new StringProperty().example("uuid")).property("startDatetime", new DateProperty()) - .property("location", new StringProperty().example("uuid")).property("indication", new StringProperty()) - .property("stopDatetime", new DateProperty()) - .property("encounters", new ArrayProperty(new StringProperty().example("uuid"))) - .property("attributes", new ArrayProperty(new RefProperty("#/definitions/VisitAttributeCreate"))) - - .required("patient").required("visitType"); + public Schema getCREATESchema(Representation rep) { + Schema schema = new ObjectSchema() + .addProperty("patient", new StringSchema().example("uuid")) + .addProperty("visitType", new StringSchema().example("uuid")) + .addProperty("startDatetime", new DateTimeSchema()) + .addProperty("location", new StringSchema().example("uuid")) + .addProperty("indication", new StringSchema()) + .addProperty("stopDatetime", new DateTimeSchema()) + .addProperty("encounters", new ArraySchema().items(new StringSchema().example("uuid"))) + .addProperty("attributes", new ArraySchema().items(new Schema().$ref("#/components/schemas/VisitAttributeCreate"))); + + schema.setRequired(Arrays.asList("patient", "visitType")); + if (rep instanceof FullRepresentation) { - model.property("patient", new RefProperty("#/definitions/PatientCreate")) - .property("visitType", new RefProperty("#/definitions/VisittypeCreate")) - .property("location", new RefProperty("#/definitions/LocationCreate")) - .property("indication", new RefProperty("#/definitions/ConceptCreate")) - .property("encounters", new ArrayProperty(new RefProperty("#/definitions/EncounterCreate"))); + schema + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientCreate")) + .addProperty("visitType", new Schema().$ref("#/components/schemas/VisittypeCreate")) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationCreate")) + .addProperty("indication", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("encounters", new ArraySchema().items(new Schema().$ref("#/components/schemas/EncounterCreate"))); } - return model; + return schema; } - + @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl().property("visitType", new RefProperty("#/definitions/VisittypeCreate")) - .property("startDatetime", new DateProperty()) - .property("location", new RefProperty("#/definitions/LocationCreate")) - .property("indication", new RefProperty("#/definitions/ConceptCreate")) - .property("stopDatetime", new DateProperty()) - .property("encounters", new ArrayProperty(new RefProperty("#/definitions/EncounterCreate"))) - .property("attributes", new ArrayProperty(new StringProperty())); //FIXME type + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("visitType", new Schema().$ref("#/components/schemas/VisittypeCreate")) + .addProperty("startDatetime", new DateTimeSchema()) + .addProperty("location", new Schema().$ref("#/components/schemas/LocationCreate")) + .addProperty("indication", new Schema().$ref("#/components/schemas/ConceptCreate")) + .addProperty("stopDatetime", new DateTimeSchema()) + .addProperty("encounters", new ArraySchema().items(new Schema().$ref("#/components/schemas/EncounterCreate"))) + .addProperty("attributes", new ArraySchema().items(new StringSchema())); //FIXME type } /** diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/test/GenericChildResource.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/test/GenericChildResource.java index c2e53d682..75c428ae7 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/test/GenericChildResource.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/test/GenericChildResource.java @@ -9,9 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.test; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.media.UUIDSchema; 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; @@ -42,25 +43,25 @@ public DelegatingResourceDescription getCreatableProperties() { return description; } - + @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("value", new StringProperty()); + public Schema getGETSchema(Representation rep) { + return super.getGETSchema(rep) + .addProperty("uuid", new UUIDSchema()) + .addProperty("value", new StringSchema()); } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("value", new StringProperty()); + public Schema getCREATESchema(Representation rep) { + return new Schema() + .addProperty("value", new StringSchema()); } - + @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl(); + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema(); } - + @Override public GenericChild newDelegate() { return new GenericChild(); diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AdministrationLinksResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AdministrationLinksResource2_0.java index 907d1182b..1b6ef30db 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AdministrationLinksResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AdministrationLinksResource2_0.java @@ -9,11 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.api.context.Context; import org.openmrs.messagesource.MessageSourceService; import org.openmrs.module.Extension; @@ -119,12 +118,12 @@ public static Map getLinks(AdministrationSectionLinks instance) } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); + public Schema getGETSchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getGETSchema(rep); if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { model - .property(MODULE_TITLE, new StringProperty()) - .property(LINKS, new ArrayProperty(new ObjectProperty())); + .addProperty(MODULE_TITLE, new StringSchema()) + .addProperty(LINKS, new ArraySchema().items(new Schema<>())); } return model; diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertRecipientResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertRecipientResource2_0.java index 6990bb361..8afff405f 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertRecipientResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertRecipientResource2_0.java @@ -9,12 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.DateTimeProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.User; import org.openmrs.api.context.Context; @@ -99,42 +98,43 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return description; } - @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property(UUID, new StringProperty()) - .property(DISPLAY, new StringProperty()); - - if (rep instanceof DefaultRepresentation) { - modelImpl - .property(RECIPIENT, new RefProperty("#/definitions/UserGetRef")) - .property(ALERT_READ, new BooleanProperty()) - .property(DATE_CHANGED, new DateTimeProperty()); - } - if (rep instanceof FullRepresentation) { - modelImpl - .property(RECIPIENT, new RefProperty("#/definitions/UserGet")) - .property(ALERT_READ, new BooleanProperty()) - .property(DATE_CHANGED, new DateTimeProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + schema + .addProperty(UUID, new StringSchema()) + .addProperty(DISPLAY, new StringSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty(RECIPIENT, new Schema<>().$ref("#/components/schemas/UserGetRef")) + .addProperty(ALERT_READ, new BooleanSchema()) + .addProperty(DATE_CHANGED, new DateTimeSchema()); + } + if (rep instanceof FullRepresentation) { + schema + .addProperty(RECIPIENT, new Schema<>().$ref("#/components/schemas/UserGet")) + .addProperty(ALERT_READ, new BooleanSchema()) + .addProperty(DATE_CHANGED, new DateTimeSchema()); + } } - return modelImpl; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl modelImpl = new ModelImpl() - .property(RECIPIENT, new StringProperty().example("uuid")); + public Schema getCREATESchema(Representation rep) { + Schema schema = new ObjectSchema() + .addProperty(RECIPIENT, new StringSchema().example("uuid")); if (rep instanceof FullRepresentation) { - modelImpl - .property(RECIPIENT, new RefProperty("#/definitions/UserCreate")); + schema.addProperty(RECIPIENT, new Schema<>().$ref("#/components/schemas/UserCreate")); } - return modelImpl; + return schema; } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } @Override diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertResource2_0.java index 6107cc925..5298ede3c 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/AlertResource2_0.java @@ -9,16 +9,14 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0; -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.DateTimeProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.DateSchema; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -149,51 +147,49 @@ public List getPropertiesToExposeAsSubResources() { } @Override - public Model getGETModel(Representation rep) { - ModelImpl modelImpl = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property(ALERT_ID, new IntegerProperty()); - - if (rep instanceof DefaultRepresentation) { - modelImpl - .property(TEXT, new StringProperty()) - .property(SATISFIED_BY_ANY, new BooleanProperty()) - .property(ALERT_READ, new BooleanProperty()) - .property(DATE_TO_EXPIRE, new DateProperty()) - .property(RECIPIENTS, new ArrayProperty(new RefProperty("#/definitions/AlertRecipientGetRef"))); - } - if (rep instanceof FullRepresentation) { - modelImpl - .property(TEXT, new StringProperty()) - .property(SATISFIED_BY_ANY, new BooleanProperty()) - .property(ALERT_READ, new BooleanProperty()) - .property(DATE_TO_EXPIRE, new DateProperty()) - .property(CREATOR, new ObjectProperty()) - .property(DATE_CREATED, new DateTimeProperty()) - .property(CHANGED_BY, new ObjectProperty()) - .property(DATE_CHANGED, new DateTimeProperty()) - .property(RECIPIENTS, new ArrayProperty(new RefProperty("#/definitions/AlertRecipientGetRef"))); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof Schema) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty(ALERT_ID, new IntegerSchema()); + + if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { + schema + .addProperty(TEXT, new StringSchema()) + .addProperty(SATISFIED_BY_ANY, new BooleanSchema()) + .addProperty(ALERT_READ, new BooleanSchema()) + .addProperty(DATE_TO_EXPIRE, new DateSchema()) + .addProperty(RECIPIENTS, new ArraySchema().items(new Schema<>().$ref("#/components/schemas/AlertRecipientGetRef"))); + } + if (rep instanceof FullRepresentation) { + schema + .addProperty(CREATOR, new ObjectSchema()) + .addProperty(DATE_CREATED, new DateTimeSchema()) + .addProperty(CHANGED_BY, new ObjectSchema()) + .addProperty(DATE_CHANGED, new DateTimeSchema()); + } } - return modelImpl; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property(TEXT, new StringProperty()) - .property(RECIPIENTS, new ArrayProperty(new RefProperty("#/definitions/AlertRecipientCreate"))) - .property(SATISFIED_BY_ANY, new BooleanProperty()) - .property(DATE_TO_EXPIRE, new DateProperty()); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty(TEXT, new StringSchema()) + .addProperty(RECIPIENTS, new ArraySchema().items(new Schema<>().$ref("#/components/schemas/AlertRecipientCreate"))) + .addProperty(SATISFIED_BY_ANY, new BooleanSchema()) + .addProperty(DATE_TO_EXPIRE, new DateSchema()); } @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property(TEXT, new StringProperty()) - .property(RECIPIENTS, new ArrayProperty(new RefProperty("#/definitions/AlertRecipientCreate"))) - .property(SATISFIED_BY_ANY, new BooleanProperty()) - .property(DATE_TO_EXPIRE, new DateProperty()); + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty(TEXT, new StringSchema()) + .addProperty(RECIPIENTS, new ArraySchema().items(new Schema<>().$ref("#/components/schemas/AlertRecipientCreate"))) + .addProperty(SATISFIED_BY_ANY, new BooleanSchema()) + .addProperty(DATE_TO_EXPIRE, new DateSchema()); } @Override diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptProposalResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptProposalResource2_0.java index 2f7bf47db..6a57e7982 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptProposalResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptProposalResource2_0.java @@ -9,11 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0; -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 io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Concept; import org.openmrs.ConceptProposal; import org.openmrs.User; @@ -113,46 +112,49 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model.property("uuid", new StringProperty().example("uuid")); - model.property("display", new StringProperty()); - model.property("encounter", new RefProperty("#/definitions/EncounterGetRef")); - model.property("originalText", new StringProperty()); - model.property("finalText", new StringProperty()); - model.property("state", new StringProperty()); - model.property("comments", new StringProperty()); - model.property("occurrences", new StringProperty()); - model.property("creator", new RefProperty("#/definitions/UserGetRef")); - model.property("dateCreated", new DateProperty()); - } else if (rep instanceof FullRepresentation) { - model.property("uuid", new StringProperty().example("uuid")); - model.property("display", new StringProperty()); - model.property("encounter", new RefProperty("#/definitions/EncounterGet")); - model.property("obsConcept", new RefProperty("#/definitions/ConceptGet")); - model.property("obs", new RefProperty("#/definitions/ObsGet")); - model.property("mappedConcept", new RefProperty("#/definitions/ConceptGet")); - model.property("originalText", new StringProperty()); - model.property("finalText", new StringProperty()); - model.property("state", new StringProperty()); - model.property("comments", new StringProperty()); - model.property("occurrences", new StringProperty()); - model.property("creator", new RefProperty("#/definitions/UserGet")); - model.property("dateCreated", new DateProperty()); - model.property("changedBy", new RefProperty("#/definitions/UserGet")); - model.property("dateChanged", new DateProperty()); - } else if (rep instanceof RefRepresentation) { - model.property("uuid", new StringProperty().example("uuid")); - model.property("display", new StringProperty()); - model.property("encounter", new RefProperty("#/definitions/EncounterGetRef")); - model.property("originalText", new StringProperty()); - model.property("state", new StringProperty()); - model.property("occurrences", new StringProperty()); - model.property("changedBy", new RefProperty("#/definitions/UserGetRef")); - model.property("dateChanged", new DateProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof Schema) { + schema + .addProperty("uuid", new StringSchema().example("uuid")) + .addProperty("display", new StringSchema()); + + if (rep instanceof DefaultRepresentation) { + schema + .addProperty("encounter", new Schema<>().$ref("#/components/schemas/EncounterGetRef")) + .addProperty("originalText", new StringSchema()) + .addProperty("finalText", new StringSchema()) + .addProperty("state", new StringSchema()) + .addProperty("comments", new StringSchema()) + .addProperty("occurrences", new StringSchema()) + .addProperty("creator", new Schema<>().$ref("#/components/schemas/UserGetRef")) + .addProperty("dateCreated", new DateTimeSchema()); + } else if (rep instanceof FullRepresentation) { + schema + .addProperty("encounter", new Schema<>().$ref("#/components/schemas/EncounterGet")) + .addProperty("obsConcept", new Schema<>().$ref("#/components/schemas/ConceptGet")) + .addProperty("obs", new Schema<>().$ref("#/components/schemas/ObsGet")) + .addProperty("mappedConcept", new Schema<>().$ref("#/components/schemas/ConceptGet")) + .addProperty("originalText", new StringSchema()) + .addProperty("finalText", new StringSchema()) + .addProperty("state", new StringSchema()) + .addProperty("comments", new StringSchema()) + .addProperty("occurrences", new StringSchema()) + .addProperty("creator", new Schema<>().$ref("#/components/schemas/UserGet")) + .addProperty("dateCreated", new DateTimeSchema()) + .addProperty("changedBy", new Schema<>().$ref("#/components/schemas/UserGet")) + .addProperty("dateChanged", new DateTimeSchema()); + } else if (rep instanceof RefRepresentation) { + schema + .addProperty("encounter", new Schema<>().$ref("#/components/schemas/EncounterGetRef")) + .addProperty("originalText", new StringSchema()) + .addProperty("state", new StringSchema()) + .addProperty("occurrences", new StringSchema()) + .addProperty("changedBy", new Schema<>().$ref("#/components/schemas/UserGetRef")) + .addProperty("dateChanged", new DateTimeSchema()); + } } - return model; + return schema; } @PropertyGetter("occurrences") @@ -177,12 +179,27 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("originalText", new StringProperty()) - .property("mappedConcept", new RefProperty("#/definitions/ConceptCreate")) - .property("encounter", new RefProperty("#/definitions/EncounterCreate")) - .property("obsConcept", new RefProperty("#/definitions/ConceptCreate")); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("originalText", new StringSchema()) + .addProperty("mappedConcept", new Schema<>().$ref("#/components/schemas/ConceptCreate")) + .addProperty("encounter", new Schema<>().$ref("#/components/schemas/EncounterCreate")) + .addProperty("obsConcept", new Schema<>().$ref("#/components/schemas/ConceptCreate")); + } + + @Override + public Schema getUPDATESchema(Representation rep) { + Schema schema = super.getUPDATESchema(rep); + if (schema instanceof ObjectSchema) { + ObjectSchema objectSchema = (ObjectSchema) schema; + objectSchema + .addProperty("finalText", new StringSchema()) + .addProperty("mappedConcept", new Schema<>().$ref("#/components/schemas/ConceptCreate")) + .addProperty("encounter", new Schema<>().$ref("#/components/schemas/EncounterCreate")) + .addProperty("obsConcept", new Schema<>().$ref("#/components/schemas/ConceptCreate")) + .addProperty("comments", new StringSchema()); + } + return schema; } @Override @@ -196,17 +213,6 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe return description; } - @Override - public Model getUPDATEModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getUPDATEModel(rep); - return model - .property("finalText", new StringProperty()) - .property("mappedConcept", new RefProperty("#/definitions/ConceptCreate")) - .property("encounter", new RefProperty("#/definitions/EncounterCreate")) - .property("obsConcept", new RefProperty("#/definitions/ConceptCreate")) - .property("comments", new StringProperty()); - } - @Override public ConceptProposal getByUniqueId(String uniqueId) { return Context.getConceptService().getConceptProposalByUuid(uniqueId); diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptStateConversionResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptStateConversionResource2_0.java index 13d6398f0..9ef45f2e7 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptStateConversionResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/ConceptStateConversionResource2_0.java @@ -9,10 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0; -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.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.ConceptStateConversion; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RequestContext; @@ -88,47 +87,34 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGetRef"))); - } else if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGetRef"))); - } else if (rep instanceof RefRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptGetRef")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowGetRef"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGetRef"))); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation || rep instanceof RefRepresentation) { + schema + .addProperty("concept", new Schema<>().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("programWorkflow", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/WorkflowGetRef"))) + .addProperty("programWorkflowState", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/WorkflowStateGetRef"))); + } } - return model; + return schema; } @Override - public Model getCREATEModel(Representation rep) { - ModelImpl model = new ModelImpl(); - if (rep instanceof DefaultRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreate"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreate"))); + public Schema getCREATESchema(Representation rep) { + Schema schema = new ObjectSchema(); + if (rep instanceof DefaultRepresentation || rep instanceof RefRepresentation) { + schema + .addProperty("concept", new Schema<>().$ref("#/components/schemas/ConceptCreate")) + .addProperty("programWorkflow", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/WorkflowCreate"))) + .addProperty("programWorkflowState", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/WorkflowStateCreate"))); } else if (rep instanceof FullRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptCreateFull")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreateFull"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateGet"))); - } else if (rep instanceof RefRepresentation) { - model - .property("concept", new RefProperty("#/definitions/ConceptCreate")) - .property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreate"))) - .property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreate"))); + schema + .addProperty("concept", new Schema<>().$ref("#/components/schemas/ConceptCreateFull")) + .addProperty("programWorkflow", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/WorkflowCreateFull"))) + .addProperty("programWorkflowState", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/WorkflowStateGet"))); } - return model; + return schema; } @Override diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/DatabaseChangeResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/DatabaseChangeResource2_0.java index 4bf7fb11e..f14225977 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/DatabaseChangeResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/DatabaseChangeResource2_0.java @@ -9,12 +9,10 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import liquibase.changelog.ChangeSet; -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; @@ -31,6 +29,7 @@ import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException; import org.openmrs.util.DatabaseUpdater; +import java.util.Arrays; import java.util.List; /** @@ -116,30 +115,30 @@ public static String getDisplay(DatabaseUpdater.OpenMRSChangeSet instance) { } @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation) { - model - .property(UUID, new StringProperty()) - .property(DISPLAY, new StringProperty()) - .property(AUTHOR, new StringProperty()) - .property(DESCRIPTION, new StringProperty()) - .property(RUN_STATUS, new EnumProperty(ChangeSet.RunStatus.class)); - } else if (rep instanceof FullRepresentation) { - model - .property(UUID, new StringProperty()) - .property(DISPLAY, new StringProperty()) - .property(AUTHOR, new StringProperty()) - .property(DESCRIPTION, new StringProperty()) - .property(RUN_STATUS, new EnumProperty(ChangeSet.RunStatus.class)) - .property(COMMENTS, new StringProperty()) - .property(RAN_DATE, new DateProperty()); - } else if (rep instanceof RefRepresentation) { - model - .property(UUID, new StringProperty()) - .property(DISPLAY, new StringProperty()); + @SuppressWarnings("unchecked") + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { + schema + .addProperty(UUID, new StringSchema()) + .addProperty(DISPLAY, new StringSchema()) + .addProperty(AUTHOR, new StringSchema()) + .addProperty(DESCRIPTION, new StringSchema()) + .addProperty(RUN_STATUS, new Schema().type("string")._enum(Arrays.asList(ChangeSet.RunStatus.values()))); + + if (rep instanceof FullRepresentation) { + schema + .addProperty(COMMENTS, new StringSchema()) + .addProperty(RAN_DATE, new DateTimeSchema()); + } + } else if (rep instanceof RefRepresentation) { + schema + .addProperty(UUID, new StringSchema()) + .addProperty(DISPLAY, new StringSchema()); + } } - return model; + return schema; } @Override diff --git a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/PatientAllergyResource2_0.java b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/PatientAllergyResource2_0.java index 4d70a749f..f4524f336 100644 --- a/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/PatientAllergyResource2_0.java +++ b/omod-2.0/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_0/PatientAllergyResource2_0.java @@ -10,14 +10,13 @@ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Allergy; import org.openmrs.Allergies; import org.openmrs.AllergyReaction; @@ -95,46 +94,47 @@ public DelegatingResourceDescription getCreatableProperties() { public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("display", new StringProperty()) - .property("uuid", new StringProperty()) - .property("allergen", new ObjectProperty()) //FIXME type - .property("severity", new RefProperty("#/definitions/ConceptGetRef")) - .property("comment", new StringProperty()) - .property("reactions", new ArrayProperty(new RefProperty("#/definitions/ConceptGetRef"))) - .property("patient", new RefProperty("#/definitions/PatientGetRef")); - } - if (rep instanceof FullRepresentation) { - model - .property("severity", new RefProperty("#/definitions/ConceptGet")) - .property("reactions", new ArrayProperty(new RefProperty("#/definitions/ConceptGet"))) - .property("patient", new RefProperty("#/definitions/PatientGet")); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("display", new StringSchema()) + .addProperty("uuid", new StringSchema()) + .addProperty("allergen", new ObjectSchema()) //FIXME type + .addProperty("severity", new Schema<>().$ref("#/components/schemas/ConceptGetRef")) + .addProperty("comment", new StringSchema()) + .addProperty("reactions", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/ConceptGetRef"))) + .addProperty("patient", new Schema<>().$ref("#/components/schemas/PatientGetRef")); + + if (rep instanceof FullRepresentation) { + schema + .addProperty("severity", new Schema<>().$ref("#/components/schemas/ConceptGet")) + .addProperty("reactions", new ArraySchema().items(new Schema<>().$ref("#/components/schemas/ConceptGet"))) + .addProperty("patient", new Schema<>().$ref("#/components/schemas/PatientGet")); + } } - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("allergen", new ObjectProperty()) //FIXME type - .property("severity", new ObjectProperty() - .property("uuid", new StringProperty())) - .property("comment", new StringProperty()) - .property("reactions", new ArrayProperty(new ObjectProperty() - .property("allergy", new ObjectProperty().property("uuid", new StringProperty())) - .property("reaction", new ObjectProperty().property("uuid", new StringProperty())))) - - .required("allergen"); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("allergen", new ObjectSchema()) //FIXME type + .addProperty("severity", new ObjectSchema() + .addProperty("uuid", new StringSchema())) + .addProperty("comment", new StringSchema()) + .addProperty("reactions", new ArraySchema().items(new ObjectSchema() + .addProperty("allergy", new ObjectSchema().addProperty("uuid", new StringSchema())) + .addProperty("reaction", new ObjectSchema().addProperty("uuid", new StringSchema())))) + .required(Collections.singletonList("allergen")); } - + @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java b/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java index 29377bcc9..8ec943a0a 100644 --- a/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java +++ b/omod-2.0/src/test/java/org/openmrs/module/unrelatedtest/rest/resource/UnrelatedGenericChildResource.java @@ -9,7 +9,7 @@ */ package org.openmrs.module.unrelatedtest.rest.resource; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.module.unrelatedtest.UnrelatedGenericChild; import org.openmrs.module.webservices.rest.doc.SwaggerSpecificationCreatorTest; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -33,25 +33,24 @@ public class UnrelatedGenericChildResource extends GenericChildResource { /******************************* * TEST METHOD IMPLEMENTATIONS * These methods are the ones we want to test against. There - * implementaion is unimportant, they just set flags so we can assert the methods were called + * implementation is unimportant, they just set flags so we can assert the methods were called * correctly by the reflector. */ - @Override - public Model getGETModel(Representation rep) { + public Schema getGETSchema(Representation rep) { getGETCalled = true; - return super.getGETModel(rep); + return super.getGETSchema(rep); } - + @Override - public Model getCREATEModel(Representation rep) { + public Schema getCREATESchema(Representation rep) { getCREATECalled = true; - return super.getCREATEModel(rep); + return super.getCREATESchema(rep); } - + @Override - public Model getUPDATEModel(Representation rep) { + public Schema getUPDATESchema(Representation rep) { getUPDATECalled = true; - return super.getUPDATEModel(rep); + return super.getUPDATESchema(rep); } } diff --git a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/doc/SwaggerSpecificationCreatorTest.java b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/doc/SwaggerSpecificationCreatorTest.java index 8d95d79d8..2b6a554c6 100644 --- a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/doc/SwaggerSpecificationCreatorTest.java +++ b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/doc/SwaggerSpecificationCreatorTest.java @@ -9,19 +9,17 @@ */ package org.openmrs.module.webservices.rest.doc; -import com.fasterxml.jackson.databind.ObjectMapper; -import io.swagger.converter.ModelConverterContextImpl; -import io.swagger.converter.ModelConverters; -import io.swagger.jackson.ModelResolver; -import io.swagger.models.Info; -import io.swagger.models.Model; -import io.swagger.models.Operation; -import io.swagger.models.Path; -import io.swagger.models.Scheme; -import io.swagger.models.Swagger; -import io.swagger.models.auth.BasicAuthDefinition; -import io.swagger.models.parameters.Parameter; -import io.swagger.util.Json; +import io.swagger.v3.core.converter.ModelConverters; +import io.swagger.v3.core.util.Json; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; import org.dbunit.database.DatabaseConnection; import org.junit.Assert; import org.junit.Before; @@ -34,6 +32,11 @@ import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.api.RestService; import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; +import org.apache.log4j.Logger; +import org.apache.log4j.Level; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.WriterAppender; +import java.io.StringWriter; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -45,260 +48,274 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertNotNull; import static junit.framework.TestCase.assertTrue; public class SwaggerSpecificationCreatorTest extends BaseModuleWebContextSensitiveTest { - - @Test - public void mainTest() { - String str = new SwaggerSpecificationCreator().getJSON(); - assertNotNull(str); - } - - @Test - public void hasSearchHandler() { - SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(); - - assertTrue(creator.hasSearchHandler("attribute", "location")); - - assertFalse(creator.hasSearchHandler("workflow", null)); - assertFalse(creator.hasSearchHandler("description", "concept")); - } - - @Test - public void cacheTest() { - if (SwaggerSpecificationCreator.isCached()) { - SwaggerSpecificationCreator.clearCache(); - } - assertFalse(SwaggerSpecificationCreator.isCached()); - new SwaggerSpecificationCreator().getJSON(); - assertTrue(SwaggerSpecificationCreator.isCached()); - } - - @Test - public void modelResolveTest() { - final ModelResolver modelResolver = new ModelResolver(new ObjectMapper()); - final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver); - final Model model = context.resolve(Patient.class); - assertNotNull(model); - } - - @Test - public void swaggerSerializeTest() { - final Info info = new Info().version("1.0.0").title("Swagger WebServices REST"); - - Swagger swagger = new Swagger().info(info).securityDefinition("basicAuth", new BasicAuthDefinition()) - .scheme(Scheme.HTTP).consumes("application/json").produces("application/json"); - - final Model patientModel = ModelConverters.getInstance().read(Patient.class).get("Patient"); - swagger.addDefinition("Patient", patientModel); - - final String swaggerJson = Json.pretty(swagger); - assertNotNull(swaggerJson); - } - - Map beforeCounts; - - public Map getRowCounts() throws Exception { - Map ret = new HashMap(); - - Connection con = this.getConnection(); - DatabaseMetaData metaData = con.getMetaData(); - DatabaseConnection dbcon = new DatabaseConnection(con); - - ResultSet rs = metaData.getTables(null, "PUBLIC", "%", null); - while (rs.next()) { - String tableName = rs.getString(3); - - ret.put(tableName, dbcon.getRowCount(tableName)); - } - - return ret; - } - - @Before - public void init() throws Exception { - // init REST - Context.getService(RestService.class).initialize(); - - Context.getAdministrationService().saveGlobalProperty( - new GlobalProperty(RestConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME, "true")); - - // ensure GP is written to database before we count the rows - Context.flushSession(); - - beforeCounts = getRowCounts(); - } - - @Test - public void checkNoDatabaseChanges() throws Exception { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - - Map afterCounts = getRowCounts(); - - Assert.assertEquals("Ensure no tables are created or destroyed", beforeCounts.size(), afterCounts.size()); - Assert.assertTrue("Ensure that no data was added or removed from any tables", - ensureCountsEqual(beforeCounts, afterCounts)); - } - - private boolean ensureCountsEqual(Map beforeCounts, Map afterCounts) { - for (String key : beforeCounts.keySet()) { - if (beforeCounts.get(key) != afterCounts.get(key)) { - System.err.println("The " + key + " table has a different number of rows (" + beforeCounts.get(key) - + " before, " + afterCounts.get(key) + " after)."); - - return false; - } - } - - return true; - } - - // makes sure that every operation has a unique operationId - @Test - public void checkOperationIdsSet() { - List operationIds = new ArrayList(); - - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - Swagger spec = ssc.getSwagger(); - - for (Path p : spec.getPaths().values()) { - for (Operation o : p.getOperations()) { - Assert.assertFalse("Ensure each operation has a unique ID", operationIds.contains(o.getOperationId())); - operationIds.add(o.getOperationId()); - } - } - } - - // makes sure that every GET operation has the "v" parameter - @Test - public void checkRepresentationParamExists() { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - Swagger spec = ssc.getSwagger(); - - for (Path p : spec.getPaths().values()) { - if (p.getGet() != null) { - Assert.assertTrue("Ensure each GET operation has the 'v' query parameter", - operationHasRepresentationParam(p.getGet())); - } - } - } - - private boolean operationHasRepresentationParam(Operation o) { - boolean ret = false; - - for (Parameter p : o.getParameters()) { - if (p.getName().equals("v")) { - ret = !ret; - } - } - - return ret; - } - - // make sure each operation that supports paging has the limit and startIndex parameters - @Test - public void checkPagingParamsExist() { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - Swagger spec = ssc.getSwagger(); - - for (Path p : spec.getPaths().values()) { - for (Operation o : p.getOperations()) { - if (o.getOperationId().matches("^getAll[A-Z].*")) { - Assert.assertTrue("Ensure each operation that supports paging has both paging parameters", - operationHasPagingParams(o)); - } - } - } - } - - private boolean operationHasPagingParams(Operation o) { - boolean limit = false, startIndex = false; - - for (Parameter p : o.getParameters()) { - if (p.getName().equals("limit")) { - limit = !limit; - } else if (p.getName().equals("startIndex")) { - startIndex = !startIndex; - } - } - - return limit && startIndex; - } - - @Test - public void addPathsWorksForCoreModels() throws NoSuchMethodException, InvocationTargetException, - IllegalAccessException, NoSuchFieldException { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - - // reflect the swagger propperty and initSwagger method so we can setup for the main test - Field swagger = ssc.getClass().getDeclaredField("swagger"); - swagger.setAccessible(true); - swagger.set(ssc, new Swagger()); - - Method initSwagger = ssc.getClass().getDeclaredMethod("initSwagger"); - initSwagger.setAccessible(true); - initSwagger.invoke(ssc); - - // make the paths method accessible - Method addPaths = ssc.getClass().getDeclaredMethod("addPaths"); - addPaths.setAccessible(true); - - addPaths.invoke(ssc); - } - - /** - * Some subresource appear to only support creation, not fetching or updating. References to the - * Get/Update definitions were still being included in the response options, despite not - * existing. Ensure that these references are not included in the resulting JSON to prevent - * swagger reference errors. See ticket: RESTWS-720 - */ - @Test - public void createOnlySubresourceDefinitions() { - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - String json = ssc.getJSON(); - - // A simple search will tell us if the problem definitions exist - assertFalse(json.contains("SystemsettingSubdetailsGet")); - assertFalse(json.contains("SystemsettingSubdetailsUpdate")); - assertTrue(json.contains("SystemsettingSubdetailsCreate")); - } - - /** - * Ensure that resources not directly related to the webservices.rest package are successfully - * defined in the swagger documentation. - */ - @Test - public void testUnrelatedResourceDefinitions() { - // ensure the statics are false first - UnrelatedGenericChildResource.getGETCalled = false; - UnrelatedGenericChildResource.getCREATECalled = false; - UnrelatedGenericChildResource.getUPDATECalled = false; - - // make sure to reset the cache for multiple tests in the same run - if (SwaggerSpecificationCreator.isCached()) { - SwaggerSpecificationCreator.clearCache(); - } - - SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); - ssc.getJSON(); - - // check our custom methods were called - assertTrue(UnrelatedGenericChildResource.getGETCalled); - assertTrue(UnrelatedGenericChildResource.getCREATECalled); - assertTrue(UnrelatedGenericChildResource.getUPDATECalled); - - // assert the definition is now in the swagger object - Swagger swagger = ssc.getSwagger(); - assertTrue(swagger.getDefinitions().containsKey("UnrelatedGet")); - assertTrue(swagger.getDefinitions().containsKey("UnrelatedUpdate")); - assertTrue(swagger.getDefinitions().containsKey("UnrelatedCreate")); - } + + @Test + public void mainTest() { + String str = new SwaggerSpecificationCreator().getJSON(); + assertNotNull(str); + } + + @Test + public void hasSearchHandler() { + SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(); + + assertTrue(creator.hasSearchHandler("attribute", "location")); + + assertFalse(creator.hasSearchHandler("workflow", null)); + assertFalse(creator.hasSearchHandler("description", "concept")); + } + + @Test + public void cacheTest() { + if (SwaggerSpecificationCreator.isCached()) { + SwaggerSpecificationCreator.clearCache(); + } + assertFalse(SwaggerSpecificationCreator.isCached()); + new SwaggerSpecificationCreator().getJSON(); + assertTrue(SwaggerSpecificationCreator.isCached()); + } + + @Test + public void modelResolveTest() { + final Schema schema = ModelConverters.getInstance().readAllAsResolvedSchema(Patient.class).schema; + assertNotNull(schema); + } + + @Test + public void swaggerSerializeTest() { + final Info info = new Info().version("1.0.0").title("OpenMRS API Docs"); + + OpenAPI openAPI = new OpenAPI() + .info(info) + .addSecurityItem(new SecurityRequirement().addList("basicAuth")) + .components(new Components().addSecuritySchemes("basicAuth", + new SecurityScheme() + .type(SecurityScheme.Type.HTTP) + .scheme("basic"))); + + final Schema patientSchema = ModelConverters.getInstance().readAllAsResolvedSchema(Patient.class).schema; + openAPI.getComponents().addSchemas("Patient", patientSchema); + + final String swaggerJson = Json.pretty(openAPI); + assertNotNull(swaggerJson); + } + + Map beforeCounts; + + public Map getRowCounts() throws Exception { + Map ret = new HashMap(); + + Connection con = this.getConnection(); + DatabaseMetaData metaData = con.getMetaData(); + DatabaseConnection dbcon = new DatabaseConnection(con); + + ResultSet rs = metaData.getTables(null, "PUBLIC", "%", null); + while (rs.next()) { + String tableName = rs.getString(3); + + ret.put(tableName, dbcon.getRowCount(tableName)); + } + + return ret; + } + + @Before + public void init() throws Exception { + // init REST + Context.getService(RestService.class).initialize(); + + Context.getAdministrationService().saveGlobalProperty( + new GlobalProperty(RestConstants.SWAGGER_QUIET_DOCS_GLOBAL_PROPERTY_NAME, "true")); + + // ensure GP is written to database before we count the rows + Context.flushSession(); + + beforeCounts = getRowCounts(); + } + + @Test + public void checkNoDatabaseChanges() throws Exception { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + ssc.getJSON(); + + Map afterCounts = getRowCounts(); + + Assert.assertEquals("Ensure no tables are created or destroyed", beforeCounts.size(), afterCounts.size()); + Assert.assertTrue("Ensure that no data was added or removed from any tables", + ensureCountsEqual(beforeCounts, afterCounts)); + } + + private boolean ensureCountsEqual(Map beforeCounts, Map afterCounts) { + for (String key : beforeCounts.keySet()) { + if (beforeCounts.get(key) != afterCounts.get(key)) { + System.err.println("The " + key + " table has a different number of rows (" + beforeCounts.get(key) + + " before, " + afterCounts.get(key) + " after)."); + + return false; + } + } + + return true; + } + + // makes sure that every operation has a unique operationId + @Test + public void checkOperationIdsSet() { + List operationIds = new ArrayList(); + + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + ssc.getJSON(); + OpenAPI spec = ssc.getOpenAPI(); + + for (PathItem p : spec.getPaths().values()) { + for (Operation o : p.readOperations()) { + Assert.assertFalse("Ensure each operation has a unique ID", operationIds.contains(o.getOperationId())); + operationIds.add(o.getOperationId()); + } + } + } + + // makes sure that every GET operation has the "v" parameter + @Test + public void checkRepresentationParamExists() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + String json = ssc.getJSON(); + OpenAPI spec = ssc.getOpenAPI(); + + Assert.assertNotNull("SwaggerSpecificationCreator should not be null", ssc); + Assert.assertNotNull("JSON should not be null", json); + Assert.assertNotNull("OpenAPI spec should not be null", spec); + Assert.assertNotNull("Paths in OpenAPI spec should not be null", spec.getPaths()); + + // If we get past the assertion, continue with the original test logic + for (PathItem p : spec.getPaths().values()) { + Assert.assertNotNull("PathItem should not be null", p); + for (Operation o : p.readOperations()) { + if (o != null) { + Assert.assertTrue("Ensure each GET operation has the 'v' query parameter", + operationHasRepresentationParam(o)); + } + } + } + } + + private boolean operationHasRepresentationParam(Operation operation) { + return operation.getParameters() != null && + operation.getParameters().stream() + .anyMatch(param -> "v".equals(param.getName()) && "query".equals(param.getIn())); + } + + // make sure each operation that supports paging has the limit and startIndex parameters + @Test + public void checkPagingParamsExist() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + ssc.getJSON(); + OpenAPI openAPI = ssc.getOpenAPI(); + + openAPI.getPaths().forEach((path, pathItem) -> { + pathItem.readOperationsMap().forEach((httpMethod, operation) -> { + if (operation.getOperationId().matches("^getAll[A-Z].*")) { + Assert.assertTrue("Ensure each operation that supports paging has both paging parameters", + operationHasPagingParams(operation)); + } + }); + }); + } + + private boolean operationHasPagingParams(io.swagger.v3.oas.models.Operation o) { + boolean limit = false, startIndex = false; + + for (io.swagger.v3.oas.models.parameters.Parameter p : o.getParameters()) { + if (p.getName().equals("limit")) { + limit = true; + } else if (p.getName().equals("startIndex")) { + startIndex = true; + } + } + + return limit && startIndex; + } + + @Test + public void addPathsWorksForCoreModels() throws NoSuchMethodException, InvocationTargetException, + IllegalAccessException, NoSuchFieldException { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + + // reflect the openAPI property and initOpenAPI method so we can setup for the main test + Field openAPIField = ssc.getClass().getDeclaredField("openAPI"); + openAPIField.setAccessible(true); + openAPIField.set(ssc, new OpenAPI()); + + Method initOpenAPI = ssc.getClass().getDeclaredMethod("initOpenAPI"); + initOpenAPI.setAccessible(true); + initOpenAPI.invoke(ssc); + + // make the paths method accessible + Method addPaths = ssc.getClass().getDeclaredMethod("addPaths"); + addPaths.setAccessible(true); + + addPaths.invoke(ssc); + } + + /** + * Some subresource appear to only support creation, not fetching or updating. References to the + * Get/Update definitions were still being included in the response options, despite not + * existing. Ensure that these references are not included in the resulting JSON to prevent + * swagger reference errors. See ticket: RESTWS-720 + */ + @Test + public void createOnlySubresourceDefinitions() { + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + String json = ssc.getJSON(); + + // A simple search will tell us if the problem definitions exist + assertFalse(json.contains("SystemsettingSubdetailsGet")); + assertFalse(json.contains("SystemsettingSubdetailsUpdate")); + assertTrue(json.contains("SystemsettingSubdetailsCreate")); + } + + /** + * Ensure that resources not directly related to the webservices.rest package are successfully + * defined in the swagger documentation. + */ + @Test + public void testUnrelatedResourceDefinitions() { + // ensure the statics are false first + UnrelatedGenericChildResource.getGETCalled = false; + UnrelatedGenericChildResource.getCREATECalled = false; + UnrelatedGenericChildResource.getUPDATECalled = false; + + // make sure to reset the cache for multiple tests in the same run + if (SwaggerSpecificationCreator.isCached()) { + SwaggerSpecificationCreator.clearCache(); + } + + SwaggerSpecificationCreator ssc = new SwaggerSpecificationCreator(); + String json = ssc.getJSON(); + + // check our custom methods were called + assertTrue(UnrelatedGenericChildResource.getGETCalled); + assertTrue(UnrelatedGenericChildResource.getCREATECalled); + assertTrue(UnrelatedGenericChildResource.getUPDATECalled); + + // assert the definition is now in the swagger object + OpenAPI openAPI = ssc.getOpenAPI(); + assertTrue(openAPI.getComponents().getSchemas().containsKey("UnrelatedGet")); + assertTrue(openAPI.getComponents().getSchemas().containsKey("UnrelatedUpdate")); + assertTrue(openAPI.getComponents().getSchemas().containsKey("UnrelatedCreate")); + + // Print out all schema keys for debugging + System.out.println("Available schemas: " + String.join(", ", openAPI.getComponents().getSchemas().keySet())); + + // Print out the JSON for further inspection + System.out.println("Generated JSON:"); + System.out.println(json); + } } diff --git a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/resource/SubDetailsResource.java b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/resource/SubDetailsResource.java index 26f76a9df..b45fa9556 100644 --- a/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/resource/SubDetailsResource.java +++ b/omod-2.0/src/test/java/org/openmrs/module/webservices/rest/resource/SubDetailsResource.java @@ -9,9 +9,8 @@ */ package org.openmrs.module.webservices.rest.resource; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.GlobalProperty; -import org.openmrs.module.webservices.rest.doc.SwaggerSpecificationCreatorTest; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.annotation.SubResource; import org.openmrs.module.webservices.rest.web.representation.Representation; @@ -73,9 +72,9 @@ public SubDetails newDelegate() { public SubDetails save(SubDetails delegate) { return delegate; } - + @Override - public Model getCREATEModel(Representation rep) { - return super.getGETModel(rep); + public Schema getCREATESchema(Representation rep) { + return super.getCREATESchema(rep); } } diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortMembershipResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortMembershipResource2_1.java index 1cc6999e0..93f050a55 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortMembershipResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortMembershipResource2_1.java @@ -11,10 +11,10 @@ import java.util.ArrayList; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.DateProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.DateTimeSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Cohort; import org.openmrs.CohortMembership; import org.openmrs.Patient; @@ -97,35 +97,35 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe d.addProperty("endDate"); return d; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()) - .property("patientUuid", new StringProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("startDate", new DateTimeSchema()) + .addProperty("endDate", new DateTimeSchema()) + .addProperty("patientUuid", new StringSchema()); } //FIXME missing props - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("patientUuid", new StringProperty()) - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("patientUuid", new StringSchema()) + .addProperty("startDate", new DateTimeSchema()) + .addProperty("endDate", new DateTimeSchema()); } - + @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("startDate", new DateProperty()) - .property("endDate", new DateProperty()); + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("startDate", new DateTimeSchema()) + .addProperty("endDate", new DateTimeSchema()); } @PropertyGetter("display") diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortResource2_1.java index da424571f..3b2716357 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/CohortResource2_1.java @@ -9,9 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_1; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.IntegerProperty; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.Cohort; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -32,13 +31,15 @@ public class CohortResource2_1 extends CohortResource1_8 { public String getResourceVersion() { return RestConstants2_1.RESOURCE_VERSION; } - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - model.getProperties().remove("memberIds"); - model.property("size", new IntegerProperty()); - return model; + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null) { + schema.getProperties().remove("memberIds"); + schema.addProperty("size", new IntegerSchema()); + } + return schema; } @Override diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ConceptSourceResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ConceptSourceResource2_1.java index 16ca83737..618aadd92 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ConceptSourceResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ConceptSourceResource2_1.java @@ -9,9 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_1; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.ConceptSource; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.Resource; @@ -28,21 +27,23 @@ @Resource(name = RestConstants.VERSION_1 + "/conceptsource", supportedClass = ConceptSource.class, supportedOpenmrsVersions = { "2.1.* - 9.*" }) public class ConceptSourceResource2_1 extends ConceptSourceResource2_0 { - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uniqueId", new StringProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema.addProperty("uniqueId", new StringSchema()); } - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation representation) { - return ((ModelImpl) super.getCREATEModel(representation)) - .property("uniqueId", new StringProperty()); + public Schema getCREATESchema(Representation representation) { + Schema schema = super.getCREATESchema(representation); + if (schema != null) { + schema.addProperty("uniqueId", new StringSchema()); + } + return schema; } /** diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ObsResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ObsResource2_1.java index ec7ba7398..835205f31 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ObsResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/ObsResource2_1.java @@ -9,35 +9,45 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_1; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.Obs; -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; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11.ObsResource1_11; +import java.util.Arrays; + /** * Resource for `obs`, supporting the new properties added in openmrs-core 2.1 (status and * interpretation) */ @Resource(name = RestConstants.VERSION_1 + "/obs", supportedClass = Obs.class, supportedOpenmrsVersions = { "2.1.* - 9.*" }) public class ObsResource2_1 extends ObsResource1_11 { - + @Override - public Model getGETModel(Representation rep) { - return ((ModelImpl) super.getGETModel(rep)) - .property("status", new EnumProperty(Obs.Status.class)) - .property("interpretation", new EnumProperty(Obs.Interpretation.class)); + @SuppressWarnings("unchecked") + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof Schema) { + schema + .addProperty("status", new Schema().type("string")._enum(Arrays.asList(Obs.Status.values()))) + .addProperty("interpretation", new Schema().type("string")._enum(Arrays.asList(Obs.Interpretation.values()))); + } + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return ((ModelImpl) super.getCREATEModel(rep)) - .property("status", new EnumProperty(Obs.Status.class)) - .property("interpretation", new EnumProperty(Obs.Interpretation.class)); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + Schema schema = super.getCREATESchema(rep); + if (schema instanceof Schema) { + schema + .addProperty("status", new Schema().type("string")._enum(Arrays.asList(Obs.Status.values()))) + .addProperty("interpretation", new Schema().type("string")._enum(Arrays.asList(Obs.Interpretation.values()))); + } + return schema; } @Override diff --git a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/PersonNameResource2_1.java b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/PersonNameResource2_1.java index 1907a621e..c8a82faae 100644 --- a/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/PersonNameResource2_1.java +++ b/omod-2.1/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_1/PersonNameResource2_1.java @@ -9,7 +9,8 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_1; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.PersonName; import org.openmrs.module.webservices.rest.web.annotation.SubResource; import org.openmrs.module.webservices.rest.web.representation.Representation; @@ -17,6 +18,8 @@ import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11.PersonResource1_11; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_0.PersonNameResource2_0; +import java.util.List; + @SubResource(parent = PersonResource1_11.class, path = "name", supportedClass = PersonName.class, supportedOpenmrsVersions = { "2.1.* - 9.*" }) public class PersonNameResource2_1 extends PersonNameResource2_0 { @@ -29,9 +32,9 @@ public DelegatingResourceDescription getCreatableProperties() { } @Override - public Model getCREATEModel(Representation rep) { - Model model = super.getCREATEModel(rep); - model.getProperties().get("familyName").setRequired(false); + public Schema getCREATESchema(Representation rep) { + ObjectSchema model = (ObjectSchema) super.getCREATESchema(rep); + model.getProperties().get("familyName"); return model; } } diff --git a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java index eef3438d4..16d36c8cc 100644 --- a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java +++ b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java @@ -9,10 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.openmrs.Condition; @@ -83,59 +82,59 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } return null; } - + /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getGETModel(Representation) + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getGETSchema(Representation) */ - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("condition", new StringProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("clinicalStatus", new StringProperty()) - .property("verificationStatus", new StringProperty()) - .property("previousVersion", new StringProperty()) - .property("onsetDate", new StringProperty()) - .property("endDate", new StringProperty()) - .property("additionalDetail", new StringProperty()) - .property("voided", new StringProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema != null && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("condition", new StringSchema()) + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetRef")) + .addProperty("clinicalStatus", new StringSchema()) + .addProperty("verificationStatus", new StringSchema()) + .addProperty("previousVersion", new StringSchema()) + .addProperty("onsetDate", new StringSchema()) + .addProperty("endDate", new StringSchema()) + .addProperty("additionalDetail", new StringSchema()) + .addProperty("voided", new StringSchema()); } - return model; + return schema; } - + /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getCREATEModel(Representation) + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getCREATESchema(Representation) */ @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("condition", new StringProperty()) - .property("patient", new StringProperty().example("uuid")) - .property("clinicalStatus", new StringProperty()) - .property("verificationStatus", new StringProperty()) - .property("previousVersion", new StringProperty()) - .property("onsetDate", new StringProperty()) - .property("endDate", new StringProperty()) - .property("additionalDetail", new StringProperty()); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("condition", new StringSchema()) + .addProperty("patient", new StringSchema().example("uuid")) + .addProperty("clinicalStatus", new StringSchema()) + .addProperty("verificationStatus", new StringSchema()) + .addProperty("previousVersion", new StringSchema()) + .addProperty("onsetDate", new StringSchema()) + .addProperty("endDate", new StringSchema()) + .addProperty("additionalDetail", new StringSchema()); } - + /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getUPDATEModel(Representation) + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getUPDATESchema(Representation) */ @Override - public Model getUPDATEModel(Representation representation) { - return new ModelImpl() - .property("condition", new StringProperty()) - .property("clinicalStatus", new StringProperty()) - .property("verificationStatus", new StringProperty()) - .property("previousVersion", new StringProperty()) - .property("onsetDate", new StringProperty()) - .property("endDate", new StringProperty()) - .property("additionalDetail", new StringProperty()) - .property("voided", new StringProperty()); + public Schema getUPDATESchema(Representation representation) { + return new ObjectSchema() + .addProperty("condition", new StringSchema()) + .addProperty("clinicalStatus", new StringSchema()) + .addProperty("verificationStatus", new StringSchema()) + .addProperty("previousVersion", new StringSchema()) + .addProperty("onsetDate", new StringSchema()) + .addProperty("endDate", new StringSchema()) + .addProperty("additionalDetail", new StringSchema()) + .addProperty("voided", new StringSchema()); } /** diff --git a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java index 4be563061..de8713ff6 100644 --- a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java +++ b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/DiagnosisResource2_2.java @@ -9,14 +9,19 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2; +import java.util.Arrays; import java.util.Date; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang3.StringUtils; import org.openmrs.ConditionVerificationStatus; import org.openmrs.Diagnosis; 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; @@ -34,12 +39,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.BooleanProperty; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8; /** @@ -129,22 +128,24 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getGETModel(Representation) + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getGETSchema(Representation) (Representation) */ @Override - public Model getGETModel(Representation rep) { - ModelImpl model = (ModelImpl) super.getGETModel(rep); - if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - model - .property("uuid", new StringProperty()) - .property("diagnosis", new StringProperty()) - .property("condition", new StringProperty()) - .property("certainty", new EnumProperty(ConditionVerificationStatus.class)) - .property("rank", new IntegerProperty()) - .property("patient", new RefProperty("#/definitions/PatientGetRef")) - .property("voided", new BooleanProperty()); + @SuppressWarnings("unchecked") + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + if (schema instanceof Schema && (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation)) { + Schema objectSchema = (Schema) schema; + objectSchema + .addProperty("uuid", new StringSchema()) + .addProperty("diagnosis", new StringSchema()) + .addProperty("condition", new StringSchema()) + .addProperty("certainty", new Schema().type("string")._enum(Arrays.asList(ConditionVerificationStatus.values()))) + .addProperty("rank", new IntegerSchema()) + .addProperty("patient", new Schema().$ref("#/components/schemas/PatientGetRef")) + .addProperty("voided", new BooleanSchema()); } - return model; + return schema; } /** @@ -179,21 +180,34 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe return description; } - + /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getCREATEModel(Representation) + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getCREATESchema(Representation) */ @Override - public Model getCREATEModel(Representation rep) { - - return new ModelImpl() - .property("diagnosis", new StringProperty()) - .property("encounter", new StringProperty()) - .property("condition", new StringProperty()) - .property("certainty", new StringProperty()) - .property("patient", new StringProperty().example("uuid")) - .property("rank", new IntegerProperty()); + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("diagnosis", new StringSchema()) + .addProperty("encounter", new StringSchema()) + .addProperty("condition", new StringSchema()) + .addProperty("certainty", new StringSchema()) + .addProperty("patient", new StringSchema().example("uuid")) + .addProperty("rank", new IntegerSchema()); + } + /** + * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getUPDATESchema(Representation) + */ + @Override + @SuppressWarnings("unchecked") + public Schema getUPDATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("diagnosis", new StringSchema()) + .addProperty("condition", new StringSchema()) + .addProperty("encounter", new StringSchema()) + .addProperty("certainty", new Schema().type("string")._enum(Arrays.asList(ConditionVerificationStatus.values()))) + .addProperty("rank", new IntegerSchema()) + .addProperty("voided", new BooleanSchema()); } /** @@ -212,20 +226,6 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe return description; } - - /** - * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getUPDATEModel(Representation) - */ - @Override - public Model getUPDATEModel(Representation rep) { - return new ModelImpl() - .property("diagnosis", new StringProperty()) - .property("condition", new StringProperty()) - .property("encounter", new StringProperty()) - .property("certainty", new EnumProperty(ConditionVerificationStatus.class)) - .property("rank", new IntegerProperty()) - .property("voided", new BooleanProperty()); - } @Override protected PageableResult doSearch(RequestContext context) { diff --git a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2.java b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2.java index 5d2bfe57a..bb35c5eb1 100644 --- a/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2.java +++ b/omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/FulfillerDetailsResource2_2.java @@ -9,12 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Order; 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.annotation.Resource; import org.openmrs.module.webservices.rest.web.annotation.SubResource; @@ -25,6 +24,8 @@ import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import java.util.Arrays; + /** * {@link Resource} for Order, supporting standard CRUD operations on fulfiller_comment and * fulfiller_status @@ -54,10 +55,11 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("fulfillerComment", new StringProperty()) - .property("fulfillerStatus", new EnumProperty(Order.FulfillerStatus.class)); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("fulfillerComment", new StringSchema()) + .addProperty("fulfillerStatus", new Schema().type("string")._enum(Arrays.asList(Order.FulfillerStatus.values()))); } @Override diff --git a/omod-2.3/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_3/FulfillerDetailsResource2_3.java b/omod-2.3/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_3/FulfillerDetailsResource2_3.java index c68e39b50..a640ffae6 100644 --- a/omod-2.3/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_3/FulfillerDetailsResource2_3.java +++ b/omod-2.3/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_3/FulfillerDetailsResource2_3.java @@ -9,12 +9,11 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_3; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Order; 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.annotation.Resource; import org.openmrs.module.webservices.rest.web.annotation.SubResource; @@ -26,6 +25,8 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2.OrderResource2_2; +import java.util.Arrays; + /** * {@link Resource} for Order, supporting standard CRUD operations on fulfiller_comment and * fulfiller_status and accession number (supplants FulfillerDetails2_2 which only supported @@ -57,11 +58,14 @@ public DelegatingResourceDescription getRepresentationDescription(Representation } @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("fulfillerComment", new StringProperty()) - .property("fulfillerStatus", new EnumProperty(Order.FulfillerStatus.class)) - .property("accessionNumber", new StringProperty()); + @SuppressWarnings("unchecked") + public Schema getCREATESchema(Representation rep) { + return new ObjectSchema() + .addProperty("fulfillerComment", new StringSchema()) + .addProperty("fulfillerStatus", new Schema() + .type("string") + ._enum(Arrays.asList(Order.FulfillerStatus.values()))) + .addProperty("accessionNumber", new StringSchema()); } @Override diff --git a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java index 010a4ed5e..7a5620ea0 100644 --- a/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java +++ b/omod-2.5/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java @@ -9,9 +9,9 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.openmrs.Diagnosis; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; @@ -68,25 +68,25 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } @Override - public Model getGETModel(Representation rep) { - return addNewProperties(super.getGETModel(rep), rep); + public Schema getGETSchema(Representation rep) { + return addNewProperties(super.getGETSchema(rep), rep); } @Override - public Model getCREATEModel(Representation rep) { - return addNewProperties(super.getCREATEModel(rep), rep); + public Schema getCREATESchema(Representation rep) { + return addNewProperties(super.getCREATESchema(rep), rep); } @Override - public Model getUPDATEModel(Representation rep) { - return addNewProperties(super.getUPDATEModel(rep), rep); + public Schema getUPDATESchema(Representation rep) { + return addNewProperties(super.getUPDATESchema(rep), rep); } - private Model addNewProperties(Model model, Representation rep) { + private Schema addNewProperties(Schema model, Representation rep) { if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { - ((ModelImpl) model) - .property("formFieldNamespace", new StringProperty()) - .property("formFieldPath", new StringProperty()); + ((ObjectSchema) model) + .addProperty("formFieldNamespace", new StringSchema()) + .addProperty("formFieldPath", new StringSchema()); } return model; } diff --git a/omod-common/pom.xml b/omod-common/pom.xml index dac56b313..3f29c0104 100644 --- a/omod-common/pom.xml +++ b/omod-common/pom.xml @@ -31,9 +31,9 @@ - io.swagger + io.swagger.core.v3 swagger-core - 1.6.2 + 2.2.23 org.slf4j @@ -45,6 +45,12 @@ + + io.swagger + swagger-annotations + 1.6.14 + compile + diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/NullSerializer.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/NullSerializer.java deleted file mode 100644 index d8eb59753..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/NullSerializer.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; - -public class NullSerializer extends JsonSerializer { - - @Override - public void serialize(Object arg0, JsonGenerator arg1, SerializerProvider arg2) throws IOException, - JsonProcessingException { - arg1.writeFieldName(""); - - } - -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Operation.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Operation.java deleted file mode 100644 index 6fb9caa6f..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Operation.java +++ /dev/null @@ -1,182 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -//Describes an operation available on a single path -public class Operation { - - public static String OPERATION_GET_ALL_METHOD = "doGetAll"; - - public static String OPERATION_GET_BY_ID = "getByUniqueId"; - - public static String OPERATION_VOID_RETIRE_METHOD = "delete"; - - public static String OPERATION_DELETE_METHOD = "purge"; - - public static String OPERATION_CREATE_METHOD = "create"; - - public static String OPERATION_UPDATE_METHOD = "save"; - - @JsonIgnore - private String name; - - //A verbose explanation of the operation behavior - private String description; - - //A short summary of what the operation does - private String summary; - - //A list of MIME types the operation can produce - private List produces; - - /*A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.*/ - private List tags; - - //A list of parameters that are applicable for this operation - private List parameters; - - //The list of possible responses as they are returned from executing this operation. - private Map responses; - - //Custom field added for specifying if the operation is a search handler - private String isSearchHandler = "false"; - - //Unique identifier for the operation - private String operationId; - - public Operation() { - - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the produces - */ - public List getProduces() { - return produces; - } - - /** - * @param produces the produces to set - */ - public void setProduces(List produces) { - this.produces = produces; - } - - /** - * @return the parameters - */ - public List getParameters() { - return parameters; - } - - /** - * @param parameters the parameters to set - */ - public void setParameters(List parameters) { - this.parameters = parameters; - } - - /** - * @return the responses - */ - public Map getResponses() { - return responses; - } - - /** - * @param responses the responses to set - */ - public void setResponses(Map responses) { - this.responses = responses; - } - - /** - * @return the tags - */ - public List getTags() { - return tags; - } - - /** - * @param tags the tags to set - */ - public void setTags(List tags) { - this.tags = tags; - } - - /** - * @return the isSearchHandler - */ - public String getIsSearchHandler() { - return isSearchHandler; - } - - /** - * @param isSearchHandler the isSearchHandler to set - */ - public void setIsSearchHandler(String isSearchHandler) { - this.isSearchHandler = isSearchHandler; - } - - /** - * @return the summary - */ - public String getSummary() { - return summary; - } - - /** - * @param summary the summary to set - */ - public void setSummary(String summary) { - this.summary = summary; - } - - public String getOperationId() { - return operationId; - } - - public void setOperationId(String operationId) { - this.operationId = operationId; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Parameter.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Parameter.java deleted file mode 100644 index a3857e776..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Parameter.java +++ /dev/null @@ -1,147 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonSetter; -import org.codehaus.jackson.annotate.JsonProperty; - -import java.util.ArrayList; -import java.util.List; - -/** - * The contents of this file are subject to the OpenMRS Public License Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. You may obtain a copy of the - * License at http://license.openmrs.org Software distributed under the License is distributed on an - * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the - * specific language governing rights and limitations under the License. Copyright (C) OpenMRS, LLC. - * All Rights Reserved. - */ - -/*Describes a single operation parameter.*/ -public class Parameter { - - /* The name of the parameter. Parameter names are case sensitive.*/ - private String name; - - /* he location of the parameter. Possible values are "query", "header", "path", "formData" or "body".*/ - private String in; - - /*A brief description of the parameter. This could contain examples of use.*/ - private String description; - - /*Determines whether this parameter is mandatory*/ - private Boolean required; - - private String type; - - @JsonProperty("enum") - private List enumeration; - - private Schema schema; - - public Parameter() { - type = "string"; // default to string - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the in - */ - public String getIn() { - return in; - } - - /** - * @param in the in to set - */ - public void setIn(String in) { - this.in = in; - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the required - */ - public Boolean getRequired() { - return required; - } - - /** - * @param required the required to set - */ - public void setRequired(Boolean required) { - this.required = required; - } - - /** - * @return the type - */ - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - @JsonGetter("enum") - public List getEnumeration() { - return this.enumeration; - } - - @JsonSetter("enum") - public void setEnumeration(List enumeration) { - this.enumeration = enumeration; - } - - public void addEnumerationItem(String enumerationItem) { - if (enumeration == null) - enumeration = new ArrayList(); - - if (!this.enumeration.contains(enumerationItem)) { - this.enumeration.add(enumerationItem); - } - } - - public Schema getSchema() { - return schema; - } - - public void setSchema(Schema schema) { - this.schema = schema; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Path.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Path.java deleted file mode 100644 index 21664efe5..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Path.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; - -//Holds the relative path to the individual endpoints. The path is appended to the basePath in order to construct the full URL -public class Path { - - //Describes the operations available on a single path - private Map operations; - - public Path() { - - } - - /** - * @return the operation - */ - @JsonAnyGetter - public Map getOperations() { - return operations; - } - - /** - * @param operation the operation to set - */ - public void setOperations(Map operations) { - this.operations = operations; - } - -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Paths.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Paths.java deleted file mode 100644 index 68389f8e6..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Paths.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; - -//List of Available Paths. -public class Paths { - - private Map paths; - - public Paths() { - - } - - /** - * @return the paths - */ - @JsonAnyGetter - public Map getPaths() { - return paths; - } - - /** - * @param paths the paths to set - */ - public void setPaths(Map paths) { - this.paths = paths; - } - -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Response.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Response.java deleted file mode 100644 index f9b7274dd..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Response.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -/* An object to hold responses to be reused across operations */ -public class Response { - - private String description; - - private Schema schema; - - public Response() { - - } - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description the description to set - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * @return the schema - */ - public Schema getSchema() { - return schema; - } - - /** - * @param schema the schema to set - */ - public void setSchema(Schema schema) { - this.schema = schema; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Schema.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Schema.java deleted file mode 100644 index e0678969c..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/Schema.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -/** - * The contents of this file are subject to the OpenMRS Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://license.openmrs.org - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. - * - * Copyright (C) OpenMRS, LLC. All Rights Reserved. - */ - -import com.fasterxml.jackson.annotation.JsonProperty; - -/*The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays.*/ -public class Schema { - - private String ref; - - public Schema() { - - } - - /** - * @return the ref - */ - @JsonProperty("$ref") - public String getRef() { - return ref; - } - - /** - * @param ref the ref to set - */ - public void setRef(String ref) { - this.ref = ref; - } - -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SecurityDefinitions.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SecurityDefinitions.java deleted file mode 100644 index ed95852d9..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SecurityDefinitions.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -public class SecurityDefinitions { - - private SecurityScheme basic_auth; - - public SecurityDefinitions() { - } - - public SecurityScheme getBasicAuth() { - return basic_auth; - } - - public void setBasicAuth(SecurityScheme basic_auth) { - this.basic_auth = basic_auth; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecification.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecification.java deleted file mode 100644 index d22a91420..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecification.java +++ /dev/null @@ -1,194 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger; - -import java.util.List; - -/* The class describes the RESTful API in accordance with the Swagger specification and is represented as JSON objects and conform to the JSON standards */ -public class SwaggerSpecification { - - //Specifies the Swagger Specification version being used - private String swagger = "2.0"; - - // Provides metadata about the API - private Info info; - - //The host (name or ip) serving the API - private String host; - - //The base path on which the API is served - private String basePath; - - //Allows adding meta data to a single tag that is used by the Operation Object. - private List tags; - - //The transfer protocol of the API - private List schemes; - - //A list of MIME types the APIs can consume - private List consumes; - - //A list of MIME types the APIs can produce - private List produces; - - //The available paths and operations for the API. - private Paths paths; - - //The security definitions - private SecurityDefinitions securityDefinitions; - - //An object to hold data types produced and consumed by operations. - private Definitions definitions; - - public SwaggerSpecification() { - - } - - /** - * @return the info - */ - public Info getInfo() { - return info; - } - - /** - * @param info the info to set - */ - public void setInfo(Info info) { - this.info = info; - } - - /** - * @return the host - */ - public String getHost() { - return host; - } - - /** - * @param host the host to set - */ - public void setHost(String host) { - this.host = host; - } - - /** - * @return the basePath - */ - public String getBasePath() { - return basePath; - } - - /** - * @param basePath the basePath to set - */ - public void setBasePath(String basePath) { - this.basePath = basePath; - } - - /** - * @return the schemes - */ - public List getSchemes() { - return schemes; - } - - /** - * @param schemes the schemes to set - */ - public void setSchemes(List schemes) { - this.schemes = schemes; - } - - /** - * @return the consumes - */ - public List getConsumes() { - return consumes; - } - - /** - * @param consumes the consumes to set - */ - public void setConsumes(List consumes) { - this.consumes = consumes; - } - - /** - * @return the produces - */ - public List getProduces() { - return produces; - } - - /** - * @param produces the produces to set - */ - public void setProduces(List produces) { - this.produces = produces; - } - - /** - * @return the paths - */ - public Paths getPaths() { - return paths; - } - - /** - * @param paths the paths to set - */ - public void setPaths(Paths paths) { - this.paths = paths; - } - - public SecurityDefinitions getSecurityDefinitions() { - return securityDefinitions; - } - - public void setSecurityDefinitions(SecurityDefinitions securityDefinitions) { - this.securityDefinitions = securityDefinitions; - } - - /** - * @return the definitions - */ - public Definitions getDefinitions() { - return definitions; - } - - /** - * @param definitions the definitions to set - */ - public void setDefinitions(Definitions definitions) { - this.definitions = definitions; - } - - /** - * @return the swagger - */ - public String getSwagger() { - return swagger; - } - - /** - * @return the tags - */ - public List getTags() { - return tags; - } - - /** - * @param tags the tags to set - */ - public void setTags(List tags) { - this.tags = tags; - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java index d0232bf2f..2b73495e6 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/SwaggerSpecificationCreator.java @@ -9,30 +9,31 @@ */ package org.openmrs.module.webservices.docs.swagger; -import io.swagger.models.Contact; -import io.swagger.models.ExternalDocs; -import io.swagger.models.Info; -import io.swagger.models.License; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.Operation; -import io.swagger.models.Path; -import io.swagger.models.RefModel; -import io.swagger.models.Response; -import io.swagger.models.Scheme; -import io.swagger.models.SecurityRequirement; -import io.swagger.models.Swagger; -import io.swagger.models.auth.BasicAuthDefinition; -import io.swagger.models.parameters.BodyParameter; -import io.swagger.models.parameters.Parameter; -import io.swagger.models.parameters.PathParameter; -import io.swagger.models.parameters.QueryParameter; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.Property; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; -import io.swagger.util.Json; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.media.Content; +import io.swagger.v3.oas.models.media.IntegerSchema; +import io.swagger.v3.oas.models.media.MediaType; +import io.swagger.v3.core.util.Json; +import io.swagger.v3.oas.models.parameters.QueryParameter; +import io.swagger.v3.oas.models.servers.Server; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.responses.ApiResponse; +import io.swagger.v3.oas.models.responses.ApiResponses; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.StringSchema; +import io.swagger.v3.oas.models.ExternalDocumentation; +import io.swagger.v3.oas.models.Paths; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Level; import org.apache.log4j.LogManager; @@ -75,13 +76,13 @@ public class SwaggerSpecificationCreator { - private static Swagger swagger; + private static OpenAPI openAPI; private String host; private String basePath; - private List schemes; + private List schemes; private String baseUrl; @@ -91,9 +92,11 @@ public class SwaggerSpecificationCreator { PrintStream originalOut; - private QueryParameter subclassTypeParameter = new QueryParameter().name("t") + private Parameter subclassTypeParameter = new Parameter() + .name("t") + .in("query") .description("The type of Subclass Resource to return") - .type("string"); + .schema(new StringSchema()); Map originalLevels = new HashMap(); @@ -112,9 +115,9 @@ public SwaggerSpecificationCreator basePath(String basePath) { return this; } - public SwaggerSpecificationCreator scheme(Scheme scheme) { + public SwaggerSpecificationCreator scheme(SwaggerDefinition.Scheme scheme) { if (schemes == null) { - this.schemes = new ArrayList(); + this.schemes = new ArrayList(); } if (!schemes.contains(scheme)) { this.schemes.add(scheme); @@ -126,31 +129,28 @@ public SwaggerSpecificationCreator scheme(Scheme scheme) { * Regenerate the swagger spec from scratch */ private void BuildJSON() { - synchronized (this) { - log.info("Initiating Swagger specification creation"); - toggleLogs(RestConstants.SWAGGER_LOGS_OFF); - try { - initSwagger(); - addPaths(); - addDefaultDefinitions(); - // addSubclassOperations(); //FIXME uncomment after fixing the method - } - catch (Exception e) { - log.error("Error while creating Swagger specification", e); - } - finally { - toggleLogs(RestConstants.SWAGGER_LOGS_ON); - log.info("Swagger specification creation complete"); - } + log.info("Initiating Swagger specification creation"); + toggleLogs(RestConstants.SWAGGER_LOGS_OFF); + try { + initOpenAPI(); + addPaths(); + addDefaultDefinitions(); + // addSubclassOperations(); //FIXME uncomment after fixing the method + } + catch (Exception e) { + log.error("Error while creating Swagger specification", e); + } + finally { + toggleLogs(RestConstants.SWAGGER_LOGS_ON); } } public String getJSON() { if (isCached()) { log.info("Returning a cached copy of Swagger specification"); - initSwagger(); + initOpenAPI(); } else { - swagger = new Swagger(); + openAPI = new OpenAPI(); BuildJSON(); } return createJSON(); @@ -159,15 +159,18 @@ public String getJSON() { private void addDefaultDefinitions() { // schema of the default response // received from fetchAll and search operations - swagger.addDefinition("FetchAll", new ModelImpl() - .property("results", new ArrayProperty() - .items(new ObjectProperty() - .property("uuid", new StringProperty()) - .property("display", new StringProperty()) - .property("links", new ArrayProperty() - .items(new ObjectProperty() - .property("rel", new StringProperty().example("self")) - .property("uri", new StringProperty(StringProperty.Format.URI))))))); + Components components = new Components(); + components.addSchemas("FetchAll", new ObjectSchema() + .addProperty("results", new ArraySchema() + .items(new ObjectSchema() + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()) + .addProperty("links", new ArraySchema() + .items(new ObjectSchema() + .addProperty("rel", new StringSchema().example("self")) + .addProperty("uri", new StringSchema().format("uri"))))))); + + openAPI.setComponents(components); } private void toggleLogs(boolean targetState) { @@ -211,7 +214,7 @@ public void write(int b) { } } - private void initSwagger() { + private void initOpenAPI() { final Info info = new Info() .version(OpenmrsConstants.OPENMRS_VERSION_SHORT) .title("OpenMRS API Docs") @@ -219,18 +222,16 @@ private void initSwagger() { .contact(new Contact().name("OpenMRS").url("http://openmrs.org")) .license(new License().name("MPL-2.0 w/ HD").url("http://openmrs.org/license")); - swagger + openAPI = new OpenAPI() .info(info) - .host(this.host) - .basePath(this.basePath) - .schemes(this.schemes) - .securityDefinition("basic_auth", new BasicAuthDefinition()) - .security(new SecurityRequirement().requirement("basic_auth")) - .consumes("application/json") - .produces("application/json") - .externalDocs(new ExternalDocs() + .addServersItem(new Server().url(this.host + this.basePath)) + .components(new Components().addSecuritySchemes("basic_auth", new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))) + .addSecurityItem(new SecurityRequirement().addList("basic_auth")) + .externalDocs(new ExternalDocumentation() .description("Find more info on REST Module Wiki") .url("https://wiki.openmrs.org/x/xoAaAQ")); + + openAPI.setPaths(new Paths()); } private List getModuleVersions() { @@ -439,13 +440,11 @@ private SimpleObject buildPOSTUpdateSimpleObject(DelegatingResourceHandler re return simpleObject; } - private Path buildFetchAllPath(Path path, + private PathItem buildFetchAllPath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - - Operation getOperation = null; + io.swagger.v3.oas.models.Operation getOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.get, resourceHandler)) { - getOperation = createOperation(resourceHandler, "get", resourceName, null, OperationEnum.get); } @@ -463,10 +462,10 @@ private Path buildFetchAllPath(Path path, return path; } - private Path buildGetWithUUIDPath(Path path, + private PathItem buildGetWithUUIDPath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - Operation getOperation = null; + io.swagger.v3.oas.models.Operation getOperation = null; if (testOperationImplemented(OperationEnum.getWithUUID, resourceHandler)) { if (resourceParentName == null) { @@ -479,15 +478,14 @@ private Path buildGetWithUUIDPath(Path path, } if (getOperation != null) { - path.get(getOperation); + path.setGet(getOperation); } return path; } - private Path buildCreatePath(Path path, + private PathItem buildCreatePath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - - Operation postCreateOperation = null; + io.swagger.v3.oas.models.Operation postCreateOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.postCreate, resourceHandler)) { @@ -502,15 +500,15 @@ private Path buildCreatePath(Path path, } if (postCreateOperation != null) { - path.post(postCreateOperation); + path.setPost(postCreateOperation); } return path; } - private Path buildUpdatePath(Path path, + private PathItem buildUpdatePath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - Operation postUpdateOperation = null; + io.swagger.v3.oas.models.Operation postUpdateOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.postUpdate, resourceHandler)) { @@ -525,15 +523,15 @@ private Path buildUpdatePath(Path path, } if (postUpdateOperation != null) { - path.post(postUpdateOperation); + path.setPost(postUpdateOperation); } return path; } - private Path buildDeletePath(Path path, + private PathItem buildDeletePath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { - Operation deleteOperation = null; + io.swagger.v3.oas.models.Operation deleteOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.delete, resourceHandler)) { @@ -548,26 +546,26 @@ private Path buildDeletePath(Path path, } if (deleteOperation != null) { - path.delete(deleteOperation); + path.setDelete(deleteOperation); } return path; } - private Path buildPurgePath(Path path, DelegatingResourceHandler resourceHandler, + private PathItem buildPurgePath(PathItem path, DelegatingResourceHandler resourceHandler, String resourceName, String resourceParentName) { if (path.getDelete() != null) { // just add optional purge parameter - Operation deleteOperation = path.getDelete(); + io.swagger.v3.oas.models.Operation deleteOperation = path.getDelete(); deleteOperation.setSummary("Delete or purge resource by uuid"); deleteOperation.setDescription("The resource will be voided/retired unless purge = 'true'"); - QueryParameter purgeParam = new QueryParameter().name("purge").type("boolean"); - deleteOperation.parameter(purgeParam); + Parameter purgeParam = new Parameter().name("purge").in("query").schema(new StringSchema()); + deleteOperation.addParametersItem(purgeParam); } else { // create standalone purge operation with required - Operation purgeOperation = null; + io.swagger.v3.oas.models.Operation purgeOperation = null; if (resourceParentName == null) { if (testOperationImplemented(OperationEnum.purge, resourceHandler)) { @@ -582,21 +580,22 @@ private Path buildPurgePath(Path path, DelegatingResourceHandler resourceHand } if (purgeOperation != null) { - path.delete(purgeOperation); + path.setDelete(purgeOperation); } } return path; } - private void addIndividualPath(String resourceParentName, String resourceName, Path path, + private void addIndividualPath(String resourceParentName, String resourceName, PathItem path, String pathSuffix) { - if (!path.getOperations().isEmpty()) { - if (resourceParentName == null) { - swagger.path("/" + resourceName + pathSuffix, path); - } else { - swagger.path("/" + resourceParentName + "/{parent-uuid}/" + resourceName + pathSuffix, path); - } + if (path.getGet() != null || path.getPost() != null || path.getDelete() != null) { + String fullPath = resourceParentName == null ? + "/" + resourceName + pathSuffix : + "/" + resourceParentName + "/{parent-uuid}/" + resourceName + pathSuffix; + + log.debug("Adding path: " + fullPath); + openAPI.getPaths().addPathItem(fullPath, path); } } @@ -622,7 +621,7 @@ private String buildSearchParameterDependencyString(Set depende } private void addSearchOperations(DelegatingResourceHandler resourceHandler, String resourceName, - String resourceParentName, Path getAllPath) { + String resourceParentName, PathItem getAllPath) { if (resourceName == null) { return; } @@ -631,17 +630,27 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S boolean wasNew = false; if (hasSearchHandler || hasDoSearch) { - Operation operation; + io.swagger.v3.oas.models.Operation operation; // query parameter - Parameter q = new QueryParameter().name("q") + Parameter q = new Parameter() + .name("q") + .in("query") .description("The search query") - .type("string"); + .schema(new StringSchema()); - if (getAllPath.getOperations().isEmpty() || getAllPath.getGet() == null) { + if (getAllPath.getGet() == null) { // create search-only operation - operation = new Operation(); - operation.tag(resourceParentName == null ? resourceName : resourceParentName); - operation.produces("application/json").produces("application/xml"); + operation = new io.swagger.v3.oas.models.Operation(); + operation.addTagsItem(resourceParentName == null ? resourceName : resourceParentName); + + // Set the responses using the proper method + ApiResponses responses = new ApiResponses(); + responses.addApiResponse("200", new ApiResponse() + .description(resourceName + " response") + .content(new Content() + .addMediaType("application/json", + new MediaType().schema(new Schema().$ref("#/components/schemas/FetchAll"))))); + operation.setResponses(responses); // if the path has no operations, add a note that at least one search parameter must be specified operation.setSummary("Search for " + resourceName); @@ -650,8 +659,8 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S // representations query parameter Parameter v = new QueryParameter().name("v") .description("The representation to return (ref, default, full or custom)") - .type("string") - ._enum(Arrays.asList("ref", "default", "full", "custom")); + .schema(new StringSchema() + ._enum(Arrays.asList("ref", "default", "full", "custom"))); // This implies that the resource has no custom SearchHandler or doGetAll, but has doSearch implemented // As there is only one query param 'q', mark it as required @@ -660,12 +669,9 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S } operation.setParameters(buildPagingParameters()); - operation.parameter(v).parameter(q); - operation.addResponse("200", new Response() - .description(resourceName + " response") - .schema(new RefProperty("#/definitions/FetchAll"))); + operation.addParametersItem(v).addParametersItem(q); if (((BaseDelegatingResource) resourceHandler).hasTypesDefined()) { - operation.parameter(subclassTypeParameter); + operation.addParametersItem(subclassTypeParameter); } // since the path has no existing get operations then it is considered new wasNew = true; @@ -673,7 +679,7 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S operation = getAllPath.getGet(); operation.setSummary("Fetch all non-retired " + resourceName + " resources or perform search"); operation.setDescription("All search parameters are optional"); - operation.parameter(q); + operation.addParametersItem(q); } Map parameterMap = new HashMap(); @@ -691,13 +697,13 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S for (SearchQuery searchQuery : searchHandler.getSearchConfig().getSearchQueries()) { // parameters with no dependencies for (SearchParameter requiredParameter : searchQuery.getRequiredParameters()) { - Parameter p = new QueryParameter().type("string"); + Parameter p = new Parameter().in("query").schema(new StringSchema()); p.setName(requiredParameter.getName()); parameterMap.put(requiredParameter.getName(), p); } // parameters with dependencies for (SearchParameter optionalParameter : searchQuery.getOptionalParameters()) { - Parameter p = new QueryParameter().type("string"); + Parameter p = new Parameter().in("query").schema(new StringSchema()); p.setName(optionalParameter.getName()); p.setDescription(buildSearchParameterDependencyString(searchQuery.getRequiredParameters())); parameterMap.put(optionalParameter.getName(), p); @@ -708,7 +714,7 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S } for (Parameter p : parameterMap.values()) { - operation.parameter(p); + operation.addParametersItem(p); } operation.setOperationId("getAll" + getOperationTitle(resourceHandler, true)); @@ -719,89 +725,111 @@ private void addSearchOperations(DelegatingResourceHandler resourceHandler, S } private void addPaths() { + log.debug("Starting addPaths method"); + + if (openAPI.getPaths() == null) { + log.debug("Paths object is null, initializing it"); + openAPI.setPaths(new Paths()); + } + // get all registered resource handlers List> resourceHandlers = Context.getService(RestService.class).getResourceHandlers(); + log.debug("Number of resource handlers: " + resourceHandlers.size()); + sortResourceHandlers(resourceHandlers); // generate swagger JSON for each handler for (DelegatingResourceHandler resourceHandler : resourceHandlers) { + try { + // get name and parent if it's a subresource + Resource annotation = resourceHandler.getClass().getAnnotation(Resource.class); - // get name and parent if it's a subresource - Resource annotation = resourceHandler.getClass().getAnnotation(Resource.class); + String resourceParentName = null; + String resourceName = null; - String resourceParentName = null; - String resourceName = null; + if (annotation != null) { + // top level resource + resourceName = annotation.name().substring(annotation.name().indexOf('/') + 1); + } else { + // subresource + SubResource subResourceAnnotation = resourceHandler.getClass().getAnnotation(SubResource.class); - if (annotation != null) { - // top level resource - resourceName = annotation.name().substring(annotation.name().indexOf('/') + 1); - } else { - // subresource - SubResource subResourceAnnotation = resourceHandler.getClass().getAnnotation(SubResource.class); + if (subResourceAnnotation != null) { + Resource parentResourceAnnotation = subResourceAnnotation.parent().getAnnotation(Resource.class); - if (subResourceAnnotation != null) { - Resource parentResourceAnnotation = subResourceAnnotation.parent().getAnnotation(Resource.class); - - resourceName = subResourceAnnotation.path(); - resourceParentName = parentResourceAnnotation.name().substring( - parentResourceAnnotation.name().indexOf('/') + 1); + resourceName = subResourceAnnotation.path(); + resourceParentName = parentResourceAnnotation.name().substring( + parentResourceAnnotation.name().indexOf('/') + 1); + } } - } - // subclass operations are handled separately in another method - if (resourceHandler instanceof DelegatingSubclassHandler) - continue; + log.debug("Processing resource: " + resourceName + (resourceParentName != null ? " (parent: " + resourceParentName + ")" : "")); + + // subclass operations are handled separately in another method + if (resourceHandler instanceof DelegatingSubclassHandler) { + log.debug("Skipping subclass handler for: " + resourceName); + continue; + } - // set up paths - Path rootPath = new Path(); - Path uuidPath = new Path(); - - ///////////////////////// - // GET all // - ///////////////////////// - Path rootPathGetAll = buildFetchAllPath(rootPath, resourceHandler, resourceName, - resourceParentName); - addIndividualPath(resourceParentName, resourceName, rootPathGetAll, ""); - - ///////////////////////// - // GET search // - ///////////////////////// - addSearchOperations(resourceHandler, resourceName, resourceParentName, rootPathGetAll); - - ///////////////////////// - // POST create // - ///////////////////////// - Path rootPathPostCreate = buildCreatePath(rootPathGetAll, resourceHandler, resourceName, - resourceParentName); - addIndividualPath(resourceParentName, resourceName, rootPathPostCreate, ""); - - ///////////////////////// - // GET with UUID // - ///////////////////////// - Path uuidPathGetAll = buildGetWithUUIDPath(uuidPath, resourceHandler, resourceName, - resourceParentName); - addIndividualPath(resourceParentName, resourceName, uuidPathGetAll, "/{uuid}"); - - ///////////////////////// - // POST update // - ///////////////////////// - Path uuidPathPostUpdate = buildUpdatePath(uuidPathGetAll, resourceHandler, resourceName, - resourceParentName); - addIndividualPath(resourceParentName, resourceName, uuidPathPostUpdate, "/{uuid}"); - - ///////////////////////// - // DELETE // - ///////////////////////// - Path uuidPathDelete = buildDeletePath(uuidPathPostUpdate, resourceHandler, resourceName, - resourceParentName); - - ///////////////////////// - // DELETE (purge) // - ///////////////////////// - Path uuidPathPurge = buildPurgePath(uuidPathDelete, resourceHandler, resourceName, - resourceParentName); - addIndividualPath(resourceParentName, resourceName, uuidPathPurge, "/{uuid}"); + // set up paths + PathItem rootPath = new PathItem(); + PathItem uuidPath = new PathItem(); + + ///////////////////////// + // GET all // + ///////////////////////// + PathItem rootPathGetAll = buildFetchAllPath(rootPath, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, rootPathGetAll, ""); + + ///////////////////////// + // GET search // + ///////////////////////// + addSearchOperations(resourceHandler, resourceName, resourceParentName, rootPathGetAll); + + ///////////////////////// + // POST create // + ///////////////////////// + PathItem rootPathPostCreate = buildCreatePath(rootPathGetAll, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, rootPathPostCreate, ""); + + ///////////////////////// + // GET with UUID // + ///////////////////////// + PathItem uuidPathGetAll = buildGetWithUUIDPath(uuidPath, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, uuidPathGetAll, "/{uuid}"); + + ///////////////////////// + // POST update // + ///////////////////////// + PathItem uuidPathPostUpdate = buildUpdatePath(uuidPathGetAll, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, uuidPathPostUpdate, "/{uuid}"); + + ///////////////////////// + // DELETE // + ///////////////////////// + PathItem uuidPathDelete = buildDeletePath(uuidPathPostUpdate, resourceHandler, resourceName, + resourceParentName); + + ///////////////////////// + // DELETE (purge) // + ///////////////////////// + PathItem uuidPathPurge = buildPurgePath(uuidPathDelete, resourceHandler, resourceName, + resourceParentName); + addIndividualPath(resourceParentName, resourceName, uuidPathPurge, "/{uuid}"); + + // After building all paths for a resource, log the number of operations + log.debug("Added " + (rootPath.readOperations().size() + uuidPath.readOperations().size()) + " operations for resource: " + resourceName); + } catch (Exception e) { + log.error("Error processing resource handler: " + resourceHandler.getClass().getName(), e); + } } + + // After processing all resources, log the total number of paths + log.debug("Finished addPaths method. Total paths: " + (openAPI.getPaths() != null ? openAPI.getPaths().size() : 0)); } private void addSubclassOperations() { @@ -816,24 +844,32 @@ private void addSubclassOperations() { String resourceName = resourceClass.getSimpleName().toLowerCase(); // 1. add non-optional enum property to model - Path path = swagger.getPath("/" + resourceName); + PathItem path = openAPI.getPaths().get("/" + resourceName); if (path == null) continue; // FIXME: implement other operations when required - Operation post = path.getPost(); + io.swagger.v3.oas.models.Operation post = path.getPost(); if (post == null) continue; - Model definition = swagger.getDefinitions().get(StringUtils.capitalize(resourceName) + "Create"); - if (definition == null) + Schema definition = openAPI.getComponents().getSchemas().get(StringUtils.capitalize(resourceName) + "Create"); + if (definition == null) { continue; + } - Map properties = definition.getProperties(); + Map properties; + if (definition instanceof ObjectSchema) { + properties = definition.getProperties(); + } else if (definition instanceof Schema) { + properties = definition.getProperties(); + } else { + log.warn("Unexpected schema type for " + resourceName + ": " + definition.getClass().getName()); + continue; + } // 2. merge subclass properties into definition - for (Map.Entry prop : resourceHandler.getGETModel(Representation.FULL).getProperties() - .entrySet()) { + for (Map.Entry prop : resourceHandler.getGETSchema(Representation.FULL).getProperties().entrySet()) { if (properties.get(prop.getKey()) == null) { properties.put(prop.getKey(), prop.getValue()); } @@ -844,52 +880,22 @@ private void addSubclassOperations() { } } - @Deprecated - private List getParametersListForSearchHandlers( - String resourceName, String searchHandlerId, int queryIndex) { - List parameters = new ArrayList(); - String resourceURL = getResourceUrl(getBaseUrl(), resourceName); - for (SearchHandlerDoc searchDoc : searchHandlerDocs) { - if (searchDoc.getSearchHandlerId().equals(searchHandlerId) && searchDoc.getResourceURL().equals(resourceURL)) { - SearchQueryDoc queryDoc = searchDoc.getSearchQueriesDoc().get(queryIndex); - for (SearchParameter requiredParameter : queryDoc.getRequiredParameters()) { - org.openmrs.module.webservices.docs.swagger.Parameter parameter = new org.openmrs.module.webservices.docs.swagger.Parameter(); - parameter.setName(requiredParameter.getName()); - parameter.setIn("query"); - parameter.setDescription(""); - parameter.setRequired(true); - parameters.add(parameter); - } - for (SearchParameter optionalParameter : queryDoc.getOptionalParameters()) { - org.openmrs.module.webservices.docs.swagger.Parameter parameter = new org.openmrs.module.webservices.docs.swagger.Parameter(); - parameter.setName(optionalParameter.getName()); - parameter.setIn("query"); - parameter.setDescription(""); - parameter.setRequired(false); - parameters.add(parameter); - } - break; - } - } - return parameters; - } - private String createJSON() { - return Json.pretty(swagger); + return Json.pretty(openAPI); } private Parameter buildRequiredUUIDParameter(String name, String desc) { - return new PathParameter().name(name).description(desc).type("string"); + return new Parameter().name(name).description(desc).schema(new StringSchema()).in("path").required(true); } private List buildPagingParameters() { List params = new ArrayList(); - Parameter limit = new QueryParameter().name("limit") - .description("The number of results to return").type("integer"); + Parameter limit = new Parameter().name("limit") + .description("The number of results to return").schema(new IntegerSchema()).in("query"); - Parameter startIndex = new QueryParameter().name("startIndex") - .description("The offset at which to start").type("integer"); + Parameter startIndex = new Parameter().name("startIndex") + .description("The offset at which to start").schema(new IntegerSchema()).in("query"); params.add(limit); params.add(startIndex); @@ -899,22 +905,19 @@ private List buildPagingParameters() { private Parameter buildPOSTBodyParameter(String resourceName, String resourceParentName, OperationEnum operationEnum) { - BodyParameter bodyParameter = new BodyParameter(); - bodyParameter.setRequired(true); + Parameter bodyParameter = new Parameter().name("resource").description("Resource to create").in("body").required(true); switch (operationEnum) { case postCreate: case postSubresource: - bodyParameter.setName("resource"); bodyParameter.setDescription("Resource to create"); break; case postUpdate: case postUpdateSubresouce: - bodyParameter.setName("resource"); bodyParameter.setDescription("Resource properties to update"); } - bodyParameter.schema(new RefModel(getSchemaRef(resourceName, resourceParentName, operationEnum))); + bodyParameter.setSchema(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, operationEnum))); return bodyParameter; } @@ -959,7 +962,7 @@ private String getSchemaName(String resourceName, String resourceParentName, Ope } private String getSchemaRef(String resourceName, String resourceParentName, OperationEnum operationEnum) { - return "#/definitions/" + getSchemaName(resourceName, resourceParentName, operationEnum); + return "#/components/schemas/" + getSchemaName(resourceName, resourceParentName, operationEnum); } private String getOperationTitle(DelegatingResourceHandler resourceHandler, Boolean pluralize) { @@ -994,189 +997,196 @@ private void createDefinition(OperationEnum operationEnum, String resourceName, DelegatingResourceHandler resourceHandler) { String definitionName = getSchemaName(resourceName, resourceParentName, operationEnum); - Model model = null; - Model modelRef = null; - Model modelFull = null; + Schema model = null; + Schema modelRef = null; + Schema modelFull = null; if (definitionName.endsWith("Get")) { - model = resourceHandler.getGETModel(Representation.DEFAULT); - modelRef = resourceHandler.getGETModel(Representation.REF); - modelFull = resourceHandler.getGETModel(Representation.FULL); + model = resourceHandler.getGETSchema(Representation.DEFAULT); + modelRef = resourceHandler.getGETSchema(Representation.REF); + modelFull = resourceHandler.getGETSchema(Representation.FULL); } else if (definitionName.endsWith("Create")) { - model = resourceHandler.getCREATEModel(Representation.DEFAULT); - modelFull = resourceHandler.getCREATEModel(Representation.FULL); + model = resourceHandler.getCREATESchema(Representation.DEFAULT); + modelFull = resourceHandler.getCREATESchema(Representation.FULL); } else if (definitionName.endsWith("Update")) { - model = resourceHandler.getUPDATEModel(Representation.DEFAULT); + model = resourceHandler.getUPDATESchema(Representation.DEFAULT); } if (model != null) { - swagger.addDefinition(definitionName, model); + openAPI.getComponents().addSchemas(definitionName, model); } if (modelRef != null) { - swagger.addDefinition(definitionName + "Ref", modelRef); + openAPI.getComponents().addSchemas(definitionName + "Ref", modelRef); } if (modelFull != null) { - swagger.addDefinition(definitionName + "Full", modelFull); + openAPI.getComponents().addSchemas(definitionName + "Full", modelFull); } } /** - * @param resourceHandler - * @param operationName get, post, delete - * @param resourceName - * @param resourceParentName - * @param representation - * @param operationEnum - * @return + * Creates an OpenAPI Operation object for a given resource and operation type. + * + * @param resourceHandler The DelegatingResourceHandler for the resource + * @param operationName The name of the operation (e.g., "get", "post") + * @param resourceName The name of the resource + * @param resourceParentName The name of the parent resource (if applicable, null otherwise) + * @param operationEnum The type of operation (from OperationEnum) + * @return An OpenAPI Operation object describing the API endpoint */ private Operation createOperation(DelegatingResourceHandler resourceHandler, String operationName, String resourceName, String resourceParentName, OperationEnum operationEnum) { Operation operation = new Operation() - .tag(resourceParentName == null ? resourceName : resourceParentName) - .consumes("application/json").produces("application/json"); + .addTagsItem(resourceParentName == null ? resourceName : resourceParentName); // create definition - if (operationName.equals("post") || operationName.equals("get") ) { + if (operationName.equals("post") || operationName.equals("get")) { createDefinition(operationEnum, resourceName, resourceParentName, resourceHandler); } // create all possible responses + ApiResponses responses = new ApiResponses(); + // 200 response (Successful operation) - Response response200 = new Response().description(resourceName + " response"); + ApiResponse response200 = new ApiResponse().description(resourceName + " response"); // 201 response (Successfully created) - Response response201 = new Response().description(resourceName + " response"); + ApiResponse response201 = new ApiResponse().description(resourceName + " response"); // 204 delete success - Response response204 = new Response().description("Delete successful"); + ApiResponse response204 = new ApiResponse().description("Delete successful"); // 401 response (User not logged in) - Response response401 = new Response().description("User not logged in"); + ApiResponse response401 = new ApiResponse().description("User not logged in"); // 404 (Object with given uuid doesn't exist) - Response response404 = new Response() - .description("Resource with given uuid doesn't exist"); + ApiResponse response404 = new ApiResponse().description("Resource with given uuid doesn't exist"); // create all possible query params // representations query parameter - Parameter v = new QueryParameter().name("v") + Parameter v = new QueryParameter() + .name("v") .description("The representation to return (ref, default, full or custom)") - .type("string") - ._enum(Arrays.asList("ref", "default", "full", "custom")); + .schema(new StringSchema()._enum(Arrays.asList("ref", "default", "full", "custom"))); - if (operationEnum == OperationEnum.get) { + switch (operationEnum) { + case get: + operation.summary("Fetch all non-retired") + .operationId("getAll" + getOperationTitle(resourceHandler, true)); + response200.content(new Content().addMediaType("application/json", + new MediaType().schema(new ArraySchema().items(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))))); + responses.addApiResponse("200", response200); + + operation.parameters(buildPagingParameters()); + operation.addParametersItem(v); + if (((BaseDelegatingResource) resourceHandler).hasTypesDefined()) { + operation.addParametersItem(subclassTypeParameter); + } + break; - operation.setSummary("Fetch all non-retired"); - operation.setOperationId("getAll" + getOperationTitle(resourceHandler, true)); - operation.addResponse("200", - response200.schema(new ArrayProperty( - new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get))))); - - operation.setParameters(buildPagingParameters()); - operation.parameter(v); - if (((BaseDelegatingResource) resourceHandler).hasTypesDefined()) { - operation.parameter(subclassTypeParameter); - } + case getWithUUID: + operation.summary("Fetch by uuid") + .operationId("get" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(v); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to filter by")); + response200.content(new Content().addMediaType("application/json", + new MediaType().schema(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, OperationEnum.get))))); + responses.addApiResponse("200", response200); + responses.addApiResponse("404", response404); + break; - } else if (operationEnum == OperationEnum.getWithUUID) { + case postCreate: + operation.summary("Create with properties in request") + .operationId("create" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postCreate)); + responses.addApiResponse("201", response201); + break; - operation.setSummary("Fetch by uuid"); - operation.setOperationId("get" + getOperationTitle(resourceHandler, false)); - operation.parameter(v); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to filter by")); - operation.addResponse("200", - response200.schema(new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))); - operation.addResponse("404", response404); + case postUpdate: + operation.summary("Edit with given uuid, only modifying properties in request") + .operationId("update" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid of resource to update")); + operation.addParametersItem(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdate)); + responses.addApiResponse("201", response201); + break; - } else if (operationEnum == OperationEnum.postCreate) { + case getSubresource: + operation.summary("Fetch all non-retired " + resourceName + " subresources") + .operationId("getAll" + getOperationTitle(resourceHandler, true)); + operation.parameters(buildPagingParameters()); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(v); + response200.content(new Content().addMediaType("application/json", + new MediaType().schema(new ObjectSchema() + .addProperty("results", new ArraySchema() + .items(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, OperationEnum.get))))))); + responses.addApiResponse("200", response200); + break; - operation.setSummary("Create with properties in request"); - operation.setOperationId("create" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postCreate)); - operation.addResponse("201", response201); + case postSubresource: + operation.summary("Create " + resourceName + " subresource with properties in request") + .operationId("create" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postSubresource)); + responses.addApiResponse("201", response201); + break; - } else if (operationEnum == OperationEnum.postUpdate) { + case postUpdateSubresouce: + operation.summary("edit " + resourceName + " subresource with given uuid, only modifying properties in request") + .operationId("update" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid of resource to update")); + operation.addParametersItem(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdateSubresouce)); + responses.addApiResponse("201", response201); + break; - operation.setSummary("Edit with given uuid, only modifying properties in request"); - operation.setOperationId("update" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid of resource to update")); - operation.parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdate)); - operation.addResponse("201", response201); + case getSubresourceWithUUID: + operation.summary("Fetch " + resourceName + " subresources by uuid") + .operationId("get" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to filter by")); + operation.addParametersItem(v); + response200.content(new Content().addMediaType("application/json", + new MediaType().schema(new Schema().$ref(getSchemaRef(resourceName, resourceParentName, OperationEnum.getSubresourceWithUUID))))); + responses.addApiResponse("200", response200); + responses.addApiResponse("404", response404); + break; - } else if (operationEnum == OperationEnum.getSubresource) { + case delete: + operation.summary("Delete resource by uuid") + .operationId("delete" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to delete")); + responses.addApiResponse("204", response204); + responses.addApiResponse("404", response404); + break; - operation.setSummary("Fetch all non-retired " + resourceName + " subresources"); - operation.setOperationId("getAll" + getOperationTitle(resourceHandler, true)); - operation.setParameters(buildPagingParameters()); - operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); - operation.parameter(v); - operation.addResponse("200", response200.schema(new ObjectProperty() - .property("results", new ArrayProperty( - new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))))); - - } else if (operationEnum == OperationEnum.postSubresource) { - - operation.setSummary("Create " + resourceName + " subresource with properties in request"); - operation.setOperationId("create" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); - operation.parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postSubresource)); - operation.addResponse("201", response201); - - } else if (operationEnum == OperationEnum.postUpdateSubresouce) { - - operation.setSummary("edit " + resourceName - + " subresource with given uuid, only modifying properties in request"); - operation.setOperationId("update" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid of resource to update")); - operation - .parameter(buildPOSTBodyParameter(resourceName, resourceParentName, OperationEnum.postUpdateSubresouce)); - operation.addResponse("201", response201); - - } else if (operationEnum == OperationEnum.getSubresourceWithUUID) { - operation.setSummary("Fetch " + resourceName + " subresources by uuid"); - operation.setOperationId("get" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to filter by")); - operation.parameter(v); - operation.addResponse("200", response200.schema(new RefProperty(getSchemaRef(resourceName, resourceParentName, - OperationEnum.getSubresourceWithUUID)))); - operation.addResponse("404", response404); - - } else if (operationEnum == OperationEnum.delete) { - - operation.setSummary("Delete resource by uuid"); - operation.setOperationId("delete" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to delete")); - operation.response(204, response204); - operation.response(404, response404); - - } else if (operationEnum == OperationEnum.deleteSubresource) { - operation.setSummary("Delete " + resourceName + " subresource by uuid"); - operation.setOperationId("delete" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to delete")); - operation.response(204, response204); - operation.response(404, response404); - - } else if (operationEnum == OperationEnum.purge) { - - operation.setSummary("Purge resource by uuid"); - operation.setOperationId("purge" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to delete")); - operation.response(204, response204); - - } else if (operationEnum == OperationEnum.purgeSubresource) { - - operation.setSummary("Purge " + resourceName + " subresource by uuid"); - operation.setOperationId("purge" + getOperationTitle(resourceHandler, false)); - operation.parameter(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); - operation.parameter(buildRequiredUUIDParameter("uuid", "uuid to delete")); - operation.response(204, response204); + case deleteSubresource: + operation.summary("Delete " + resourceName + " subresource by uuid") + .operationId("delete" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to delete")); + responses.addApiResponse("204", response204); + responses.addApiResponse("404", response404); + break; + + case purge: + operation.summary("Purge resource by uuid") + .operationId("purge" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to delete")); + responses.addApiResponse("204", response204); + break; + + case purgeSubresource: + operation.summary("Purge " + resourceName + " subresource by uuid") + .operationId("purge" + getOperationTitle(resourceHandler, false)); + operation.addParametersItem(buildRequiredUUIDParameter("parent-uuid", "parent resource uuid")); + operation.addParametersItem(buildRequiredUUIDParameter("uuid", "uuid to delete")); + responses.addApiResponse("204", response204); + break; } - operation.response(401, response401); + responses.addApiResponse("401", response401); + operation.responses(responses); return operation; } @@ -1222,19 +1232,23 @@ public String getBaseUrl() { return baseUrl; } - public Swagger getSwagger() { - return swagger; + public OpenAPI getOpenAPI() { + if (openAPI == null) { + log.debug("OpenAPI object is null, creating new specification"); + BuildJSON(); + } + return openAPI; } /** - * @return true if and only if swagger is not null, and its paths are also set. + * @return true if and only if openAPI is not null, and its paths are also set. */ public static boolean isCached() { - return swagger != null && swagger.getPaths() != null; + return openAPI != null && openAPI.getPaths() != null; } public static void clearCache() { - swagger = null; + openAPI = null; } -} +} \ No newline at end of file diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/core/property/EnumProperty.java b/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/core/property/EnumProperty.java deleted file mode 100644 index 35348dee1..000000000 --- a/omod-common/src/main/java/org/openmrs/module/webservices/docs/swagger/core/property/EnumProperty.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * This Source Code Form is subject to the terms of the Mozilla Public License, - * v. 2.0. If a copy of the MPL was not distributed with this file, You can - * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under - * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. - * - * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS - * graphic logo is a trademark of OpenMRS Inc. - */ -package org.openmrs.module.webservices.docs.swagger.core.property; - -import io.swagger.models.properties.StringProperty; - -import java.util.Arrays; -import java.util.List; - -public class EnumProperty extends StringProperty { - - public EnumProperty(Class> e) { - _enum(getEnumsAsList(e)); - } - - private List getEnumsAsList(Class> e) { - return Arrays.asList(getEnums(e)); - } - - private String[] getEnums(Class> e) { - return Arrays.toString(e.getEnumConstants()) - .replaceAll("^.|.$", "").split(", "); - } -} diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java index 179b0327a..663eaf024 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingResource.java @@ -23,6 +23,10 @@ import java.util.Map.Entry; import java.util.Set; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; @@ -56,53 +60,43 @@ import org.openmrs.util.OpenmrsConstants; import org.openmrs.util.OpenmrsUtil; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.ObjectProperty; -import io.swagger.models.properties.StringProperty; - /** * A base implementation of a resource or sub-resource that delegates operations to a wrapped * object. Implementations generally should extend either {@link DelegatingCrudResource} or * {@link DelegatingSubResource} rather than this class directly. - * + * * @param the class we're delegating to */ public abstract class BaseDelegatingResource extends BaseDelegatingConverter implements Converter, Resource, DelegatingResourceHandler { - + private final Log log = LogFactory.getLog(getClass()); - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = new ModelImpl(); + public Schema getGETSchema(Representation rep) { + Schema schema = new Schema(); if (rep instanceof DefaultRepresentation) { - model - .property("links", new ArrayProperty() - .items(new ObjectProperty() - .property("rel", new StringProperty().example("self|full")) - .property("uri", new StringProperty(StringProperty.Format.URI)))); - + schema.addProperty("links", new ArraySchema() + .items(new ObjectSchema() + .addProperty("rel", new StringSchema().example("self|full")) + .addProperty("uri", new StringSchema().format("uri")))); } else if (rep instanceof FullRepresentation) { - model - .property("auditInfo", new StringProperty()) - .property("links", new ArrayProperty() - .items(new ObjectProperty() - .property("rel", new StringProperty()).example("self") - .property("uri", new StringProperty(StringProperty.Format.URI)))); - + schema + .addProperty("auditInfo", new StringSchema()) + .addProperty("links", new ArraySchema() + .items(new ObjectSchema() + .addProperty("rel", new StringSchema().example("self")) + .addProperty("uri", new StringSchema().format("uri")))); } else if (rep instanceof RefRepresentation) { - model - .property("links", new ArrayProperty() - .items(new ObjectProperty() - .property("rel", new StringProperty().example("self")) - .property("uri", new StringProperty(StringProperty.Format.URI)))); + schema.addProperty("links", new ArraySchema() + .items(new ObjectSchema() + .addProperty("rel", new StringSchema().example("self")) + .addProperty("uri", new StringSchema().format("uri")))); } - return model; + return schema; } - + protected Set propertiesIgnoredWhenUpdating = new HashSet(); - + /** * Properties that should silently be ignored if you try to get them. Implementations should * generally configure this property with a list of properties that were added to their @@ -111,13 +105,13 @@ public Model getGETModel(Representation rep) { * wasn't added to PatientIdentifierType until OpenMRS 1.9. delegate class */ protected Set allowedMissingProperties = new HashSet(); - + /** * If this resource represents a class hierarchy (rather than a single class), this will hold * handlers for each subclass */ protected volatile List> subclassHandlers; - + /** * Default constructor will set propertiesIgnoredWhenUpdating to include "display", "links", and * "resourceVersion" @@ -128,18 +122,18 @@ protected BaseDelegatingResource() { propertiesIgnoredWhenUpdating.add("auditInfo"); propertiesIgnoredWhenUpdating.add(RestConstants.PROPERTY_FOR_RESOURCE_VERSION); } - + /** * All our resources support letting modules register subclass handlers. If any are registered, * then the resource represents a class hierarchy, e.g. requiring a "type" parameter when * creating a new instance. - * + * * @return whether there are any subclass handlers registered with this resource */ public boolean hasTypesDefined() { return subclassHandlers != null && subclassHandlers.size() > 0; } - + /** * This will be automatically called with the first call to {@link #getSubclassHandler(Class)} * or {@link #getSubclassHandler(String)}. It finds all subclass handlers intended for this @@ -148,21 +142,21 @@ public boolean hasTypesDefined() { @SuppressWarnings({ "unchecked", "rawtypes" }) public void init() { List> tmpSubclassHandlers = new ArrayList>(); - + List handlers = Context.getRegisteredComponents(DelegatingSubclassHandler.class); for (DelegatingSubclassHandler handler : handlers) { - + Class handlerClass = handler.getClass(); Class forDelegateClass = ReflectionUtil.getParameterizedTypeFromInterface(handlerClass, - DelegatingSubclassHandler.class, 0); + DelegatingSubclassHandler.class, 0); if (forDelegateClass == null) { throw new IllegalStateException( - "Could not determine type information. Make sure that " - + handlerClass.getName() - + " explicitly says implements DelegatingSubclassHandler<...>. It is not sufficient to just extend a base class that implements this."); + "Could not determine type information. Make sure that " + + handlerClass.getName() + + " explicitly says implements DelegatingSubclassHandler<...>. It is not sufficient to just extend a base class that implements this."); } Resource resourceForHandler = Context.getService(RestService.class) - .getResourceBySupportedClass(forDelegateClass); + .getResourceBySupportedClass(forDelegateClass); if (getClass().equals(resourceForHandler.getClass())) { SubClassHandler annotation = handlerClass.getAnnotation(SubClassHandler.class); if (annotation != null) { @@ -175,18 +169,18 @@ public void init() { } } else { log.warn("SubclassHandler " - + handlerClass.getName() - + " does not have a @SubClassHandler annotation. This can cause conflicts in resolving handlers for your subclass."); + + handlerClass.getName() + + " does not have a @SubClassHandler annotation. This can cause conflicts in resolving handlers for your subclass."); } } } - + subclassHandlers = tmpSubclassHandlers; } - + /** * Registers the given subclass handler. - * + * * @param handler */ public void registerSubclassHandler(DelegatingSubclassHandler handler) { @@ -201,7 +195,7 @@ public void registerSubclassHandler(DelegatingSubclassHandler ha } subclassHandlers.add(handler); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getResourceVersion() */ @@ -209,22 +203,22 @@ public void registerSubclassHandler(DelegatingSubclassHandler ha public String getResourceVersion() { return RestConstants.PROPERTY_FOR_RESOURCE_VERSION_DEFAULT_VALUE; } - + /** * @return the value of the {@link org.openmrs.module.webservices.rest.web.annotation.Resource} * annotation on the concrete subclass */ protected String getResourceName() { org.openmrs.module.webservices.rest.web.annotation.Resource ann = getClass().getAnnotation( - org.openmrs.module.webservices.rest.web.annotation.Resource.class); + org.openmrs.module.webservices.rest.web.annotation.Resource.class); if (ann == null) throw new RuntimeException("There is no " + Resource.class + " annotation on " + getClass()); if (StringUtils.isEmpty(ann.name())) throw new RuntimeException(Resource.class.getSimpleName() + " annotation on " + getClass() - + " must specify a name"); + + " must specify a name"); return ann.name(); } - + /** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#newInstance(java.lang.String) */ @@ -233,67 +227,67 @@ public T newInstance(String type) { if (hasTypesDefined()) { if (type == null) throw new IllegalArgumentException(getClass().getSimpleName() + " requires a '" - + RestConstants.PROPERTY_FOR_TYPE + "' property to create a new object"); + + RestConstants.PROPERTY_FOR_TYPE + "' property to create a new object"); DelegatingResourceHandler handler = getResourceHandler(type); return handler.newDelegate(); } else { return newDelegate(); } } - + /** * Gets the delegate object with the given unique id. Implementations may decide whether * "unique id" means a uuid, or if they also want to retrieve delegates based on a unique * human-readable property. - * + * * @param uniqueId * @return the delegate for the given uniqueId */ @Override public abstract T getByUniqueId(String uniqueId); - + /** * Void or retire delegate, whichever action is appropriate for the resource type. Subclasses * need to override this method, which is called internally by * {@link #delete(String, String, RequestContext)}. - * + * * @param delegate * @param reason * @param context * @throws ResponseException */ protected abstract void delete(T delegate, String reason, RequestContext context) throws ResponseException; - + /** * Unvoid or unretire delegate, whichever action is appropriate for the resource type. * Subclasses need to override this method, which is called internally by * {@link #undelete(String, RequestContext)}. - * + * * @param delegate * @param context * @throws ResponseException * @return Object */ protected T undelete(T delegate, RequestContext context) throws ResponseException { - //Default implementation of this method if not overriden by sub-class is to raise an + //Default implementation of this method if not overriden by sub-class is to raise an //exception stating "undelete action not yet supported for this resource" throw new ResourceDoesNotSupportOperationException("undelete action not yet supported for this resource"); } - + /** * Purge delegate from persistent storage. Subclasses need to override this method, which is * called internally by {@link #purge(String, RequestContext)}. - * + * * @param delegate * @param context * @throws ResponseException */ @Override public abstract void purge(T delegate, RequestContext context) throws ResponseException; - + /** * Gets a description of resource's properties which can be set on creation. - * + * * @return the description * @throws ResponseException */ @@ -301,18 +295,18 @@ protected T undelete(T delegate, RequestContext context) throws ResponseExceptio public DelegatingResourceDescription getCreatableProperties() throws ResourceDoesNotSupportOperationException { throw new ResourceDoesNotSupportOperationException(); } - + @Override - public Model getCREATEModel(Representation rep) { + public Schema getCREATESchema(Representation rep) { return null; } - + /** * Gets a description of resource's properties which can be edited. *

* By default delegates to {@link #getCreatableProperties()} and removes sub-resources returned * by {@link #getPropertiesToExposeAsSubResources()}. - * + * * @return the description * @throws ResponseException */ @@ -324,29 +318,29 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } return description; } - + @Override - public Model getUPDATEModel(Representation rep) { - ModelImpl model = (ModelImpl) getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + ObjectSchema schema = (ObjectSchema) getCREATESchema(rep); for (String property : getPropertiesToExposeAsSubResources()) { - model.getProperties().remove(property); + schema.getProperties().remove(property); } - return model; + return schema; } - + /** * Implementations should override this method if they support sub-resources - * + * * @return a list of properties available as sub-resources or an empty list */ public List getPropertiesToExposeAsSubResources() { return Collections.emptyList(); } - + /** * Implementations should override this method if T is not uniquely identified by a "uuid" * property. - * + * * @param delegate * @return the uuid property of delegate */ @@ -358,11 +352,11 @@ protected String getUniqueId(T delegate) { throw new RuntimeException("Cannot find String uuid property on " + delegate.getClass(), null); } } - + /** * Creates an object of the given representation, pulling values from fields and methods as * specified by a subclass - * + * * @param representation * @return * Should return valid RefRepresentation @@ -373,20 +367,20 @@ protected String getUniqueId(T delegate) { public SimpleObject asRepresentation(T delegate, Representation representation) throws ConversionException { if (delegate == null) throw new NullPointerException(); - + DelegatingResourceHandler handler = getResourceHandler(delegate); - + // first call getRepresentationDescription() DelegatingResourceDescription repDescription = handler.getRepresentationDescription(representation); if (repDescription != null) { SimpleObject simple = convertDelegateToRepresentation(delegate, repDescription); - + maybeDecorateWithType(simple, delegate); decorateWithResourceVersion(simple, representation); - + return simple; } - + // otherwise look for a method annotated to handle this representation Method meth = findAnnotatedMethodForRepresentation(handler.getClass(), representation); if (meth != null) { @@ -397,30 +391,30 @@ public SimpleObject asRepresentation(T delegate, Representation representation) simple = (SimpleObject) meth.invoke(handler, delegate); else simple = (SimpleObject) meth.invoke(handler, delegate, representation); - + maybeDecorateWithType(simple, delegate); decorateWithResourceVersion(simple, representation); - + return simple; } catch (Exception ex) { throw new ConversionException(null, ex); } } - + // finally if it is a custom representation and not supported by any other handler if (representation instanceof CustomRepresentation) { repDescription = ConversionUtil.getCustomRepresentationDescription((CustomRepresentation) representation); return convertDelegateToRepresentation(delegate, repDescription); } - + throw new ConversionException("Don't know how to get " + getClass().getSimpleName() + "(" + delegate.getClass() - + ") as " + representation.getRepresentation(), null); + + ") as " + representation.getRepresentation(), null); } - + /** * Sets resourceVersion to {@link #getResourceVersion()} for representations other than REF. - * + * * @param simple the simplified representation which will be decorated with the resource version * @param representation the type of representation */ @@ -429,10 +423,10 @@ private void decorateWithResourceVersion(SimpleObject simple, Representation rep simple.put(RestConstants.PROPERTY_FOR_RESOURCE_VERSION, getResourceVersion()); } } - + /** * If this resource supports subclasses, then we add a type property to the input, and return it - * + * * @param simple simplified representation which will be decorated with the user-friendly type * name * @param delegate the object that simple represents @@ -441,11 +435,11 @@ private void maybeDecorateWithType(SimpleObject simple, T delegate) { if (hasTypesDefined()) simple.add(RestConstants.PROPERTY_FOR_TYPE, getTypeName(delegate)); } - + /** * If this resources supports subclasses, this method gets the user-friendly type name for the * given subclass - * + * * @param subclass * @return */ @@ -463,14 +457,14 @@ protected String getTypeName(Class subclass) { } return null; } - + /** * @see #getTypeName(Class) */ protected String getTypeName(T delegate) { return getTypeName((Class) delegate.getClass()); } - + /** * @param type user-friendly type name * @return the actual java class for this type @@ -482,7 +476,7 @@ protected Class getActualSubclass(String type) { // otherwise we need to return our own declared class return ReflectionUtil.getParameterizedTypeFromInterface(getClass(), DelegatingResourceHandler.class, 0); } - + /** * @param type user-friendly type name * @return a subclass handler if any is suitable for type, or this resource itself if it is @@ -497,9 +491,9 @@ protected DelegatingResourceHandler getResourceHandler(String type) if (getResourceName().endsWith(type)) return this; throw new IllegalArgumentException("type=" + type + " is not handled by this resource (" + getClass() - + ") or any subclass"); + + ") or any subclass"); } - + /** * Delegates to @see {@link #getResourceHandler(Class)} */ @@ -511,7 +505,7 @@ protected DelegatingResourceHandler getResourceHandler(T delegate) return null; return getResourceHandler((Class) delegate.getClass()); } - + /** * @param clazz * @return a subclass handler if any is suitable for the given class, or this resource itself if @@ -525,7 +519,7 @@ protected DelegatingResourceHandler getResourceHandler(Class getResourceHandler(Class getResourceHandler(Class getResourceHandler(Class getResourceHandler(ClassShould allow setting a null value */ public void setConvertedProperties(T delegate, Map propertyMap, - DelegatingResourceDescription description, boolean mustIncludeRequiredProperties) throws ConversionException { + DelegatingResourceDescription description, boolean mustIncludeRequiredProperties) throws ConversionException { Map allowedProperties = new LinkedHashMap(description.getProperties()); - + Map propertiesToSet = new HashMap(propertyMap); propertiesToSet.keySet().removeAll(propertiesIgnoredWhenUpdating); - + // Apply properties in the order specified in the resource description (necessary e.g. so the obs resource // can apply "concept" before "value"); we have already excluded unchanged and ignored properties. // Because some resources (e.g. any AttributeResource) require some properties to be set before others can @@ -599,14 +593,14 @@ public void setConvertedProperties(T delegate, Map propertyMap, propertiesToSet.remove(property); continue; } - + setProperty(delegate, property, propertiesToSet.get(property)); } } - + // If any non-settable properties remain after the above logic, fail Collection notAllowedProperties = CollectionUtils.subtract(propertiesToSet.keySet(), - allowedProperties.keySet()); + allowedProperties.keySet()); // Do allow posting back an unchanged value to an unchangeable property for (Iterator iterator = notAllowedProperties.iterator(); iterator.hasNext();) { String property = iterator.next(); @@ -618,9 +612,9 @@ public void setConvertedProperties(T delegate, Map propertyMap, } if (!notAllowedProperties.isEmpty()) { throw new ConversionException("Some properties are not allowed to be set: " - + StringUtils.join(notAllowedProperties, ", ")); + + StringUtils.join(notAllowedProperties, ", ")); } - + if (mustIncludeRequiredProperties) { Set missingProperties = new HashSet(); for (Entry prop : allowedProperties.entrySet()) { @@ -630,11 +624,11 @@ public void setConvertedProperties(T delegate, Map propertyMap, } if (!missingProperties.isEmpty()) { throw new ConversionException("Some required properties are missing: " - + StringUtils.join(missingProperties, ", ")); + + StringUtils.join(missingProperties, ", ")); } } } - + private boolean unchangedValue(Object oldValue, Object newValue) { if (newValue instanceof Map && oldValue != null && !(oldValue instanceof Map)) { newValue = ConversionUtil.convert(newValue, oldValue.getClass()); @@ -644,11 +638,11 @@ private boolean unchangedValue(Object oldValue, Object newValue) { } return OpenmrsUtil.nullSafeEquals(oldValue, newValue); } - + /** * Finds a method on clazz or a superclass that is annotated with {@link RepHandler} and is * suitable for rep - * + * * @param clazz * @param rep * @return @@ -664,7 +658,7 @@ private Method findAnnotatedMethodForRepresentation(Class clazz, Representati } return null; } - + /** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#getProperty(java.lang.Object, * java.lang.String) @@ -673,13 +667,13 @@ private Method findAnnotatedMethodForRepresentation(Class clazz, Representati public Object getProperty(T instance, String propertyName) throws ConversionException { try { DelegatingResourceHandler handler = getResourceHandler(instance); - + // try to find a @PropertyGetter-annotated method Method annotatedGetter = ReflectionUtil.findPropertyGetterMethod(handler, propertyName); if (annotatedGetter != null) { return annotatedGetter.invoke(handler, instance); } - + return PropertyUtils.getProperty(instance, propertyName); } catch (Exception ex) { @@ -689,7 +683,7 @@ public Object getProperty(T instance, String propertyName) throws ConversionExce throw new ConversionException(propertyName + " on " + instance.getClass(), ex); } } - + /** * @see org.openmrs.module.webservices.rest.web.resource.api.Converter#setProperty(java.lang.Object, * java.lang.String, java.lang.Object) @@ -701,7 +695,7 @@ public void setProperty(Object instance, String propertyName, Object value) thro } try { DelegatingResourceHandler handler; - + try { handler = getResourceHandler((T) instance); } @@ -710,7 +704,7 @@ public void setProperty(Object instance, String propertyName, Object value) thro // but I'm putting in here just in case handler = this; } - + // try to find a @PropertySetter-annotated method Method annotatedSetter = ReflectionUtil.findPropertySetterMethod(handler, propertyName); if (annotatedSetter != null) { @@ -719,25 +713,25 @@ public void setProperty(Object instance, String propertyName, Object value) thro annotatedSetter.invoke(handler, instance, value); return; } - + // we need the generic type of this property, not just the class Method setter = PropertyUtils.getPropertyDescriptor(instance, propertyName).getWriteMethod(); - + // Convert the value to the specified type value = ConversionUtil.convert(value, setter.getGenericParameterTypes()[0], instance); - + setPropertyWhichMayBeAHibernateCollection(instance, propertyName, value); } catch (Exception ex) { throw new ConversionException(propertyName + " on " + instance.getClass(), ex); } } - + /** * Removes any elements from the passed-in collection that aren't of the given type. This is a * convenience method for subclass-aware resources that want to limit query results to a given * type. - * + * * @param collection * @param type a user-friendly type name */ @@ -748,11 +742,11 @@ protected void filterByType(Collection collection, String type) { i.remove(); } } - + /** * Convenience method that looks for a specific method on the subclass handler for the given * type - * + * * @param type user-friendly type name * @param methodName * @param argumentTypes @@ -769,11 +763,11 @@ protected Method findSubclassHandlerMethod(String type, String methodName, Class return null; } } - + /** * Convenience method that finds a specific method on the subclass handler for the given type, * and invokes it - * + * * @param type user-friendly type name * @param methodName * @param arguments @@ -802,7 +796,7 @@ protected Object findAndInvokeSubclassHandlerMethod(String type, String methodNa throw new RuntimeException(ex); } } - + /** * @param delegate * @return the URI for the given delegate object @@ -812,15 +806,15 @@ protected Object findAndInvokeSubclassHandlerMethod(String type, String methodNa public String getUri(Object delegate) { if (delegate == null) return ""; - + org.openmrs.module.webservices.rest.web.annotation.Resource res = getClass().getAnnotation( - org.openmrs.module.webservices.rest.web.annotation.Resource.class); + org.openmrs.module.webservices.rest.web.annotation.Resource.class); if (res != null) { return RestConstants.URI_PREFIX + res.name() + "/" + getUniqueId((T) delegate); } throw new RuntimeException(getClass() + " needs a @Resource or @SubResource annotation"); } - + /** * @see org.openmrs.module.webservices.rest.util.ReflectionUtil#findMethod(Class,String) * @deprecated It is always best to annotate the method with @PropertyGetter instead of finding @@ -831,10 +825,10 @@ public String getUri(Object delegate) { protected Method findMethod(String name) { return ReflectionUtil.findMethod(getClass(), name); } - + /** * Gets the audit information of a resource. - * + * * @param resource the resource. * @return a {@link SimpleObject} with the audit information. */ @@ -842,10 +836,10 @@ protected Method findMethod(String name) { public SimpleObject getAuditInfo(Object resource) { return ConversionUtil.getAuditInfo(resource); } - + @Override public T newDelegate(SimpleObject object) { return newDelegate(); } - + } diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingSubclassHandler.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingSubclassHandler.java index c7796267a..6d85da5e8 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingSubclassHandler.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/BaseDelegatingSubclassHandler.java @@ -9,7 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.resource.impl; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.OpenmrsData; import org.openmrs.OpenmrsMetadata; import org.openmrs.api.context.Context; @@ -78,8 +78,8 @@ public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoe } @Override - public Model getUPDATEModel(Representation rep) { - return getCREATEModel(rep); + public Schema getUPDATESchema(Representation rep) { + return getCREATESchema(rep); } /** diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingResourceHandler.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingResourceHandler.java index 23aa4f01d..38ef4c108 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingResourceHandler.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/DelegatingResourceHandler.java @@ -9,7 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.resource.impl; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.representation.Representation; @@ -23,8 +23,8 @@ * @param the class of the delegate this resource handles */ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor { - - /** + + /** * Indicates a version of the supported resource. * * @return the resource version @@ -34,7 +34,7 @@ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor /** * Instantiates a new instance of the handled delegate * - * @return + * @return T */ T newDelegate(); @@ -45,7 +45,7 @@ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor * to {@link #newDelegate()}. * * @param object - * @return + * @return T */ T newDelegate(SimpleObject object); @@ -91,37 +91,37 @@ public interface DelegatingResourceHandler extends DelegatingPropertyAccessor DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException; /** - * Returns a {@link Model} object representing GET representation schema for the resource. + * Returns a {@link Schema} object representing GET representation schema for the resource. * - * @param rep representation type under which the resource {@link Model} should be fetched. It + * @param rep representation type under which the resource {@link Schema} should be fetched. It * can take {@link Representation#DEFAULT}, {@link Representation#REF}, or * {@link Representation#FULL} - * @return a {@link Model} object or null in case if such model does not exist or not + * @return a {@link Schema} object or null in case if such model does not exist or not * documented. */ - Model getGETModel(Representation rep); + Schema getGETSchema(Representation rep); /** - * Returns a {@link Model} object representing CREATE representation schema for the resource. + * Returns a {@link Schema} object representing CREATE representation schema for the resource. * The returned model object will hold properties (and example values) required to create the * underlying resource. * - * @param rep representation type under which the resource {@link Model} should be fetched. It + * @param rep representation type under which the resource {@link Schema} should be fetched. It * can take {@link Representation#DEFAULT}, or {@link Representation#FULL} - * @return a {@link Model} object or null in case if such model does not exist or not + * @return a {@link Schema} object or null in case if such model does not exist or not * documented. */ - Model getCREATEModel(Representation rep); + Schema getCREATESchema(Representation rep); /** - * Returns a {@link Model} object representing UPDATE representation schema for the resource. + * Returns a {@link Schema} object representing UPDATE representation schema for the resource. * The returned model object will hold properties (and example values) required to update the * underlying resource. * - * @param rep representation type under which the resource {@link Model} should be fetched. It + * @param rep representation type under which the resource {@link Schema} should be fetched. It * can take {@link Representation#DEFAULT}, or {@link Representation#FULL} - * @return a {@link Model} object or null in case if such model does not exist or not + * @return a {@link Schema} object or null in case if such model does not exist or not * documented. */ - Model getUPDATEModel(Representation rep); + Schema getUPDATESchema(Representation rep); } diff --git a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java index bf4defa25..2aacd0d38 100644 --- a/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java +++ b/omod-common/src/main/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResource.java @@ -9,12 +9,13 @@ */ package org.openmrs.module.webservices.rest.web.resource.impl; +import java.util.Collections; import java.util.Date; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.properties.BooleanProperty; -import io.swagger.models.properties.StringProperty; +import io.swagger.v3.oas.models.media.BooleanSchema; +import io.swagger.v3.oas.models.media.ObjectSchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.media.StringSchema; import org.apache.commons.lang.StringUtils; import org.openmrs.OpenmrsMetadata; import org.openmrs.api.context.Context; @@ -37,27 +38,31 @@ * @param */ public abstract class MetadataDelegatingCrudResource extends DelegatingCrudResource { - + @Override - public Model getGETModel(Representation rep) { - ModelImpl model = ((ModelImpl) super.getGETModel(rep)) - .property("uuid", new StringProperty()) - .property("display", new StringProperty()); + public Schema getGETSchema(Representation rep) { + Schema schema = super.getGETSchema(rep); + schema + .addProperty("uuid", new StringSchema()) + .addProperty("display", new StringSchema()); + if (rep instanceof FullRepresentation) { - model - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .property("retired", new BooleanProperty()); + schema + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()) + .addProperty("retired", new BooleanSchema()); } - return model; + return schema; } - + @Override - public Model getCREATEModel(Representation rep) { - return new ModelImpl() - .property("name", new StringProperty()) - .property("description", new StringProperty()) - .required("name"); + public Schema getCREATESchema(Representation rep) { + ObjectSchema schema = new ObjectSchema(); + schema + .addProperty("name", new StringSchema()) + .addProperty("description", new StringSchema()); + schema.setRequired(Collections.singletonList("name")); + return schema; } /** diff --git a/omod-common/src/test/java/org/mockingbird/test/rest/resource/CatSubclassHandler_1_9.java b/omod-common/src/test/java/org/mockingbird/test/rest/resource/CatSubclassHandler_1_9.java index 8ce4ad0ba..1b900572e 100644 --- a/omod-common/src/test/java/org/mockingbird/test/rest/resource/CatSubclassHandler_1_9.java +++ b/omod-common/src/test/java/org/mockingbird/test/rest/resource/CatSubclassHandler_1_9.java @@ -9,7 +9,7 @@ */ package org.mockingbird.test.rest.resource; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.mockingbird.test.Animal; import org.mockingbird.test.Cat; import org.openmrs.module.webservices.rest.SimpleObject; @@ -89,19 +89,19 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { return null; } - + @Override - public Model getGETModel(Representation representation) { + public Schema getGETSchema(Representation rep) { return null; } - + @Override - public Model getCREATEModel(Representation representation) { + public Schema getCREATESchema(Representation rep) { return null; } - + @Override - public Model getUPDATEModel(Representation representation) { + public Schema getUPDATESchema(Representation rep) { return null; } } diff --git a/omod-common/src/test/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResourceTest.java b/omod-common/src/test/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResourceTest.java index 7ff2fce86..b9ede12d3 100644 --- a/omod-common/src/test/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResourceTest.java +++ b/omod-common/src/test/java/org/openmrs/module/webservices/rest/web/resource/impl/MetadataDelegatingCrudResourceTest.java @@ -9,7 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.resource.impl; -import io.swagger.models.Model; +import io.swagger.v3.oas.models.media.Schema; import org.junit.Test; import org.openmrs.Location; import org.openmrs.api.context.ServiceContext; @@ -101,19 +101,19 @@ public void purge(Location delegate, RequestContext context) throws ResponseExce public DelegatingResourceDescription getRepresentationDescription(Representation rep) { return null; } - + @Override - public Model getGETModel(Representation representation) { + public Schema getGETSchema(Representation rep) { return null; } - + @Override - public Model getCREATEModel(Representation representation) { + public Schema getCREATESchema(Representation rep) { return null; } - + @Override - public Model getUPDATEModel(Representation representation) { + public Schema getUPDATESchema(Representation rep) { return null; } } diff --git a/omod/src/main/java/org/openmrs/module/webservices/rest/web/controller/SwaggerSpecificationController.java b/omod/src/main/java/org/openmrs/module/webservices/rest/web/controller/SwaggerSpecificationController.java index af6c74777..17f3db3e6 100644 --- a/omod/src/main/java/org/openmrs/module/webservices/rest/web/controller/SwaggerSpecificationController.java +++ b/omod/src/main/java/org/openmrs/module/webservices/rest/web/controller/SwaggerSpecificationController.java @@ -9,8 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.controller; -import com.google.common.net.HttpHeaders; -import io.swagger.models.Scheme; import org.openmrs.module.webservices.docs.swagger.SwaggerSpecificationCreator; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -24,22 +22,25 @@ public class SwaggerSpecificationController { @RequestMapping(method = RequestMethod.GET) - public @ResponseBody - String getSwaggerSpecification(HttpServletRequest request) throws Exception { + @SuppressWarnings("unused") + public @ResponseBody String getOpenAPISpecification(HttpServletRequest request) throws Exception { - String host = request.getHeader(HttpHeaders.HOST); + String host = request.getServerName(); + int port = request.getServerPort(); + String contextPath = request.getContextPath(); - String scheme = request.getHeader(HttpHeaders.X_FORWARDED_PROTO); + String scheme = request.getHeader("X-Forwarded-Proto"); if (scheme == null) { scheme = request.getScheme(); } - return new SwaggerSpecificationCreator() - .host(host) - .basePath(request.getContextPath() + "/ws/rest/v1") - .scheme(Scheme.forValue(scheme)) - - .getJSON(); + String baseUrl = scheme + "://" + host + (port == 80 || port == 443 ? "" : ":" + port) + contextPath; + + SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(); + creator.host(baseUrl) + .basePath("/ws/rest/v1"); + + return creator.getJSON(); } } diff --git a/omod/src/main/webapp/apiDocs.jsp b/omod/src/main/webapp/apiDocs.jsp index 011bc8a30..0209d8f17 100644 --- a/omod/src/main/webapp/apiDocs.jsp +++ b/omod/src/main/webapp/apiDocs.jsp @@ -8,7 +8,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -72,15 +72,15 @@

- - + +