Skip to content

Commit

Permalink
RESTWS-957: Fix Swagger definition errors for subclass resources in m…
Browse files Browse the repository at this point in the history
…odules extending REST servicae (#630)
  • Loading branch information
mherman22 authored Oct 15, 2024
1 parent 2bb38f2 commit 61a27fa
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ public Model getCREATEModel(Representation rep) {
.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("orderReason", new RefProperty("#/definitions/ConceptCreate"))
.property("orderReasonNonCoded", new StringProperty())
.property("instructions", new StringProperty())
.property("commentToFulfiller", new StringProperty());
}
//FIXME missing prop: type
return model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public Model getCREATEModel(Representation rep) {

@Override
public Model getUPDATEModel(Representation rep) {
return new ModelImpl(); //FIXME missing props
return getCREATEModel(rep);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import io.swagger.models.properties.UUIDProperty;
import org.apache.commons.lang3.StringUtils;
import org.openmrs.ConceptReferenceTerm;
import org.openmrs.api.ConceptService;
Expand Down Expand Up @@ -95,28 +96,26 @@ public DelegatingResourceDescription getCreatableProperties() {
@Override
public Model getGETModel(Representation rep) {
ModelImpl model = (ModelImpl) super.getGETModel(rep);
if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) {
model
.property("code", new StringProperty())
.property("version", new StringProperty());

}
if (rep instanceof DefaultRepresentation) {
model
.property("conceptSource", new RefProperty("#/definitions/ConceptsourceGetRef"));
model.property("uuid", new UUIDProperty());
model.property("conceptSource", new RefProperty("#/definitions/ConceptsourceGetRef"));
model.property("code", new StringProperty());
model.property("version", new StringProperty());
} else if (rep instanceof FullRepresentation) {
model
.property("conceptSource", new RefProperty("#/definitions/ConceptsourceGet"));
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());
}
return model;

}

@Override
public Model getCREATEModel(Representation rep) {
return ((ModelImpl) super.getCREATEModel(rep))
.property("code", new StringProperty())
.property("conceptSource", new StringProperty())
.property("conceptSource", new RefProperty("#/definitions/ConceptsourceCreate"))
.property("version", new StringProperty())

.required("code").required("conceptSource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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.DateProperty;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import org.openmrs.Concept;
import org.openmrs.ConceptProposal;
import org.openmrs.User;
Expand Down Expand Up @@ -107,6 +112,49 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
return null;
}

@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());
}
return model;
}

@PropertyGetter("occurrences")
public Integer getOccurrencesProperty(ConceptProposal proposal) {
Map<String, List<ConceptProposal>> proposalsMap = getProposalsMapByOriginalText(false);
Expand All @@ -128,6 +176,15 @@ public DelegatingResourceDescription getCreatableProperties() throws ResourceDoe
return description;
}

@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"));
}

@Override
public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException {
DelegatingResourceDescription description = new DelegatingResourceDescription();
Expand All @@ -139,6 +196,17 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@ public Model getCREATEModel(Representation rep) {
ModelImpl model = new ModelImpl();
if (rep instanceof DefaultRepresentation) {
model
.property("concept", new RefProperty("#/definitions/ConceptGetRef"))
.property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreateRef")))
.property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreateRef")));
.property("concept", new RefProperty("#/definitions/ConceptCreate"))
.property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreate")))
.property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreate")));
} else if (rep instanceof FullRepresentation) {
model
.property("concept", new RefProperty("#/definitions/ConceptGetRef"))
.property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowGet")))
.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/ConceptGetRef"))
.property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreateRef")))
.property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreateRef")));
.property("concept", new RefProperty("#/definitions/ConceptCreate"))
.property("programWorkflow", new ArrayProperty(new RefProperty("#/definitions/WorkflowCreate")))
.property("programWorkflowState", new ArrayProperty(new RefProperty("#/definitions/WorkflowStateCreate")));
}
return model;
}
Expand Down
Loading

0 comments on commit 61a27fa

Please sign in to comment.