|
| 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 io.swagger.v3.jaxrs2.Reader; |
| 8 | +import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder; |
| 9 | +import io.swagger.v3.oas.integration.OpenApiConfigurationException; |
| 10 | +import org.glassfish.jersey.jackson.JacksonFeature; |
| 11 | +import org.glassfish.jersey.server.ResourceConfig; |
| 12 | +import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature; |
| 13 | + |
| 14 | +import com.google.common.collect.Sets; |
| 15 | + |
| 16 | +import de.symeda.sormas.rest.swagger.SwaggerConfig; |
| 17 | +import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource; |
| 18 | +import io.swagger.v3.oas.integration.SwaggerConfiguration; |
| 19 | +import io.swagger.v3.oas.models.OpenAPI; |
| 20 | +import io.swagger.v3.oas.models.info.Contact; |
| 21 | +import io.swagger.v3.oas.models.info.Info; |
| 22 | +import io.swagger.v3.oas.models.info.License; |
| 23 | + |
| 24 | +/** |
| 25 | + * Resource configuration used only for external resources i.e. for external systems which communicate with SORMAS |
| 26 | + * Separate from the other resource configuration in order to limit create the swagger documentation only for resources in this package |
| 27 | + */ |
| 28 | +@ApplicationPath("/") |
| 29 | +public class ExternalRestResourceConfig extends ResourceConfig { |
| 30 | + |
| 31 | + @Context |
| 32 | + private ServletConfig servletConfig; |
| 33 | + |
| 34 | + public ExternalRestResourceConfig() { |
| 35 | + |
| 36 | + super(ExternalRestResourceConfig.class); |
| 37 | + |
| 38 | + packages(getClass().getPackage().getName()); |
| 39 | + register(RolesAllowedDynamicFeature.class); |
| 40 | + register(JacksonFeature.class); |
| 41 | + |
| 42 | + SwaggerConfig.init(); |
| 43 | + |
| 44 | + Info info = new Info().title("SORMAS external symptom journal API") |
| 45 | + .description( |
| 46 | + "The purpose of this API is to enable communication between SORMAS and other symptom journals. " |
| 47 | + + "Only users with the role ``REST_EXTERNAL_VISITS_USER`` are authorized to use the endpoints. " |
| 48 | + + "If you would like to receive access, please contact the team to have a user set up. " |
| 49 | + + "Authentication is done using basic auth, with the user and password.") |
| 50 | + .contact(new Contact().url("https://gitter.im/SORMAS-Project/dev-support")) |
| 51 | + .license(new License().name("GNU General Public License").url("https://www.gnu.org/licenses/")); |
| 52 | + |
| 53 | + Reader reader = new Reader(new OpenAPI().info(info)); |
| 54 | + OpenAPI openAPI = reader.read(ExternalVisitsResource.class); |
| 55 | + SwaggerConfiguration openAPIConfiguration = new SwaggerConfiguration().prettyPrint(true) |
| 56 | + .openAPI(openAPI) |
| 57 | + .resourceClasses(Sets.newHashSet(ExternalVisitsResource.class.getSimpleName())); |
| 58 | + OpenApiResource openApiResource = new OpenApiResource(); |
| 59 | + openApiResource.setOpenApiConfiguration(openAPIConfiguration); |
| 60 | + register(openApiResource); |
| 61 | + } |
| 62 | +} |
0 commit comments