Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit a3701cc

Browse files
author
vlad-ciucescu
authored
Merge pull request SORMAS-Foundation#3597 from hzi-braunschweig/3372-api-info
SORMAS-Foundation#3372 provide external API info at runtime
2 parents abc4802 + 6f8687a commit a3701cc

6 files changed

Lines changed: 90 additions & 21 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ SORMAS officially supports and is tested on **Chromium-based browsers** (like Go
2727

2828
#### Is there a ReST API documentation?
2929
Yes! Please download the [latest release](https://github.com/hzi-braunschweig/SORMAS-Project/releases/latest) and copy the content of /deploy/openapi/sormas-rest.yaml to an editor that generates a visual API documentation (e.g. https://editor.swagger.io/).
30+
<br/>
31+
Runtime Swagger documentation of the External Visits Resource (used by external symptom journals such as CLIMEDO or PIA) is also available at ``<<host>>/sormas-rest/visits-external/openapi.json`` or ``<<host>>/sormas-rest/visits-external/openapi.yaml``
3032

3133
<p align="center"><img src="https://user-images.githubusercontent.com/23701005/74659600-ebb8fc00-5194-11ea-836b-a7ca9d682301.png"/></p>
3234

sormas-base/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@
711711
<!-- ** Vaadin END ** -->
712712

713713
<!-- *** Compile dependencies END *** -->
714-
714+
715715
<!-- *** Test dependencies *** -->
716716

717717
<dependency>
@@ -778,6 +778,12 @@
778778
<scope>test</scope>
779779
</dependency>
780780

781+
<dependency>
782+
<groupId>io.swagger.core.v3</groupId>
783+
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
784+
<version>${swagger.version}</version>
785+
</dependency>
786+
781787
<dependency>
782788
<groupId>p6spy</groupId>
783789
<artifactId>p6spy</artifactId>

sormas-rest/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
<artifactId>swagger-jaxrs2</artifactId>
5858
</dependency>
5959

60+
<dependency>
61+
<groupId>io.swagger.core.v3</groupId>
62+
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
63+
</dependency>
64+
65+
<!-- Keycloak -->
6066
<dependency>
6167
<groupId>org.keycloak</groupId>
6268
<artifactId>keycloak-servlet-filter-adapter</artifactId>

sormas-rest/src/main/java/de/symeda/sormas/rest/RestConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
*******************************************************************************/
1818
package de.symeda.sormas.rest;
1919

20+
import javax.ws.rs.ApplicationPath;
21+
2022
import org.glassfish.jersey.jackson.JacksonFeature;
2123
import org.glassfish.jersey.server.ResourceConfig;
2224
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
2325

24-
import javax.ws.rs.ApplicationPath;
25-
2626
import de.symeda.sormas.rest.swagger.SwaggerConfig;
2727

2828
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package de.symeda.sormas.rest.external;
2+
3+
import javax.servlet.ServletConfig;
4+
import javax.ws.rs.ApplicationPath;
5+
import javax.ws.rs.core.Context;
6+
7+
import org.apache.commons.collections4.SetUtils;
8+
import org.glassfish.jersey.jackson.JacksonFeature;
9+
import org.glassfish.jersey.server.ResourceConfig;
10+
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
11+
12+
import de.symeda.sormas.rest.swagger.SwaggerConfig;
13+
import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
14+
import io.swagger.v3.oas.integration.SwaggerConfiguration;
15+
import io.swagger.v3.oas.models.OpenAPI;
16+
import io.swagger.v3.oas.models.info.Contact;
17+
import io.swagger.v3.oas.models.info.Info;
18+
import io.swagger.v3.oas.models.info.License;
19+
20+
/**
21+
* Resource configuration used only for external resources i.e. for external systems which communicate with SORMAS
22+
* Separate from the other resource configuration in order to limit create the swagger documentation only for resources in this package
23+
*/
24+
@ApplicationPath("/visits-external")
25+
public class ExternalRestResourceConfig extends ResourceConfig {
26+
27+
@Context
28+
private ServletConfig servletConfig;
29+
30+
public ExternalRestResourceConfig() {
31+
32+
super(ExternalRestResourceConfig.class);
33+
34+
packages(getClass().getPackage().getName());
35+
register(RolesAllowedDynamicFeature.class);
36+
register(JacksonFeature.class);
37+
38+
SwaggerConfig.init();
39+
40+
Info info = new Info().title("SORMAS external symptom journal API")
41+
.description(
42+
"The purpose of this API is to enable communication between SORMAS and other symptom journals. "
43+
+ "Only users with the role ``REST_EXTERNAL_VISITS_USER`` are authorized to use the endpoints. "
44+
+ "If you would like to receive access, please contact the System Administrator. "
45+
+ "For technical details please contact the dev team on gitter. "
46+
+ "Authentication is done using basic auth, with the user and password.")
47+
.contact(new Contact().url("https://gitter.im/SORMAS-Project/dev-support"))
48+
.license(new License().name("GNU General Public License").url("https://www.gnu.org/licenses/"));
49+
50+
OpenAPI openAPI = new OpenAPI().info(info);
51+
SwaggerConfiguration openAPIConfiguration = new SwaggerConfiguration().prettyPrint(true)
52+
.openAPI(openAPI)
53+
.resourceClasses(SetUtils.hashSet(ExternalVisitsResource.class.getSimpleName()));
54+
OpenApiResource openApiResource = new OpenApiResource();
55+
openApiResource.setOpenApiConfiguration(openAPIConfiguration);
56+
register(openApiResource);
57+
}
58+
}

sormas-rest/src/main/java/de/symeda/sormas/rest/ExternalVisitsResource.java renamed to sormas-rest/src/main/java/de/symeda/sormas/rest/external/ExternalVisitsResource.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
package de.symeda.sormas.rest;
1+
package de.symeda.sormas.rest.external;
2+
3+
import java.util.Date;
4+
import java.util.List;
5+
6+
import javax.annotation.security.RolesAllowed;
7+
import javax.ws.rs.Consumes;
8+
import javax.ws.rs.GET;
9+
import javax.ws.rs.POST;
10+
import javax.ws.rs.Path;
11+
import javax.ws.rs.PathParam;
12+
import javax.ws.rs.Produces;
13+
import javax.ws.rs.core.MediaType;
214

315
import de.symeda.sormas.api.FacadeProvider;
416
import de.symeda.sormas.api.PushResult;
517
import de.symeda.sormas.api.person.JournalPersonDto;
618
import de.symeda.sormas.api.person.PersonFollowUpEndDto;
7-
import de.symeda.sormas.api.person.PersonDto;
8-
import de.symeda.sormas.api.person.PersonQuarantineEndDto;
919
import de.symeda.sormas.api.person.PersonSymptomJournalStatusDto;
1020
import de.symeda.sormas.api.visit.ExternalVisitDto;
21+
import de.symeda.sormas.rest.EntityDtoResource;
1122
import io.swagger.v3.oas.annotations.Operation;
12-
import io.swagger.v3.oas.annotations.Parameter;
13-
import io.swagger.v3.oas.annotations.enums.ParameterIn;
1423
import io.swagger.v3.oas.annotations.media.Content;
1524
import io.swagger.v3.oas.annotations.media.Schema;
1625
import io.swagger.v3.oas.annotations.parameters.RequestBody;
1726
import io.swagger.v3.oas.annotations.responses.ApiResponse;
1827

19-
import javax.annotation.security.RolesAllowed;
20-
import javax.ws.rs.Consumes;
21-
import javax.ws.rs.GET;
22-
import javax.ws.rs.POST;
23-
import javax.ws.rs.Path;
24-
import javax.ws.rs.PathParam;
25-
import javax.ws.rs.Produces;
26-
import javax.ws.rs.QueryParam;
27-
import javax.ws.rs.core.MediaType;
28-
import java.util.Date;
29-
import java.util.List;
30-
31-
@Path("/visits-external")
28+
@Path("/")
3229
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
3330
@Consumes(MediaType.APPLICATION_JSON + "; charset=UTF-8")
3431
@RolesAllowed("REST_EXTERNAL_VISITS_USER")

0 commit comments

Comments
 (0)