Permalink
Browse files

Add swagger support (#98)

fix #97
  • Loading branch information...
darkman97i authored and monkiki committed Sep 21, 2018
1 parent 55fa69d commit 77544258ab80eeb486c5cf2f36e9736db9439b2c
32 pom.xml
@@ -160,6 +160,13 @@
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<!-- Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.9</version>
</dependency>
<!-- Misc -->
<dependency>
@@ -533,6 +540,10 @@
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.geronimo.javamail</groupId>
<artifactId>geronimo-javamail_1.4_mail</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
@@ -550,7 +561,24 @@
<artifactId>wss4j</artifactId>
<version>1.6.4</version>
</dependency>
<!-- CXF swagger support -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>3.17.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
@@ -812,7 +840,7 @@
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
<version>0.9.11</version>
</dependency>
<!-- ZIP -->
@@ -0,0 +1,68 @@
/**
* OpenKM, Open Document Management System (http://www.openkm.com)
* Copyright (c) Paco Avila & Josep Llort
* <p>
* No bytes were intentionally harmed during the development of this application.
* <p>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package com.openkm.core;
import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
public class Swagger2Config extends Swagger2Feature {
/*
* Swagger2 integration notes
*
* The reason why has been created the class rather using xml annotation into appContext.xml class is that the number
* of properties available from there are limited and someones like licenseUrl raise and error meanwhile from class
* it works right.
*
* The best starting point at -> http://cxf.apache.org/docs/swagger2feature.html
* For looking -> https://adarshthimmappa.wordpress.com/2017/11/22/rest-api-documentation-via-swagger/
* For looking -> http://massfords.com/Spring-Swagger-CXF/
*
* Explain mandatory tags ( in our case @Path was missing what caused the services where not scanned )
* https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X
*
* Issue with multiple jars server, to solve should be used setUsePathBasedConfig but at the end has not been working
* and decided going into single server point rather than multiple for each service class
* https://stackoverflow.com/questions/32948315/swagger-integration-for-multiple-jaxrs-servers
*
* Another good documentation but because we are using Apache CXF can not be applied in our case:
* https://www.concretepage.com/spring-4/spring-rest-swagger-2-integration-with-annotation-xml-example
* http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
* https://stackoverflow.com/questions/26720090/a-simple-way-to-implement-swagger-in-a-spring-mvc-application
*/
public Swagger2Config() {
super();
//this.setBasePath("/OpenKM/services");
//this.setUsePathBasedConfig(true); // not working for several jaxrs:server
this.setResourcePackage("com.openkm.rest");
this.setScan(true);
this.setTitle("OpenKM REST API");
this.setContact("contact@openkm.com");
this.setDescription("Copyright © OpenKM Knowledge Management System S.L. \n" +
"This program is free software; you can redistribute it and/or modify\n" +
"it under the terms of the GNU General Public License as published by\n" +
"the Free Software Foundation; either version 2 of the License, or\n" +
"(at your option) any later version");
this.setLicense("Community license of API");
this.setLicenseUrl("https://docs.openkm.com/kcenter/view/licenses/");
}
}
@@ -21,21 +21,26 @@
package com.openkm.rest.endpoint;
import java.util.Map;
import java.util.Map.Entry;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.module.AuthModule;
import com.openkm.module.ModuleManager;
import com.openkm.principal.PrincipalAdapterException;
import com.openkm.rest.GenericException;
import com.openkm.rest.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Map;
import java.util.Map.Entry;
import io.swagger.annotations.Api;
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="auth-service", value="auth-service")
@Path("/auth")
public class AuthService {
private static Logger log = LoggerFactory.getLogger(AuthService.class);
@@ -26,16 +26,7 @@
import java.io.OutputStream;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
@@ -55,8 +46,11 @@
import com.openkm.rest.util.DocumentList;
import com.openkm.rest.util.VersionList;
import io.swagger.annotations.Api;
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="document-service", value="document-service")
@Path("/document")
public class DocumentService {
private static Logger log = LoggerFactory.getLogger(DocumentService.class);
@@ -21,20 +21,24 @@
package com.openkm.rest.endpoint;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.openkm.bean.Folder;
import com.openkm.core.MimeTypeConfig;
import com.openkm.module.FolderModule;
import com.openkm.module.ModuleManager;
import com.openkm.rest.GenericException;
import com.openkm.rest.util.FolderList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import io.swagger.annotations.Api;
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="folder-service", value="folder-service")
@Path("/folder")
public class FolderService {
private static Logger log = LoggerFactory.getLogger(FolderService.class);
@@ -31,6 +31,7 @@
import com.openkm.rest.GenericException;
import com.openkm.rest.util.MailList;
import com.openkm.util.PathUtils;
import io.swagger.annotations.Api;
import org.apache.commons.io.IOUtils;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.slf4j.Logger;
@@ -45,6 +46,7 @@
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="mail-service", value="mail-service")
@Path("/mail")
public class MailService {
private static Logger log = LoggerFactory.getLogger(MailService.class);
@@ -26,6 +26,7 @@
import com.openkm.module.NoteModule;
import com.openkm.rest.GenericException;
import com.openkm.rest.util.NoteList;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,6 +35,7 @@
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="note-service", value="note-service")
@Path("/note")
public class NoteService {
private static Logger log = LoggerFactory.getLogger(NoteService.class);
@@ -32,6 +32,7 @@
import com.openkm.rest.util.SimplePropertyGroup;
import com.openkm.rest.util.SimplePropertyGroupList;
import com.openkm.ws.util.FormElementComplex;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,6 +45,7 @@
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="gropertyGroup-service", value="gropertyGroup-service")
@Path("/propertyGroup")
public class PropertyGroupService {
private static Logger log = LoggerFactory.getLogger(PropertyGroupService.class);
@@ -232,7 +234,7 @@ public Boolean hasGroup(@QueryParam("nodeId") String nodeId, @QueryParam("grpNam
log.debug("hasGroup({}, {})", new Object[]{nodeId, grpName});
PropertyGroupModule cm = ModuleManager.getPropertyGroupModule();
boolean ret = cm.hasGroup(null, nodeId, grpName);
log.debug("hasGroup: {}", ret);
log.debug("hasGroup: {}", ret);
return new Boolean(ret);
} catch (Exception e) {
throw new GenericException(e);
@@ -24,6 +24,7 @@
import com.openkm.module.ModuleManager;
import com.openkm.module.PropertyModule;
import com.openkm.rest.GenericException;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +33,7 @@
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="property-service", value="property-service")
@Path("/property")
public class PropertyService {
private static Logger log = LoggerFactory.getLogger(PropertyService.class);
@@ -37,6 +37,7 @@
import com.openkm.rest.util.SqlQueryResultColumns;
import com.openkm.rest.util.SqlQueryResults;
import com.openkm.spring.PrincipalUtils;
import io.swagger.annotations.Api;
import org.apache.commons.io.IOUtils;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.hibernate.QueryException;
@@ -54,6 +55,7 @@
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="repository-service", value="repository-service")
@Path("/repository")
public class RepositoryService {
private static Logger log = LoggerFactory.getLogger(RepositoryService.class);
@@ -29,6 +29,7 @@
import com.openkm.rest.GenericException;
import com.openkm.rest.util.*;
import com.openkm.util.ISO8601;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,6 +40,7 @@
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="search-service", value="search-service")
@Path("/search")
public class SearchService {
private static Logger log = LoggerFactory.getLogger(SearchService.class);
@@ -23,6 +23,7 @@
import com.openkm.bean.Note;
import com.openkm.rest.GenericException;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,6 +34,7 @@
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Api(description="test-service", value="test-service")
@Path("/test")
public class TestService {
private static Logger log = LoggerFactory.getLogger(TestService.class);
@@ -19,6 +19,9 @@
<beans:import resource="soap.xml"/>
<beans:import resource="rest.xml"/>
<beans:import resource="cmis.xml"/>
<!-- Swagger -->
<beans:bean id="swagger2Feature" class="com.openkm.core.Swagger2Config" />
<!--
<beans:bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
@@ -27,5 +27,8 @@
<property name="supportUnwrapped" value="true"/>
</bean>
</jaxrs:providers>
<jaxrs:features>
<ref bean="swagger2Feature" />
</jaxrs:features>
</jaxrs:server>
</beans:beans>

0 comments on commit 7754425

Please sign in to comment.