[
https://issues.apache.org/jira/browse/SCB-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16521764#comment-16521764
]
ASF GitHub Bot commented on SCB-684:
------------------------------------
liubao68 closed pull request #773: [SCB-684]Following swagger conventions.
Adding and change some test cases.
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/773
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/TestMgr.java
b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/TestMgr.java
index 80c5bf0f57..f2218bcdab 100644
--- a/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/TestMgr.java
+++ b/demo/demo-schema/src/main/java/org/apache/servicecomb/demo/TestMgr.java
@@ -74,6 +74,10 @@ public static void failed(String desc, Throwable e) {
errorList.add(error);
}
+ public static boolean isSuccess() {
+ return errorList.isEmpty();
+ }
+
public static void summary() {
if (errorList.isEmpty()) {
LOGGER.info("............. test finished ............");
diff --git
a/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml
b/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml
index 8dc482433e..09a4d0e698 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml
@@ -18,6 +18,7 @@
APPLICATION_ID: springmvctest
service_description:
name: springmvcClient
+ environment: development
version: 0.0.1
servicecomb:
service:
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvcForSchema.java
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvcForSchema.java
new file mode 100644
index 0000000000..fd5ddcecf2
--- /dev/null
+++
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/CodeFirstSpringmvcForSchema.java
@@ -0,0 +1,67 @@
+/*
+ * 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.demo.springmvc.server;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RequestPart;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * Created for testing schema to accommodate swagger api specification. When
change this class, please use
+ * http://editor.swagger.io/ to validate the generated schema and should not
give any errors. In test case,
+ * only checksum is validated to make sure schema is not changed.
+ */
+@RestSchema(schemaId = "CodeFirstSpringmvcForSchema")
+@RequestMapping(path = "/forScheam")
+public class CodeFirstSpringmvcForSchema {
+ /*
+ * Using http://editor.swagger.io/ . Listing errors not handled:
+ *
+ * #1. Should NOT have additional properties additionalProperty: type,
format, name, in, required
+ /reduce:
+ get:
+ operationId: "reduce"
+ parameters:
+ - name: "b"
+ in: "cookie"
+ required: false
+ This schema gives error, but according to
https://swagger.io/docs/specification/describing-parameters/#cookie-parameters
+ This should supported.
+
+
+ * #2. Operations with Parameters of "in: formData" must include
"application/x-www-form-urlencoded" or "multipart/form-data" in their
"consumes" property
+ This error can be fixed by user code.
+
+
+ *
+ */
+
+
+ @RequestMapping(path = "/uploadFile", method = RequestMethod.POST,
+ consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces =
MediaType.APPLICATION_JSON_VALUE)
+ @ResponseBody
+ public boolean uploadAwardFile(@RequestParam("fileType") String fileType,
@RequestParam("zoneId") String zoneId,
+ @RequestPart("file") MultipartFile file) {
+ throw new UnsupportedOperationException("only for testing schema");
+ }
+}
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java
new file mode 100644
index 0000000000..687273b5bc
--- /dev/null
+++
b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerSchemaFactoryHolder.java
@@ -0,0 +1,83 @@
+/*
+ * 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.demo.springmvc.server;
+
+import org.apache.servicecomb.core.BootListener;
+import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.apache.servicecomb.core.definition.schema.ProducerSchemaFactory;
+import org.apache.servicecomb.demo.TestMgr;
+import org.apache.servicecomb.serviceregistry.RegistryUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.google.common.base.Charsets;
+import com.google.common.hash.Hashing;
+
+import io.swagger.models.Swagger;
+import io.swagger.util.Yaml;
+
+/**
+ * Testing schemas generation should be same for each boot up and accommodate
swagger.
+ */
+@Component
+public class ProducerSchemaFactoryHolder implements BootListener {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ProducerSchemaFactoryHolder.class);
+
+ private ObjectWriter writer = Yaml.pretty();
+
+ @Autowired
+ private ProducerSchemaFactory factory;
+
+ public void test() {
+ LOGGER.info("ProducerSchemaFactoryHolder testing start");
+ SchemaMeta meta =
+ factory.getOrCreateProducerSchema("customer-service",
+ "test1",
+ CodeFirstSpringmvcForSchema.class,
+ new CodeFirstSpringmvcForSchema());
+ String codeFirst = getSwaggerContent(meta.getSwagger());
+
TestMgr.check("07a48acef4cc1a7f2387d695923c49e98951a974e4f51cf1356d6878db48888f",
+ RegistryUtils.calcSchemaSummary(codeFirst));
+ TestMgr.check(codeFirst.length(), 899);
+
+ if (!TestMgr.isSuccess()) {
+ TestMgr.summary();
+ throw new IllegalStateException("schema not the same. ");
+ }
+ }
+
+ private String getSwaggerContent(Swagger swagger) {
+ try {
+ return writer.writeValueAsString(swagger);
+ } catch (JsonProcessingException e) {
+ throw new Error(e);
+ }
+ }
+
+ @Override
+ public void onBootEvent(BootEvent event) {
+ if (event.getEventType() == BootListener.EventType.AFTER_REGISTRY) {
+ test();
+ }
+ }
+}
+
diff --git
a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
index b9c96385e6..c2a2087f42 100644
--- a/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-server/src/main/resources/microservice.yaml
@@ -21,6 +21,7 @@ APPLICATION_ID: springmvctest
service_description:
name: springmvc
version: 0.0.3
+ environment: development
paths:
- path: /test1/testpath
property:
diff --git
a/integration-tests/springmvc-tests/springmvc-tests-common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/endpoints/CodeFirstSpringmvc.java
b/integration-tests/springmvc-tests/springmvc-tests-common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/endpoints/CodeFirstSpringmvc.java
index 7748ff6133..c235b79990 100644
---
a/integration-tests/springmvc-tests/springmvc-tests-common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/endpoints/CodeFirstSpringmvc.java
+++
b/integration-tests/springmvc-tests/springmvc-tests-common/src/test/java/org/apache/servicecomb/demo/springmvc/tests/endpoints/CodeFirstSpringmvc.java
@@ -56,7 +56,7 @@
public class CodeFirstSpringmvc extends CodeFirstSpringmvcBase {
@ResponseHeaders({@ResponseHeader(name = "h1", response = String.class),
@ResponseHeader(name = "h2", response = String.class)})
- @RequestMapping(path = "/responseEntity", method = RequestMethod.POST)
+ @RequestMapping(path = "/responseEntity", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@Override
public ResponseEntity<Date> responseEntity(InvocationContext c1,
@RequestAttribute("date") Date date) {
return super.responseEntity(c1, date);
@@ -89,14 +89,14 @@ public String textPlain(@RequestBody String body) {
return super.bytes(input);
}
- @RequestMapping(path = "/upload", method = RequestMethod.POST, produces =
MediaType.TEXT_PLAIN_VALUE)
+ @RequestMapping(path = "/upload", method = RequestMethod.POST, produces =
MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@Override
public String fileUpload(@RequestPart(name = "file1") MultipartFile file1,
@RequestPart(name = "someFile") MultipartFile file2,
@RequestAttribute("name") String name) {
return super.fileUpload(file1, file2, name);
}
- @RequestMapping(path = "/uploadWithoutAnnotation", method =
RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE)
+ @RequestMapping(path = "/uploadWithoutAnnotation", method =
RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE, consumes =
MediaType.MULTIPART_FORM_DATA_VALUE)
public String fileUploadWithoutAnnotation(MultipartFile file1, MultipartFile
file2,
@RequestAttribute("name") String name) {
return super.fileUpload(file1, file2, name);
@@ -114,7 +114,7 @@ public int add(@RequestParam("a") int a) {
return a;
}
- @RequestMapping(path = "/add", method = RequestMethod.POST)
+ @RequestMapping(path = "/add", method = RequestMethod.POST, consumes =
MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@Override
public int add(@RequestAttribute("a") int a, @RequestAttribute("b") int b) {
return super.add(a, b);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Following swagger conventions
> -----------------------------
>
> Key: SCB-684
> URL: https://issues.apache.org/jira/browse/SCB-684
> Project: Apache ServiceComb
> Issue Type: Improvement
> Components: Java-Chassis
> Reporter: liubao
> Assignee: liubao
> Priority: Major
> Fix For: Java-chassis-1.0.0
>
>
> Check with swagger validator, some warnings and errors are given:
>
>
> Errors Hide Semantic error at paths./add.post Operations with Parameters of
> "in: formData" must include "application/x-www-form-urlencoded" or
> "multipart/form-data" in their "consumes" property Jump to line 13 Semantic
> error at paths./add.post Operations with Parameters of "in: formData" must
> include "application/x-www-form-urlencoded" or "multipart/form-data" in their
> "consumes" property Jump to line 13 Schema error at
> paths['/reduce'].get.parameters[0] should NOT have additional properties
> additionalProperty: type, format, name, in, required Jump to line 36 Schema
> error at paths['/reduce'].get.parameters[0].required should be equal to one
> of the allowed values allowedValues: true Jump to line 36 Schema error at
> paths['/reduce'].get.paramete
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)