Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTWS-958: Ensure the module's rest is updated to use swagger 3.0 #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,6 @@
REST interface
</description>

<dependencies>
<!--
Add other dependencies from parent's pom:
<dependency>
<groupId>org.other.library</groupId>
<artifactId>library-name</artifactId>
</dependency>
-->

<!-- Begin OpenMRS core -->
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<scope>compile</scope>
</dependency>
<!-- End OpenMRS core -->
</dependencies>

<build>
<resources>
<resource>
Expand Down
54 changes: 24 additions & 30 deletions omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,58 @@
</description>

<dependencies>
<!--
Add other dependencies from parent's pom:
<dependency>
<groupId>org.other.library</groupId>
<artifactId>library-name</artifactId>
</dependency>
-->

<!-- Begin OpenMRS modules -->
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api</artifactId>
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod</artifactId>
<artifactId>legacyui-omod</artifactId>
</dependency>
<!-- End OpenMRS modules -->
<!-- Begin Rest Web Services -->
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod-common</artifactId>
<artifactId>webservices.rest-omod-1.8</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod-common</artifactId>
<artifactId>webservices.rest-omod-2.0</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>legacyui-omod</artifactId>
<artifactId>webservices.rest-omod-2.0</artifactId>
<scope>provided</scope>
</dependency>
<!-- End OpenMRS modules -->


<!-- Begin OpenMRS core -->
<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
</dependency>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<type>test-jar</type>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod-1.8</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openmrs.web</groupId>
<artifactId>openmrs-web</artifactId>
<type>test-jar</type>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod-common</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<scope>test</scope>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest-omod-common</artifactId>
<scope>provided</scope>
</dependency>
<!-- End OpenMRS core -->
<!-- End Rest Web Services -->

<dependency>
<groupId>javax.servlet</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import java.util.Collection;
import java.util.Set;

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.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.media.UUIDSchema;
import org.openmrs.Cohort;
import org.openmrs.Patient;
import org.openmrs.PatientIdentifier;
import org.openmrs.api.context.Context;
Expand Down Expand Up @@ -103,39 +103,36 @@ public DelegatingResourceDescription getUpdatableProperties() {
}

@Override
public Model getCREATEModel(Representation rep) {
return new ModelImpl().property("cohort", new RefProperty("#/definitions/CohortCreate"))
.property("endDate", new DateProperty()).property("patient", new RefProperty("#/definitions/PatientCreate"))
.property("startDate", new DateProperty()).property("voided", new BooleanProperty())
.property("attributes", new RefProperty("#/definitions/CohortmCohortmemberAttributeCreate"));
public Schema<?> getCREATESchema(Representation rep) {
return new Schema<>().addProperty("cohort", new Schema<Cohort>().$ref("#/components/schemas/CohortCreate"))
.addProperty("endDate", new DateSchema())
.addProperty("patient", new Schema<Patient>().$ref("#/components/schemas/PatientCreate"))
.addProperty("startDate", new DateSchema()).addProperty("voided", new BooleanSchema())
.addProperty("attributes", new Schema<>().$ref("#/components/schemas/CohortmCohortmemberAttributeCreate"));
}

@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) {
model.property("patient", new RefProperty("#/definitions/PatientGetRef"));
model.property("startDate", new DateProperty());
model.property("endDate", new DateProperty());
model.property("uuid", new StringProperty());
model.property("voided", new BooleanProperty());
model.addProperty("patient", new Schema<Patient>().$ref("#/components/schemas/PatientGetRef"))
.addProperty("startDate", new DateSchema()).addProperty("endDate", new DateSchema())
.addProperty("uuid", new StringSchema()).addProperty("voided", new BooleanSchema());
} else if (rep instanceof FullRepresentation) {
model.property("display", new StringProperty());
model.property("startDate", new DateProperty());
model.property("endDate", new DateProperty());
model.property("uuid", new StringProperty());
model.property("voided", new BooleanProperty());
model.property("patient", new RefProperty("#/definitions/PatientGetFull"));
model.property("auditInfo", new StringProperty());
model.addProperty("display", new StringSchema()).addProperty("startDate", new DateSchema())
.addProperty("endDate", new DateSchema()).addProperty("uuid", new UUIDSchema())
.addProperty("voided", new BooleanSchema())
.addProperty("patient", new Schema<Patient>().$ref("#/components/schemas/PatientGetFull"))
.addProperty("auditInfo", new StringSchema());
}
return model;
}

@Override
public Model getUPDATEModel(Representation rep) {
ModelImpl model = (ModelImpl) super.getUPDATEModel(rep);
return model.property("endDate", new DateProperty()).property("startDate", new DateProperty()).property("voided",
new BooleanProperty());
public Schema<?> getUPDATESchema(Representation rep) {
Schema<?> model = super.getUPDATESchema(rep);
return model.addProperty("endDate", new DateSchema()).addProperty("startDate", new DateSchema())
.addProperty("voided", new BooleanSchema());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.*;
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.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.openmrs.Location;
import org.openmrs.User;
import org.openmrs.api.APIException;
import org.openmrs.api.context.Context;
Expand Down Expand Up @@ -125,62 +129,59 @@ private void addSharedDelegatingResourceProperties(DelegatingResourceDescription
description.addProperty("cohortMembers");
}

@Override
public Model getCREATEModel(Representation rep) {
ModelImpl model = new ModelImpl();
model.property("name", new StringProperty()).required("name");
model.property("description", new StringProperty());
model.property("location", new RefProperty("#/definitions/LocationCreate"));
model.property("startDate", new DateProperty());
model.property("endDate", new DateProperty());
model.property("cohortType", new RefProperty("#/definitions/CohortmCohorttypeCreate"));
model.property("definitionHandlerClassname", new StringProperty());
model.property("attributes", new ArrayProperty(new RefProperty("#/definitions/CohortmCohortmemberAttributeCreate")));
model.addProperty("cohortMembers", new ArrayProperty(new RefProperty("#/definitions/CohortMembershipCreate")));
model.property("voided", new BooleanProperty());
model.property("groupCohort", new BooleanProperty());
public Schema<?> getCREATESchema(Representation rep) {
Schema<Object> model = new Schema<>();
model.addProperty("name", new StringSchema()).addProperty("description", new StringSchema())
.addProperty("location", new Schema<>().$ref("#/components/schemas/LocationCreate"))
.addProperty("startDate", new DateSchema()).addProperty("endDate", new DateSchema())
.addProperty("cohortType", new Schema<CohortType>().$ref("#/components/schemas/CohortmCohorttypeCreate"))
.addProperty("definitionHandlerClassname", new StringSchema())
.addProperty("attributes",
new ArraySchema().items(new Schema<>().$ref("#/components/schemas/CohortmCohortmemberAttributeCreate")))
.addProperty("cohortMembers",
new ArraySchema().items(new Schema<CohortMember>().$ref("#/components/schemas/CohortMembershipCreate")))
.addProperty("voided", new BooleanSchema()).addProperty("groupCohort", new BooleanSchema());

model.setRequired(Collections.singletonList("name"));

return model;
}

@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) {
model.property("name", new StringProperty());
model.property("description", new StringProperty());
model.property("startDate", new DateProperty());
model.property("endDate", new DateProperty());
model.property("groupCohort", new BooleanProperty());
model.property("uuid", new StringProperty().example("uuid"));
model.property("location", new RefProperty("#/definitions/LocationGetRef"));
model.property("cohortType", new RefProperty("#/definitions/CohortmCohorttypeGetRef"));
model.property("attributes", new RefProperty("#/definitions/CohortmCohortmemberAttributeGetRef"));
model.property("voided", new BooleanProperty());
model.property("voidReason", new StringProperty());
model.property("display", new StringProperty());
model.addProperty("name", new StringSchema()).addProperty("description", new StringSchema())
.addProperty("startDate", new DateSchema()).addProperty("endDate", new DateSchema())
.addProperty("groupCohort", new BooleanSchema()).addProperty("uuid", new StringSchema().example("uuid"))
.addProperty("location", new Schema<Location>().$ref("#/components/schemas/LocationGetRef"))
.addProperty("cohortType", new Schema<CohortType>().$ref("#/components/schemas/CohortmCohorttypeGetRef"))
.addProperty("attributes",
new Schema<>().$ref("#/components/schemas/CohortmCohortmemberAttributeGetRef"))
.addProperty("voided", new BooleanSchema()).addProperty("voidReason", new StringSchema())
.addProperty("display", new StringSchema());
} else if (rep instanceof FullRepresentation) {
model.property("name", new StringProperty());
model.property("description", new StringProperty());
model.property("startDate", new DateProperty());
model.property("endDate", new DateProperty());
model.property("groupCohort", new BooleanProperty());
model.property("location", new RefProperty("#/definitions/LocationGetFull"));
model.addProperty("cohortMembers", new ArrayProperty(new RefProperty("#/definitions/CohortMembershipGetFull")));
model.property("cohortType", new RefProperty("#/definitions/CohortmCohorttypeGetFull"));
model.property("attributes", new RefProperty("#/definitions/CohortmCohortmemberAttributeGetFull"));
model.property("voided", new BooleanProperty());
model.property("voidReason", new StringProperty());
model.property("display", new StringProperty());
model.property("auditInfo", new StringProperty());
model.property("uuid", new StringProperty().example("uuid"));
model.addProperty("name", new StringSchema()).addProperty("description", new StringSchema())
.addProperty("startDate", new DateSchema()).addProperty("endDate", new DateSchema())
.addProperty("groupCohort", new BooleanSchema())
.addProperty("location", new Schema<Location>().$ref("#/components/schemas/LocationGetFull"))
.addProperty("cohortMembers",
new ArraySchema().items(new Schema<>().$ref("#/components/schemas/CohortMembershipGetFull")))
.addProperty("cohortType",
new Schema<CohortType>().$ref("#/components/schemas/CohortmCohorttypeGetFull"))
.addProperty("attributes",
new Schema<>().$ref("#/components/schemas/CohortmCohortmemberAttributeGetFull"))
.addProperty("voided", new BooleanSchema()).addProperty("voidReason", new StringSchema())
.addProperty("display", new StringSchema()).addProperty("auditInfo", new StringSchema())
.addProperty("uuid", new StringSchema().example("uuid"));
}
return model;
}

@Override
public Model getUPDATEModel(Representation rep) {
ModelImpl model = (ModelImpl) getCREATEModel(rep);
model.property("voidReason", new StringProperty());
public Schema<?> getUPDATESchema(Representation rep) {
Schema<?> model = getCREATESchema(rep);
model.addProperty("voidReason", new StringSchema());
return model;
}

Expand Down
Loading
Loading