mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
tweaks for swagger
This commit is contained in:
@@ -8,15 +8,28 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.wordnik.swagger.annotations.ApiClass;
|
||||
import com.wordnik.swagger.annotations.ApiProperty;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@ApiClass("List of entries with some metadata")
|
||||
public class Entries implements Serializable {
|
||||
|
||||
@ApiProperty("Name of the feed or the category requested")
|
||||
private String name;
|
||||
|
||||
@ApiProperty("Error or warning message")
|
||||
private String message;
|
||||
|
||||
@ApiProperty("TImes the server tried to refresh the feed and failed")
|
||||
private int errorCount;
|
||||
|
||||
@ApiProperty("List generation Timestamp")
|
||||
private long timestamp;
|
||||
|
||||
@ApiProperty("List of entries")
|
||||
private List<Entry> entries = Lists.newArrayList();
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.commafeed.frontend.rest;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.GET;
|
||||
@@ -13,6 +14,7 @@ import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||
import com.commafeed.frontend.model.Entries;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiOperation;
|
||||
@@ -25,6 +27,9 @@ import com.wordnik.swagger.jaxrs.JavaApiListing;
|
||||
@Produces({ "application/json" })
|
||||
public class ApiListingResource extends JavaApiListing {
|
||||
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
@Override
|
||||
@GET
|
||||
@ApiOperation(value = "Returns list of all available api endpoints", responseClass = "List[DocumentationEndPoint]")
|
||||
@@ -32,16 +37,19 @@ public class ApiListingResource extends JavaApiListing {
|
||||
@Context Application app, @Context HttpHeaders headers,
|
||||
@Context UriInfo uriInfo) {
|
||||
|
||||
return super.getAllApis(new ServletConfigProxy(sc), app, headers,
|
||||
uriInfo);
|
||||
return super.getAllApis(new ServletConfigProxy(
|
||||
applicationSettingsService.get().getPublicUrl(), sc), app,
|
||||
headers, uriInfo);
|
||||
}
|
||||
|
||||
public static class ServletConfigProxy implements ServletConfig {
|
||||
|
||||
private ServletConfig sc;
|
||||
private String publicUrl;
|
||||
|
||||
public ServletConfigProxy(ServletConfig sc) {
|
||||
public ServletConfigProxy(String publicUrl, ServletConfig sc) {
|
||||
this.sc = sc;
|
||||
this.publicUrl = publicUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,6 +67,9 @@ public class ApiListingResource extends JavaApiListing {
|
||||
if ("swagger.config.reader".equals(name)) {
|
||||
return CustomConfigReader.class.getName();
|
||||
}
|
||||
if (CustomConfigReader.class.getName().equals(name)) {
|
||||
return publicUrl;
|
||||
}
|
||||
return sc.getInitParameter(name);
|
||||
}
|
||||
|
||||
@@ -70,12 +81,20 @@ public class ApiListingResource extends JavaApiListing {
|
||||
|
||||
public static class CustomConfigReader extends ConfigReader {
|
||||
|
||||
private ServletConfig config;
|
||||
|
||||
public CustomConfigReader(ServletConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String basePath() {
|
||||
return "http://localhost:8082/commafeed/rest";
|
||||
String publicUrl = config.getInitParameter(CustomConfigReader.class
|
||||
.getName());
|
||||
if (publicUrl.endsWith("/")) {
|
||||
publicUrl = publicUrl.substring(0, publicUrl.length() - 1);
|
||||
}
|
||||
return publicUrl + "/rest";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.commafeed.backend.feeds.FeedFetcher;
|
||||
import com.commafeed.backend.feeds.OPMLImporter;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||
import com.commafeed.backend.services.PasswordEncryptionService;
|
||||
import com.commafeed.backend.services.UserService;
|
||||
@@ -60,6 +61,9 @@ public abstract class AbstractREST extends JavaHelp {
|
||||
@Context
|
||||
HttpServletResponse response;
|
||||
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
@Inject
|
||||
FeedDAO feedDAO;
|
||||
|
||||
@@ -165,7 +169,8 @@ public abstract class AbstractREST extends JavaHelp {
|
||||
@ApiOperation(value = "Returns information about API parameters", responseClass = "com.wordnik.swagger.core.Documentation")
|
||||
public Response getHelp(@Context ServletConfig sc,
|
||||
@Context HttpHeaders headers, @Context UriInfo uriInfo) {
|
||||
return super.getHelp(new ServletConfigProxy(sc), headers, uriInfo);
|
||||
return super.getHelp(new ServletConfigProxy(applicationSettingsService
|
||||
.get().getPublicUrl(), sc), headers, uriInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,14 +43,14 @@ public class EntriesREST extends AbstractREST {
|
||||
|
||||
@Path("/get")
|
||||
@GET
|
||||
@ApiOperation(value = "Find entry by ID", notes = "Add extra notes here", responseClass = "com.commafeed.frontend.model.Entries")
|
||||
@ApiOperation(value = "Get entries", notes = "Get a list of entries matching the query", responseClass = "com.commafeed.frontend.model.Entries")
|
||||
public Entries getEntries(
|
||||
@ApiParam(value = "ID of entry that needs to be fetched", allowableValues = "range[1,5]", required = true) @QueryParam("type") Type type,
|
||||
@QueryParam("id") String id,
|
||||
@QueryParam("readType") ReadType readType,
|
||||
@DefaultValue("0") @QueryParam("offset") int offset,
|
||||
@DefaultValue("-1") @QueryParam("limit") int limit,
|
||||
@QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
|
||||
@ApiParam(value = "Type of query", allowableValues = "category,feed", required = true) @QueryParam("type") Type type,
|
||||
@ApiParam(value = "ID of the category or the feed", required = true) @QueryParam("id") String id,
|
||||
@ApiParam(value = "All entries or only unread ones", allowableValues = "all,unread", required = true) @QueryParam("readType") ReadType readType,
|
||||
@ApiParam(value = "Offset for paging") @DefaultValue("0") @QueryParam("offset") int offset,
|
||||
@ApiParam(value = "Limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit,
|
||||
@ApiParam(value = "Ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
|
||||
|
||||
Preconditions.checkNotNull(type);
|
||||
Preconditions.checkNotNull(id);
|
||||
|
||||
Reference in New Issue
Block a user