From 707da02c7e3e822532eca04d4de56b57909fe97d Mon Sep 17 00:00:00 2001 From: Madhawa Date: Thu, 12 May 2016 21:58:23 +0530 Subject: [PATCH 1/4] Adding swagger annotations to beans --- .../pom.xml | 6 +++++ .../mgt/core/dto/CertificateResponse.java | 23 +++++++++++++++++++ .../device/mgt/jaxrs/api/Certificate.java | 3 +-- .../device/mgt/jaxrs/api/Configuration.java | 10 ++++---- .../org.wso2.carbon.device.mgt.core/pom.xml | 6 +++++ .../device/mgt/core/dto/DeviceType.java | 7 ++++++ 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index dd66b2ab02..41cd547d10 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -166,6 +166,12 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + + + io.swagger + swagger-annotations + provided + diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dto/CertificateResponse.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dto/CertificateResponse.java index 5ffb8270f3..9d0504e2dc 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dto/CertificateResponse.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dto/CertificateResponse.java @@ -18,19 +18,42 @@ package org.wso2.carbon.certificate.mgt.core.dto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.math.BigInteger; +@ApiModel(value = "CertificateResponse", description = "This class carries all information related to certificates") public class CertificateResponse { + @ApiModelProperty(name = "certificate", value = "The certificate in bytes", required = true) byte[] certificate; + + @ApiModelProperty(name = "serialNumber", value = "It is the unique ID that is used to identify a certificate", required = true) String serialNumber; + + @ApiModelProperty(name = "tenantId", value = "The ID of the tenant who adds the certificate", required = true) int tenantId; + + @ApiModelProperty(name = "commonName", value = "In mutual SSL the common name refers to the serial number of the Android device.", required = true) String commonName; + + @ApiModelProperty(name = "notAfter", value = "The expiration date of the certificate that is inherent to the certificate", required = true) long notAfter; + + @ApiModelProperty(name = "notBefore", value = "The date from when the certificate is valid", required = true) long notBefore; + + @ApiModelProperty(name = "certificateserial", value = "The serial number of the certificate", required = true) BigInteger certificateserial; + + @ApiModelProperty(name = "issuer", value = "The identity of the authority that signs the SSL certificate", required = true) String issuer; + + @ApiModelProperty(name = "subject", value = "The identity of the certificate", required = true) String subject; + + @ApiModelProperty(name = "certificateVersion", value = "The version of the certificate", required = true) int certificateVersion; public long getNotAfter() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java index 8bfcd31f66..96c865f07f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java @@ -56,8 +56,7 @@ public interface Certificate { produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "POST", value = "Adding an SSL Certificate", - notes = "Add a new SSL certificate to the client end database", - response = MediaType.class) + notes = "Add a new SSL certificate to the client end database") @ApiResponses(value = { @ApiResponse(code = 200, message = "Added successfully"), @ApiResponse(code = 500, message = "Error occurred while saving the certificate") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java index c7bc7759cf..12e21f451b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java @@ -46,10 +46,9 @@ public interface Configuration { produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "POST", value = "Configuring general platform settings", - notes = "Configure the general platform settings using this REST API", - response = ResponsePayload.class) + notes = "Configure the general platform settings using this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "Tenant configuration saved successfully"), + @ApiResponse(code = 201, message = "Tenant configuration saved successfully"), @ApiResponse(code = 500, message = "Error occurred while saving the tenant configuration") }) Response saveTenantConfiguration(@ApiParam(name = "configuration", value = "The required properties to " @@ -76,10 +75,9 @@ public interface Configuration { produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "PUT", value = "Updating General Platform Configurations", - notes = "Update the notification frequency using this REST API", - response = ResponsePayload.class) + notes = "Update the notification frequency using this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "Tenant configuration updated successfully"), + @ApiResponse(code = 201, message = "Tenant configuration updated successfully"), @ApiResponse(code = 500, message = "Error occurred while updating the tenant configuration") }) Response updateConfiguration(@ApiParam(name = "configuration", value = "The required properties to update" diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index bb73550ff6..183d211f8e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -245,6 +245,12 @@ 1.7.1 + + io.swagger + swagger-annotations + provided + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java index 52ca3ac891..eb363fff1c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java @@ -18,12 +18,19 @@ package org.wso2.carbon.device.mgt.core.dto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; +@ApiModel(value = "DeviceType", description = "This class carries all information related device types") public class DeviceType implements Serializable { private static final long serialVersionUID = 7927802716452548282L; + + @ApiModelProperty(name = "id", value = "Device type id", required = true) private int id; + @ApiModelProperty(name = "name", value = "Device type name", required = true) private String name; public DeviceType() { From fffc7f3205890e07c4e3a08517d6c791a8105635 Mon Sep 17 00:00:00 2001 From: Madhawa Date: Thu, 12 May 2016 22:12:23 +0530 Subject: [PATCH 2/4] Adding swagger annotations to beans --- .../certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml | 1 + components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index 41cd547d10..cf72d3d1a2 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -83,6 +83,7 @@ javax.xml.bind, org.wso2.carbon.utils.*, org.wso2.carbon.device.mgt.common.*, + io.swagger.annotations.*, org.wso2.carbon.device.mgt.core.*, org.bouncycastle.pkcs.jcajce diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 183d211f8e..3e6c845eb9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -83,6 +83,7 @@ org.apache.catalina.core, org.apache.commons.collections, org.wso2.carbon.email.sender.*, + io.swagger.annotations.*, org.wso2.carbon, org.wso2.carbon.base From 85f485df4cc5e0120a66705297bb2015c09110fe Mon Sep 17 00:00:00 2001 From: Madhawa Date: Thu, 12 May 2016 22:19:17 +0530 Subject: [PATCH 3/4] Few changes to interfaces with swagger annotations --- .../device/mgt/jaxrs/api/DeviceNotification.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java index f17e584051..e01110ff77 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java @@ -89,10 +89,9 @@ public interface DeviceNotification { httpMethod = "PUT", value = "Updating the Device Notification Status", notes = "When a user has read the the device notification the device notification status must " - + "change from NEW to CHECKED. Update the device notification status using this REST API", - response = ResponsePayload.class) + + "change from NEW to CHECKED. Update the device notification status using this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "Notification status updated successfully"), + @ApiResponse(code = 201, message = "Notification status updated successfully"), @ApiResponse(code = 500, message = "Error occurred while updating notification status") }) Response updateNotificationStatus( @ApiParam(name = "id", value = "Provide the ID of the notification" @@ -107,10 +106,9 @@ public interface DeviceNotification { produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "POST", value = "Sending a Device Notification", - notes = "Notify users on device operation failures and other information using this REST API", - response = ResponsePayload.class) + notes = "Notify users on device operation failures and other information using this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "NNotification has added successfully"), + @ApiResponse(code = 201, message = "NNotification has added successfully"), @ApiResponse(code = 500, message = "Error occurred while updating notification status") }) Response addNotification(Notification notification); From 07c5362104cbd418faa9a201fe6b2c48452c3aa2 Mon Sep 17 00:00:00 2001 From: Madhawa Date: Thu, 12 May 2016 23:11:23 +0530 Subject: [PATCH 4/4] Adding swagger annotations to beans and some modifications to api interfaces --- .../carbon/device/mgt/jaxrs/api/Certificate.java | 2 +- .../wso2/carbon/device/mgt/jaxrs/api/Policy.java | 6 ++++-- .../wso2/carbon/device/mgt/jaxrs/api/User.java | 16 +++++++--------- .../device/mgt/common/PaginationResult.java | 12 ++++++++++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java index 96c865f07f..962603e262 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java @@ -36,7 +36,7 @@ import javax.ws.rs.core.Response; /** * All the certificate related tasks such as saving certificates, can be done through this endpoint. */ -@Api(value = "Certificate", description = "certificate related tasks such as saving certificates") +@Api(value = "Certificate", description = "Certificate related tasks such as saving certificates") @SuppressWarnings("NonJaxWsWebServices") @Produces({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java index e266e8ee94..59ecc88a83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java @@ -97,7 +97,8 @@ public interface Policy { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Details of a Policy.", - notes = "Retrieve the details of a selected policy in WSO2 EMM.") + notes = "Retrieve the details of a selected policy in WSO2 EMM.", + response = org.wso2.carbon.policy.mgt.common.Policy.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Fetched policy details."), @ApiResponse(code = 500, message = "Policy Management related error occurred when " + "fetching the policies.") }) @@ -254,7 +255,8 @@ public interface Policy { value = "Getting Policy Enforced Details of a Device.", notes = "When a device registers with WSO2 EMM a policy is enforced on the device. Initially the EMM " + "filters the policies based on the Platform (device type), filters based on the device ownership" + - " type , filters based on the user role or name and finally the policy is enforced on the device.") + " type , filters based on the user role or name and finally the policy is enforced on the device.", + response = org.wso2.carbon.policy.mgt.common.Policy.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Fetched current policy."), @ApiResponse(code = 500, message = "Error occurred while getting the current policy.") }) Response getDeviceActivePolicy(@ApiParam(name = "type", value = "Define the device type as the value for {type}." + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java index 6c5e45b7b9..d531fa25be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java @@ -112,8 +112,7 @@ public interface User { value = "Deleting a User", notes = "In a situation where an employee leaves the organization you will need to remove the" + " user details from WSO2 EMM. In such situations you can use this REST API " - + "to remove a user", - response = ResponsePayload.class) + + "to remove a user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User by username: 'username' was successfully removed"), @ApiResponse(code = 400, message = "User by username: 'username' does not exist for removal"), @@ -150,7 +149,8 @@ public interface User { value = "Getting Details of Users", notes = "If you wish to get the details of all the user registered with WSO2 EMM, you can do so " + "using the REST API", - response = ResponsePayload.class) + response = UserWrapper.class, + responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 201, message = "All users were successfully retrieved"), @ApiResponse(code = 500, message = "Error occurred while retrieving the list of users") @@ -275,10 +275,9 @@ public interface User { produces = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Changing the User Password", - notes = "A user is able to change the password to secure their EMM profile via this REST API", - response = UserCredentialWrapper.class) + notes = "A user is able to change the password to secure their EMM profile via this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "UserImpl password by username: 'Username' was " + @ApiResponse(code = 201, message = "UserImpl password by username: 'Username' was " + "successfully changed"), @ApiResponse(code = 400, message = "Old password does not match"), @ApiResponse(code = 400, message = "Could not change the password of the user: 'Username'. The" @@ -301,10 +300,9 @@ public interface User { notes = "In a situation where you need to block a user from accessing their EMM profile, " + "the EMM administrator is able to reset the password. This will change the user's " + "password and the user will not be able to able to login to the account as he/she is " - + "not aware of the new password.", - response = UserCredentialWrapper.class) + + "not aware of the new password.") @ApiResponses(value = { - @ApiResponse(code = 200, message = "UserImpl password by username: 'Username' was " + @ApiResponse(code = 201, message = "UserImpl password by username: 'Username' was " + "successfully changed"), @ApiResponse(code = 400, message = "Old password does not match"), @ApiResponse(code = 400, message = "Could not change the password of the user: 'Username'. The" diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationResult.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationResult.java index 0125b0fd90..433553b2da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationResult.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationResult.java @@ -18,18 +18,30 @@ package org.wso2.carbon.device.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; import java.util.List; /** * This class holds necessary data to represent a paginated result. */ +@ApiModel(value = "PaginationResult", description = "This class carries all information related Pagination Result") public class PaginationResult implements Serializable { private static final long serialVersionUID = 1998101711L; + + @ApiModelProperty(name = "recordsTotal", value = "The total number of records that are given before filtering", required = true) private int recordsTotal; + + @ApiModelProperty(name = "recordsFiltered", value = "The total number of records that are given after filtering", required = true) private int recordsFiltered; + + @ApiModelProperty(name = "draw", value = "The draw counter that this object is a response to, from the draw parameter sent as part of the data request", required = true) private int draw; + + @ApiModelProperty(name = "data", value = "The details of the SSL certificate", required = true) private List data; public int getRecordsTotal() {