You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by se...@apache.org on 2021/09/18 22:24:34 UTC

[openmeetings] branch feature/OPENMEETINGS-2667-update-schema-definition-for-response-wrapping-in-root-element updated: OPENMEETINGS-2667 Fix schema with root element and example values for responses.

This is an automated email from the ASF dual-hosted git repository.

sebawagner pushed a commit to branch feature/OPENMEETINGS-2667-update-schema-definition-for-response-wrapping-in-root-element
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/feature/OPENMEETINGS-2667-update-schema-definition-for-response-wrapping-in-root-element by this push:
     new 1876650  OPENMEETINGS-2667 Fix schema with root element and example values for responses.
1876650 is described below

commit 18766503ef073e80f29cb051c8683148b276f44e
Author: Sebastian Wagner <se...@gmail.com>
AuthorDate: Sun Sep 19 10:24:22 2021 +1200

    OPENMEETINGS-2667 Fix schema with root element and example values for responses.
---
 .../openmeetings/webservice/UserWebService.java    |  14 ++-
 .../webservice/schema/ServiceResultWrapper.java    |  16 +--
 .../webservice/schema/UserDTOListWrapper.java      | 111 +++++++++++++++++++++
 .../webservice/schema/UserDTOWrapper.java          |  68 +++++++++++++
 4 files changed, 198 insertions(+), 11 deletions(-)

diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java
index 8c4f975..24bb2f3 100644
--- a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/UserWebService.java
@@ -29,7 +29,6 @@ import static org.apache.openmeetings.webservice.Constants.USER_SERVICE_PORT_NAM
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.responses.ApiResponse;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
 import io.swagger.v3.oas.annotations.media.Content;
 import io.swagger.v3.oas.annotations.media.Schema;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -71,6 +70,8 @@ import org.apache.openmeetings.util.OmException;
 import org.apache.openmeetings.webservice.error.InternalServiceException;
 import org.apache.openmeetings.webservice.error.ServiceException;
 import org.apache.openmeetings.webservice.schema.ServiceResultWrapper;
+import org.apache.openmeetings.webservice.schema.UserDTOListWrapper;
+import org.apache.openmeetings.webservice.schema.UserDTOWrapper;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.validation.IValidationError;
 import org.apache.wicket.validation.IValidator;
@@ -160,7 +161,8 @@ public class UserWebService extends BaseWebService {
 	@Operation(
 			description = "Lists all users in the system!",
 			responses = {
-					@ApiResponse(responseCode = "200", description = "list of users", content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserDTO.class)))),
+					@ApiResponse(responseCode = "200", description = "list of users",
+							content = @Content(schema = @Schema(implementation = UserDTOListWrapper.class))),
 					@ApiResponse(responseCode = "500", description = "Error in case of invalid credentials or server error")
 			}
 		)
@@ -192,7 +194,7 @@ public class UserWebService extends BaseWebService {
 					+ " Account To do SSO see the methods to create a hash and use those ones!",
 			responses = {
 					@ApiResponse(responseCode = "200", description = "list of users",
-						content = @Content(array = @ArraySchema(schema = @Schema(implementation = UserDTO.class)))),
+						content = @Content(schema = @Schema(implementation = UserDTOWrapper.class))),
 					@ApiResponse(responseCode = "500", description = "Error in case of invalid credentials or server error")
 			}
 		)
@@ -318,7 +320,8 @@ public class UserWebService extends BaseWebService {
 	@Operation(
 			description = "Delete a certain user by its external user id",
 			responses = {
-					@ApiResponse(responseCode = "200", description = "id of user deleted, or error code", content = @Content(schema = @Schema(implementation = ServiceResultWrapper.class))),
+					@ApiResponse(responseCode = "200", description = "id of user deleted, or error code",
+							content = @Content(schema = @Schema(implementation = ServiceResultWrapper.class))),
 					@ApiResponse(responseCode = "500", description = "Error in case of invalid credentials or server error")
 			}
 		)
@@ -361,7 +364,8 @@ public class UserWebService extends BaseWebService {
 					+ " Session-Object you can use the SID + a RoomId to enter any Room. ...\n"
 					+ " Session-Hashs are deleted 15 minutes after the creation if not used.",
 			responses = {
-					@ApiResponse(responseCode = "200", description = "secure hash or error code", content = @Content(schema = @Schema(implementation = ServiceResultWrapper.class))),
+					@ApiResponse(responseCode = "200", description = "secure hash or error code",
+							content = @Content(schema = @Schema(implementation = ServiceResultWrapper.class))),
 					@ApiResponse(responseCode = "500", description = "Error in case of invalid credentials or server error")
 			}
 		)
diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/ServiceResultWrapper.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/ServiceResultWrapper.java
index 1433f22..4390e31 100644
--- a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/ServiceResultWrapper.java
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/ServiceResultWrapper.java
@@ -20,19 +20,23 @@ package org.apache.openmeetings.webservice.schema;
 
 import org.apache.openmeetings.db.dto.basic.ServiceResult;
 
+import io.swagger.v3.oas.annotations.media.Schema;
+
 /**
  *
  * @author Sebastian.wagner
  *
- * This is required for generating the right schema documentation.
- *
- * Because of the way how CXF-RS generates root elements into the response it is required to
- * generate a wrapper element to match the schema of the actual response.
+ * Provide the correct schema response including the wrapping root element + add example response.
  *
- * A better way would be to drop the root element in CXF, but that would be a breaking change
- * to existing clients. See https://issues.apache.org/jira/browse/OPENMEETINGS-2667
+ * See https://issues.apache.org/jira/browse/OPENMEETINGS-2667
  *
  */
+@Schema(example = "{\n"
+		+ "    \"serviceResult\": {\n"
+		+ "        \"message\": \"9dbb6907-61fc-42c0-a2b2-5dbfbe053ac6\",\n"
+		+ "        \"type\": \"SUCCESS\"\n"
+		+ "    }\n"
+		+ "}")
 public class ServiceResultWrapper {
 	private ServiceResult serviceResult;
 
diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/UserDTOListWrapper.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/UserDTOListWrapper.java
new file mode 100644
index 0000000..9c2a055
--- /dev/null
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/UserDTOListWrapper.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.webservice.schema;
+
+import java.util.List;
+
+import org.apache.openmeetings.db.dto.user.UserDTO;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+
+/**
+ *
+ * @author Sebastian.wagner
+ *
+ * Provide the correct schema response including the wrapping root element + add example response.
+ *
+ * See https://issues.apache.org/jira/browse/OPENMEETINGS-2667
+ *
+ */
+@Schema(example = "{\n"
+		+ "    \"userDTO\": [\n"
+		+ "        {\n"
+		+ "            \"address\": {\n"
+		+ "                \"created\": 1630191589000,\n"
+		+ "                \"deleted\": false,\n"
+		+ "                \"country\": \"NZ\",\n"
+		+ "                \"mail\": \"seba.wagner@gmail.com\"\n"
+		+ "            },\n"
+		+ "            \"firstname\": \"firstname\",\n"
+		+ "            \"id\": 1,\n"
+		+ "            \"languageId\": 1,\n"
+		+ "            \"lastname\": \"lastname\",\n"
+		+ "            \"login\": \"admin\",\n"
+		+ "            \"rights\": [\n"
+		+ "                \"ROOM\",\n"
+		+ "                \"SOAP\",\n"
+		+ "                \"DASHBOARD\",\n"
+		+ "                \"ADMIN\",\n"
+		+ "                \"LOGIN\"\n"
+		+ "            ],\n"
+		+ "            \"timeZoneId\": \"Europe/Berlin\",\n"
+		+ "            \"type\": \"USER\"\n"
+		+ "        },\n"
+		+ "        {\n"
+		+ "            \"address\": {\n"
+		+ "                \"created\": 1631324533000,\n"
+		+ "                \"deleted\": false,\n"
+		+ "                \"country\": \"NZ\",\n"
+		+ "                \"mail\": \"john.doe@gmail.com\"\n"
+		+ "            },\n"
+		+ "            \"externalId\": \"uniqueId1\",\n"
+		+ "            \"externalType\": \"myCMS\",\n"
+		+ "            \"firstname\": \"John\",\n"
+		+ "            \"id\": 2,\n"
+		+ "            \"languageId\": 1,\n"
+		+ "            \"lastname\": \"Doe\",\n"
+		+ "            \"login\": \"john.doe\",\n"
+		+ "            \"pictureUri\": \"\",\n"
+		+ "            \"rights\": \"ROOM\",\n"
+		+ "            \"timeZoneId\": \"Europe/Berlin\",\n"
+		+ "            \"type\": \"EXTERNAL\"\n"
+		+ "        },\n"
+		+ "        {\n"
+		+ "            \"address\": {\n"
+		+ "                \"created\": 1631958373000,\n"
+		+ "                \"deleted\": false,\n"
+		+ "                \"country\": \"NZ\",\n"
+		+ "                \"mail\": \"test@test.com\"\n"
+		+ "            },\n"
+		+ "            \"id\": 3,\n"
+		+ "            \"languageId\": 1,\n"
+		+ "            \"login\": \"soapuser\",\n"
+		+ "            \"rights\": [\n"
+		+ "                \"ROOM\",\n"
+		+ "                \"SOAP\",\n"
+		+ "                \"DASHBOARD\",\n"
+		+ "                \"ADMIN\",\n"
+		+ "                \"LOGIN\"\n"
+		+ "            ],\n"
+		+ "            \"timeZoneId\": \"Europe/Berlin\",\n"
+		+ "            \"type\": \"USER\"\n"
+		+ "        }\n"
+		+ "    ]\n"
+		+ "}")
+public class UserDTOListWrapper {
+	private List<UserDTO> userDTO;
+
+	public List<UserDTO> getUserDTO() {
+		return userDTO;
+	}
+
+	public void setUserDTO(List<UserDTO> userDTO) {
+		this.userDTO = userDTO;
+	}
+}
diff --git a/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/UserDTOWrapper.java b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/UserDTOWrapper.java
new file mode 100644
index 0000000..d8e8f19
--- /dev/null
+++ b/openmeetings-webservice/src/main/java/org/apache/openmeetings/webservice/schema/UserDTOWrapper.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.webservice.schema;
+
+import org.apache.openmeetings.db.dto.user.UserDTO;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+
+/**
+ *
+ * @author Sebastian.wagner
+ *
+ * Provide the correct schema response including the wrapping root element + add example response.
+ *
+ * See https://issues.apache.org/jira/browse/OPENMEETINGS-2667
+ *
+ */
+@Schema(example = "{\n"
+		+ "  \"userDTO\": {\n"
+		+ "    \"address\": {\n"
+		+ "      \"created\": 1630191589000,\n"
+		+ "      \"deleted\": false,\n"
+		+ "      \"country\": \"NZ\",\n"
+		+ "      \"mail\": \"seba.wagner@gmail.com\"\n"
+		+ "    },\n"
+		+ "    \"firstname\": \"firstname\",\n"
+		+ "    \"id\": 1,\n"
+		+ "    \"languageId\": 1,\n"
+		+ "    \"lastname\": \"lastname\",\n"
+		+ "    \"login\": \"admin\",\n"
+		+ "    \"rights\": [\n"
+		+ "      \"ROOM\",\n"
+		+ "      \"SOAP\",\n"
+		+ "      \"DASHBOARD\",\n"
+		+ "      \"ADMIN\",\n"
+		+ "      \"LOGIN\"\n"
+		+ "    ],\n"
+		+ "    \"timeZoneId\": \"Europe/Berlin\",\n"
+		+ "    \"type\": \"USER\"\n"
+		+ "  }\n"
+		+ "}")
+public class UserDTOWrapper {
+	private UserDTO userDTO;
+
+	public UserDTO getUserDTO() {
+		return userDTO;
+	}
+
+	public void setUserDTO(UserDTO userDTO) {
+		this.userDTO = userDTO;
+	}
+}