You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2019/05/16 01:56:22 UTC
[servicecomb-java-chassis] branch weak-contract-type updated:
[SCB-1284][WIP][WEAK] operationId should not be empty
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch weak-contract-type
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/weak-contract-type by this push:
new 72dbb7e [SCB-1284][WIP][WEAK] operationId should not be empty
72dbb7e is described below
commit 72dbb7ecb2ad6c131e679873f97cd2b284ea9dab
Author: wujimin <wu...@huawei.com>
AuthorDate: Tue May 14 23:18:54 2019 +0800
[SCB-1284][WIP][WEAK] operationId should not be empty
---
.../generator/core/model/SwaggerOperations.java | 7 ++++
.../core/model/TestSwaggerOperations.java | 42 ++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/model/SwaggerOperations.java b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/model/SwaggerOperations.java
index 6717143..c182022 100644
--- a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/model/SwaggerOperations.java
+++ b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/model/SwaggerOperations.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.commons.lang3.StringUtils;
import org.apache.servicecomb.swagger.generator.SwaggerGenerator;
import io.swagger.models.HttpMethod;
@@ -48,6 +49,12 @@ public class SwaggerOperations {
for (Entry<String, Path> pathEntry : paths.entrySet()) {
for (Entry<HttpMethod, Operation> operationEntry : pathEntry.getValue().getOperationMap().entrySet()) {
Operation operation = operationEntry.getValue();
+ if (StringUtils.isEmpty(operation.getOperationId())) {
+ throw new IllegalStateException(String
+ .format("OperationId can not be empty, path=%s, httpMethod=%s.",
+ pathEntry.getKey(), operationEntry.getKey()));
+ }
+
SwaggerOperation swaggerOperation = new SwaggerOperation(swagger, pathEntry.getKey(), operationEntry.getKey(),
operation);
if (operations.putIfAbsent(operation.getOperationId(), swaggerOperation) != null) {
diff --git a/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/model/TestSwaggerOperations.java b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/model/TestSwaggerOperations.java
new file mode 100644
index 0000000..413af31
--- /dev/null
+++ b/swagger/swagger-generator/generator-core/src/test/java/org/apache/servicecomb/swagger/generator/core/model/TestSwaggerOperations.java
@@ -0,0 +1,42 @@
+/*
+ * 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.servicecomb.swagger.generator.core.model;
+
+import org.apache.servicecomb.swagger.SwaggerUtils;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import io.swagger.models.Swagger;
+
+public class TestSwaggerOperations {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void emptyOperationId() {
+ Swagger swagger = SwaggerUtils.parseSwagger(this.getClass().getResource("/schemas/boolean.yaml"));
+ swagger.getPaths().values().stream()
+ .findFirst().get()
+ .getPost().setOperationId("");
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("OperationId can not be empty, path=/testboolean, httpMethod=POST.");
+
+ new SwaggerOperations(swagger);
+ }
+}