tweaks for swagger

This commit is contained in:
Athou
2013-04-15 22:24:37 +02:00
parent a9eb2595fe
commit e124fdbe8f
23 changed files with 57 additions and 15 deletions

View File

@@ -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() {

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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);

View File

Before

Width:  |  Height:  |  Size: 770 B

After

Width:  |  Height:  |  Size: 770 B

View File

Before

Width:  |  Height:  |  Size: 824 B

After

Width:  |  Height:  |  Size: 824 B

View File

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 980 B

After

Width:  |  Height:  |  Size: 980 B

View File

@@ -18,8 +18,15 @@
<script type="text/javascript">
$(function () {
var url = window.location.href;
if (url.indexOf('#')> -1) {
url = url.substring(0, url.lastIndexOf('#'));
}
url = url.substring(0, url.length - 1);
url = url.substring(0, url.lastIndexOf('/'));
url = url + '/rest/resources';
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://petstore.swagger.wordnik.com/api/api-docs.json",
discoveryUrl:url,
apiKey:"special-key",
dom_id:"swagger-ui-container",
supportHeaderParams: false,

View File

@@ -10,7 +10,6 @@
<div>
<form name="settingsForm" class="form-horizontal" ng-submit="save()">
<!-- not needed atm
<div class="control-group">
<label class="control-label" for="publicUrl">Public URL</label>
<div class="controls">
@@ -18,7 +17,6 @@
ng-model="settings.publicUrl" />
</div>
</div>
-->
<div class="control-group">
<label class="control-label" for="allowRegistrations">Allow
registrations</label>