Skip to content

The Unified and Autonomous Development Platform

Draft version of RESTful api help

Robin Shenddd8a9c508ce
diff --git a/pom.xml b/pom.xml
index 23eb2c70d5..8024a6f013 100644
--- a/pom.xml
+++ b/pom.xml
@@ -449,6 +449,11 @@
<artifactId>flexmark-ext-autolink</artifactId>
<version>${flexmark.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.objenesis</groupId>
+ <artifactId>objenesis</artifactId>
+ <version>3.2</version>
+ </dependency>
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-ext-anchorlink</artifactId>
diff --git a/server-core/pom.xml b/server-core/pom.xml
index dc60b2acc8..8ea80aebfc 100644
--- a/server-core/pom.xml
+++ b/server-core/pom.xml
@@ -312,6 +312,10 @@
<groupId>io.onedev</groupId>
<artifactId>k8s-helper</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.objenesis</groupId>
+ <artifactId>objenesis</artifactId>
+ </dependency>
</dependencies>
<properties>
<moduleClass>io.onedev.server.CoreModule</moduleClass>
diff --git a/server-core/src/main/java/io/onedev/server/CoreModule.java b/server-core/src/main/java/io/onedev/server/CoreModule.java
index 9829eef619..86b1b0b2b5 100644
--- a/server-core/src/main/java/io/onedev/server/CoreModule.java
+++ b/server-core/src/main/java/io/onedev/server/CoreModule.java
@@ -217,7 +217,7 @@ import io.onedev.server.persistence.annotation.Sessional;
import io.onedev.server.persistence.annotation.Transactional;
import io.onedev.server.persistence.dao.Dao;
import io.onedev.server.persistence.dao.DefaultDao;
-import io.onedev.server.rest.RestConstants;
+import io.onedev.server.rest.RestUtils;
import io.onedev.server.rest.jersey.DefaultServletContainer;
import io.onedev.server.rest.jersey.JerseyConfigurator;
import io.onedev.server.rest.jersey.ResourceConfigProvider;
@@ -569,7 +569,7 @@ public class CoreModule extends AbstractPluginModule {
@Override
public void configure(ResourceConfig resourceConfig) {
- resourceConfig.packages(RestConstants.class.getPackage().getName());
+ resourceConfig.packages(RestUtils.class.getPackage().getName());
}
});
diff --git a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSshKeyManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSshKeyManager.java
index f1f5dff2df..5c0122dc14 100644
--- a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSshKeyManager.java
+++ b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSshKeyManager.java
@@ -63,7 +63,7 @@ public class DefaultSshKeyManager extends BaseEntityManager<SshKey> implements S
sshKey.setDigest(digest);
sshKey.setContent(content);
sshKey.setOwner(user);
- sshKey.setDate(new Date());
+ sshKey.setCreatedAt(new Date());
syncMap.put(content, sshKey);
} catch (IOException | GeneralSecurityException e) {
logger.error("Error parsing SSH key", e);
diff --git a/server-core/src/main/java/io/onedev/server/model/AbstractEntity.java b/server-core/src/main/java/io/onedev/server/model/AbstractEntity.java
index 8347d05c53..f49e147773 100644
--- a/server-core/src/main/java/io/onedev/server/model/AbstractEntity.java
+++ b/server-core/src/main/java/io/onedev/server/model/AbstractEntity.java
@@ -17,6 +17,7 @@ import org.hibernate.proxy.HibernateProxy;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.onedev.server.model.support.EntityWatch;
+import io.onedev.server.rest.annotation.Api;
@MappedSuperclass
@JsonIgnoreProperties("handler")
@@ -24,8 +25,11 @@ public abstract class AbstractEntity implements Serializable, Comparable<Abstrac
private static final long serialVersionUID = 1L;
+ public static final String PROP_ID = "id";
+
private transient Object customData;
+ @Api(order=1)
@Id
@GenericGenerator(name="entity_id", strategy="io.onedev.server.persistence.IdGenerator")
@GeneratedValue(generator="entity_id")
diff --git a/server-core/src/main/java/io/onedev/server/model/Build.java b/server-core/src/main/java/io/onedev/server/model/Build.java
index 142de3c1a5..533241cdaa 100644
--- a/server-core/src/main/java/io/onedev/server/model/Build.java
+++ b/server-core/src/main/java/io/onedev/server/model/Build.java
@@ -114,8 +114,6 @@ import io.onedev.server.web.util.WicketUtils;
public class Build extends AbstractEntity implements Referenceable {
private static final long serialVersionUID = 1L;
-
- public static final String PROP_ID = "id";
public static final String PROP_NUMBER_SCOPE = "numberScope";
@@ -360,7 +358,7 @@ public class Build extends AbstractEntity implements Referenceable {
}
@Override
- public String getPrefix() {
+ public String getType() {
return "build";
}
diff --git a/server-core/src/main/java/io/onedev/server/model/BuildDependence.java b/server-core/src/main/java/io/onedev/server/model/BuildDependence.java
index 9b0e0ca523..f9a10062bd 100644
--- a/server-core/src/main/java/io/onedev/server/model/BuildDependence.java
+++ b/server-core/src/main/java/io/onedev/server/model/BuildDependence.java
@@ -9,6 +9,8 @@ import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
+import io.onedev.server.rest.annotation.Api;
+
@Entity
@Table(
indexes={@Index(columnList="o_dependent_id"), @Index(columnList="o_dependency_id")},
@@ -22,6 +24,7 @@ public class BuildDependence extends AbstractEntity {
public static final String PROP_DEPENDENCY = "dependency";
+ @Api(exampleProvider="getDependentExample")
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
private Build dependent;
@@ -67,4 +70,11 @@ public class BuildDependence extends AbstractEntity {
this.artifacts = artifacts;
}
+ @SuppressWarnings("unused")
+ private static Build getDependentExample() {
+ Build build = new Build();
+ build.setId(2L);
+ return build;
+ }
+
}
diff --git a/server-core/src/main/java/io/onedev/server/model/Issue.java b/server-core/src/main/java/io/onedev/server/model/Issue.java
index dac26d89b7..f0adaa1a08 100644
--- a/server-core/src/main/java/io/onedev/server/model/Issue.java
+++ b/server-core/src/main/java/io/onedev/server/model/Issue.java
@@ -286,7 +286,7 @@ public class Issue extends AbstractEntity implements Referenceable, AttachmentSt
}
@Override
- public String getPrefix() {
+ public String getType() {
return "issue";
}
diff --git a/server-core/src/main/java/io/onedev/server/model/PullRequest.java b/server-core/src/main/java/io/onedev/server/model/PullRequest.java
index 5b0d32827b..26573387d1 100644
--- a/server-core/src/main/java/io/onedev/server/model/PullRequest.java
+++ b/server-core/src/main/java/io/onedev/server/model/PullRequest.java
@@ -65,6 +65,7 @@ import io.onedev.server.model.support.LastUpdate;
import io.onedev.server.model.support.pullrequest.CloseInfo;
import io.onedev.server.model.support.pullrequest.MergePreview;
import io.onedev.server.model.support.pullrequest.MergeStrategy;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
import io.onedev.server.storage.AttachmentStorageSupport;
import io.onedev.server.util.CollectionUtils;
@@ -206,6 +207,7 @@ public class PullRequest extends AbstractEntity implements Referenceable, Attach
@Embedded
private CloseInfo closeInfo;
+ @Api(order=100)
@Column(nullable=false)
@OptimisticLock(excluded=true)
private String title;
@@ -252,6 +254,7 @@ public class PullRequest extends AbstractEntity implements Referenceable, Attach
@OptimisticLock(excluded=true)
private String noSpaceTitle;
+ @JsonIgnore
@Embedded
private MergePreview lastMergePreview;
@@ -282,6 +285,7 @@ public class PullRequest extends AbstractEntity implements Referenceable, Attach
* after pull request is discarded
*/
@Version
+ @JsonIgnore
private int revision;
@OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
@@ -1044,7 +1048,7 @@ public class PullRequest extends AbstractEntity implements Referenceable, Attach
}
@Override
- public String getPrefix() {
+ public String getType() {
return "pull request";
}
diff --git a/server-core/src/main/java/io/onedev/server/model/PullRequestUpdate.java b/server-core/src/main/java/io/onedev/server/model/PullRequestUpdate.java
index 897fb53cb1..c124723397 100644
--- a/server-core/src/main/java/io/onedev/server/model/PullRequestUpdate.java
+++ b/server-core/src/main/java/io/onedev/server/model/PullRequestUpdate.java
@@ -25,7 +25,6 @@ import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
-import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import io.onedev.commons.utils.ExceptionUtils;
@@ -88,7 +87,6 @@ public class PullRequestUpdate extends AbstractEntity {
this.date = date;
}
- @JsonProperty
public String getHeadRef() {
Preconditions.checkNotNull(getId());
return REFS_PREFIX + getId();
diff --git a/server-core/src/main/java/io/onedev/server/model/SshKey.java b/server-core/src/main/java/io/onedev/server/model/SshKey.java
index b6d91da839..cb5584ff98 100644
--- a/server-core/src/main/java/io/onedev/server/model/SshKey.java
+++ b/server-core/src/main/java/io/onedev/server/model/SshKey.java
@@ -79,7 +79,7 @@ public class SshKey extends AbstractEntity implements Validatable {
return createdAt;
}
- public void setDate(Date createdAt) {
+ public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
diff --git a/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueChangeData.java b/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueChangeData.java
index b01fc78908..85a4ebc969 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueChangeData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueChangeData.java
@@ -28,4 +28,5 @@ public interface IssueChangeData extends Serializable {
Map<String, Group> getNewGroups();
boolean affectsBoards();
+
}
diff --git a/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromCodeCommentData.java b/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromCodeCommentData.java
index 6458d5dcb2..b52687c4dc 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromCodeCommentData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromCodeCommentData.java
@@ -11,6 +11,7 @@ import io.onedev.server.model.Group;
import io.onedev.server.model.Issue;
import io.onedev.server.model.IssueChange;
import io.onedev.server.model.User;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.util.CommentAware;
import io.onedev.server.web.component.codecomment.referencedfrom.ReferencedFromCodeCommentPanel;
@@ -18,6 +19,7 @@ public class IssueReferencedFromCodeCommentData implements IssueChangeData {
private static final long serialVersionUID = 1L;
+ @EntityId(CodeComment.class)
private final Long commentId;
public IssueReferencedFromCodeCommentData(CodeComment comment) {
diff --git a/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromIssueData.java b/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromIssueData.java
index 266500231c..99dbabe682 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromIssueData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromIssueData.java
@@ -10,6 +10,7 @@ import io.onedev.server.model.Group;
import io.onedev.server.model.Issue;
import io.onedev.server.model.IssueChange;
import io.onedev.server.model.User;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.util.CommentAware;
import io.onedev.server.web.component.issue.referencedfrom.ReferencedFromIssuePanel;
@@ -17,6 +18,7 @@ public class IssueReferencedFromIssueData implements IssueChangeData {
private static final long serialVersionUID = 1L;
+ @EntityId(Issue.class)
private final Long issueId;
public IssueReferencedFromIssueData(Issue issue) {
diff --git a/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromPullRequestData.java b/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromPullRequestData.java
index 95e1c70f30..a13cc4010f 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromPullRequestData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/issue/changedata/IssueReferencedFromPullRequestData.java
@@ -11,6 +11,7 @@ import io.onedev.server.model.Issue;
import io.onedev.server.model.IssueChange;
import io.onedev.server.model.PullRequest;
import io.onedev.server.model.User;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.util.CommentAware;
import io.onedev.server.web.component.pullrequest.referencedfrom.ReferencedFromPullRequestPanel;
@@ -18,6 +19,7 @@ public class IssueReferencedFromPullRequestData implements IssueChangeData {
private static final long serialVersionUID = 1L;
+ @EntityId(PullRequest.class)
private final Long requestId;
public IssueReferencedFromPullRequestData(PullRequest request) {
@@ -60,5 +62,5 @@ public class IssueReferencedFromPullRequestData implements IssueChangeData {
public boolean affectsBoards() {
return false;
}
-
+
}
diff --git a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/ReviewResult.java b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/ReviewResult.java
index 2c78446084..980665972f 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/ReviewResult.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/ReviewResult.java
@@ -27,11 +27,11 @@ public class ReviewResult implements Serializable {
this.commit = commit;
}
- public boolean isApproved() {
+ public Boolean isApproved() {
return approved;
}
- public void setApproved(boolean approved) {
+ public void setApproved(Boolean approved) {
this.approved = approved;
}
diff --git a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestDescriptionChangeData.java b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestDescriptionChangeData.java
index 87a69ffde7..a9a052e95f 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestDescriptionChangeData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestDescriptionChangeData.java
@@ -44,5 +44,5 @@ public class PullRequestDescriptionChangeData implements PullRequestChangeData {
public CommentAware getCommentAware() {
return null;
}
-
+
}
diff --git a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromCodeCommentData.java b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromCodeCommentData.java
index 9cef429d67..6a06c39ab7 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromCodeCommentData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromCodeCommentData.java
@@ -5,6 +5,7 @@ import org.apache.wicket.Component;
import io.onedev.server.model.CodeComment;
import io.onedev.server.model.PullRequest;
import io.onedev.server.model.PullRequestChange;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.util.CommentAware;
import io.onedev.server.web.component.codecomment.referencedfrom.ReferencedFromCodeCommentPanel;
@@ -12,6 +13,7 @@ public class PullRequestReferencedFromCodeCommentData implements PullRequestChan
private static final long serialVersionUID = 1L;
+ @EntityId(CodeComment.class)
private final Long commentId;
public PullRequestReferencedFromCodeCommentData(CodeComment comment) {
diff --git a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromIssueData.java b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromIssueData.java
index 975dbf140d..95b9e77add 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromIssueData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromIssueData.java
@@ -5,6 +5,7 @@ import org.apache.wicket.Component;
import io.onedev.server.model.Issue;
import io.onedev.server.model.PullRequest;
import io.onedev.server.model.PullRequestChange;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.util.CommentAware;
import io.onedev.server.web.component.issue.referencedfrom.ReferencedFromIssuePanel;
@@ -12,6 +13,7 @@ public class PullRequestReferencedFromIssueData implements PullRequestChangeData
private static final long serialVersionUID = 1L;
+ @EntityId(Issue.class)
private final Long issueId;
public PullRequestReferencedFromIssueData(Issue issue) {
@@ -40,5 +42,4 @@ public class PullRequestReferencedFromIssueData implements PullRequestChangeData
return null;
}
-
}
diff --git a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromPullRequestData.java b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromPullRequestData.java
index cebe22f940..9021718163 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromPullRequestData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestReferencedFromPullRequestData.java
@@ -4,6 +4,7 @@ import org.apache.wicket.Component;
import io.onedev.server.model.PullRequest;
import io.onedev.server.model.PullRequestChange;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.util.CommentAware;
import io.onedev.server.web.component.pullrequest.referencedfrom.ReferencedFromPullRequestPanel;
@@ -11,6 +12,7 @@ public class PullRequestReferencedFromPullRequestData implements PullRequestChan
private static final long serialVersionUID = 1L;
+ @EntityId(PullRequest.class)
private final Long requestId;
public PullRequestReferencedFromPullRequestData(PullRequest request) {
diff --git a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestTitleChangeData.java b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestTitleChangeData.java
index b718f23df8..4c56c65b54 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestTitleChangeData.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/pullrequest/changedata/PullRequestTitleChangeData.java
@@ -42,4 +42,4 @@ public class PullRequestTitleChangeData implements PullRequestChangeData {
return null;
}
-}
+}
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/rest/BuildQuerySettingResource.java b/server-core/src/main/java/io/onedev/server/rest/BuildQuerySettingResource.java
index b533a82f7d..dcad916fc6 100644
--- a/server-core/src/main/java/io/onedev/server/rest/BuildQuerySettingResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/BuildQuerySettingResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.BuildQuerySettingManager;
import io.onedev.server.model.BuildQuerySetting;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=5300)
@Path("/build-query-settings")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class BuildQuerySettingResource {
this.querySettingManager = querySettingManager;
}
+ @Api(order=100)
@Path("/{querySettingId}")
@GET
public BuildQuerySetting get(@PathParam("querySettingId") Long querySettingId) {
@@ -41,6 +44,7 @@ public class BuildQuerySettingResource {
return querySetting;
}
+ @Api(order=200)
@POST
public Long save(@NotNull BuildQuerySetting querySetting) {
if (!SecurityUtils.canAccess(querySetting.getProject())
@@ -51,6 +55,7 @@ public class BuildQuerySettingResource {
return querySetting.getId();
}
+ @Api(order=300)
@Path("/{querySettingId}")
@DELETE
public Response delete(@PathParam("querySettingId") Long querySettingId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/BuildResource.java b/server-core/src/main/java/io/onedev/server/rest/BuildResource.java
index 16b92e22e2..4a07639c35 100644
--- a/server-core/src/main/java/io/onedev/server/rest/BuildResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/BuildResource.java
@@ -21,10 +21,12 @@ import io.onedev.server.entitymanager.BuildManager;
import io.onedev.server.model.Build;
import io.onedev.server.model.BuildDependence;
import io.onedev.server.model.BuildParam;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.rest.jersey.InvalidParamException;
import io.onedev.server.search.entity.build.BuildQuery;
import io.onedev.server.security.SecurityUtils;
+@Api(order=4000)
@Path("/builds")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -38,6 +40,7 @@ public class BuildResource {
this.buildManager = buildManager;
}
+ @Api(order=100)
@Path("/{buildId}")
@GET
public Build get(@PathParam("buildId") Long buildId) {
@@ -47,6 +50,7 @@ public class BuildResource {
return build;
}
+ @Api(order=200)
@Path("/{buildId}/params")
@GET
public Collection<BuildParam> getParams(@PathParam("buildId") Long buildId) {
@@ -56,6 +60,7 @@ public class BuildResource {
return build.getParams();
}
+ @Api(order=300)
@Path("/{buildId}/dependencies")
@GET
public Collection<BuildDependence> getDependencies(@PathParam("buildId") Long buildId) {
@@ -65,6 +70,7 @@ public class BuildResource {
return build.getDependencies();
}
+ @Api(order=400)
@Path("/{buildId}/dependents")
@GET
public Collection<BuildDependence> getDependents(@PathParam("buildId") Long buildId) {
@@ -74,6 +80,7 @@ public class BuildResource {
return build.getDependents();
}
+ @Api(order=500)
@Path("/{buildId}/fixed-issue-numbers")
@GET
public Collection<Long> getFixedIssueNumbers(@PathParam("buildId") Long buildId) {
@@ -83,12 +90,13 @@ public class BuildResource {
return build.getFixedIssueNumbers();
}
+ @Api(order=600)
@GET
public List<Build> query(@QueryParam("query") String query, @QueryParam("offset") int offset,
@QueryParam("count") int count) {
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
BuildQuery parsedQuery;
try {
@@ -100,6 +108,7 @@ public class BuildResource {
return buildManager.query(null, parsedQuery, offset, count);
}
+ @Api(order=700)
@Path("/{buildId}")
@DELETE
public Response delete(@PathParam("buildId") Long buildId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/CodeCommentQuerySettingResource.java b/server-core/src/main/java/io/onedev/server/rest/CodeCommentQuerySettingResource.java
index 957878934a..e55c0197ad 100644
--- a/server-core/src/main/java/io/onedev/server/rest/CodeCommentQuerySettingResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/CodeCommentQuerySettingResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.CodeCommentQuerySettingManager;
import io.onedev.server.model.CodeCommentQuerySetting;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=5500)
@Path("/code-comment-query-settings")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class CodeCommentQuerySettingResource {
this.querySettingManager = querySettingManager;
}
+ @Api(order=100)
@Path("/{querySettingId}")
@GET
public CodeCommentQuerySetting get(@PathParam("querySettingId") Long querySettingId) {
@@ -41,6 +44,7 @@ public class CodeCommentQuerySettingResource {
return querySetting;
}
+ @Api(order=200)
@POST
public Long save(@NotNull CodeCommentQuerySetting querySetting) {
if (!SecurityUtils.canAccess(querySetting.getProject())
@@ -51,6 +55,7 @@ public class CodeCommentQuerySettingResource {
return querySetting.getId();
}
+ @Api(order=300)
@Path("/{querySettingId}")
@DELETE
public Response delete(@PathParam("querySettingId") Long querySettingId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/CodeCommentReplyResource.java b/server-core/src/main/java/io/onedev/server/rest/CodeCommentReplyResource.java
index 6e2f2b3285..8d8921d77b 100644
--- a/server-core/src/main/java/io/onedev/server/rest/CodeCommentReplyResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/CodeCommentReplyResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.CodeCommentReplyManager;
import io.onedev.server.model.CodeCommentReply;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=4600)
@Path("/code-comment-replies")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class CodeCommentReplyResource {
this.replyManager = replyManager;
}
+ @Api(order=100)
@Path("/{replyId}")
@GET
public CodeCommentReply get(@PathParam("commentId") Long replyId) {
@@ -41,6 +44,7 @@ public class CodeCommentReplyResource {
return reply;
}
+ @Api(order=200)
@POST
public Long save(@NotNull CodeCommentReply reply) {
if (!SecurityUtils.canReadCode(reply.getComment().getProject()) ||
@@ -52,6 +56,7 @@ public class CodeCommentReplyResource {
return reply.getId();
}
+ @Api(order=300)
@Path("/{replyId}")
@DELETE
public Response delete(@PathParam("replyId") Long replyId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/CodeCommentResource.java b/server-core/src/main/java/io/onedev/server/rest/CodeCommentResource.java
index 0038c8f280..8b1b35bd97 100644
--- a/server-core/src/main/java/io/onedev/server/rest/CodeCommentResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/CodeCommentResource.java
@@ -25,10 +25,12 @@ import io.onedev.server.model.CodeComment;
import io.onedev.server.model.CodeCommentReply;
import io.onedev.server.model.Project;
import io.onedev.server.model.PullRequest;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.rest.jersey.InvalidParamException;
import io.onedev.server.search.entity.codecomment.CodeCommentQuery;
import io.onedev.server.security.SecurityUtils;
+@Api(order=4500)
@Path("/code-comments")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -49,6 +51,7 @@ public class CodeCommentResource {
this.pullRequestManager = pullRequestManager;
}
+ @Api(order=100)
@Path("/{commentId}")
@GET
public CodeComment get(@PathParam("commentId") Long commentId) {
@@ -58,6 +61,7 @@ public class CodeCommentResource {
return comment;
}
+ @Api(order=200)
@Path("/{commentId}/replies")
@GET
public Collection<CodeCommentReply> getReplies(@PathParam("commentId") Long commentId) {
@@ -67,13 +71,14 @@ public class CodeCommentResource {
return comment.getReplies();
}
+ @Api(order=300)
@GET
public Collection<CodeComment> query(@QueryParam("projectId") Long projectId,
@QueryParam("pullRequestId") Long pullRequestId, @QueryParam("query") String query,
@QueryParam("offset") int offset, @QueryParam("count") int count) {
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
Project project;
if (projectId != null)
@@ -109,6 +114,7 @@ public class CodeCommentResource {
return commentManager.query(project, pullRequest, parsedQuery, offset, count);
}
+ @Api(order=400)
@POST
public Long save(@NotNull CodeComment comment) {
if (!SecurityUtils.canReadCode(comment.getProject()) ||
@@ -120,6 +126,7 @@ public class CodeCommentResource {
return comment.getId();
}
+ @Api(order=500)
@Path("/{commentId}")
@DELETE
public Response delete(@PathParam("commentId") Long commentId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/CommitQuerySettingResource.java b/server-core/src/main/java/io/onedev/server/rest/CommitQuerySettingResource.java
index 93b330d429..07b99962ec 100644
--- a/server-core/src/main/java/io/onedev/server/rest/CommitQuerySettingResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/CommitQuerySettingResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.CommitQuerySettingManager;
import io.onedev.server.model.CommitQuerySetting;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=5400)
@Path("/commit-query-settings")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class CommitQuerySettingResource {
this.querySettingManager = querySettingManager;
}
+ @Api(order=100)
@Path("/{querySettingId}")
@GET
public CommitQuerySetting get(@PathParam("querySettingId") Long querySettingId) {
@@ -41,6 +44,7 @@ public class CommitQuerySettingResource {
return querySetting;
}
+ @Api(order=200)
@POST
public Long save(@NotNull CommitQuerySetting querySetting) {
if (!SecurityUtils.canAccess(querySetting.getProject())
@@ -51,6 +55,7 @@ public class CommitQuerySettingResource {
return querySetting.getId();
}
+ @Api(order=300)
@Path("/{querySettingId}")
@DELETE
public Response delete(@PathParam("querySettingId") Long querySettingId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/GroupAuthorizationResource.java b/server-core/src/main/java/io/onedev/server/rest/GroupAuthorizationResource.java
index 0c5a575d33..00f7d463fc 100644
--- a/server-core/src/main/java/io/onedev/server/rest/GroupAuthorizationResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/GroupAuthorizationResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.GroupAuthorizationManager;
import io.onedev.server.model.GroupAuthorization;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=9000)
@Path("/group-authorizations")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class GroupAuthorizationResource {
this.authorizationManager = authorizationManager;
}
+ @Api(order=100)
@Path("/{authorizationId}")
@GET
public GroupAuthorization get(@PathParam("authorizationId") Long authorizationId) {
@@ -40,6 +43,7 @@ public class GroupAuthorizationResource {
return authorizationManager.load(authorizationId);
}
+ @Api(order=200)
@POST
public Long save(@NotNull GroupAuthorization authorization) {
if (!SecurityUtils.isAdministrator())
@@ -48,6 +52,7 @@ public class GroupAuthorizationResource {
return authorization.getId();
}
+ @Api(order=300)
@Path("/{authorizationId}")
@DELETE
public Response delete(@PathParam("authorizationId") Long authorizationId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/GroupResource.java b/server-core/src/main/java/io/onedev/server/rest/GroupResource.java
index 11be029a83..bd4ae7e645 100644
--- a/server-core/src/main/java/io/onedev/server/rest/GroupResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/GroupResource.java
@@ -26,9 +26,11 @@ import io.onedev.server.model.Group;
import io.onedev.server.model.GroupAuthorization;
import io.onedev.server.model.Membership;
import io.onedev.server.persistence.dao.EntityCriteria;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.rest.jersey.InvalidParamException;
import io.onedev.server.security.SecurityUtils;
+@Api(order=6000)
@Path("/groups")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -42,6 +44,7 @@ public class GroupResource {
this.groupManager = groupManager;
}
+ @Api(order=100)
@Path("/{groupId}")
@GET
public Group get(@PathParam("groupId") Long groupId) {
@@ -50,6 +53,7 @@ public class GroupResource {
return groupManager.load(groupId);
}
+ @Api(order=200)
@Path("/{groupId}/authorizations")
@GET
public Collection<GroupAuthorization> getAuthorizations(@PathParam("groupId") Long groupId) {
@@ -58,6 +62,7 @@ public class GroupResource {
return groupManager.load(groupId).getAuthorizations();
}
+ @Api(order=300)
@Path("/{groupId}/memberships")
@GET
public Collection<Membership> getMemberships(@PathParam("groupId") Long groupId) {
@@ -66,6 +71,7 @@ public class GroupResource {
return groupManager.load(groupId).getMemberships();
}
+ @Api(order=400)
@GET
public List<Group> query(@QueryParam("name") String name, @QueryParam("offset") int offset,
@QueryParam("count") int count) {
@@ -73,8 +79,8 @@ public class GroupResource {
if (!SecurityUtils.isAdministrator())
throw new UnauthorizedException();
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
EntityCriteria<Group> criteria = EntityCriteria.of(Group.class);
if (name != null)
@@ -83,6 +89,7 @@ public class GroupResource {
return groupManager.query(criteria, offset, count);
}
+ @Api(order=500)
@POST
public Long save(@NotNull Group group) {
if (!SecurityUtils.isAdministrator())
@@ -91,6 +98,7 @@ public class GroupResource {
return group.getId();
}
+ @Api(order=600)
@Path("/{groupId}")
@DELETE
public Response delete(@PathParam("groupId") Long groupId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/IssueCommentResource.java b/server-core/src/main/java/io/onedev/server/rest/IssueCommentResource.java
index ba73b52ca4..4b22598222 100644
--- a/server-core/src/main/java/io/onedev/server/rest/IssueCommentResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/IssueCommentResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.IssueCommentManager;
import io.onedev.server.model.IssueComment;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=2300)
@Path("/issue-comments")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class IssueCommentResource {
this.commentManager = commentManager;
}
+ @Api(order=100)
@Path("/{commentId}")
@GET
public IssueComment get(@PathParam("commentId") Long commentId) {
@@ -41,6 +44,7 @@ public class IssueCommentResource {
return comment;
}
+ @Api(order=200)
@POST
public Long save(@NotNull IssueComment comment) {
if (!SecurityUtils.canAccess(comment.getIssue().getProject()) ||
@@ -52,6 +56,7 @@ public class IssueCommentResource {
return comment.getId();
}
+ @Api(order=300)
@Path("/{commentId}")
@DELETE
public Response delete(@PathParam("commentId") Long commentId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/IssueQuerySettingResource.java b/server-core/src/main/java/io/onedev/server/rest/IssueQuerySettingResource.java
index d470b2d4bf..ab58ad3877 100644
--- a/server-core/src/main/java/io/onedev/server/rest/IssueQuerySettingResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/IssueQuerySettingResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.IssueQuerySettingManager;
import io.onedev.server.model.IssueQuerySetting;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=5100)
@Path("/issue-query-settings")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class IssueQuerySettingResource {
this.querySettingManager = querySettingManager;
}
+ @Api(order=100)
@Path("/{querySettingId}")
@GET
public IssueQuerySetting get(@PathParam("querySettingId") Long querySettingId) {
@@ -41,6 +44,7 @@ public class IssueQuerySettingResource {
return querySetting;
}
+ @Api(order=200)
@POST
public Long save(@NotNull IssueQuerySetting querySetting) {
if (!SecurityUtils.canAccess(querySetting.getProject())
@@ -51,6 +55,7 @@ public class IssueQuerySettingResource {
return querySetting.getId();
}
+ @Api(order=300)
@Path("/{querySettingId}")
@DELETE
public Response delete(@PathParam("querySettingId") Long querySettingId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/IssueResource.java b/server-core/src/main/java/io/onedev/server/rest/IssueResource.java
index e8e86b78fd..e34deb2220 100644
--- a/server-core/src/main/java/io/onedev/server/rest/IssueResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/IssueResource.java
@@ -25,7 +25,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.hibernate.validator.constraints.NotEmpty;
@@ -45,10 +44,13 @@ import io.onedev.server.model.Project;
import io.onedev.server.model.PullRequest;
import io.onedev.server.model.User;
import io.onedev.server.model.support.issue.field.spec.FieldSpec;
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.rest.jersey.InvalidParamException;
import io.onedev.server.search.entity.issue.IssueQuery;
import io.onedev.server.security.SecurityUtils;
+@Api(order=2000)
@Path("/issues")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -76,6 +78,7 @@ public class IssueResource {
this.projectManager = projectManager;
}
+ @Api(order=100)
@Path("/{issueId}")
@GET
public Issue get(@PathParam("issueId") Long issueId) {
@@ -85,6 +88,7 @@ public class IssueResource {
return issue;
}
+ @Api(order=200)
@Path("/{issueId}/fields")
@GET
public Collection<IssueField> getFields(@PathParam("issueId") Long issueId) {
@@ -94,6 +98,7 @@ public class IssueResource {
return issue.getFields();
}
+ @Api(order=300)
@Path("/{issueId}/changes")
@GET
public Collection<IssueChange> getChanges(@PathParam("issueId") Long issueId) {
@@ -103,6 +108,7 @@ public class IssueResource {
return issue.getChanges();
}
+ @Api(order=400)
@Path("/{issueId}/comments")
@GET
public Collection<IssueComment> getComments(@PathParam("issueId") Long issueId) {
@@ -112,6 +118,7 @@ public class IssueResource {
return issue.getComments();
}
+ @Api(order=500)
@Path("/{issueId}/votes")
@GET
public Collection<IssueVote> getVotes(@PathParam("issueId") Long issueId) {
@@ -121,6 +128,7 @@ public class IssueResource {
return issue.getVotes();
}
+ @Api(order=600)
@Path("/{issueId}/watches")
@GET
public Collection<IssueWatch> getWatches(@PathParam("issueId") Long issueId) {
@@ -130,6 +138,7 @@ public class IssueResource {
return issue.getWatches();
}
+ @Api(order=700)
@Path("/{issueId}/pull-requests")
@GET
public Collection<PullRequest> getPullRequests(@PathParam("issueId") Long issueId) {
@@ -139,6 +148,7 @@ public class IssueResource {
return issue.getPullRequests();
}
+ @Api(order=800)
@Path("/{issueId}/commits")
@GET
public Collection<String> getCommits(@PathParam("issueId") Long issueId) {
@@ -148,12 +158,13 @@ public class IssueResource {
return issue.getCommits().stream().map(it->it.name()).collect(Collectors.toList());
}
+ @Api(order=900)
@GET
public List<Issue> query(@QueryParam("query") String query, @QueryParam("offset") int offset,
@QueryParam("count") int count) {
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
IssueQuery parsedQuery;
try {
@@ -165,11 +176,10 @@ public class IssueResource {
return issueManager.query(null, parsedQuery, offset, count, false);
}
+ @Api(order=1000)
@POST
public Long open(@NotNull @Valid IssueOpenData data) {
User user = SecurityUtils.getUser();
- if (user == null)
- throw new UnauthenticatedException();
Project project = projectManager.load(data.getProjectId());
if (!SecurityUtils.canAccess(project))
@@ -211,6 +221,7 @@ public class IssueResource {
return issue.getId();
}
+ @Api(order=1100)
@Path("/{issueId}/title")
@POST
public Response setTitle(@PathParam("issueId") Long issueId, @NotEmpty String title) {
@@ -221,6 +232,7 @@ public class IssueResource {
return Response.ok().build();
}
+ @Api(order=1200)
@Path("/{issueId}/description")
@POST
public Response setDescription(@PathParam("issueId") Long issueId, String description) {
@@ -231,6 +243,7 @@ public class IssueResource {
return Response.ok().build();
}
+ @Api(order=1300)
@Path("/{issueId}/milestone")
@POST
public Response setMilestone(@PathParam("issueId") Long issueId, Long milestoneId) {
@@ -249,6 +262,7 @@ public class IssueResource {
return Response.ok().build();
}
+ @Api(order=1400)
@Path("/{issueId}/fields")
@POST
public Response setFields(@PathParam("issueId") Long issueId, @NotNull Map<String, String> fields) {
@@ -277,6 +291,7 @@ public class IssueResource {
return Response.ok().build();
}
+ @Api(order=1500)
@Path("/{issueId}/state-transitions")
@POST
public Response transitState(@PathParam("issueId") Long issueId, @NotNull @Valid StateTransitionData data) {
@@ -310,6 +325,7 @@ public class IssueResource {
return fieldObjs;
}
+ @Api(order=1600)
@Path("/{issueId}")
@DELETE
public Response delete(@PathParam("issueId") Long issueId) {
@@ -324,12 +340,14 @@ public class IssueResource {
private static final long serialVersionUID = 1L;
+ @EntityId(Project.class)
private Long projectId;
private String title;
private String description;
+ @EntityId(Project.class)
private Long milestoneId;
private Map<String, String> fields = new HashMap<>();
diff --git a/server-core/src/main/java/io/onedev/server/rest/IssueVoteResource.java b/server-core/src/main/java/io/onedev/server/rest/IssueVoteResource.java
index 9b04aacd45..c038af775a 100644
--- a/server-core/src/main/java/io/onedev/server/rest/IssueVoteResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/IssueVoteResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.IssueVoteManager;
import io.onedev.server.model.IssueVote;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=2100)
@Path("/issue-votes")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class IssueVoteResource {
this.voteManager = voteManager;
}
+ @Api(order=100)
@Path("/{voteId}")
@GET
public IssueVote get(@PathParam("voteId") Long voteId) {
@@ -41,6 +44,7 @@ public class IssueVoteResource {
return vote;
}
+ @Api(order=200)
@POST
public Long save(@NotNull IssueVote vote) {
if (!SecurityUtils.canAccess(vote.getIssue().getProject())
@@ -51,6 +55,7 @@ public class IssueVoteResource {
return vote.getId();
}
+ @Api(order=300)
@Path("/{voteId}")
@DELETE
public Response delete(@PathParam("voteId") Long voteId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/IssueWatchResource.java b/server-core/src/main/java/io/onedev/server/rest/IssueWatchResource.java
index 480de51fb9..4bf79504db 100644
--- a/server-core/src/main/java/io/onedev/server/rest/IssueWatchResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/IssueWatchResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.IssueWatchManager;
import io.onedev.server.model.IssueWatch;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=2200)
@Path("/issue-watches")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class IssueWatchResource {
this.watchManager = watchManager;
}
+ @Api(order=100)
@Path("/{watchId}")
@GET
public IssueWatch get(@PathParam("watchId") Long watchId) {
@@ -41,6 +44,7 @@ public class IssueWatchResource {
return watch;
}
+ @Api(order=200)
@POST
public Long save(@NotNull IssueWatch watch) {
if (!SecurityUtils.canAccess(watch.getIssue().getProject())
@@ -51,6 +55,7 @@ public class IssueWatchResource {
return watch.getId();
}
+ @Api(order=300)
@Path("/{watchId}")
@DELETE
public Response delete(@PathParam("watchId") Long watchId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/JobRunResource.java b/server-core/src/main/java/io/onedev/server/rest/JobRunResource.java
index f1a48ade58..6492a6a9a4 100644
--- a/server-core/src/main/java/io/onedev/server/rest/JobRunResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/JobRunResource.java
@@ -30,9 +30,12 @@ import io.onedev.server.entitymanager.PullRequestManager;
import io.onedev.server.model.Build;
import io.onedev.server.model.Project;
import io.onedev.server.model.PullRequest;
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.security.SecurityUtils;
import io.onedev.server.util.validation.annotation.CommitHash;
+@Api(order=3500)
@Path("/job-runs")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -56,8 +59,9 @@ public class JobRunResource {
this.pullRequestManager = pullRequestManager;
}
+ @Api(order=100)
@POST
- public Long save(@NotNull @Valid JobRun jobRun) {
+ public Long run(@NotNull @Valid JobRun jobRun) {
Project project = projectManager.load(jobRun.projectId);
if (!SecurityUtils.canRunJob(project, jobRun.jobName))
throw new UnauthorizedException();
@@ -87,9 +91,10 @@ public class JobRunResource {
jobRun.jobName, jobRun.params, reason).getId();
}
+ @Api(order=200)
@Path("/rerun")
@POST
- public Response save(@NotNull @Valid JobRerun jobRerun) {
+ public Response rerun(@NotNull @Valid JobRerun jobRerun) {
Build build = buildManager.load(jobRerun.buildId);
if (!SecurityUtils.canRunJob(build.getProject(), build.getJobName()))
throw new UnauthorizedException();
@@ -97,6 +102,7 @@ public class JobRunResource {
return Response.ok().build();
}
+ @Api(order=300)
@Path("/{buildId}")
@DELETE
public Response delete(@PathParam("buildId") Long buildId) {
@@ -112,6 +118,7 @@ public class JobRunResource {
private static final long serialVersionUID = 1L;
+ @EntityId(Project.class)
private Long projectId;
private String commitHash;
@@ -122,6 +129,7 @@ public class JobRunResource {
private String refName;
+ @EntityId(PullRequest.class)
private Long pullRequestId;
private String reason;
diff --git a/server-core/src/main/java/io/onedev/server/rest/MembershipResource.java b/server-core/src/main/java/io/onedev/server/rest/MembershipResource.java
index 0f3ca5e1b7..ae29439535 100644
--- a/server-core/src/main/java/io/onedev/server/rest/MembershipResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/MembershipResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.MembershipManager;
import io.onedev.server.model.Membership;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=6100)
@Path("/memberships")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class MembershipResource {
this.membershipManager = membershipManager;
}
+ @Api(order=100)
@Path("/{membershipId}")
@GET
public Membership get(@PathParam("membershipId") Long membershipId) {
@@ -40,6 +43,7 @@ public class MembershipResource {
return membershipManager.load(membershipId);
}
+ @Api(order=200)
@POST
public Long save(@NotNull Membership membership) {
if (!SecurityUtils.isAdministrator())
@@ -48,6 +52,7 @@ public class MembershipResource {
return membership.getId();
}
+ @Api(order=300)
@Path("/{membershipId}")
@DELETE
public Response delete(@PathParam("membershipId") Long membershipId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/MilestoneResource.java b/server-core/src/main/java/io/onedev/server/rest/MilestoneResource.java
index 33baf28caf..4009365ab8 100644
--- a/server-core/src/main/java/io/onedev/server/rest/MilestoneResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/MilestoneResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.MilestoneManager;
import io.onedev.server.model.Milestone;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=2500)
@Path("/milestones")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class MilestoneResource {
this.milestoneManager = milestoneManager;
}
+ @Api(order=100)
@Path("/{milestoneId}")
@GET
public Milestone get(@PathParam("milestoneId") Long milestoneId) {
@@ -41,6 +44,7 @@ public class MilestoneResource {
return milestone;
}
+ @Api(order=200)
@POST
public Long save(@NotNull Milestone milestone) {
if (!SecurityUtils.canManageIssues(milestone.getProject()))
@@ -49,6 +53,7 @@ public class MilestoneResource {
return milestone.getId();
}
+ @Api(order=300)
@Path("/{milestoneId}")
@DELETE
public Response delete(@PathParam("milestoneId") Long milestoneId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/ProjectResource.java b/server-core/src/main/java/io/onedev/server/rest/ProjectResource.java
index 725fde5c3e..2f2e715f75 100644
--- a/server-core/src/main/java/io/onedev/server/rest/ProjectResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/ProjectResource.java
@@ -3,7 +3,6 @@ package io.onedev.server.rest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Date;
import java.util.List;
import javax.inject.Inject;
@@ -20,7 +19,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.hibernate.criterion.Restrictions;
@@ -39,10 +37,12 @@ import io.onedev.server.model.support.build.ProjectBuildSetting;
import io.onedev.server.model.support.issue.ProjectIssueSetting;
import io.onedev.server.model.support.pullrequest.ProjectPullRequestSetting;
import io.onedev.server.persistence.dao.EntityCriteria;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.rest.jersey.InvalidParamException;
import io.onedev.server.search.entity.project.ProjectQuery;
import io.onedev.server.security.SecurityUtils;
+@Api(order=1000)
@Path("/projects")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -59,15 +59,17 @@ public class ProjectResource {
this.milestoneManager = milestoneManager;
}
+ @Api(order=100)
@Path("/{projectId}")
@GET
- public Project get(@PathParam("projectId") Long projectId) {
+ public Project get(@Api(description="Internal id of project") @PathParam("projectId") Long projectId) {
Project project = projectManager.load(projectId);
if (!SecurityUtils.canAccess(project))
throw new UnauthorizedException();
return project;
}
+ @Api(order=200)
@Path("/{projectId}/setting")
@GET
public ProjectSetting getSetting(@PathParam("projectId") Long projectId) {
@@ -86,6 +88,7 @@ public class ProjectResource {
return setting;
}
+ @Api(order=300)
@Path("/{projectId}/forks")
@GET
public Collection<Project> getForks(@PathParam("projectId") Long projectId) {
@@ -95,6 +98,7 @@ public class ProjectResource {
return project.getForks();
}
+ @Api(order=400)
@Path("/{projectId}/group-authorizations")
@GET
public Collection<GroupAuthorization> getGroupAuthorizations(@PathParam("projectId") Long projectId) {
@@ -103,6 +107,7 @@ public class ProjectResource {
return projectManager.load(projectId).getGroupAuthorizations();
}
+ @Api(order=500)
@Path("/{projectId}/user-authorizations")
@GET
public Collection<UserAuthorization> getUserAuthorizations(@PathParam("projectId") Long projectId) {
@@ -112,66 +117,66 @@ public class ProjectResource {
return project.getUserAuthorizations();
}
+ @Api(order=700)
+ @GET
+ public List<Project> query(@QueryParam("query") String query, @QueryParam("offset") int offset,
+ @QueryParam("count") int count) {
+
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
+
+ ProjectQuery parsedQuery;
+ try {
+ parsedQuery = ProjectQuery.parse(query);
+ } catch (Exception e) {
+ throw new InvalidParamException("Error parsing query", e);
+ }
+
+ return projectManager.query(parsedQuery, offset, count);
+ }
+
+ @Api(order=750)
@Path("/{projectId}/milestones")
@GET
public List<Milestone> queryMilestones(@PathParam("projectId") Long projectId, @QueryParam("name") String name,
- @QueryParam("dueBefore") Date dueBefore, @QueryParam("dueAfter") Date dueAfter,
+ @QueryParam("dueBefore") String dueBefore, @QueryParam("dueAfter") String dueAfter,
@QueryParam("closed") Boolean closed, @QueryParam("offset") int offset,
@QueryParam("count") int count) {
Project project = projectManager.load(projectId);
if (!SecurityUtils.canAccess(project))
throw new UnauthorizedException();
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
EntityCriteria<Milestone> criteria = EntityCriteria.of(Milestone.class);
criteria.add(Restrictions.eq(Milestone.PROP_PROJECT, project));
if (name != null)
criteria.add(Restrictions.ilike(Milestone.PROP_NAME, name.replace('%', '*')));
if (dueBefore != null)
- criteria.add(Restrictions.le(Milestone.PROP_DUE_DATE, dueBefore));
+ criteria.add(Restrictions.le(Milestone.PROP_DUE_DATE, RestUtils.toDate(dueBefore)));
if (dueAfter != null)
- criteria.add(Restrictions.ge(Milestone.PROP_DUE_DATE, dueAfter));
+ criteria.add(Restrictions.ge(Milestone.PROP_DUE_DATE, RestUtils.toDate(dueAfter)));
if (closed != null)
criteria.add(Restrictions.eq(Milestone.PROP_CLOSED, closed));
return milestoneManager.query(criteria, offset, count);
}
- @GET
- public List<Project> query(@QueryParam("query") String query, @QueryParam("offset") int offset,
- @QueryParam("count") int count) {
-
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
-
- ProjectQuery parsedQuery;
- try {
- parsedQuery = ProjectQuery.parse(query);
- } catch (Exception e) {
- throw new InvalidParamException("Error parsing query", e);
- }
-
- return projectManager.query(parsedQuery, offset, count);
- }
-
+ @Api(order=800)
@POST
public Long save(@NotNull Project project) {
- if (project.isNew()) {
- if (SecurityUtils.getUser() == null)
- throw new UnauthenticatedException();
- else
- projectManager.create(project);
- } else {
- if (!SecurityUtils.canManage(project))
- throw new UnauthorizedException();
- else
- projectManager.save(project, (String) project.getCustomData());
- }
+ if (project.isNew())
+ projectManager.create(project);
+ else if (!SecurityUtils.canManage(project))
+ throw new UnauthorizedException();
+ else
+ projectManager.save(project, (String) project.getCustomData());
+
return project.getId();
}
+ @Api(order=900)
@Path("/{projectId}/setting")
@POST
public Response saveSetting(@PathParam("projectId") Long projectId, @NotNull ProjectSetting setting) {
@@ -190,6 +195,7 @@ public class ProjectResource {
return Response.ok().build();
}
+ @Api(order=1000)
@Path("/{projectId}")
@DELETE
public Response delete(@PathParam("projectId") Long projectId) {
@@ -204,21 +210,85 @@ public class ProjectResource {
private static final long serialVersionUID = 1L;
- ArrayList<BranchProtection> branchProtections;
+ private ArrayList<BranchProtection> branchProtections = new ArrayList<>();
- ArrayList<TagProtection> tagProtections;
+ private ArrayList<TagProtection> tagProtections = new ArrayList<>();
- ProjectIssueSetting issueSetting;
+ private ProjectIssueSetting issueSetting = new ProjectIssueSetting();
- ProjectBuildSetting buildSetting;
+ private ProjectBuildSetting buildSetting = new ProjectBuildSetting();
- ProjectPullRequestSetting pullRequestSetting;
+ private ProjectPullRequestSetting pullRequestSetting = new ProjectPullRequestSetting();
- ArrayList<NamedCommitQuery> namedCommitQueries;
+ private ArrayList<NamedCommitQuery> namedCommitQueries = new ArrayList<>();
- ArrayList<NamedCodeCommentQuery> namedCodeCommentQueries;
+ private ArrayList<NamedCodeCommentQuery> namedCodeCommentQueries = new ArrayList<>();
- ArrayList<WebHook> webHooks;
+ private ArrayList<WebHook> webHooks = new ArrayList<>();
+
+ public ArrayList<BranchProtection> getBranchProtections() {
+ return branchProtections;
+ }
+
+ public void setBranchProtections(ArrayList<BranchProtection> branchProtections) {
+ this.branchProtections = branchProtections;
+ }
+
+ public ArrayList<TagProtection> getTagProtections() {
+ return tagProtections;
+ }
+
+ public void setTagProtections(ArrayList<TagProtection> tagProtections) {
+ this.tagProtections = tagProtections;
+ }
+
+ public ProjectIssueSetting getIssueSetting() {
+ return issueSetting;
+ }
+
+ public void setIssueSetting(ProjectIssueSetting issueSetting) {
+ this.issueSetting = issueSetting;
+ }
+
+ public ProjectBuildSetting getBuildSetting() {
+ return buildSetting;
+ }
+
+ public void setBuildSetting(ProjectBuildSetting buildSetting) {
+ this.buildSetting = buildSetting;
+ }
+
+ public ProjectPullRequestSetting getPullRequestSetting() {
+ return pullRequestSetting;
+ }
+
+ public void setPullRequestSetting(ProjectPullRequestSetting pullRequestSetting) {
+ this.pullRequestSetting = pullRequestSetting;
+ }
+
+ public ArrayList<NamedCommitQuery> getNamedCommitQueries() {
+ return namedCommitQueries;
+ }
+
+ public void setNamedCommitQueries(ArrayList<NamedCommitQuery> namedCommitQueries) {
+ this.namedCommitQueries = namedCommitQueries;
+ }
+
+ public ArrayList<NamedCodeCommentQuery> getNamedCodeCommentQueries() {
+ return namedCodeCommentQueries;
+ }
+
+ public void setNamedCodeCommentQueries(ArrayList<NamedCodeCommentQuery> namedCodeCommentQueries) {
+ this.namedCodeCommentQueries = namedCodeCommentQueries;
+ }
+
+ public ArrayList<WebHook> getWebHooks() {
+ return webHooks;
+ }
+
+ public void setWebHooks(ArrayList<WebHook> webHooks) {
+ this.webHooks = webHooks;
+ }
}
}
diff --git a/server-core/src/main/java/io/onedev/server/rest/PullRequestAssignmentResource.java b/server-core/src/main/java/io/onedev/server/rest/PullRequestAssignmentResource.java
index 2d9ea673e4..273b1f6271 100644
--- a/server-core/src/main/java/io/onedev/server/rest/PullRequestAssignmentResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/PullRequestAssignmentResource.java
@@ -18,8 +18,10 @@ import io.onedev.commons.utils.ExplicitException;
import io.onedev.server.entitymanager.PullRequestAssignmentManager;
import io.onedev.server.model.PullRequest;
import io.onedev.server.model.PullRequestAssignment;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=3100)
@Path("/pull-request-assignments")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -33,6 +35,7 @@ public class PullRequestAssignmentResource {
this.assignmentManager = assignmentManager;
}
+ @Api(order=100)
@Path("/{assignmentId}")
@GET
public PullRequestAssignment get(@PathParam("assignmentId") Long assignmentId) {
@@ -42,6 +45,7 @@ public class PullRequestAssignmentResource {
return assignment;
}
+ @Api(order=200)
@POST
public Long save(PullRequestAssignment assignment) {
PullRequest pullRequest = assignment.getRequest();
@@ -54,6 +58,7 @@ public class PullRequestAssignmentResource {
return assignment.getId();
}
+ @Api(order=300)
@Path("/{assignmentId}")
@DELETE
public Response delete(@PathParam("assignmentId") Long assignmentId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/PullRequestCommentResource.java b/server-core/src/main/java/io/onedev/server/rest/PullRequestCommentResource.java
index b5b9358aa3..760fa09eae 100644
--- a/server-core/src/main/java/io/onedev/server/rest/PullRequestCommentResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/PullRequestCommentResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.PullRequestCommentManager;
import io.onedev.server.model.PullRequestComment;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=3200)
@Path("/pull-request-comments")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class PullRequestCommentResource {
this.commentManager = commentManager;
}
+ @Api(order=100)
@Path("/{commentId}")
@GET
public PullRequestComment get(@PathParam("commentId") Long commentId) {
@@ -41,6 +44,7 @@ public class PullRequestCommentResource {
return comment;
}
+ @Api(order=200)
@POST
public Long save(@NotNull PullRequestComment comment) {
if (!SecurityUtils.canReadCode(comment.getProject()) ||
@@ -52,6 +56,7 @@ public class PullRequestCommentResource {
return comment.getId();
}
+ @Api(order=300)
@Path("/{commentId}")
@DELETE
public Response delete(@PathParam("commentId") Long commentId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/PullRequestQuerySettingResource.java b/server-core/src/main/java/io/onedev/server/rest/PullRequestQuerySettingResource.java
index e96eb80a73..fa73ac1809 100644
--- a/server-core/src/main/java/io/onedev/server/rest/PullRequestQuerySettingResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/PullRequestQuerySettingResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.PullRequestQuerySettingManager;
import io.onedev.server.model.PullRequestQuerySetting;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=5200)
@Path("/pull-request-query-settings")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class PullRequestQuerySettingResource {
this.querySettingManager = querySettingManager;
}
+ @Api(order=100)
@Path("/{querySettingId}")
@GET
public PullRequestQuerySetting get(@PathParam("querySettingId") Long querySettingId) {
@@ -41,6 +44,7 @@ public class PullRequestQuerySettingResource {
return querySetting;
}
+ @Api(order=200)
@POST
public Long save(@NotNull PullRequestQuerySetting querySetting) {
if (!SecurityUtils.canAccess(querySetting.getProject())
@@ -51,6 +55,7 @@ public class PullRequestQuerySettingResource {
return querySetting.getId();
}
+ @Api(order=300)
@Path("/{querySettingId}")
@DELETE
public Response delete(@PathParam("querySettingId") Long querySettingId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/PullRequestResource.java b/server-core/src/main/java/io/onedev/server/rest/PullRequestResource.java
index da19ee14ec..5da35b6129 100644
--- a/server-core/src/main/java/io/onedev/server/rest/PullRequestResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/PullRequestResource.java
@@ -19,7 +19,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.eclipse.jgit.lib.ObjectId;
import org.hibernate.validator.constraints.NotEmpty;
@@ -33,6 +32,7 @@ import io.onedev.server.entitymanager.PullRequestManager;
import io.onedev.server.entitymanager.UserManager;
import io.onedev.server.git.GitUtils;
import io.onedev.server.model.Build;
+import io.onedev.server.model.Project;
import io.onedev.server.model.PullRequest;
import io.onedev.server.model.PullRequestAssignment;
import io.onedev.server.model.PullRequestChange;
@@ -43,11 +43,14 @@ import io.onedev.server.model.PullRequestWatch;
import io.onedev.server.model.User;
import io.onedev.server.model.support.pullrequest.MergePreview;
import io.onedev.server.model.support.pullrequest.MergeStrategy;
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.rest.annotation.EntityId;
import io.onedev.server.rest.jersey.InvalidParamException;
import io.onedev.server.search.entity.pullrequest.PullRequestQuery;
import io.onedev.server.security.SecurityUtils;
import io.onedev.server.util.ProjectAndBranch;
+@Api(order=3000)
@Path("/pull-requests")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -68,6 +71,7 @@ public class PullRequestResource {
this.userManager = userManager;
}
+ @Api(order=100)
@Path("/{requestId}")
@GET
public PullRequest get(@PathParam("requestId") Long requestId) {
@@ -77,6 +81,7 @@ public class PullRequestResource {
return pullRequest;
}
+ @Api(order=200)
@Path("/{requestId}/merge-preview")
@GET
public MergePreview getMergePreview(@PathParam("requestId") Long requestId) {
@@ -86,6 +91,7 @@ public class PullRequestResource {
return pullRequest.getMergePreview();
}
+ @Api(order=300)
@Path("/{requestId}/assignments")
@GET
public Collection<PullRequestAssignment> getAssignments(@PathParam("requestId") Long requestId) {
@@ -95,6 +101,7 @@ public class PullRequestResource {
return pullRequest.getAssignments();
}
+ @Api(order=400)
@Path("/{requestId}/reviews")
@GET
public Collection<PullRequestReview> getReviews(@PathParam("requestId") Long requestId) {
@@ -104,6 +111,7 @@ public class PullRequestResource {
return pullRequest.getReviews();
}
+ @Api(order=500)
@Path("/{requestId}/comments")
@GET
public Collection<PullRequestComment> getComments(@PathParam("requestId") Long requestId) {
@@ -113,6 +121,7 @@ public class PullRequestResource {
return pullRequest.getComments();
}
+ @Api(order=600)
@Path("/{requestId}/watches")
@GET
public Collection<PullRequestWatch> getWatches(@PathParam("requestId") Long requestId) {
@@ -122,6 +131,7 @@ public class PullRequestResource {
return pullRequest.getWatches();
}
+ @Api(order=700)
@Path("/{requestId}/updates")
@GET
public Collection<PullRequestUpdate> getUpdates(@PathParam("requestId") Long requestId) {
@@ -131,6 +141,7 @@ public class PullRequestResource {
return pullRequest.getSortedUpdates();
}
+ @Api(order=800)
@Path("/{requestId}/current-builds")
@GET
public Collection<Build> getCurrentBuilds(@PathParam("requestId") Long requestId) {
@@ -140,6 +151,7 @@ public class PullRequestResource {
return pullRequest.getCurrentBuilds();
}
+ @Api(order=900)
@Path("/{requestId}/changes")
@GET
public Collection<PullRequestChange> getChanges(@PathParam("requestId") Long requestId) {
@@ -149,6 +161,7 @@ public class PullRequestResource {
return pullRequest.getChanges();
}
+ @Api(order=1000)
@Path("/{requestId}/fixed-issue-numbers")
@GET
public Collection<Long> getFixedIssueNumbers(@PathParam("requestId") Long requestId) {
@@ -158,12 +171,13 @@ public class PullRequestResource {
return pullRequest.getFixedIssueNumbers();
}
+ @Api(order=1100)
@GET
public List<PullRequest> query(@QueryParam("query") String query, @QueryParam("offset") int offset,
@QueryParam("count") int count) {
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
PullRequestQuery parsedQuery;
try {
@@ -175,11 +189,10 @@ public class PullRequestResource {
return pullRequestManager.query(null, parsedQuery, offset, count, false, false);
}
+ @Api(order=1200)
@POST
public Long open(@NotNull PullRequestOpenData data) {
User user = SecurityUtils.getUser();
- if (user == null)
- throw new UnauthenticatedException();
ProjectAndBranch target = new ProjectAndBranch(data.getTargetProjectId(), data.getTargetBranch());
ProjectAndBranch source = new ProjectAndBranch(data.getSourceProjectId(), data.getSourceBranch());
@@ -252,6 +265,7 @@ public class PullRequestResource {
return request.getId();
}
+ @Api(order=1300)
@Path("/{requestId}/title")
@POST
public Response setTitle(@PathParam("requestId") Long requestId, @NotEmpty String title) {
@@ -262,6 +276,7 @@ public class PullRequestResource {
return Response.ok().build();
}
+ @Api(order=1400)
@Path("/{requestId}/description")
@POST
public Response setDescription(@PathParam("requestId") Long requestId, String description) {
@@ -272,6 +287,7 @@ public class PullRequestResource {
return Response.ok().build();
}
+ @Api(order=1500)
@Path("/{requestId}/merge-strategy")
@POST
public Response setMergeStrategy(@PathParam("requestId") Long requestId, @NotNull MergeStrategy mergeStrategy) {
@@ -282,6 +298,7 @@ public class PullRequestResource {
return Response.ok().build();
}
+ @Api(order=1600)
@Path("/{requestId}/reopen")
@POST
public Response reopen(@PathParam("requestId") Long requestId, String note) {
@@ -296,6 +313,7 @@ public class PullRequestResource {
return Response.ok().build();
}
+ @Api(order=1700)
@Path("/{requestId}/discard")
@POST
public Response discard(@PathParam("requestId") Long requestId, String note) {
@@ -309,6 +327,7 @@ public class PullRequestResource {
return Response.ok().build();
}
+ @Api(order=1800)
@Path("/{requestId}/merge")
@POST
public Response merge(@PathParam("requestId") Long requestId, String note) {
@@ -323,6 +342,7 @@ public class PullRequestResource {
return Response.ok().build();
}
+ @Api(order=1900)
@Path("/{requestId}/delete-source-branch")
@POST
public Response deleteSourceBranch(@PathParam("requestId") Long requestId, String note) {
@@ -341,6 +361,7 @@ public class PullRequestResource {
return Response.ok().build();
}
+ @Api(order=2000)
@Path("/{requestId}/restore-source-branch")
@POST
public Response restoreSourceBranch(@PathParam("requestId") Long requestId, String note) {
@@ -359,6 +380,7 @@ public class PullRequestResource {
return Response.ok().build();
}
+ @Api(order=2100)
@Path("/{requestId}")
@DELETE
public Response delete(@PathParam("requestId") Long requestId) {
@@ -373,8 +395,10 @@ public class PullRequestResource {
private static final long serialVersionUID = 1L;
+ @EntityId(Project.class)
private Long targetProjectId;
+ @EntityId(Project.class)
private Long sourceProjectId;
private String targetBranch;
diff --git a/server-core/src/main/java/io/onedev/server/rest/PullRequestReviewResource.java b/server-core/src/main/java/io/onedev/server/rest/PullRequestReviewResource.java
index 75c84dd9fe..1fb495241d 100644
--- a/server-core/src/main/java/io/onedev/server/rest/PullRequestReviewResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/PullRequestReviewResource.java
@@ -20,8 +20,10 @@ import com.google.common.collect.Lists;
import io.onedev.commons.utils.ExplicitException;
import io.onedev.server.entitymanager.PullRequestReviewManager;
import io.onedev.server.model.PullRequestReview;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=3300)
@Path("/pull-request-reviews")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -35,6 +37,7 @@ public class PullRequestReviewResource {
this.reviewManager = reviewManager;
}
+ @Api(order=100)
@Path("/{reviewId}")
@GET
public PullRequestReview get(@PathParam("reviewId") Long reviewId) {
@@ -44,6 +47,7 @@ public class PullRequestReviewResource {
return review;
}
+ @Api(order=200)
@POST
public Long save(@NotNull PullRequestReview review) {
if (!SecurityUtils.canReadCode(review.getRequest().getProject())
@@ -61,6 +65,7 @@ public class PullRequestReviewResource {
return review.getId();
}
+ @Api(order=300)
@Path("/{reviewId}")
@DELETE
public Response delete(@PathParam("reviewId") Long reviewId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/PullRequestWatchResource.java b/server-core/src/main/java/io/onedev/server/rest/PullRequestWatchResource.java
index a51308fe2f..874f0f8683 100644
--- a/server-core/src/main/java/io/onedev/server/rest/PullRequestWatchResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/PullRequestWatchResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.PullRequestWatchManager;
import io.onedev.server.model.PullRequestWatch;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=3400)
@Path("/pull-request-watches")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class PullRequestWatchResource {
this.watchManager = watchManager;
}
+ @Api(order=100)
@Path("/{watchId}")
@GET
public PullRequestWatch get(@PathParam("watchId") Long watchId) {
@@ -41,6 +44,7 @@ public class PullRequestWatchResource {
return watch;
}
+ @Api(order=200)
@POST
public Long save(@NotNull PullRequestWatch watch) {
if (!SecurityUtils.canReadCode(watch.getRequest().getProject())
@@ -51,6 +55,7 @@ public class PullRequestWatchResource {
return watch.getId();
}
+ @Api(order=300)
@Path("/{watchId}")
@DELETE
public Response delete(@PathParam("watchId") Long watchId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/RestConstants.java b/server-core/src/main/java/io/onedev/server/rest/RestConstants.java
deleted file mode 100644
index 501b449b4b..0000000000
--- a/server-core/src/main/java/io/onedev/server/rest/RestConstants.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package io.onedev.server.rest;
-
-public class RestConstants {
-
- public static final int PAGE_SIZE = 100;
-
- public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
-
-}
diff --git a/server-core/src/main/java/io/onedev/server/rest/RestUtils.java b/server-core/src/main/java/io/onedev/server/rest/RestUtils.java
new file mode 100644
index 0000000000..f4aaa5b8f4
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/rest/RestUtils.java
@@ -0,0 +1,15 @@
+package io.onedev.server.rest;
+
+import java.util.Date;
+
+import org.joda.time.format.ISODateTimeFormat;
+
+public class RestUtils {
+
+ public static final int MAX_PAGE_SIZE = 100;
+
+ public static Date toDate(String dateString) {
+ return ISODateTimeFormat.dateTimeParser().parseDateTime(dateString).toDate();
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/rest/RoleResource.java b/server-core/src/main/java/io/onedev/server/rest/RoleResource.java
index fe05872c04..ac6c8602c7 100644
--- a/server-core/src/main/java/io/onedev/server/rest/RoleResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/RoleResource.java
@@ -23,9 +23,11 @@ import org.hibernate.criterion.Restrictions;
import io.onedev.server.entitymanager.RoleManager;
import io.onedev.server.model.Role;
import io.onedev.server.persistence.dao.EntityCriteria;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.rest.jersey.InvalidParamException;
import io.onedev.server.security.SecurityUtils;
+@Api(order=7000)
@Path("/roles")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -39,6 +41,7 @@ public class RoleResource {
this.roleManager = roleManager;
}
+ @Api(order=100)
@Path("/{roleId}")
@GET
public Role get(@PathParam("roleId") Long roleId) {
@@ -47,6 +50,7 @@ public class RoleResource {
return roleManager.load(roleId);
}
+ @Api(order=200)
@GET
public List<Role> query(@QueryParam("name") String name, @QueryParam("offset") int offset,
@QueryParam("count") int count) {
@@ -54,8 +58,8 @@ public class RoleResource {
if (!SecurityUtils.isAdministrator())
throw new UnauthorizedException();
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
EntityCriteria<Role> criteria = EntityCriteria.of(Role.class);
if (name != null)
@@ -64,6 +68,7 @@ public class RoleResource {
return roleManager.query(criteria, offset, count);
}
+ @Api(order=300)
@POST
public Long save(@NotNull Role role) {
if (!SecurityUtils.isAdministrator())
@@ -72,6 +77,7 @@ public class RoleResource {
return role.getId();
}
+ @Api(order=400)
@Path("/{roleId}")
@DELETE
public Response delete(@PathParam("roleId") Long roleId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/SettingResource.java b/server-core/src/main/java/io/onedev/server/rest/SettingResource.java
index bd8dccd701..0c775382fd 100644
--- a/server-core/src/main/java/io/onedev/server/rest/SettingResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/SettingResource.java
@@ -29,8 +29,10 @@ import io.onedev.server.model.support.administration.SystemSetting;
import io.onedev.server.model.support.administration.authenticator.Authenticator;
import io.onedev.server.model.support.administration.jobexecutor.JobExecutor;
import io.onedev.server.model.support.administration.sso.SsoConnector;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=100000)
@Path("/settings")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -44,6 +46,7 @@ public class SettingResource {
this.settingManager = settingManager;
}
+ @Api(order=100)
@Path("/system")
@GET
public SystemSetting getSystemSetting() {
@@ -52,6 +55,7 @@ public class SettingResource {
return settingManager.getSystemSetting();
}
+ @Api(order=200)
@Path("/authenticator")
@GET
public Authenticator getAuthenticator() {
@@ -60,6 +64,7 @@ public class SettingResource {
return settingManager.getAuthenticator();
}
+ @Api(order=300)
@Path("/backup")
@GET
public BackupSetting getBackupSetting() {
@@ -68,6 +73,7 @@ public class SettingResource {
return settingManager.getBackupSetting();
}
+ @Api(order=400)
@Path("/build")
@GET
public GlobalBuildSetting getBuildSetting() {
@@ -76,6 +82,7 @@ public class SettingResource {
return settingManager.getBuildSetting();
}
+ @Api(order=500)
@Path("/groovy-scripts")
@GET
public List<GroovyScript> getGroovyScripts() {
@@ -84,6 +91,7 @@ public class SettingResource {
return settingManager.getGroovyScripts();
}
+ @Api(order=600)
@Path("/issue")
@GET
public GlobalIssueSetting getIssueSetting() {
@@ -92,6 +100,7 @@ public class SettingResource {
return settingManager.getIssueSetting();
}
+ @Api(order=700)
@Path("/job-executors")
@GET
public List<JobExecutor> getJobExecutors() {
@@ -100,6 +109,7 @@ public class SettingResource {
return settingManager.getJobExecutors();
}
+ @Api(order=800)
@Path("/mail")
@GET
public MailSetting getMailSetting() {
@@ -108,6 +118,7 @@ public class SettingResource {
return settingManager.getMailSetting();
}
+ @Api(order=1000)
@Path("/project")
@GET
public GlobalProjectSetting getProjectSetting() {
@@ -116,6 +127,7 @@ public class SettingResource {
return settingManager.getProjectSetting();
}
+ @Api(order=1100)
@Path("/pull-request")
@GET
public GlobalPullRequestSetting getPullRequestSetting() {
@@ -124,6 +136,7 @@ public class SettingResource {
return settingManager.getPullRequestSetting();
}
+ @Api(order=1200)
@Path("/security")
@GET
public SecuritySetting getSecuritySetting() {
@@ -132,6 +145,7 @@ public class SettingResource {
return settingManager.getSecuritySetting();
}
+ @Api(order=1300)
@Path("/ssh")
@GET
public SshSetting getSshSetting() {
@@ -140,6 +154,7 @@ public class SettingResource {
return settingManager.getSshSetting();
}
+ @Api(order=1400)
@Path("/sso-connectors")
@GET
public List<SsoConnector> getSsoConnectors() {
@@ -148,6 +163,7 @@ public class SettingResource {
return settingManager.getSsoConnectors();
}
+ @Api(order=1500)
@Path("/system")
@POST
public Response setSystemSetting(@NotNull SystemSetting systemSetting) {
@@ -157,6 +173,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=1600)
@Path("/authenticator")
@POST
public Response setAuthenticator(Authenticator authenticator) {
@@ -166,6 +183,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=1700)
@Path("/backup")
@POST
public Response setBackupSetting(BackupSetting backupSetting) {
@@ -175,6 +193,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=1800)
@Path("/build")
@POST
public Response setBuildSetting(@NotNull GlobalBuildSetting buildSetting) {
@@ -184,6 +203,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=1900)
@Path("/groovy-scripts")
@POST
public Response setGroovyScripts(@NotNull List<GroovyScript> groovyScripts) {
@@ -193,6 +213,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=2000)
@Path("/issue")
@POST
public Response setIssueSetting(@NotNull GlobalIssueSetting issueSetting) {
@@ -202,6 +223,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=2100)
@Path("/job-executors")
@POST
public Response setJobExecutors(@NotNull List<JobExecutor> jobExecutors) {
@@ -211,6 +233,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=2200)
@Path("/mail")
@POST
public Response setMailSetting(MailSetting mailSetting) {
@@ -220,6 +243,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=2300)
@Path("/project")
@POST
public Response setProjectSetting(@NotNull GlobalProjectSetting projectSetting) {
@@ -229,6 +253,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=2400)
@Path("/pull-request")
@POST
public Response setPullRequestSetting(@NotNull GlobalPullRequestSetting pullRequestSetting) {
@@ -238,6 +263,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=2500)
@Path("/security")
@POST
public Response setSecuritySetting(@NotNull SecuritySetting securitySetting) {
@@ -247,6 +273,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=2600)
@Path("/ssh")
@POST
public Response setSshSetting(@NotNull SshSetting sshSetting) {
@@ -256,6 +283,7 @@ public class SettingResource {
return Response.ok().build();
}
+ @Api(order=2700)
@Path("/sso-connectors")
@POST
public Response setSsoConnectors(@NotNull List<SsoConnector> ssoConnectors) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/SshKeyResource.java b/server-core/src/main/java/io/onedev/server/rest/SshKeyResource.java
index 4d78f72aeb..a0bf8725df 100644
--- a/server-core/src/main/java/io/onedev/server/rest/SshKeyResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/SshKeyResource.java
@@ -15,8 +15,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.SshKeyManager;
import io.onedev.server.model.SshKey;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=5100)
@Path("/ssh-keys")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -30,6 +32,7 @@ public class SshKeyResource {
this.sshKeyManager = sshKeyManager;
}
+ @Api(order=100)
@Path("/{sshKeyId}")
@GET
public SshKey get(@PathParam("sshKeyId") Long sshKeyId) {
@@ -39,6 +42,7 @@ public class SshKeyResource {
return sshKey;
}
+ @Api(order=200)
@Path("/{sshKeyId}")
@DELETE
public Response delete(@PathParam("sshKeyId") Long sshKeyId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/UserAuthorizationResource.java b/server-core/src/main/java/io/onedev/server/rest/UserAuthorizationResource.java
index b000d64abc..059fc5139b 100644
--- a/server-core/src/main/java/io/onedev/server/rest/UserAuthorizationResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/UserAuthorizationResource.java
@@ -17,8 +17,10 @@ import org.apache.shiro.authz.UnauthorizedException;
import io.onedev.server.entitymanager.UserAuthorizationManager;
import io.onedev.server.model.UserAuthorization;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.security.SecurityUtils;
+@Api(order=8000)
@Path("/user-authorizations")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -32,6 +34,7 @@ public class UserAuthorizationResource {
this.authorizationManager = authorizationManager;
}
+ @Api(order=100)
@Path("/{authorizationId}")
@GET
public UserAuthorization get(@PathParam("authorizationId") Long authorizationId) {
@@ -41,6 +44,7 @@ public class UserAuthorizationResource {
return authorization;
}
+ @Api(order=200)
@POST
public Long save(@NotNull UserAuthorization authorization) {
if (!SecurityUtils.canManage(authorization.getProject()))
@@ -49,6 +53,7 @@ public class UserAuthorizationResource {
return authorization.getId();
}
+ @Api(order=300)
@Path("/{authorizationId}")
@DELETE
public Response delete(@PathParam("authorizationId") Long authorizationId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/UserResource.java b/server-core/src/main/java/io/onedev/server/rest/UserResource.java
index 054254fe38..06c29c455d 100644
--- a/server-core/src/main/java/io/onedev/server/rest/UserResource.java
+++ b/server-core/src/main/java/io/onedev/server/rest/UserResource.java
@@ -56,11 +56,13 @@ import io.onedev.server.model.support.build.NamedBuildQuery;
import io.onedev.server.model.support.issue.NamedIssueQuery;
import io.onedev.server.model.support.pullrequest.NamedPullRequestQuery;
import io.onedev.server.persistence.dao.EntityCriteria;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.rest.jersey.InvalidParamException;
import io.onedev.server.security.CipherUtils;
import io.onedev.server.security.SecurityUtils;
import io.onedev.server.ssh.SshKeyUtils;
+@Api(order=5000)
@Path("/users")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@@ -80,6 +82,7 @@ public class UserResource {
this.passwordService = passwordService;
}
+ @Api(order=100)
@Path("/{userId}")
@GET
public User get(@PathParam("userId") Long userId) {
@@ -89,6 +92,7 @@ public class UserResource {
return user;
}
+ @Api(order=200)
@Path("/me")
@GET
public User getMe() {
@@ -98,6 +102,7 @@ public class UserResource {
return user;
}
+ @Api(order=300)
@Path("/{userId}/authorizations")
@GET
public Collection<UserAuthorization> getAuthorizations(@PathParam("userId") Long userId) {
@@ -106,6 +111,7 @@ public class UserResource {
return userManager.load(userId).getAuthorizations();
}
+ @Api(order=400)
@Path("/{userId}/memberships")
@GET
public Collection<Membership> getMemberships(@PathParam("userId") Long userId) {
@@ -114,6 +120,7 @@ public class UserResource {
return userManager.load(userId).getMemberships();
}
+ @Api(order=500)
@Path("/{userId}/sso-info")
@GET
public SsoInfo getSsoInfo(@PathParam("userId") Long userId) {
@@ -123,6 +130,7 @@ public class UserResource {
return user.getSsoInfo();
}
+ @Api(order=600)
@Path("/{userId}/pull-request-reviews")
@GET
public Collection<PullRequestReview> getPullRequestReviews(@PathParam("userId") Long userId) {
@@ -132,6 +140,7 @@ public class UserResource {
return user.getPullRequestReviews();
}
+ @Api(order=700)
@Path("/{userId}/issue-votes")
@GET
public Collection<IssueVote> getIssueVotes(@PathParam("userId") Long userId) {
@@ -141,6 +150,7 @@ public class UserResource {
return user.getIssueVotes();
}
+ @Api(order=800)
@Path("/{userId}/issue-watches")
@GET
public Collection<IssueWatch> getIssueWatches(@PathParam("userId") Long userId) {
@@ -150,6 +160,7 @@ public class UserResource {
return user.getIssueWatches();
}
+ @Api(order=900)
@Path("/{userId}/project-build-query-settings")
@GET
public Collection<BuildQuerySetting> getProjectBuildQuerySettings(@PathParam("userId") Long userId) {
@@ -159,6 +170,7 @@ public class UserResource {
return user.getProjectBuildQuerySettings();
}
+ @Api(order=1000)
@Path("/{userId}/project-code-comment-query-settings")
@GET
public Collection<CodeCommentQuerySetting> getProjectCodeCommentQuerySettings(@PathParam("userId") Long userId) {
@@ -168,6 +180,7 @@ public class UserResource {
return user.getProjectCodeCommentQuerySettings();
}
+ @Api(order=1100)
@Path("/{userId}/project-commit-query-settings")
@GET
public Collection<CommitQuerySetting> getProjectCommitQuerySettings(@PathParam("userId") Long userId) {
@@ -177,6 +190,7 @@ public class UserResource {
return user.getProjectCommitQuerySettings();
}
+ @Api(order=1200)
@Path("/{userId}/project-issue-query-settings")
@GET
public Collection<IssueQuerySetting> getProjecIssueQuerySettings(@PathParam("userId") Long userId) {
@@ -186,6 +200,7 @@ public class UserResource {
return user.getProjectIssueQuerySettings();
}
+ @Api(order=1300)
@Path("/{userId}/project-pull-request-query-settings")
@GET
public Collection<PullRequestQuerySetting> getProjecPullRequestQuerySettings(@PathParam("userId") Long userId) {
@@ -195,6 +210,7 @@ public class UserResource {
return user.getProjectPullRequestQuerySettings();
}
+ @Api(order=1400)
@Path("/{userId}/pull-request-assignments")
@GET
public Collection<PullRequestAssignment> getPullRequestAssignments(@PathParam("userId") Long userId) {
@@ -204,6 +220,7 @@ public class UserResource {
return user.getPullRequestAssignments();
}
+ @Api(order=1500)
@Path("/{userId}/pull-request-watches")
@GET
public Collection<PullRequestWatch> getPullRequestWatches(@PathParam("userId") Long userId) {
@@ -213,6 +230,7 @@ public class UserResource {
return user.getPullRequestWatches();
}
+ @Api(order=1600)
@Path("/{userId}/ssh-keys")
@GET
public Collection<SshKey> getSshKeys(@PathParam("userId") Long userId) {
@@ -222,6 +240,7 @@ public class UserResource {
return user.getSshKeys();
}
+ @Api(order=1700)
@Path("/{userId}/queries-and-watches")
@GET
public QueriesAndWatches getQueriesAndWatches(@PathParam("userId") Long userId) {
@@ -242,6 +261,7 @@ public class UserResource {
return queriesAndWatches;
}
+ @Api(order=1800)
@GET
public List<User> query(@QueryParam("name") String name, @QueryParam("fullName") String fullName,
@QueryParam("email") String email, @QueryParam("offset") int offset,
@@ -250,8 +270,8 @@ public class UserResource {
if (!SecurityUtils.isAdministrator())
throw new UnauthorizedException();
- if (count > RestConstants.PAGE_SIZE)
- throw new InvalidParamException("Count should be less than " + RestConstants.PAGE_SIZE);
+ if (count > RestUtils.MAX_PAGE_SIZE)
+ throw new InvalidParamException("Count should be less than " + RestUtils.MAX_PAGE_SIZE);
EntityCriteria<User> criteria = EntityCriteria.of(User.class);
criteria.add(Restrictions.not(Restrictions.eq("id", User.SYSTEM_ID)));
@@ -265,6 +285,7 @@ public class UserResource {
return userManager.query(criteria, offset, count);
}
+ @Api(order=1900)
@POST
public Long save(@NotNull User user) {
if (user.isNew()) {
@@ -283,6 +304,7 @@ public class UserResource {
return user.getId();
}
+ @Api(order=2000)
@Path("/{userId}/password")
@POST
public Response setPassword(@PathParam("userId") Long userId, @NotEmpty String password) {
@@ -304,6 +326,7 @@ public class UserResource {
}
}
+ @Api(order=2100)
@Path("/{userId}/sso-info")
@POST
public Response setSsoInfo(@PathParam("userId") Long userId, @NotNull SsoInfo ssoInfo) {
@@ -315,6 +338,7 @@ public class UserResource {
return Response.ok().build();
}
+ @Api(order=2100)
@Path("/{userId}/queries-and-watches")
@POST
public Response setQueriesAndWatches(@PathParam("userId") Long userId, @NotNull QueriesAndWatches queriesAndWatches) {
@@ -335,16 +359,15 @@ public class UserResource {
return Response.ok().build();
}
+ @Api(order=2200)
@Path("/{userId}/ssh-keys")
@POST
public Long addSshKey(@PathParam("userId") Long userId, @NotNull String content) {
User user = SecurityUtils.getUser();
- if (user == null)
- throw new UnauthenticatedException();
SshKey sshKey = new SshKey();
sshKey.setContent(content);
- sshKey.setDate(new Date());
+ sshKey.setCreatedAt(new Date());
sshKey.setOwner(user);
try {
@@ -359,6 +382,7 @@ public class UserResource {
return sshKey.getId();
}
+ @Api(order=2300)
@Path("/{userId}")
@DELETE
public Response delete(@PathParam("userId") Long userId) {
diff --git a/server-core/src/main/java/io/onedev/server/rest/annotation/Api.java b/server-core/src/main/java/io/onedev/server/rest/annotation/Api.java
new file mode 100644
index 0000000000..2c0c26c9a6
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/rest/annotation/Api.java
@@ -0,0 +1,22 @@
+package io.onedev.server.rest.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
+public @interface Api {
+
+ boolean exclude() default false;
+
+ String exampleProvider() default "";
+
+ String description() default "";
+
+ int order() default 100;
+
+ String permission() default "";
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/rest/annotation/EntityId.java b/server-core/src/main/java/io/onedev/server/rest/annotation/EntityId.java
new file mode 100644
index 0000000000..82c74874c1
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/rest/annotation/EntityId.java
@@ -0,0 +1,14 @@
+package io.onedev.server.rest.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD})
+public @interface EntityId {
+
+ Class<?> value();
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/rest/jersey/AnonymousCheckFilter.java b/server-core/src/main/java/io/onedev/server/rest/jersey/AnonymousCheckFilter.java
new file mode 100644
index 0000000000..08ab0fc9cc
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/rest/jersey/AnonymousCheckFilter.java
@@ -0,0 +1,41 @@
+package io.onedev.server.rest.jersey;
+
+import java.io.IOException;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.shiro.authz.UnauthenticatedException;
+
+import io.onedev.server.entitymanager.SettingManager;
+import io.onedev.server.security.SecurityUtils;
+
+@Provider
+public class AnonymousCheckFilter implements ContainerRequestFilter {
+
+ private final SettingManager settingManager;
+
+ @Context
+ private HttpServletRequest request;
+
+ @Inject
+ public AnonymousCheckFilter(SettingManager settingManager) {
+ this.settingManager = settingManager;
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ if (SecurityUtils.getUser() == null) {
+ String method = request.getMethod();
+ if (method.equals("POST") || method.equals("DELETE") || method.equals("PUT")
+ || !settingManager.getSecuritySetting().isEnableAnonymousAccess()) {
+ throw new UnauthenticatedException();
+ }
+ }
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/rest/jersey/JerseyApplication.java b/server-core/src/main/java/io/onedev/server/rest/jersey/JerseyApplication.java
index 3676c70717..ebac0bb749 100644
--- a/server-core/src/main/java/io/onedev/server/rest/jersey/JerseyApplication.java
+++ b/server-core/src/main/java/io/onedev/server/rest/jersey/JerseyApplication.java
@@ -14,7 +14,7 @@ import org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge;
import io.onedev.commons.launcher.loader.AppLoader;
public class JerseyApplication extends ResourceConfig {
-
+
@Inject
public JerseyApplication(ServiceLocator serviceLocator) {
GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
@@ -35,6 +35,7 @@ public class JerseyApplication extends ResourceConfig {
for (JerseyConfigurator configurator: AppLoader.getExtensions(JerseyConfigurator.class)) {
configurator.configure(this);
}
+
}
}
diff --git a/server-core/src/main/java/io/onedev/server/rest/jersey/ResourceParamFilter.java b/server-core/src/main/java/io/onedev/server/rest/jersey/ParamCheckFilter.java
similarity index 80%
rename from server-core/src/main/java/io/onedev/server/rest/jersey/ResourceParamFilter.java
rename to server-core/src/main/java/io/onedev/server/rest/jersey/ParamCheckFilter.java
index a7ed22c8d7..0500423b13 100644
--- a/server-core/src/main/java/io/onedev/server/rest/jersey/ResourceParamFilter.java
+++ b/server-core/src/main/java/io/onedev/server/rest/jersey/ParamCheckFilter.java
@@ -18,7 +18,7 @@ import javax.ws.rs.ext.Provider;
import org.hibernate.validator.constraints.NotEmpty;
@Provider
-public class ResourceParamFilter implements ContainerRequestFilter {
+public class ParamCheckFilter implements ContainerRequestFilter {
@Context
private ResourceInfo resourceInfo;
@@ -34,12 +34,8 @@ public class ResourceParamFilter implements ContainerRequestFilter {
QueryParam queryParam = param.getAnnotation(QueryParam.class);
if (queryParam != null) {
definedQueryParams.add(queryParam.value());
- if (param.getType().isPrimitive()
- || param.getAnnotation(NotNull.class) != null
- || param.getAnnotation(NotEmpty.class) != null
- || param.getAnnotation(Size.class)!=null && param.getAnnotation(Size.class).min()>0) {
+ if (isRequired(param))
requiredQueryParams.add(queryParam.value());
- }
}
}
@@ -53,4 +49,10 @@ public class ResourceParamFilter implements ContainerRequestFilter {
throw new InvalidParamException("Missing query params: " + requiredQueryParams);
}
+ public static boolean isRequired(Parameter param) {
+ return param.getType().isPrimitive()
+ || param.getAnnotation(NotNull.class) != null
+ || param.getAnnotation(NotEmpty.class) != null
+ || param.getAnnotation(Size.class)!=null && param.getAnnotation(Size.class).min()>0;
+ }
}
diff --git a/server-core/src/main/java/io/onedev/server/util/BeanUtils.java b/server-core/src/main/java/io/onedev/server/util/BeanUtils.java
index af978fe8a5..3343a5ae49 100644
--- a/server-core/src/main/java/io/onedev/server/util/BeanUtils.java
+++ b/server-core/src/main/java/io/onedev/server/util/BeanUtils.java
@@ -33,6 +33,15 @@ public class BeanUtils {
}
}
+ public static boolean isSetter(Method method) {
+ if (method.getName().startsWith("set") &&
+ !Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
/**
* Get declared fields in the whole class hierarchy.
* If there are fields with the same name in super-class and sub-class,
@@ -124,6 +133,21 @@ public class BeanUtils {
return new ArrayList<Method>(getters.values());
}
+ public static List<Method> findSetters(Class<?> clazz) {
+ Map<String, Method> setters = new LinkedHashMap<>();
+
+ Class<?> current = clazz;
+ while (current != null) {
+ for (Method method: current.getDeclaredMethods()) {
+ if (!method.isSynthetic() && isSetter(method) && !setters.containsKey(method.getName())) {
+ setters.put(method.getName(), method);
+ }
+ }
+ current = current.getSuperclass();
+ }
+ return new ArrayList<Method>(setters.values());
+ }
+
/**
* Find getter method by property name in specified class and super classes.
*
@@ -164,6 +188,11 @@ public class BeanUtils {
return getter;
}
+ public static Method findSetter(Class<?> clazz, String propertyName, Class<?> paramType) {
+ String methodSuffix = getAccessorSuffix(propertyName);
+ return ReflectionUtils.findMethod(clazz, "set" + methodSuffix, paramType);
+ }
+
/**
* Get property name associated with the getter method.
*
diff --git a/server-core/src/main/java/io/onedev/server/util/Referenceable.java b/server-core/src/main/java/io/onedev/server/util/Referenceable.java
index e97836b033..26b9d607c5 100644
--- a/server-core/src/main/java/io/onedev/server/util/Referenceable.java
+++ b/server-core/src/main/java/io/onedev/server/util/Referenceable.java
@@ -8,10 +8,10 @@ public interface Referenceable {
long getNumber();
- String getPrefix();
+ String getType();
public static String asReference(Referenceable referenceable) {
- return String.format("%s %s#%d", referenceable.getPrefix(),
+ return String.format("%s %s#%d", referenceable.getType(),
referenceable.getProject().getName(), referenceable.getNumber());
}
diff --git a/server-core/src/main/java/io/onedev/server/util/ReflectionUtils.java b/server-core/src/main/java/io/onedev/server/util/ReflectionUtils.java
index a139c773fb..107af056f8 100644
--- a/server-core/src/main/java/io/onedev/server/util/ReflectionUtils.java
+++ b/server-core/src/main/java/io/onedev/server/util/ReflectionUtils.java
@@ -16,6 +16,8 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nullable;
+
import com.google.common.base.Preconditions;
import io.onedev.commons.utils.ExceptionUtils;
@@ -93,7 +95,8 @@ public class ReflectionUtils {
* @return
* the underlying class, or <tt>null</tt> if the type is a variable type
*/
- private static Class<?> getClass(Type type) {
+ @Nullable
+ public static Class<?> getClass(Type type) {
if (type instanceof Class) {
return (Class<?>) type;
} else if (type instanceof ParameterizedType) {
@@ -382,55 +385,39 @@ public class ReflectionUtils {
return null;
}
- public static Class<?> getCollectionElementType(Type type) {
+ @Nullable
+ public static Class<?> getCollectionElementClass(Type type) {
+ Type elementType = getCollectionElementType(type);
+ return elementType!=null? getClass(elementType): null;
+ }
+
+ @Nullable
+ public static Type getCollectionElementType(Type type) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType)type;
Type rawType = parameterizedType.getRawType();
- if (rawType instanceof Class<?>) {
- Class<?> rawClazz = (Class<?>) rawType;
- if (Collection.class.isAssignableFrom(rawClazz)) {
- Type elementType = parameterizedType.getActualTypeArguments()[0];
- if (elementType instanceof Class<?>)
- return (Class<?>) elementType;
- }
- }
+ Preconditions.checkState(Collection.class.isAssignableFrom((Class<?>) rawType));
+ return parameterizedType.getActualTypeArguments()[0];
}
return null;
}
- public static Class<?> getMapKeyType(Type type) {
- if (type instanceof ParameterizedType) {
- ParameterizedType parameterizedType = (ParameterizedType)type;
- Type rawType = parameterizedType.getRawType();
-
- if (rawType instanceof Class<?>) {
- Class<?> rawClazz = (Class<?>) rawType;
- if (Map.class.isAssignableFrom(rawClazz)) {
- Type valueType = parameterizedType.getActualTypeArguments()[0];
- if (valueType instanceof Class<?>)
- return (Class<?>) valueType;
- }
- }
- }
- return null;
+ public static Type getMapKeyType(Type type) {
+ return getMapElementType(type, 0);
}
-
- public static Class<?> getMapValueType(Type type) {
+
+ @Nullable
+ public static Type getMapValueType(Type type) {
+ return getMapElementType(type, 1);
+ }
+
+ @Nullable
+ private static Type getMapElementType(Type type, int index) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType)type;
Type rawType = parameterizedType.getRawType();
-
- if (rawType instanceof Class<?>) {
- Class<?> rawClazz = (Class<?>) rawType;
- if (Map.class.isAssignableFrom(rawClazz)) {
- Type valueType = parameterizedType.getActualTypeArguments()[1];
- if (valueType instanceof Class<?>) {
- return (Class<?>) valueType;
- } else if (valueType instanceof ParameterizedType) {
- return (Class<?>) ((ParameterizedType)valueType).getRawType();
- }
- }
- }
+ Preconditions.checkState(Map.class.isAssignableFrom((Class<?>) rawType));
+ return parameterizedType.getActualTypeArguments()[index];
}
return null;
}
diff --git a/server-core/src/main/java/io/onedev/server/util/jackson/ObjectMapperProvider.java b/server-core/src/main/java/io/onedev/server/util/jackson/ObjectMapperProvider.java
index 83a7ef734d..b16c5e7bef 100644
--- a/server-core/src/main/java/io/onedev/server/util/jackson/ObjectMapperProvider.java
+++ b/server-core/src/main/java/io/onedev/server/util/jackson/ObjectMapperProvider.java
@@ -14,6 +14,7 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -22,6 +23,7 @@ import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
+import com.fasterxml.jackson.databind.util.StdDateFormat;
@Singleton
public class ObjectMapperProvider implements Provider<ObjectMapper> {
@@ -54,6 +56,7 @@ public class ObjectMapperProvider implements Provider<ObjectMapper> {
return !Collection.class.isAssignableFrom(t.getRawClass())
&& !Map.class.isAssignableFrom(t.getRawClass())
&& t.getRawClass() != JsonNode.class
+ && !Enum.class.isAssignableFrom(t.getRawClass())
&& !t.isConcrete();
}
@@ -61,12 +64,14 @@ public class ObjectMapperProvider implements Provider<ObjectMapper> {
typer = typer.init(JsonTypeInfo.Id.CLASS, null);
typer = typer.inclusion(JsonTypeInfo.As.PROPERTY);
mapper.setDefaultTyping(typer);
+ mapper.setDateFormat(new StdDateFormat().withColonInTimeZone(true));
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
+ mapper.configure(MapperFeature.PROPAGATE_TRANSIENT_MARKER, true);
for (ObjectMapperConfigurator each: configurators)
each.configure(mapper);
diff --git a/server-core/src/main/java/io/onedev/server/web/OneUrlMapper.java b/server-core/src/main/java/io/onedev/server/web/OneUrlMapper.java
index aec43140ae..2dc2e91689 100644
--- a/server-core/src/main/java/io/onedev/server/web/OneUrlMapper.java
+++ b/server-core/src/main/java/io/onedev/server/web/OneUrlMapper.java
@@ -46,6 +46,9 @@ import io.onedev.server.web.page.admin.user.password.UserPasswordPage;
import io.onedev.server.web.page.admin.user.profile.UserProfilePage;
import io.onedev.server.web.page.admin.user.ssh.UserSshKeysPage;
import io.onedev.server.web.page.builds.BuildListPage;
+import io.onedev.server.web.page.help.MethodDetailPage;
+import io.onedev.server.web.page.help.ResourceDetailPage;
+import io.onedev.server.web.page.help.ResourceListPage;
import io.onedev.server.web.page.issues.IssueListPage;
import io.onedev.server.web.page.my.accesstoken.MyAccessTokenPage;
import io.onedev.server.web.page.my.avatar.MyAvatarPage;
@@ -133,12 +136,17 @@ public class OneUrlMapper extends CompoundRequestMapper {
addMyPages();
addAdministrationPages();
addSecurityPages();
-
addResources();
-
+ addHelpPages();
addErrorPages();
}
+ private void addHelpPages() {
+ add(new DynamicPathPageMapper("help/api", ResourceListPage.class));
+ add(new DynamicPathPageMapper("help/api/${resource}", ResourceDetailPage.class));
+ add(new DynamicPathPageMapper("help/api/${resource}/${method}", MethodDetailPage.class));
+ }
+
private void addMyPages() {
add(new DynamicPathPageMapper("my/profile", MyProfilePage.class));
add(new DynamicPathPageMapper("my/avatar", MyAvatarPage.class));
diff --git a/server-core/src/main/java/io/onedev/server/web/component/entity/reference/ReferencePanel.html b/server-core/src/main/java/io/onedev/server/web/component/entity/reference/ReferencePanel.html
index 4b3bbb1ab4..b7e4d229b1 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/entity/reference/ReferencePanel.html
+++ b/server-core/src/main/java/io/onedev/server/web/component/entity/reference/ReferencePanel.html
@@ -1,5 +1,5 @@
<wicket:panel>
- <div class="head">Reference <a title="Can be referenced via below string in markdown" class="ml-2 text-gray"><wicket:svg href="question-o" class="icon icon-sm"/></a></div>
+ <div class="head">Reference <a wicket:id="referenceHelp" class="ml-2 text-gray"><wicket:svg href="question-o" class="icon icon-sm"/></a></div>
<div class="body">
<div class="d-flex align-items-center flex-nowrap">
<span wicket:id="reference" class="text-nowrap text-truncate mr-3"></span>
diff --git a/server-core/src/main/java/io/onedev/server/web/component/entity/reference/ReferencePanel.java b/server-core/src/main/java/io/onedev/server/web/component/entity/reference/ReferencePanel.java
index 40ba31b6d5..e010589c00 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/entity/reference/ReferencePanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/entity/reference/ReferencePanel.java
@@ -2,6 +2,9 @@ package io.onedev.server.web.component.entity.reference;
import io.onedev.server.util.Referenceable;
import io.onedev.server.web.component.link.copytoclipboard.CopyToClipboardLink;
+
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
@@ -17,6 +20,18 @@ public abstract class ReferencePanel extends Panel {
protected void onInitialize() {
super.onInitialize();
+ add(new WebMarkupContainer("referenceHelp") {
+
+ @Override
+ protected void onComponentTag(ComponentTag tag) {
+ super.onComponentTag(tag);
+ tag.put("title", "Reference this " + getReferenceable().getType()
+ + " in markdown or commit message via below string. "
+ + "Project name can be ommitted if reference from current project");
+ }
+
+ });
+
String reference = Referenceable.asReference(getReferenceable());
add(new Label("reference", reference));
diff --git a/server-core/src/main/java/io/onedev/server/web/component/user/sshkey/InsertSshKeyPanel.java b/server-core/src/main/java/io/onedev/server/web/component/user/sshkey/InsertSshKeyPanel.java
index 54a7e525f5..472c17ea33 100644
--- a/server-core/src/main/java/io/onedev/server/web/component/user/sshkey/InsertSshKeyPanel.java
+++ b/server-core/src/main/java/io/onedev/server/web/component/user/sshkey/InsertSshKeyPanel.java
@@ -72,7 +72,7 @@ public abstract class InsertSshKeyPanel extends Panel {
target.add(form);
} else {
sshKey.setOwner(getUser());
- sshKey.setDate(new Date());
+ sshKey.setCreatedAt(new Date());
sshKeyManager.save(sshKey);
onSave(target);
}
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListEditSupport.java
index 472ab9e335..b890756467 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListEditSupport.java
@@ -22,7 +22,7 @@ public class BeanListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass != null && ClassUtils.isConcrete(elementClass)
&& elementClass.getAnnotation(Editable.class) != null) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListPropertyEditor.java b/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListPropertyEditor.java
index e6d96e686c..317ba5ccdb 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListPropertyEditor.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListPropertyEditor.java
@@ -56,7 +56,7 @@ public class BeanListPropertyEditor extends PropertyEditor<List<Serializable>> {
public BeanListPropertyEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<Serializable>> model) {
super(id, propertyDescriptor, model);
- elementClass = ReflectionUtils.getCollectionElementType(propertyDescriptor.getPropertyGetter().getGenericReturnType());
+ elementClass = ReflectionUtils.getCollectionElementClass(propertyDescriptor.getPropertyGetter().getGenericReturnType());
propertyContexts = new ArrayList<>();
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListPropertyViewer.java b/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListPropertyViewer.java
index fe4b16c70c..70bbf53e27 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListPropertyViewer.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListPropertyViewer.java
@@ -42,7 +42,7 @@ public class BeanListPropertyViewer extends Panel {
excludedProperties.add(each);
}
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
propertyContexts = new ArrayList<>();
for (List<PropertyDescriptor> groupProperties: new BeanDescriptor(elementClass).getProperties().values()) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/branchchoice/BranchChoiceEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/branchchoice/BranchChoiceEditSupport.java
index 42d167d32d..cbfe849e09 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/branchchoice/BranchChoiceEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/branchchoice/BranchChoiceEditSupport.java
@@ -26,7 +26,7 @@ public class BranchChoiceEditSupport implements EditSupport {
Method propertyGetter = descriptor.getPropertyGetter();
if (propertyGetter.getAnnotation(BranchChoice.class) != null) {
if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && ReflectionUtils.getCollectionElementType(propertyGetter.getGenericReturnType()) == String.class) {
+ && ReflectionUtils.getCollectionElementClass(propertyGetter.getGenericReturnType()) == String.class) {
return new PropertyContext<List<String>>(descriptor) {
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/build/choice/BuildChoiceEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/build/choice/BuildChoiceEditSupport.java
index 98b986dbd5..131337b170 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/build/choice/BuildChoiceEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/build/choice/BuildChoiceEditSupport.java
@@ -26,7 +26,7 @@ public class BuildChoiceEditSupport implements EditSupport {
BuildChoice buildChoice = propertyGetter.getAnnotation(BuildChoice.class);
if (buildChoice != null) {
if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && ReflectionUtils.getCollectionElementType(propertyGetter.getGenericReturnType()) == Long.class) {
+ && ReflectionUtils.getCollectionElementClass(propertyGetter.getGenericReturnType()) == Long.class) {
return new PropertyContext<List<Long>>(descriptor) {
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/imports/ImportListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/imports/ImportListEditSupport.java
index b11f74f35e..4cc916e920 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/imports/ImportListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/imports/ImportListEditSupport.java
@@ -21,7 +21,7 @@ public class ImportListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == Import.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/choice/JobChoiceEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/choice/JobChoiceEditSupport.java
index 6646eed52d..27d8329041 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/choice/JobChoiceEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/choice/JobChoiceEditSupport.java
@@ -26,7 +26,7 @@ public class JobChoiceEditSupport implements EditSupport {
JobChoice jobChoice = propertyGetter.getAnnotation(JobChoice.class);
if (jobChoice != null) {
if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && ReflectionUtils.getCollectionElementType(propertyGetter.getGenericReturnType()) == String.class) {
+ && ReflectionUtils.getCollectionElementClass(propertyGetter.getGenericReturnType()) == String.class) {
return new PropertyContext<List<String>>(descriptor) {
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/jobdependency/JobDependencyListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/jobdependency/JobDependencyListEditSupport.java
index 7ce958bfa6..4e0f27cbd7 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/jobdependency/JobDependencyListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/jobdependency/JobDependencyListEditSupport.java
@@ -21,7 +21,7 @@ public class JobDependencyListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == JobDependency.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/postbuildaction/PostBuildActionListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/postbuildaction/PostBuildActionListEditSupport.java
index c5ccc17fdb..c740fa3736 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/postbuildaction/PostBuildActionListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/postbuildaction/PostBuildActionListEditSupport.java
@@ -21,7 +21,7 @@ public class PostBuildActionListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == PostBuildAction.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/privilege/JobPrivilegeListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/privilege/JobPrivilegeListEditSupport.java
index 5c4b7640b1..9f348190fc 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/privilege/JobPrivilegeListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/privilege/JobPrivilegeListEditSupport.java
@@ -21,7 +21,7 @@ public class JobPrivilegeListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == JobPrivilege.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/projectdependency/ProjectDependencyListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/projectdependency/ProjectDependencyListEditSupport.java
index 9281f772d8..fd7e6dcc44 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/projectdependency/ProjectDependencyListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/projectdependency/ProjectDependencyListEditSupport.java
@@ -21,7 +21,7 @@ public class ProjectDependencyListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == ProjectDependency.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/trigger/JobTriggerListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/trigger/JobTriggerListEditSupport.java
index 6b210a5456..d90b1b94a0 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/trigger/JobTriggerListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/job/trigger/JobTriggerListEditSupport.java
@@ -21,7 +21,7 @@ public class JobTriggerListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == JobTrigger.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/param/spec/ParamSpecListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/param/spec/ParamSpecListEditSupport.java
index 26894b9955..47fc38a5f1 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/param/spec/ParamSpecListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/param/spec/ParamSpecListEditSupport.java
@@ -21,7 +21,7 @@ public class ParamSpecListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == ParamSpec.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/param/supply/ParamListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/param/supply/ParamListEditSupport.java
index 5c057c0740..528080459f 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/param/supply/ParamListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/param/supply/ParamListEditSupport.java
@@ -22,7 +22,7 @@ public class ParamListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == ParamSupply.class && descriptor.getPropertyGetter().getAnnotation(ParamSpecProvider.class) != null) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/step/StepListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/step/StepListEditSupport.java
index 85fa8dc742..5528bfc19c 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/buildspec/step/StepListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/buildspec/step/StepListEditSupport.java
@@ -21,7 +21,7 @@ public class StepListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == Step.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/code/CodeEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/code/CodeEditSupport.java
index 563d83961f..90087ec76f 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/code/CodeEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/code/CodeEditSupport.java
@@ -23,7 +23,7 @@ public class CodeEditSupport implements EditSupport {
Class<?> propertyClass = descriptor.getPropertyGetter().getReturnType();
Code annotation = descriptor.getPropertyGetter().getAnnotation(Code.class);
if (annotation != null) {
- if (List.class.isAssignableFrom(propertyClass) && ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType()) == String.class) {
+ if (List.class.isAssignableFrom(propertyClass) && ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType()) == String.class) {
return new PropertyContext<List<String>>(descriptor) {
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/enumlist/EnumListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/enumlist/EnumListEditSupport.java
index 46197d66c8..7d82403de9 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/enumlist/EnumListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/enumlist/EnumListEditSupport.java
@@ -20,7 +20,7 @@ public class EnumListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- final Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ final Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass != null && Enum.class.isAssignableFrom(elementClass)) {
return new PropertyContext<List<Enum<?>>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/enumlist/EnumListPropertyEditor.java b/server-core/src/main/java/io/onedev/server/web/editable/enumlist/EnumListPropertyEditor.java
index f83e1e2cd2..b1bd860143 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/enumlist/EnumListPropertyEditor.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/enumlist/EnumListPropertyEditor.java
@@ -30,7 +30,7 @@ public class EnumListPropertyEditor extends PropertyEditor<List<Enum<?>>> {
public EnumListPropertyEditor(String id, PropertyDescriptor propertyDescriptor, IModel<List<Enum<?>>> propertyModel) {
super(id, propertyDescriptor, propertyModel);
- enumClass = (Class<Enum>) ReflectionUtils.getCollectionElementType(propertyDescriptor.getPropertyGetter().getGenericReturnType());
+ enumClass = (Class<Enum>) ReflectionUtils.getCollectionElementClass(propertyDescriptor.getPropertyGetter().getGenericReturnType());
}
private String getDisplayValue(String choice) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/groupchoice/GroupChoiceEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/groupchoice/GroupChoiceEditSupport.java
index 90d848be47..4c6ae23c3b 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/groupchoice/GroupChoiceEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/groupchoice/GroupChoiceEditSupport.java
@@ -25,7 +25,7 @@ public class GroupChoiceEditSupport implements EditSupport {
Method propertyGetter = descriptor.getPropertyGetter();
if (propertyGetter.getAnnotation(GroupChoice.class) != null) {
if (Collection.class.isAssignableFrom(propertyGetter.getReturnType())
- && ReflectionUtils.getCollectionElementType(propertyGetter.getGenericReturnType()) == String.class) {
+ && ReflectionUtils.getCollectionElementClass(propertyGetter.getGenericReturnType()) == String.class) {
return new PropertyContext<Collection<String>>(descriptor) {
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/issue/fieldsupply/FieldListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/issue/fieldsupply/FieldListEditSupport.java
index 7194f760e8..5469f76687 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/issue/fieldsupply/FieldListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/issue/fieldsupply/FieldListEditSupport.java
@@ -21,7 +21,7 @@ public class FieldListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == FieldSupply.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/project/choice/ProjectChoiceEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/project/choice/ProjectChoiceEditSupport.java
index 9b8303d15e..7cf0a35a04 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/project/choice/ProjectChoiceEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/project/choice/ProjectChoiceEditSupport.java
@@ -26,7 +26,7 @@ public class ProjectChoiceEditSupport implements EditSupport {
ProjectChoice projectChoice = propertyGetter.getAnnotation(ProjectChoice.class);
if (projectChoice != null) {
if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && ReflectionUtils.getCollectionElementType(propertyGetter.getGenericReturnType()) == String.class) {
+ && ReflectionUtils.getCollectionElementClass(propertyGetter.getGenericReturnType()) == String.class) {
return new PropertyContext<List<String>>(descriptor) {
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/rolechoice/RoleChoiceEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/rolechoice/RoleChoiceEditSupport.java
index d959b9d5f3..9334040157 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/rolechoice/RoleChoiceEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/rolechoice/RoleChoiceEditSupport.java
@@ -26,7 +26,7 @@ public class RoleChoiceEditSupport implements EditSupport {
RoleChoice roleChoice = propertyGetter.getAnnotation(RoleChoice.class);
if (roleChoice != null) {
if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && ReflectionUtils.getCollectionElementType(propertyGetter.getGenericReturnType()) == String.class) {
+ && ReflectionUtils.getCollectionElementClass(propertyGetter.getGenericReturnType()) == String.class) {
return new PropertyContext<List<String>>(descriptor) {
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/servicelocator/ServiceLocatorListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/servicelocator/ServiceLocatorListEditSupport.java
index 7b688443e3..23c200b1c1 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/servicelocator/ServiceLocatorListEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/servicelocator/ServiceLocatorListEditSupport.java
@@ -21,7 +21,7 @@ public class ServiceLocatorListEditSupport implements EditSupport {
@Override
public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {
if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {
- Class<?> elementClass = ReflectionUtils.getCollectionElementType(descriptor.getPropertyGetter().getGenericReturnType());
+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());
if (elementClass == ServiceLocator.class) {
return new PropertyContext<List<Serializable>>(descriptor) {
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/userchoice/UserChoiceEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/userchoice/UserChoiceEditSupport.java
index 9b30c34d7a..414d841e66 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/userchoice/UserChoiceEditSupport.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/userchoice/UserChoiceEditSupport.java
@@ -26,7 +26,7 @@ public class UserChoiceEditSupport implements EditSupport {
UserChoice userChoice = propertyGetter.getAnnotation(UserChoice.class);
if (userChoice != null) {
if (List.class.isAssignableFrom(propertyGetter.getReturnType())
- && ReflectionUtils.getCollectionElementType(propertyGetter.getGenericReturnType()) == String.class) {
+ && ReflectionUtils.getCollectionElementClass(propertyGetter.getGenericReturnType()) == String.class) {
return new PropertyContext<List<String>>(descriptor) {
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationCssResourceReference.java b/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationCssResourceReference.java
new file mode 100644
index 0000000000..05b1b34175
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationCssResourceReference.java
@@ -0,0 +1,13 @@
+package io.onedev.server.web.page.admin;
+
+import org.apache.wicket.request.resource.CssResourceReference;
+
+public class AdministrationCssResourceReference extends CssResourceReference {
+
+ private static final long serialVersionUID = 1L;
+
+ public AdministrationCssResourceReference() {
+ super(AdministrationCssResourceReference.class, "administration.css");
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationPage.java b/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationPage.java
index cc34e357f6..086e8ccb44 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationPage.java
@@ -30,7 +30,7 @@ public abstract class AdministrationPage extends LayoutPage implements ScriptIde
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
- response.render(CssHeaderItem.forReference(new AdministrationResourceReference()));
+ response.render(CssHeaderItem.forReference(new AdministrationCssResourceReference()));
}
@Override
diff --git a/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationResourceReference.java b/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationResourceReference.java
deleted file mode 100644
index c8d92ce813..0000000000
--- a/server-core/src/main/java/io/onedev/server/web/page/admin/AdministrationResourceReference.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package io.onedev.server.web.page.admin;
-
-import org.apache.wicket.request.resource.CssResourceReference;
-
-public class AdministrationResourceReference extends CssResourceReference {
-
- private static final long serialVersionUID = 1L;
-
- public AdministrationResourceReference() {
- super(AdministrationResourceReference.class, "administration.css");
- }
-
-}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ApiComparator.java b/server-core/src/main/java/io/onedev/server/web/page/help/ApiComparator.java
new file mode 100644
index 0000000000..d5d5d3444e
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ApiComparator.java
@@ -0,0 +1,24 @@
+package io.onedev.server.web.page.help;
+
+import java.lang.reflect.AnnotatedElement;
+import java.util.Comparator;
+
+import io.onedev.server.rest.annotation.Api;
+
+public class ApiComparator implements Comparator<AnnotatedElement> {
+
+ @Override
+ public int compare(AnnotatedElement o1, AnnotatedElement o2) {
+ Api api1 = o1.getAnnotation(Api.class);
+ Api api2 = o2.getAnnotation(Api.class);
+ int order1 = Integer.MAX_VALUE;
+ if (api1 != null)
+ order1 = api1.order();
+ int order2 = Integer.MAX_VALUE;
+ if (api2 != null)
+ order2 = api2.order();
+
+ return order1 - order2;
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpCssResourceReference.java b/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpCssResourceReference.java
new file mode 100644
index 0000000000..0d855f2f29
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpCssResourceReference.java
@@ -0,0 +1,13 @@
+package io.onedev.server.web.page.help;
+
+import org.apache.wicket.request.resource.CssResourceReference;
+
+public class ApiHelpCssResourceReference extends CssResourceReference {
+
+ private static final long serialVersionUID = 1L;
+
+ public ApiHelpCssResourceReference() {
+ super(ApiHelpCssResourceReference.class, "api-help.css");
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpPage.html b/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpPage.html
new file mode 100644
index 0000000000..56985cb883
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpPage.html
@@ -0,0 +1,7 @@
+<wicket:extend>
+ <div class="api-help card m-2 m-sm-5">
+ <div class="card-body">
+ <wicket:child></wicket:child>
+ </div>
+ </div>
+</wicket:extend>
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpPage.java b/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpPage.java
new file mode 100644
index 0000000000..541e7d7162
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpPage.java
@@ -0,0 +1,66 @@
+package io.onedev.server.web.page.help;
+
+import java.lang.reflect.Method;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.head.CssHeaderItem;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+import io.onedev.commons.utils.WordUtils;
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.web.page.layout.LayoutPage;
+
+@SuppressWarnings("serial")
+public abstract class ApiHelpPage extends LayoutPage {
+
+ public ApiHelpPage(PageParameters params) {
+ super(params);
+ }
+
+ @Override
+ protected String getPageTitle() {
+ return "RESTful API Help";
+ }
+
+ @Override
+ protected Component newTopbarTitle(String componentId) {
+ return new Label(componentId, "RESTful API Help");
+ }
+
+ protected String getResourceTitle(Class<?> resourceClass) {
+ return StringUtils.capitalize(
+ WordUtils.uncamel(
+ StringUtils.substringBeforeLast(
+ resourceClass.getSimpleName(), "Resource")).toLowerCase());
+ }
+
+ protected String getResourceDescription(Class<?> resourceClass) {
+ Api api = resourceClass.getAnnotation(Api.class);
+ if (api != null && api.description().length() != 0)
+ return api.description();
+ else
+ return getResourceTitle(resourceClass);
+ }
+
+ protected String getMethodTitle(Method resourceMethod) {
+ return StringUtils.capitalize(WordUtils.uncamel(resourceMethod.getName()).toLowerCase());
+ }
+
+ protected String getMethodDescription(Method resourceMethod) {
+ Api api = resourceMethod.getAnnotation(Api.class);
+ if (api != null && api.description().length() != 0)
+ return api.description();
+ else
+ return getMethodTitle(resourceMethod);
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(new ApiHelpCssResourceReference()));
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpUtils.java b/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpUtils.java
new file mode 100644
index 0000000000..933daaa0f6
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ApiHelpUtils.java
@@ -0,0 +1,161 @@
+package io.onedev.server.web.page.help;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Transient;
+
+import org.objenesis.ObjenesisStd;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.collect.Sets;
+
+import edu.emory.mathcs.backport.java.util.Collections;
+import io.onedev.commons.launcher.loader.ImplementationRegistry;
+import io.onedev.server.OneDev;
+import io.onedev.server.model.AbstractEntity;
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.util.BeanUtils;
+import io.onedev.server.util.ReflectionUtils;
+
+public class ApiHelpUtils {
+
+ public static Object getExampleValue(Type valueType) {
+ return getExampleValue(valueType, Sets.newHashSet());
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static Object getExampleValue(Type valueType, Set<Class<?>> parsedTypes) {
+ Class<?> valueClass = ReflectionUtils.getClass(valueType);
+ Object value = new ExampleProvider(valueClass, valueClass.getAnnotation(Api.class)).getExample();
+ if (value == null) {
+ if (valueClass == int.class || valueClass == Integer.class) {
+ value = 1;
+ } else if (valueClass == long.class || valueClass == Long.class) {
+ value = 1L;
+ } else if (valueClass == String.class) {
+ value = "string";
+ } else if (valueClass == boolean.class || valueClass == Boolean.class) {
+ value = true;
+ } else if (valueClass == Date.class) {
+ value = new Date();
+ } else if (Enum.class.isAssignableFrom(valueClass)) {
+ value = EnumSet.allOf((Class<Enum>) valueClass).iterator().next();
+ } else if (Collection.class.isAssignableFrom(valueClass)) {
+ Class<?> collectionElementType = ReflectionUtils.getCollectionElementClass(valueType);
+ if (collectionElementType == null)
+ throw new RuntimeException("Do not know how to generate collection element example");
+ Collection<Object> collection;
+ if (valueClass == List.class || valueClass == Collection.class) {
+ collection = new ArrayList<Object>();
+ } else if (valueClass == Set.class) {
+ collection = new HashSet<>();
+ } else {
+ try {
+ collection = (Collection<Object>) valueClass.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ collection.add(getExampleValue(collectionElementType, parsedTypes));
+ return collection;
+ } else if (Map.class.isAssignableFrom(valueClass)) {
+ Type mapKeyType = ReflectionUtils.getMapKeyType(valueType);
+ if (mapKeyType == null)
+ throw new RuntimeException("Do not know how to generate map key example");
+ Type mapValueType = ReflectionUtils.getMapValueType(valueType);
+ if (mapValueType == null)
+ throw new RuntimeException("Do not know how to generate map value example");
+
+ Map<Object, Object> map;
+ if (valueClass == Map.class) {
+ map = new HashMap<>();
+ } else {
+ try {
+ map = (Map<Object, Object>) valueClass.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ map.put(getExampleValue(mapKeyType, parsedTypes), getExampleValue(mapValueType, parsedTypes));
+
+ return map;
+ } else {
+ try {
+ if (parsedTypes.add(valueClass)) {
+ Class<?> instantiationClass;
+ if (Modifier.isAbstract(valueClass.getModifiers())) {
+ instantiationClass = OneDev.getInstance(ImplementationRegistry.class)
+ .getImplementations(valueClass).iterator().next();
+ } else {
+ instantiationClass = valueClass;
+ }
+ value = new ObjenesisStd(true).getInstantiatorOf(instantiationClass).newInstance();
+ for (Field field: getJsonFields(instantiationClass)) {
+ Object fieldValue = new ExampleProvider(valueClass, field.getAnnotation(Api.class)).getExample();
+ if (fieldValue == null) {
+ if (field.getAnnotation(ManyToOne.class) != null) {
+ fieldValue = field.getType().newInstance();
+ Field idField = AbstractEntity.class.getDeclaredField("id");
+ Object id = new ExampleProvider(idField.getType(), idField.getAnnotation(Api.class)).getExample();
+ if (id == null)
+ id = getExampleValue(idField.getGenericType(), new HashSet<>(parsedTypes));
+ idField.setAccessible(true);
+ idField.set(fieldValue, id);
+ } else {
+ fieldValue = getExampleValue(field.getGenericType(), new HashSet<>(parsedTypes));
+ }
+ }
+ field.setAccessible(true);
+ field.set(value, fieldValue);
+ }
+ }
+ } catch (InstantiationException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ return value;
+ }
+
+ public static List<Field> getJsonFields(Class<?> beanClass) {
+ List<Field> fields = new ArrayList<>();
+ for (Field field: BeanUtils.findFields(beanClass)) {
+ if (field.getAnnotation(JsonIgnore.class) != null
+ || field.getAnnotation(OneToMany.class) != null
+ || field.getAnnotation(Transient.class) != null
+ || Modifier.isTransient(field.getModifiers()))
+ continue;
+ if (field.getAnnotation(JsonProperty.class) != null) {
+ fields.add(field);
+ } else {
+ Method getter = BeanUtils.findGetter(beanClass, field.getName());
+ Method setter = BeanUtils.findSetter(beanClass, field.getName(), field.getType());
+
+ if ((getter == null || getter.getAnnotation(JsonIgnore.class) == null)
+ && (setter == null || setter.getAnnotation(JsonIgnore.class) == null)) {
+ fields.add(field);
+ }
+ }
+ }
+
+ Collections.sort(fields, new ApiComparator());
+
+ return fields;
+ }
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ExampleProvider.java b/server-core/src/main/java/io/onedev/server/web/page/help/ExampleProvider.java
new file mode 100644
index 0000000000..ff79221974
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ExampleProvider.java
@@ -0,0 +1,30 @@
+package io.onedev.server.web.page.help;
+
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.util.ReflectionUtils;
+
+class ExampleProvider {
+
+ private final Class<?> apiDeclaringClass;
+
+ private final Api api;
+
+ public ExampleProvider(Class<?> apiDeclaringClass, @Nullable Api api) {
+ this.apiDeclaringClass = apiDeclaringClass;
+ this.api = api;
+ }
+
+ @Nullable
+ public Object getExample() {
+ if (api != null && api.exampleProvider().length() != 0) {
+ return Preconditions.checkNotNull(ReflectionUtils.invokeStaticMethod(
+ apiDeclaringClass, api.exampleProvider()));
+ } else {
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ExampleValuePanel.html b/server-core/src/main/java/io/onedev/server/web/page/help/ExampleValuePanel.html
new file mode 100644
index 0000000000..aee59b1d99
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ExampleValuePanel.html
@@ -0,0 +1,66 @@
+<wicket:panel>
+ <wicket:container wicket:id="content"></wicket:container>
+ <a wicket:id="hint" class="example-value-hint" title="More info about this property"><wicket:svg href="info-circle" class="icon icon-sm"/></a>
+
+ <wicket:fragment wicket:id="objectFrag">
+ <span class="example-value-brace">{</span>
+ <div class="example-value-properties ml-5">
+ <div wicket:id="typeInfo"></div>
+ <div wicket:id="properties">
+ <wicket:container wicket:id="name"></wicket:container>
+ <span class="example-value-code">:</span>
+ <span wicket:id="value"></span>
+ <span wicket:id="comma" class="example-value-comma">,</span>
+ </div>
+ </div>
+ <span class="example-value-brace">}</span>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="arrayFrag">
+ <span class="example-value-bracket">[</span>
+ <wicket:container wicket:id="elements">
+ <span wicket:id="element"></span>
+ <span wicket:id="comma" class="example-value-comma">,</span>
+ </wicket:container>
+ <span class="example-value-bracket">]</span>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="scalarFrag">
+ <span wicket:id="value" class="example-value-scalar"></span>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="hintFrag">
+ <div class="example-value-hint">
+ <div wicket:id="typeHint"></div>
+ <div wicket:id="description"></div>
+ </div>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="idOfCurrentEntityHintFrag">
+ Internal id of current object
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="idOfCurrentEntityInRequestBodyHintFrag">
+ Update object with this id. Remove this property or set this property as <i>null</i> if you want to create new object
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="entityIdHintFrag">
+ Internal id of <a wicket:id="entity"><span wicket:id="label"></span></a>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="enumHintFrag">
+ Possible values: <i wicket:id="possibleValues"></i>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="dateHintFrag">
+ This date is using <a href="https://www.w3.org/TR/NOTE-datetime">ISO 8601 format</a>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="typeInfoFrag">
+ <wicket:container wicket:id="name"></wicket:container>
+ <span class="example-value-code">:</span>
+ <wicket:container wicket:id="value"></wicket:container>
+ <a wicket:id="implementations" class="example-value-implementations" title="All possible classes"><wicket:svg href="play" class="icon rotate-90"/></a>
+ <span wicket:id="comma" class="example-value-comma">,</span>
+ </wicket:fragment>
+</wicket:panel>
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ExampleValuePanel.java b/server-core/src/main/java/io/onedev/server/web/page/help/ExampleValuePanel.java
new file mode 100644
index 0000000000..5cdc93ba79
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ExampleValuePanel.java
@@ -0,0 +1,462 @@
+package io.onedev.server.web.page.help;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Nullable;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.ws.rs.Path;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.glassfish.jersey.server.ResourceConfig;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import io.onedev.commons.launcher.loader.ImplementationRegistry;
+import io.onedev.commons.utils.StringUtils;
+import io.onedev.commons.utils.WordUtils;
+import io.onedev.server.OneDev;
+import io.onedev.server.model.AbstractEntity;
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.rest.annotation.EntityId;
+import io.onedev.server.util.ReflectionUtils;
+import io.onedev.server.web.component.floating.FloatingPanel;
+import io.onedev.server.web.component.link.DropdownLink;
+import io.onedev.server.web.component.link.ViewStateAwarePageLink;
+import io.onedev.server.web.component.menu.MenuItem;
+import io.onedev.server.web.component.menu.MenuLink;
+
+@SuppressWarnings("serial")
+public class ExampleValuePanel extends Panel {
+
+ private static final Map<Class<?>, Class<?>> resourceMap = new HashMap<>();
+
+ static {
+ ResourceConfig config = OneDev.getInstance(ResourceConfig.class);
+
+ for (Class<?> clazz: config.getClasses()) {
+ if (clazz.getAnnotation(Path.class) != null) {
+ Api api = clazz.getAnnotation(Api.class);
+ if (api == null || !api.exclude()) {
+ try {
+ Method method = clazz.getMethod("get", Long.class);
+ if (AbstractEntity.class.isAssignableFrom(method.getReturnType()))
+ resourceMap.put(method.getReturnType(), clazz);
+ } catch (NoSuchMethodException | SecurityException e) {
+ }
+ }
+ }
+ }
+ }
+
+ private final Object value;
+
+ private final IModel<ValueInfo> valueInfoModel;
+
+ private final boolean requestBody;
+
+ public ExampleValuePanel(String id, Object value, boolean requestBody) {
+ this(id, value, newNullValueModel(), requestBody);
+ }
+
+ public ExampleValuePanel(String id, Object value, IModel<ValueInfo> valueInfoModel, boolean requestBody) {
+ super(id);
+ this.value = value;
+ this.valueInfoModel = valueInfoModel;
+ this.requestBody = requestBody;
+ }
+
+ @Override
+ protected void onDetach() {
+ valueInfoModel.detach();
+ super.onDetach();
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ if (value == null || value.getClass() == String.class
+ || value.getClass() == boolean.class || value.getClass() == Boolean.class
+ || value.getClass() == int.class || value.getClass() == Integer.class
+ || value.getClass() == long.class || value.getClass() == Long.class
+ || value.getClass() == Date.class || value instanceof Enum) {
+ add(newScalarFragment(value));
+ } else if (getField() != null && getField().getAnnotation(ManyToOne.class) != null) {
+ add(newScalarFragment(((AbstractEntity)value).getId()));
+ } else if (value instanceof Collection) {
+ add(newArrayFragment());
+ } else if (value instanceof Map) {
+ add(newMapFragment());
+ } else {
+ add(newObjectFragment());
+ }
+
+ if (newValueHint("psuedoId") != null) {
+ add(new DropdownLink("hint") {
+
+ @Override
+ protected Component newContent(String id, FloatingPanel dropdown) {
+ return newValueHint(id);
+ }
+
+ });
+ } else {
+ add(new WebMarkupContainer("hint").setVisible(false));
+ }
+
+ setOutputMarkupId(true);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Nullable
+ private Component newValueHint(String componentId) {
+ Fragment fragment = new Fragment(componentId, "hintFrag", this);
+
+ boolean hasHint = false;
+
+ if (value instanceof Date) {
+ fragment.add(new Fragment("typeHint", "dateHintFrag", this));
+ hasHint = true;
+ } else if (value instanceof Enum && getDeclaredClass() != null) {
+ Fragment typeHintFrag = new Fragment("typeHint", "enumHintFrag", this);
+ List<String> possibleValues = new ArrayList<>();
+ for (Object each: EnumSet.allOf((Class<Enum>) getDeclaredClass()))
+ possibleValues.add(((Enum<?>)each).name());
+
+ typeHintFrag.add(new Label("possibleValues", StringUtils.join(possibleValues)));
+ fragment.add(typeHintFrag);
+ hasHint = true;
+ } else if (getField() != null) {
+ if (getField().getAnnotation(ManyToOne.class) != null
+ || getField().getAnnotation(EntityId.class) != null) {
+ Class<?> entityClass;
+ if (value instanceof AbstractEntity)
+ entityClass = value.getClass();
+ else
+ entityClass = getField().getAnnotation(EntityId.class).value();
+ Class<?> resourceClass = resourceMap.get(entityClass);
+ if (resourceClass != null) {
+ Fragment typeHintFrag = new Fragment("typeHint", "entityIdHintFrag", this);
+ Link<Void> link = new ViewStateAwarePageLink<Void>("entity", ResourceDetailPage.class,
+ ResourceDetailPage.paramsOf(resourceClass));
+ link.add(new Label("label", WordUtils.uncamel(resourceClass.getSimpleName()).toLowerCase()));
+ typeHintFrag.add(link);
+ fragment.add(typeHintFrag);
+ hasHint = true;
+ } else {
+ fragment.add(new WebMarkupContainer("typeHint").setVisible(false));
+ }
+ } else if (getField().getAnnotation(Id.class) != null) {
+ if (requestBody) {
+ fragment.add(new Fragment("typeHint", "idOfCurrentEntityInRequestBodyHintFrag", this));
+ hasHint = true;
+ } else {
+ fragment.add(new Fragment("typeHint", "idOfCurrentEntityHintFrag", this));
+ hasHint = true;
+ }
+ } else {
+ fragment.add(new WebMarkupContainer("typeHint").setVisible(false));
+ }
+ } else {
+ fragment.add(new WebMarkupContainer("typeHint").setVisible(false));
+ }
+
+ String description = "";
+ if (getField() != null && getField().getAnnotation(Api.class) != null)
+ description = getField().getAnnotation(Api.class).description();
+ if (description.length() == 0 && value != null
+ && value.getClass().getAnnotation(Api.class) != null) {
+ description = value.getClass().getAnnotation(Api.class).description();
+ }
+ if (description.length() != 0) {
+ hasHint = true;
+ fragment.add(new Label("description", description));
+ } else {
+ fragment.add(new WebMarkupContainer("description").setVisible(false));
+ }
+
+ if (hasHint)
+ return fragment;
+ else
+ return null;
+ }
+
+ private Fragment newScalarFragment(Object value) {
+ Fragment fragment = new Fragment("content", "scalarFrag", this);
+ fragment.add(new Label("value", toJson(value)));
+ return fragment;
+ }
+
+ private static IModel<ValueInfo> newNullValueModel() {
+ return new AbstractReadOnlyModel<ValueInfo>() {
+
+ @Override
+ public ValueInfo getObject() {
+ return null;
+ }
+
+ };
+ }
+
+ private Fragment newArrayFragment() {
+ Fragment fragment = new Fragment("content", "arrayFrag", this);
+ fragment.add(new ListView<Object>("elements", new ArrayList<Object>(((Collection<?>)value))) {
+
+ @Override
+ protected void populateItem(ListItem<Object> item) {
+ IModel<ValueInfo> valueInfoModel;
+ if (getValueInfo() != null) {
+ valueInfoModel = new LoadableDetachableModel<ValueInfo>() {
+
+ @Override
+ protected ValueInfo load() {
+ Field field = getField();
+ Type declaredType = ReflectionUtils.getCollectionElementType(getDeclaredType());
+ return new ValueInfo(field, declaredType);
+ }
+
+ };
+ } else {
+ valueInfoModel = newNullValueModel();
+ }
+ item.add(new ExampleValuePanel("element", item.getModelObject(), valueInfoModel, requestBody));
+ item.add(new WebMarkupContainer("comma")
+ .setVisible(item.getIndex() < getModelObject().size()-1));
+ }
+
+ });
+ return fragment;
+ }
+
+ private Fragment newMapFragment() {
+ Fragment fragment = new Fragment("content", "objectFrag", this);
+
+ fragment.add(new WebMarkupContainer("typeInfo").setVisible(false));
+
+ IModel<List<Map.Entry<?, ?>>> entriesModel = new LoadableDetachableModel<List<Map.Entry<?, ?>>>() {
+
+ @Override
+ protected List<Map.Entry<?, ?>> load() {
+ return new ArrayList<Map.Entry<?, ?>>(((Map<?, ?>)value).entrySet());
+ }
+
+ };
+
+ fragment.add(new ListView<Map.Entry<?, ?>>("properties", entriesModel) {
+
+ @Override
+ protected void populateItem(ListItem<Map.Entry<?, ?>> item) {
+ IModel<ValueInfo> valueInfoModel;
+ if (getValueInfo() != null) {
+ valueInfoModel = new LoadableDetachableModel<ValueInfo>() {
+
+ @Override
+ protected ValueInfo load() {
+ Field field = getField();
+ Type declaredType = ReflectionUtils.getMapKeyType(getDeclaredType());
+ return new ValueInfo(field, declaredType);
+ }
+
+ };
+ } else {
+ valueInfoModel = newNullValueModel();
+ }
+ item.add(new ExampleValuePanel("name", item.getModelObject().getKey(), valueInfoModel, requestBody));
+
+ if (getValueInfo() != null) {
+ valueInfoModel = new LoadableDetachableModel<ValueInfo>() {
+
+ @Override
+ protected ValueInfo load() {
+ Field field = getField();
+ Type declaredType = ReflectionUtils.getMapValueType(getDeclaredType());
+ return new ValueInfo(field, declaredType);
+ }
+
+ };
+ } else {
+ valueInfoModel = newNullValueModel();
+ }
+ item.add(new ExampleValuePanel("value", item.getModelObject().getValue(), valueInfoModel, requestBody));
+ item.add(new WebMarkupContainer("comma")
+ .setVisible(item.getIndex() < getModelObject().size()-1));
+ }
+
+ });
+ return fragment;
+ }
+
+ private Fragment newObjectFragment() {
+ Fragment fragment = new Fragment("content", "objectFrag", this);
+
+ IModel<List<Field>> fieldsModel = new LoadableDetachableModel<List<Field>>() {
+
+ @Override
+ protected List<Field> load() {
+ return ApiHelpUtils.getJsonFields(value.getClass());
+ }
+
+ };
+
+ if (getDeclaredClass() != null
+ && Modifier.isAbstract(getDeclaredClass().getModifiers())
+ && !Collection.class.isAssignableFrom(getDeclaredClass())
+ && !Map.class.isAssignableFrom(getDeclaredClass())) {
+ Fragment typeInfoFragment = new Fragment("typeInfo", "typeInfoFrag", this);
+ typeInfoFragment.add(new ExampleValuePanel("name", JsonTypeInfo.Id.CLASS.getDefaultPropertyName(), requestBody));
+ typeInfoFragment.add(new ExampleValuePanel("value", value.getClass().getName(), requestBody));
+
+ typeInfoFragment.add(new MenuLink("implementations") {
+
+ @Override
+ protected List<MenuItem> getMenuItems(FloatingPanel dropdown) {
+ List<MenuItem> items = new ArrayList<>();
+ ImplementationRegistry registry = OneDev.getInstance(ImplementationRegistry.class);
+ for (Class<?> clazz: registry.getImplementations(getDeclaredClass())) {
+ items.add(new MenuItem() {
+
+ @Override
+ public String getLabel() {
+ return clazz.getName();
+ }
+
+ @Override
+ public WebMarkupContainer newLink(String id) {
+ return new AjaxLink<Void>(id) {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ Object newValue = ApiHelpUtils.getExampleValue(clazz);
+ Component newExampleValuePanel = new ExampleValuePanel(
+ ExampleValuePanel.this.getId(), newValue, valueInfoModel, requestBody);
+ ExampleValuePanel.this.replaceWith(newExampleValuePanel);
+ target.add(newExampleValuePanel);
+ }
+
+ };
+ }
+
+ });
+ }
+ return items;
+ }
+
+ });
+
+ typeInfoFragment.add(new WebMarkupContainer("comma")
+ .setVisible(!fieldsModel.getObject().isEmpty()));
+ fragment.add(typeInfoFragment);
+ } else {
+ fragment.add(new WebMarkupContainer("typeInfo").setVisible(false));
+ }
+
+ fragment.add(new ListView<Field>("properties", fieldsModel) {
+
+ @Override
+ protected void populateItem(ListItem<Field> item) {
+ Field field = item.getModelObject();
+ if (field.getAnnotation(ManyToOne.class) != null)
+ item.add(new ExampleValuePanel("name", field.getName() + "Id", requestBody));
+ else
+ item.add(new ExampleValuePanel("name", field.getName(), requestBody));
+
+ field.setAccessible(true);
+ try {
+ IModel<ValueInfo> valueInfoModel = new LoadableDetachableModel<ValueInfo>() {
+
+ @Override
+ protected ValueInfo load() {
+ Field field = item.getModelObject();
+ return new ValueInfo(field, field.getGenericType());
+ }
+
+ };
+ item.add(new ExampleValuePanel("value", field.get(value), valueInfoModel, requestBody));
+ } catch (IllegalArgumentException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ item.add(new WebMarkupContainer("comma")
+ .setVisible(item.getIndex() < getModelObject().size()-1));
+ }
+
+ });
+ return fragment;
+ }
+
+ @Nullable
+ private ValueInfo getValueInfo() {
+ return valueInfoModel.getObject();
+ }
+
+ @Nullable
+ private Field getField() {
+ return getValueInfo()!=null? getValueInfo().getField(): null;
+ }
+
+ @Nullable
+ private Type getDeclaredType() {
+ return getValueInfo()!=null? getValueInfo().getDeclaredType(): null;
+ }
+
+ @Nullable
+ private Class<?> getDeclaredClass() {
+ if (getDeclaredType() != null)
+ return ReflectionUtils.getClass(getDeclaredType());
+ else
+ return null;
+ }
+
+ private String toJson(Object value) {
+ try {
+ return OneDev.getInstance(ObjectMapper.class).writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static class ValueInfo {
+
+ private final Field field;
+
+ private final Type declaredType;
+
+ public ValueInfo(Field field, Type declaredType) {
+ this.field = field;
+ this.declaredType = declaredType;
+ }
+
+ public Field getField() {
+ return field;
+ }
+
+ public Type getDeclaredType() {
+ return declaredType;
+ }
+
+ }
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/MethodDetailPage.html b/server-core/src/main/java/io/onedev/server/web/page/help/MethodDetailPage.html
new file mode 100644
index 0000000000..56be4ee979
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/MethodDetailPage.html
@@ -0,0 +1,96 @@
+<wicket:extend>
+ <h5 wicket:id="title" class="mb-4"></h5>
+ <div class="method-detail">
+ <dl class="content">
+ <dt>Method</dt>
+ <dd wicket:id="method"></dd>
+ <dt>Path</dt>
+ <dd wicket:id="path"></dd>
+ <wicket:enclosure child="pathPlaceholders">
+ <dt>Path Placeholders</dt>
+ <dd>
+ <dl wicket:id="pathPlaceholders">
+ <dt wicket:id="name"></dt>
+ <dd>
+ <dl>
+ <dt>Description</dt>
+ <dd wicket:id="description"></dd>
+ <dt>Example</dt>
+ <dd wicket:id="example"></dd>
+ </dl>
+ </dd>
+ </dl>
+ </dd>
+ </wicket:enclosure>
+ <wicket:enclosure child="queryParams">
+ <dt>Query Parameters</dt>
+ <dd>
+ <dl wicket:id="queryParams">
+ <dt wicket:id="name"></dt>
+ <dd>
+ <dl>
+ <dt>Description</dt>
+ <dd wicket:id="description"></dd>
+ <dt>Required</dt>
+ <dd wicket:id="required"></dd>
+ <dt>Example</dt>
+ <dd wicket:id="example"></dd>
+ </dl>
+ </dd>
+ </dl>
+ </dd>
+ </wicket:enclosure>
+ <wicket:enclosure child="requestBodyExample">
+ <dt>Request Body</dt>
+ <dd>
+ <dl>
+ <dt>Content Type</dt>
+ <dd>application/json</dd>
+ <dt>Example</dt>
+ <dd wicket:id="requestBodyExample"></dd>
+ </dl>
+ </dd>
+ </wicket:enclosure>
+ <dt>Required Permission</dt>
+ <dd wicket:id="permission"></dd>
+ <dt>Response</dt>
+ <dd>
+ <dl>
+ <dt>Operation Successful</dt>
+ <dd>
+ <dl>
+ <dt>Status Code</dt>
+ <dd>200</dd>
+ <dt>Response Body</dt>
+ <dd wicket:id="successResponseBody"></dd>
+ </dl>
+ </dd>
+ <dt>Operation Failed</dt>
+ <dd>
+ <dl>
+ <dt>Status code</dt>
+ <dd>Status code other than 200 indicating the error type</dd>
+ <dt>Response Body</dt>
+ <dd>Error detail of content type &quot;text/plain&quot;</dd>
+ </dl>
+ </dd>
+ </dl>
+ </dd>
+ </dl>
+ </div>
+ <wicket:fragment wicket:id="topbarTitleFrag">
+ <a wicket:id="resources">Resources</a>
+ <span class="dot"></span>
+ <a wicket:id="resource"><span wicket:id="label"></span></a>
+ <span class="dot"></span>
+ <span wicket:id="method"></span>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="hasResponseBodyFrag">
+ <dl>
+ <dt>Content Type</dt>
+ <dd>application/json</dd>
+ <dt>Example</dt>
+ <dd wicket:id="example"></dd>
+ </dl>
+ </wicket:fragment>
+</wicket:extend>
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/MethodDetailPage.java b/server-core/src/main/java/io/onedev/server/web/page/help/MethodDetailPage.java
new file mode 100644
index 0000000000..7faca6c3b2
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/MethodDetailPage.java
@@ -0,0 +1,235 @@
+package io.onedev.server.web.page.help;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.util.ArrayList;
+import java.util.List;
+
+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.QueryParam;
+import javax.ws.rs.core.Response;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+import io.onedev.commons.utils.ExplicitException;
+import io.onedev.commons.utils.StringUtils;
+import io.onedev.commons.utils.WordUtils;
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.rest.jersey.ParamCheckFilter;
+import io.onedev.server.web.component.link.ViewStateAwarePageLink;
+import io.onedev.server.web.util.TextUtils;
+
+@SuppressWarnings("serial")
+public class MethodDetailPage extends ApiHelpPage {
+
+ private static final String PARAM_RESOURCE = "resource";
+
+ private static final String PARAM_METHOD = "method";
+
+ private final Class<?> resourceClass;
+
+ private final String methodName;
+
+ private final IModel<Method> methodModel = new LoadableDetachableModel<Method>() {
+
+ @Override
+ protected Method load() {
+ for (Method method: resourceClass.getMethods()) {
+ if (method.getName().equals(methodName))
+ return method;
+ }
+ String errorMessage = String.format("Unable to find resource method (resource: %s, method: %s)",
+ resourceClass.getName(), methodName);
+ throw new ExplicitException(errorMessage);
+ }
+
+ };
+
+ public MethodDetailPage(PageParameters params) {
+ super(params);
+
+ try {
+ resourceClass = Class.forName(params.get(PARAM_RESOURCE).toString());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+
+ methodName = params.get(PARAM_METHOD).toString();
+ }
+
+ @Override
+ protected void onDetach() {
+ methodModel.detach();
+ super.onDetach();
+ }
+
+ private Method getResourceMethod() {
+ return methodModel.getObject();
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ Method method = getResourceMethod();
+ add(new Label("title", getMethodDescription(method)));
+
+ if (method.getAnnotation(GET.class) != null)
+ add(new Label("method", "GET"));
+ else if (method.getAnnotation(POST.class) != null)
+ add(new Label("method", "POST"));
+ else if (method.getAnnotation(PUT.class) != null)
+ add(new Label("method", "PUT"));
+ else
+ add(new Label("method", "DELETE"));
+
+ String resourcePathValue = resourceClass.getAnnotation(Path.class).value();
+ Path methodPath = method.getAnnotation(Path.class);
+ if (methodPath != null)
+ add(new Label("path", "/api" + resourcePathValue + methodPath.value()));
+ else
+ add(new Label("path", "/api" + resourcePathValue));
+
+ add(new ListView<Parameter>("pathPlaceholders", new LoadableDetachableModel<List<Parameter>>() {
+
+ @Override
+ protected List<Parameter> load() {
+ List<Parameter> params = new ArrayList<>();
+ for (Parameter param: getResourceMethod().getParameters()) {
+ if (param.getAnnotation(PathParam.class) != null)
+ params.add(param);
+ }
+ return params;
+ }
+
+ }) {
+
+ @Override
+ protected void populateItem(ListItem<Parameter> item) {
+ Parameter param = item.getModelObject();
+ PathParam pathParam = param.getAnnotation(PathParam.class);
+ item.add(new Label("name", "{" + pathParam.value() + "}"));
+ Api api = param.getAnnotation(Api.class);
+ if (api != null && api.description().length() != 0)
+ item.add(new Label("description", api.description()));
+ else
+ item.add(new Label("description", StringUtils.capitalize(WordUtils.uncamel(pathParam.value()))));
+
+ Object exampleValue = new ExampleProvider(getResourceMethod().getDeclaringClass(), api).getExample();
+ if (exampleValue == null)
+ exampleValue = ApiHelpUtils.getExampleValue(param.getParameterizedType());
+ item.add(new ExampleValuePanel("example", exampleValue, false));
+ }
+
+ });
+
+ add(new ListView<Parameter>("queryParams", new LoadableDetachableModel<List<Parameter>>() {
+
+ @Override
+ protected List<Parameter> load() {
+ List<Parameter> params = new ArrayList<>();
+ for (Parameter param: getResourceMethod().getParameters()) {
+ if (param.getAnnotation(QueryParam.class) != null)
+ params.add(param);
+ }
+ return params;
+ }
+
+ }) {
+
+ @Override
+ protected void populateItem(ListItem<Parameter> item) {
+ Parameter param = item.getModelObject();
+ QueryParam queryParam = param.getAnnotation(QueryParam.class);
+ item.add(new Label("name", queryParam.value()));
+ Api api = param.getAnnotation(Api.class);
+ if (api != null && api.description().length() != 0)
+ item.add(new Label("description", api.description()));
+ else
+ item.add(new Label("description", StringUtils.capitalize(WordUtils.uncamel(queryParam.value()))));
+ item.add(new Label("required", TextUtils.describe(ParamCheckFilter.isRequired(param))));
+
+ Object exampleValue = new ExampleProvider(getResourceMethod().getDeclaringClass(), api).getExample();
+ if (exampleValue == null)
+ exampleValue = ApiHelpUtils.getExampleValue(param.getParameterizedType());
+ item.add(new ExampleValuePanel("example", exampleValue, false));
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(!getModelObject().isEmpty());
+ }
+
+ });
+
+ Parameter requestBodyParam = null;
+ for (Parameter param: method.getParameters()) {
+ if (param.getAnnotation(PathParam.class) == null && param.getAnnotation(QueryParam.class) == null) {
+ requestBodyParam = param;
+ break;
+ }
+ }
+
+ if (requestBodyParam != null) {
+ Object exampleValue = new ExampleProvider(resourceClass, requestBodyParam.getAnnotation(Api.class)).getExample();
+ if (exampleValue == null) {
+ exampleValue = ApiHelpUtils.getExampleValue(requestBodyParam.getParameterizedType());
+ }
+ add(new ExampleValuePanel("requestBodyExample", exampleValue, true));
+ } else {
+ add(new WebMarkupContainer("requestBodyExample").setVisible(false));
+ }
+
+ Api api = method.getAnnotation(Api.class);
+ if (api != null && api.permission().length() != 0)
+ add(new Label("permission", api.permission()));
+ else
+ add(new Label("permission", "Anyone can perform this operation"));
+
+ if (method.getReturnType() == Response.class) {
+ add(new Label("successResponseBody", "No response body if successful; error"));
+ } else {
+ Fragment fragment = new Fragment("successResponseBody", "hasResponseBodyFrag", MethodDetailPage.this);
+ Object exampleValue = new ExampleProvider(resourceClass, method.getAnnotation(Api.class)).getExample();
+ if (exampleValue == null)
+ exampleValue = ApiHelpUtils.getExampleValue(method.getGenericReturnType());
+ fragment.add(new ExampleValuePanel("example", exampleValue, false));
+ add(fragment);
+ }
+
+ }
+
+ @Override
+ protected Component newTopbarTitle(String componentId) {
+ Fragment fragment = new Fragment(componentId, "topbarTitleFrag", this);
+ fragment.add(new ViewStateAwarePageLink<Void>("resources", ResourceListPage.class));
+ Link<Void> resourceLink = new ViewStateAwarePageLink<Void>("resource", ResourceDetailPage.class,
+ ResourceDetailPage.paramsOf(resourceClass));
+ resourceLink.add(new Label("label", getResourceTitle(resourceClass)));
+ fragment.add(resourceLink);
+ fragment.add(new Label("method", getMethodTitle(getResourceMethod())));
+ return fragment;
+ }
+
+ public static PageParameters paramsOf(Class<?> resourceClass, String resourceMethod) {
+ PageParameters params = new PageParameters();
+ params.add(PARAM_RESOURCE, resourceClass.getName());
+ params.add(PARAM_METHOD, resourceMethod);
+ return params;
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ResourceDetailPage.html b/server-core/src/main/java/io/onedev/server/web/page/help/ResourceDetailPage.html
new file mode 100644
index 0000000000..3510493b69
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ResourceDetailPage.html
@@ -0,0 +1,13 @@
+<wicket:extend>
+ <h5 wicket:id="title" class="mb-4"></h5>
+ <table class="table resource-detail">
+ <tr wicket:id="methods" class="method">
+ <td>
+ <a wicket:id="link" class="title`"><span wicket:id="label"></span></a>
+ </td>
+ </tr>
+ </table>
+ <wicket:fragment wicket:id="topbarTitleFrag">
+ <a wicket:id="resources">Resources</a> <span class="dot"></span> <span wicket:id="resource"></span>
+ </wicket:fragment>
+</wicket:extend>
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ResourceDetailPage.java b/server-core/src/main/java/io/onedev/server/web/page/help/ResourceDetailPage.java
new file mode 100644
index 0000000000..3b33efaf34
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ResourceDetailPage.java
@@ -0,0 +1,95 @@
+package io.onedev.server.web.page.help;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+import edu.emory.mathcs.backport.java.util.Collections;
+import io.onedev.server.web.component.link.ViewStateAwarePageLink;
+
+@SuppressWarnings("serial")
+public class ResourceDetailPage extends ApiHelpPage {
+
+ private static final String PARAM_RESOURCE = "resource";
+
+ private final Class<?> resourceClass;
+
+ public ResourceDetailPage(PageParameters params) {
+ super(params);
+ try {
+ resourceClass = Class.forName(params.get(PARAM_RESOURCE).toString());
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new Label("title", getResourceDescription(resourceClass)));
+
+ add(new ListView<Method>("methods", new LoadableDetachableModel<List<Method>>() {
+
+ @Override
+ protected List<Method> load() {
+ List<Method> methods = new ArrayList<>();
+
+ for (Method method: resourceClass.getMethods()) {
+ if (method.getAnnotation(GET.class) != null
+ || method.getAnnotation(POST.class) != null
+ || method.getAnnotation(DELETE.class) != null
+ || method.getAnnotation(PUT.class) != null) {
+ methods.add(method);
+ }
+ }
+
+ Collections.sort(methods, new ApiComparator());
+ return methods;
+ }
+
+ }) {
+
+ @Override
+ protected void populateItem(ListItem<Method> item) {
+ Method method = item.getModelObject();
+
+ Link<Void> link = new ViewStateAwarePageLink<Void>("link", MethodDetailPage.class,
+ MethodDetailPage.paramsOf(resourceClass, method.getName()));
+ link.add(new Label("label", getMethodDescription(method)));
+
+ item.add(link);
+ }
+
+ });
+ }
+
+ @Override
+ protected Component newTopbarTitle(String componentId) {
+ Fragment fragment = new Fragment(componentId, "topbarTitleFrag", this);
+ fragment.add(new ViewStateAwarePageLink<Void>("resources", ResourceListPage.class));
+ fragment.add(new Label("resource", getResourceTitle(resourceClass)));
+ return fragment;
+ }
+
+ public static PageParameters paramsOf(Class<?> resourceClass) {
+ PageParameters params = new PageParameters();
+ params.add(PARAM_RESOURCE, resourceClass.getName());
+ return params;
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ResourceListPage.html b/server-core/src/main/java/io/onedev/server/web/page/help/ResourceListPage.html
new file mode 100644
index 0000000000..52ae7fce11
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ResourceListPage.html
@@ -0,0 +1,14 @@
+<wicket:extend>
+ <h5 class="mb-4">All RESTful Resources</h5>
+ <div class="alert alert-light-info">
+ In case anonymous access is disabled or anonymous user does not have enough permission for a resource operation,
+ you will need to authenticate by providing user name and password (or access token) via http basic auth header
+ </div>
+ <table class="table resources">
+ <tr wicket:id="resources" class="resource">
+ <td>
+ <a wicket:id="link" class="title"><span wicket:id="label"></span></a>
+ </td>
+ </tr>
+ </table>
+</wicket:extend>
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/ResourceListPage.java b/server-core/src/main/java/io/onedev/server/web/page/help/ResourceListPage.java
new file mode 100644
index 0000000000..98c5374f4b
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/ResourceListPage.java
@@ -0,0 +1,71 @@
+package io.onedev.server.web.page.help;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Path;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.glassfish.jersey.server.ResourceConfig;
+
+import edu.emory.mathcs.backport.java.util.Collections;
+import io.onedev.server.OneDev;
+import io.onedev.server.rest.annotation.Api;
+import io.onedev.server.web.component.link.ViewStateAwarePageLink;
+
+@SuppressWarnings("serial")
+public class ResourceListPage extends ApiHelpPage {
+
+ public ResourceListPage(PageParameters params) {
+ super(params);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new ListView<Class<?>>("resources", new LoadableDetachableModel<List<Class<?>>>() {
+
+ @Override
+ protected List<Class<?>> load() {
+ List<Class<?>> clazzes = new ArrayList<>();
+ ResourceConfig config = OneDev.getInstance(ResourceConfig.class);
+ for (Class<?> clazz: config.getClasses()) {
+ if (clazz.getAnnotation(Path.class) != null) {
+ Api api = clazz.getAnnotation(Api.class);
+ if (api == null || !api.exclude())
+ clazzes.add(clazz);
+ }
+ }
+ Collections.sort(clazzes, new ApiComparator());
+ return clazzes;
+ }
+
+ }) {
+
+ @Override
+ protected void populateItem(ListItem<Class<?>> item) {
+ Class<?> clazz = item.getModelObject();
+
+ Link<Void> link = new ViewStateAwarePageLink<Void>("link", ResourceDetailPage.class,
+ ResourceDetailPage.paramsOf(clazz));
+ link.add(new Label("label", getResourceDescription(clazz)));
+
+ item.add(link);
+ }
+
+ });
+ }
+
+ @Override
+ protected Component newTopbarTitle(String componentId) {
+ return new Label(componentId, "Resources");
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/help/api-help.css b/server-core/src/main/java/io/onedev/server/web/page/help/api-help.css
new file mode 100644
index 0000000000..53073e3f2f
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/web/page/help/api-help.css
@@ -0,0 +1,26 @@
+.api-help dd>dl {
+ margin-left: 2rem;
+}
+.api-help dt {
+ font-weight: 600;
+}
+.api-help dl {
+ margin-bottom: 0;
+}
+
+.example-value-scalar, .example-value-brace,
+.example-value-bracket, .example-value-comma {
+ font-family: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
+ font-size: 87.5%;
+}
+
+a.example-value-hint {
+ margin-left: 0.2rem;
+}
+a.example-value-implementations>.icon {
+ width: 12px;
+ height: 12px;
+}
+.floating>.content>.example-value-hint {
+ padding: 1rem;
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/layout/LayoutPage.html b/server-core/src/main/java/io/onedev/server/web/page/layout/LayoutPage.html
index 3cd94cba62..f243823e15 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/layout/LayoutPage.html
+++ b/server-core/src/main/java/io/onedev/server/web/page/layout/LayoutPage.html
@@ -23,6 +23,7 @@
<div class="dropdown-menu">
<a wicket:id="docLink" class="dropdown-item" target="_blank">Documentation</a>
<a href="https://code.onedev.io/projects/onedev-server/issues?query=%22State%22+is+%22Open%22" class="dropdown-item" target="_blank">Support &amp; Bug Report</a>
+ <a href="/help/api" class="dropdown-item" target="_blank">RESTful API</a>
</div>
</div>
</div>
diff --git a/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.html b/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.html
index b47194918b..795b443f3a 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.html
+++ b/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.html
@@ -1,2 +1,3 @@
<wicket:extend>
+ <a wicket:id="test">test</a>
</wicket:extend>
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.java b/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.java
index 066be5dd6a..c331d117bb 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.java
@@ -3,6 +3,7 @@ package io.onedev.server.web.page.test;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import io.onedev.server.web.page.base.BasePage;
@@ -17,6 +18,14 @@ public class TestPage extends BasePage {
@Override
protected void onInitialize() {
super.onInitialize();
+
+ add(new Link<Void>("test") {
+
+ @Override
+ public void onClick() {
+ }
+
+ });
}
@Override
diff --git a/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesResource.java b/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesResource.java
index 0a0c60a60e..3c450199c9 100644
--- a/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesResource.java
+++ b/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesResource.java
@@ -45,9 +45,11 @@ import io.onedev.k8shelper.ServerExecutionResult;
import io.onedev.server.buildspec.job.Job;
import io.onedev.server.buildspec.job.JobContext;
import io.onedev.server.buildspec.job.JobManager;
+import io.onedev.server.rest.annotation.Api;
import io.onedev.server.util.ExceptionUtils;
import io.onedev.server.util.SimpleLogger;
+@Api(exclude=true)
@Path("/k8s")
@Consumes(MediaType.WILDCARD)
@Singleton
diff --git a/server-product/src/test/java/io/onedev/server/product/Test.java b/server-product/src/test/java/io/onedev/server/product/Test.java
index e29e84b6bf..a96bf27a34 100644
--- a/server-product/src/test/java/io/onedev/server/product/Test.java
+++ b/server-product/src/test/java/io/onedev/server/product/Test.java
@@ -5,5 +5,5 @@ public class Test {
@org.junit.Test
public void test() {
}
-
+
}
\ No newline at end of file