Skip to content

Commit

Permalink
RESTWS-958: Ensure the REST Module Api Docs are upgraded to use Swagg…
Browse files Browse the repository at this point in the history
…er 2.2.23
  • Loading branch information
mherman22 committed Oct 15, 2024
1 parent 14701fd commit e47142d
Show file tree
Hide file tree
Showing 123 changed files with 3,927 additions and 4,435 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CareSetting.CareSettingType>()
.type("string")
._enum(Arrays.asList(CareSetting.CareSettingType.values())));
}
return model;
return schema;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<Drug>().$ref("#/components/schemas/DrugGetRef"))
.addProperty("conceptReferenceTerm", new Schema<ConceptReferenceTerm>().$ref("#/components/schemas/ConceptreferencetermGetRef"))
.addProperty("conceptMapType", new Schema<ConceptMapType>().$ref("#/components/schemas/ConceptmaptypeGetRef"));
} else if (rep instanceof FullRepresentation) {
schema
.addProperty("auditInfo", new StringSchema())
.addProperty("drug", new Schema<Drug>().$ref("#/components/schemas/DrugGet"))
.addProperty("conceptReferenceTerm", new Schema<ConceptReferenceTerm>().$ref("#/components/schemas/ConceptreferencetermGet"))
.addProperty("conceptMapType", new Schema<ConceptMapType>().$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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<DrugReferenceMap>().$ref("#/components/schemas/DrugreferencemapGetRef"));
} else if (rep instanceof FullRepresentation) {
schema.addProperty("drugReferenceMaps", new Schema<DrugReferenceMap>().$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<DrugReferenceMap>().$ref("#/components/schemas/DrugreferencemapCreate"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Order.Action>()._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<Order.Urgency>()._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<Encounter>().$ref("#/components/schemas/EncounterCreate"))
.addProperty("patient", new Schema<Patient>().$ref("#/components/schemas/PatientCreate"))
.addProperty("concept", new Schema<Concept>().$ref("#/components/schemas/ConceptCreate"))
.addProperty("orderer", new Schema<User>().$ref("#/components/schemas/UserCreate"))
.addProperty("previousOrder", new Schema<Order>().$ref("#/components/schemas/OrderCreate"))
.addProperty("orderReason", new Schema<Concept>().$ref("#/components/schemas/ConceptCreate"))
.addProperty("orderReasonNonCoded", new StringSchema())
.addProperty("instructions", new StringSchema())
.addProperty("commentToFulfiller", new StringSchema());
}
return model;
return schema;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ConceptClass>().$ref("#/components/schemas/ConceptclassGetRef")))
.addProperty("parent", new Schema<OrderType>().$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<ConceptClass>().$ref("#/components/schemas/ConceptclassGetFull")))
.addProperty("parent", new Schema<OrderType>().$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;
}
}
Loading

0 comments on commit e47142d

Please sign in to comment.