From 7b8518a9db108e096daac23614666c02da22be7d Mon Sep 17 00:00:00 2001 From: madhawap Date: Thu, 6 Oct 2016 11:59:20 +0530 Subject: [PATCH] changes to swagger SecurityDefinitionConfigurator and annotations --- .../device/mgt/jaxrs/beans/ActivityList.java | 8 ++++---- .../mgt/jaxrs/beans/BasePaginatedResult.java | 8 +++----- .../carbon/device/mgt/jaxrs/beans/RoleList.java | 3 ++- .../SecurityDefinitionConfigurator.java | 11 ++++++----- .../device/mgt/common/DeviceIdentifier.java | 12 ++++++++++-- .../mgt/common/operation/mgt/Activity.java | 12 ++++++++---- .../common/operation/mgt/ActivityStatus.java | 6 ++++-- .../common/operation/mgt/OperationResponse.java | 17 ++++++++++++++--- 8 files changed, 51 insertions(+), 26 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ActivityList.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ActivityList.java index deb4f513ad..08e6f268df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ActivityList.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ActivityList.java @@ -26,13 +26,14 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import java.util.ArrayList; import java.util.List; -@ApiModel(value = "List of activities", description = "This contains a set of activities that matches a given " + - "criteria as a collection") +@ApiModel(value = "List of activities", description = "This contains a set of activities that matches a given" + + " criteria as a collection") public class ActivityList extends BasePaginatedResult { private List activities; - @ApiModelProperty(value = "List of devices returned") + @ApiModelProperty(value = "Returns the list of activities that match the offset and limit parameter values" + + " that were specified.") @JsonProperty("activities") public List getList() { return activities; @@ -46,7 +47,6 @@ public class ActivityList extends BasePaginatedResult { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{\n"); - sb.append(" count: ").append(getCount()).append(",\n"); sb.append(" devices: [").append(activities).append("\n"); sb.append("]}\n"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java index b3a60032e1..422a3d3008 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java @@ -23,15 +23,13 @@ import io.swagger.annotations.ApiModelProperty; public class BasePaginatedResult { - private int count; - private String next; - private String previous; - /** * Number of Resources returned. */ - @ApiModelProperty(value = "Number of resources returned.") + @ApiModelProperty(value = "Number of total resources.", example = "2") @JsonProperty("count") + private int count; + public int getCount() { return count; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleList.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleList.java index 311c4e0634..bfd9afe99d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleList.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleList.java @@ -29,7 +29,8 @@ public class RoleList extends BasePaginatedResult { private List roles; - @ApiModelProperty(value = "List of roles returned") + @ApiModelProperty(value = "Returns the list of roles that match the offset and limit parameter values " + + "that were specified.") @JsonProperty("roles") public List getList() { return roles; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/swagger/extension/SecurityDefinitionConfigurator.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/swagger/extension/SecurityDefinitionConfigurator.java index 45cadd4738..32503d4c3a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/swagger/extension/SecurityDefinitionConfigurator.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/swagger/extension/SecurityDefinitionConfigurator.java @@ -29,12 +29,12 @@ import java.util.HashMap; import java.util.Map; @SwaggerDefinition( - basePath = "/api-device-mgt-v1.0", + basePath = "/api/device-mgt/v1.0", host = "localhost:9443" ) public class SecurityDefinitionConfigurator implements ReaderListener { - public static final String TOKEN_AUTH_SCHEME = "tokenAuthScheme"; + public static final String TOKEN_AUTH_SCHEME = "swagger_auth"; @Override public void beforeScan(Reader reader, Swagger swagger) { @@ -45,9 +45,10 @@ public class SecurityDefinitionConfigurator implements ReaderListener { public void afterScan(Reader reader, Swagger swagger) { OAuth2Definition tokenScheme = new OAuth2Definition(); tokenScheme.setType("oauth2"); - tokenScheme.setFlow("password"); - tokenScheme.setTokenUrl("https://" + swagger.getHost() + "/oauth/token"); - tokenScheme.setAuthorizationUrl("https://" + swagger.getHost() + "/oauth/authorize"); + tokenScheme.setFlow("application"); + tokenScheme.setTokenUrl("https://" + swagger.getHost() + "/oauth2/token"); + tokenScheme.setAuthorizationUrl("https://" + swagger.getHost() + "/oauth2/authorize"); + tokenScheme.addScope("write:everything", "Full access"); Map schemes = new HashMap<>(); schemes.put(TOKEN_AUTH_SCHEME, tokenScheme); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index 3a7f39b6e6..5b0e234218 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -28,12 +28,20 @@ import java.io.Serializable; "uniquely.") public class DeviceIdentifier implements Serializable{ + @ApiModelProperty( + name = "id", + value = "Identity of the device.", + required = true, + example = "123456") @JsonProperty(value = "id", required = true) - @ApiModelProperty(name = "id", value = "Identity of the device.", required = true) private String id; + @ApiModelProperty( + name = "type", + value = "Type of the device.", + required = true, + example = "android") @JsonProperty(value = "type", required = true) - @ApiModelProperty(name = "type", value = "Type of the device.", required = true) private String type; public DeviceIdentifier() {} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Activity.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Activity.java index d5febd6217..e7d01bd5c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Activity.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Activity.java @@ -36,14 +36,16 @@ public class Activity { @ApiModelProperty( name = "activityId", value = "Activity identifier", - required = true) + required = true, + example = "ACTIVITY_1") @JsonProperty("activityId") private String activityId; @ApiModelProperty( name = "code", value = "Activity code", - required = true) + required = true, + example = "DEVICE_RING") @JsonProperty("code") private String code; @@ -51,14 +53,16 @@ public class Activity { name = "type", value = "Activity type", required = true, - allowableValues = "CONFIG, MESSAGE, INFO, COMMAND, PROFILE, POLICY") + allowableValues = "CONFIG, MESSAGE, INFO, COMMAND, PROFILE, POLICY", + example = "COMMAND") @JsonProperty("type") private Type type; @ApiModelProperty( name = "createdTimeStamp", value = "Timestamp recorded when the activity took place", - required = true) + required = true, + example = "Thu Oct 06 11:18:47 IST 2016") @JsonProperty("createdTimestamp") private String createdTimeStamp; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/ActivityStatus.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/ActivityStatus.java index 28aeb08a76..1007c18058 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/ActivityStatus.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/ActivityStatus.java @@ -43,7 +43,8 @@ public class ActivityStatus { @ApiModelProperty( name = "status", value = "Status of the activity performed.", - required = true) + required = true, + example = "PENDING") @JsonProperty("status") private Status status; @@ -57,7 +58,8 @@ public class ActivityStatus { @ApiModelProperty( name = "updatedTimestamp ", value = "Last updated time of the activity.", - required = true) + required = true, + example = "Thu Oct 06 11:18:47 IST 2016") @JsonProperty("updatedTimestamp") private String updatedTimestamp; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java index 5b3e99104f..1d4ed19588 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.common.operation.mgt; +import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -26,10 +27,20 @@ import io.swagger.annotations.ApiModelProperty; + " responses") public class OperationResponse { - @ApiModelProperty(name = "response", value = "Operation response returned from the device", required = true) + @ApiModelProperty( + name = "response", + value = "Operation response returned from the device", + required = true, + example = "SUCCESSFUL") + @JsonProperty("response") private String response; - @ApiModelProperty(name = "receivedTimeStamp", value = "Time that the operation response received", - required = true) + + @ApiModelProperty( + name = "receivedTimeStamp", + value = "Time that the operation response received", + required = true, + example = "Thu Oct 06 11:18:47 IST 2016") + @JsonProperty("receivedTimeStamp") private String receivedTimeStamp; public String getResponse() {