This is an automated email from the ASF dual-hosted git repository. liubao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit c6eeb90ff403df19a4c61ad8eb2c7668b7e8c00b Author: liubao <[email protected]> AuthorDate: Tue Aug 22 22:21:53 2023 +0800 [SCB-2803]fix checkstyle and test fails --- ci/checkstyle/checkstyle.xml | 4 + .../schema/TestSchemaToProtoGenerator.java | 14 ++-- .../rest/RestProducerInvocationCreatorTest.java | 2 - pom.xml | 2 +- .../apache/servicecomb/swagger/SwaggerUtils.java | 4 +- .../swagger/generator/springmvc/Echo.java | 11 ++- .../springmvc/MethodMixupAnnotations.java | 24 +++--- .../springmvc/model/DefaultParameterSchema.java | 4 +- .../resources/schemas/DefaultParameterSchema.yaml | 13 +--- .../src/test/resources/schemas/echo.yaml | 32 -------- .../test/resources/schemas/mixupAnnotations.yaml | 90 ++++++---------------- 11 files changed, 58 insertions(+), 142 deletions(-) diff --git a/ci/checkstyle/checkstyle.xml b/ci/checkstyle/checkstyle.xml index 8c34ac08b..3813950a5 100644 --- a/ci/checkstyle/checkstyle.xml +++ b/ci/checkstyle/checkstyle.xml @@ -41,6 +41,10 @@ <property name="message" value="Trailing whitespace"/> <property name="severity" value="error"/> </module> + <module name="SuppressWithPlainTextCommentFilter"> + <property name="offCommentFormat" value="CHECKSTYLE.OFF"/> + <property name="onCommentFormat" value="CHECKSTYLE.ON"/> + </module> <module name="TreeWalker"> <module name="AvoidStarImport"/> <module name="EmptyStatement"/> diff --git a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java index c1b5f029a..4c0e0321f 100644 --- a/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java +++ b/common/common-protobuf/src/test/java/org/apache/servicecomb/codec/protobuf/schema/TestSchemaToProtoGenerator.java @@ -31,6 +31,7 @@ import io.swagger.v3.oas.models.media.ObjectSchema; import io.swagger.v3.oas.models.media.StringSchema; import jakarta.ws.rs.core.MediaType; +//CHECKSTYLE:OFF @SuppressWarnings("unused") public class TestSchemaToProtoGenerator { @Test @@ -117,8 +118,7 @@ public class TestSchemaToProtoGenerator { message testIntRequest { int32 value = 1; } - - """, new ProtoToStringGenerator(proto).protoToString()); + """.trim(), new ProtoToStringGenerator(proto).protoToString().trim()); protoGenerator = new SchemaToProtoGenerator("test.int", openAPI, @@ -134,8 +134,7 @@ public class TestSchemaToProtoGenerator { message testIntResponse { int32 value = 1; } - - """, new ProtoToStringGenerator(proto).protoToString()); + """.trim(), new ProtoToStringGenerator(proto).protoToString().trim()); } @@ -163,8 +162,7 @@ public class TestSchemaToProtoGenerator { message testModelRequest { Model value = 1; } - - """, new ProtoToStringGenerator(proto).protoToString()); + """.trim(), new ProtoToStringGenerator(proto).protoToString().trim()); protoGenerator = new SchemaToProtoGenerator("test.model", openAPI, @@ -185,7 +183,7 @@ public class TestSchemaToProtoGenerator { message testIntResponse { Model value = 1; } - - """, new ProtoToStringGenerator(proto).protoToString()); + """.trim(), new ProtoToStringGenerator(proto).protoToString().trim()); } } +//CHECKSTYLE:ON diff --git a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java index 108fb8722..ecc21f73f 100644 --- a/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java +++ b/common/common-rest/src/test/java/org/apache/servicecomb/common/rest/RestProducerInvocationCreatorTest.java @@ -17,7 +17,6 @@ package org.apache.servicecomb.common.rest; -import static jakarta.ws.rs.core.Response.Status.NOT_ACCEPTABLE; import static jakarta.ws.rs.core.Response.Status.NOT_FOUND; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; @@ -50,7 +49,6 @@ import org.mockito.Mockito; import io.vertx.core.json.Json; import io.vertx.ext.web.RoutingContext; -import jakarta.ws.rs.core.HttpHeaders; public class RestProducerInvocationCreatorTest { diff --git a/pom.xml b/pom.xml index 0f40c2972..0f8b4bb0c 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ <werror.properties></werror.properties> <!-- plugin version start --> <!-- sort by alpha --> - <checkstyle-maven-plugin.version>3.2.2</checkstyle-maven-plugin.version> + <checkstyle-maven-plugin.version>3.3.0</checkstyle-maven-plugin.version> <coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version> <dependency-check-maven-plugin.version>8.3.1</dependency-check-maven-plugin.version> <docker-maven-plugin.version>0.43.3</docker-maven-plugin.version> diff --git a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/SwaggerUtils.java b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/SwaggerUtils.java index b8da1ed61..6f6a591c6 100644 --- a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/SwaggerUtils.java +++ b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/SwaggerUtils.java @@ -300,8 +300,8 @@ public final class SwaggerUtils { return false; } boolean result = true; - for (String key : properties1.keySet()) { - if (!schemaEquals(properties1.get(key), properties2.get(key))) { + for (Entry<String, Schema> item : properties1.entrySet()) { + if (!schemaEquals(item.getValue(), properties2.get(item.getKey()))) { result = false; break; } diff --git a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/Echo.java b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/Echo.java index 92d6d450b..48ac1256c 100644 --- a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/Echo.java +++ b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/Echo.java @@ -80,28 +80,27 @@ public class Echo { } - // TODO: this should fail. RequestMapping not parse consumes and produces. - @RequestMapping("partArray") + @RequestMapping(value = "partArray", consumes = MediaType.MULTIPART_FORM_DATA) public void partArray(@RequestPart MultipartFile[] part) { } - @RequestMapping("partList") + @RequestMapping(value = "partList", consumes = MediaType.MULTIPART_FORM_DATA) public void partList(@RequestPart List<MultipartFile> part) { } - @RequestMapping("partAnnotation") + @RequestMapping(value = "partAnnotation", consumes = MediaType.MULTIPART_FORM_DATA) public void partAnnotation(@RequestPart MultipartFile part) { } - @RequestMapping("partArrayAnnotation") + @RequestMapping(value = "partArrayAnnotation", consumes = MediaType.MULTIPART_FORM_DATA) public void partArrayAnnotation(@RequestPart MultipartFile[] part) { } - @RequestMapping("partListAnnotation") + @RequestMapping(value = "partListAnnotation", consumes = MediaType.MULTIPART_FORM_DATA) public void partListAnnotation(@RequestPart List<MultipartFile> part) { } diff --git a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/MethodMixupAnnotations.java b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/MethodMixupAnnotations.java index 2513b4e91..5d93a2862 100644 --- a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/MethodMixupAnnotations.java +++ b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/MethodMixupAnnotations.java @@ -54,8 +54,8 @@ public class MethodMixupAnnotations { @RequestMapping( path = "usingRequestMapping/{targetName}", method = {RequestMethod.POST}, - consumes = {"text/plain", "application/*"}, - produces = {"text/plain", "application/*"}) + consumes = {"text/plain", "application/json"}, + produces = {"text/plain", "application/json"}) public String usingRequestMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word) { return String.format("%s %s %s %s", srcUser.name, header, targetName, word); @@ -63,8 +63,8 @@ public class MethodMixupAnnotations { @GetMapping( path = "usingGetMapping/{targetName}", - consumes = {"text/plain", "application/*"}, - produces = {"text/plain", "application/*"}) + consumes = {"text/plain", "application/json"}, + produces = {"text/plain", "application/json"}) public String usingGetMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word) { return String.format("%s %s %s %s", srcUser.name, header, targetName, word); @@ -72,8 +72,8 @@ public class MethodMixupAnnotations { @PutMapping( path = "usingPutMapping/{targetName}", - consumes = {"text/plain", "application/*"}, - produces = {"text/plain", "application/*"}) + consumes = {"text/plain", "application/json"}, + produces = {"text/plain", "application/json"}) public String usingPutMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word) { return String.format("%s %s %s %s", srcUser.name, header, targetName, word); @@ -81,8 +81,8 @@ public class MethodMixupAnnotations { @PostMapping( path = "usingPostMapping/{targetName}", - consumes = {"text/plain", "application/*"}, - produces = {"text/plain", "application/*"}) + consumes = {"text/plain", "application/json"}, + produces = {"text/plain", "application/json"}) public String usingPostMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word) { return String.format("%s %s %s %s", srcUser.name, header, targetName, word); @@ -90,8 +90,8 @@ public class MethodMixupAnnotations { @PatchMapping( path = "usingPatchMapping/{targetName}", - consumes = {"text/plain", "application/*"}, - produces = {"text/plain", "application/*"}) + consumes = {"text/plain", "application/json"}, + produces = {"text/plain", "application/json"}) public String usingPatchMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word) { return String.format("%s %s %s %s", srcUser.name, header, targetName, word); @@ -99,8 +99,8 @@ public class MethodMixupAnnotations { @DeleteMapping( path = "usingDeleteMapping/{targetName}", - consumes = {"text/plain", "application/*"}, - produces = {"text/plain", "application/*"}) + consumes = {"text/plain", "application/json"}, + produces = {"text/plain", "application/json"}) public String usingDeleteMapping(@RequestBody User srcUser, @RequestHeader String header, @PathVariable String targetName, @RequestParam(name = "word") String word) { return String.format("%s %s %s %s", srcUser.name, header, targetName, word); diff --git a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/model/DefaultParameterSchema.java b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/model/DefaultParameterSchema.java index bb987bc59..9a2bae4d5 100644 --- a/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/model/DefaultParameterSchema.java +++ b/swagger/swagger-generator/generator-springmvc/src/test/java/org/apache/servicecomb/swagger/generator/springmvc/model/DefaultParameterSchema.java @@ -43,7 +43,7 @@ public class DefaultParameterSchema { return null; } - @RequestMapping(path = "testSingleMediaType", method = RequestMethod.POST, consumes = MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_XML) + @RequestMapping(path = "testSingleMediaType", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON) public String testSingleMediaType(String input) { return input; } @@ -55,7 +55,7 @@ public class DefaultParameterSchema { return input; } - @RequestMapping(path = "testBlankMediaType", method = RequestMethod.POST, consumes = "", produces = "") + @RequestMapping(path = "testBlankMediaType", method = RequestMethod.POST) public String testBlankMediaType(String input) { return input; } diff --git a/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/DefaultParameterSchema.yaml b/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/DefaultParameterSchema.yaml index 42c4a2ad0..202825a95 100644 --- a/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/DefaultParameterSchema.yaml +++ b/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/DefaultParameterSchema.yaml @@ -56,13 +56,10 @@ paths: "200": description: response of 200 content: - application/json: - schema: - type: string - application/protobuf: + text/plain: schema: type: string - text/plain: + application/json: schema: type: string /testObjectParam: @@ -127,12 +124,6 @@ paths: application/json: schema: type: string - application/protobuf: - schema: - type: string - text/plain: - schema: - type: string /testUnsupportedParamType: get: operationId: testUnsupportedParamType diff --git a/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/echo.yaml b/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/echo.yaml index 77cc098d7..2553544fc 100644 --- a/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/echo.yaml +++ b/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/echo.yaml @@ -35,11 +35,6 @@ paths: type: array items: type: string - application/protobuf: - schema: - type: array - items: - type: string text/plain: schema: type: array @@ -76,13 +71,6 @@ paths: - RED - YELLOW - BLUE - application/protobuf: - schema: - type: string - enum: - - RED - - YELLOW - - BLUE text/plain: schema: type: string @@ -119,13 +107,6 @@ paths: type: array items: type: string - application/protobuf: - schema: - type: array - items: - type: array - items: - type: string text/plain: schema: type: array @@ -146,13 +127,6 @@ paths: type: array items: type: string - application/protobuf: - schema: - type: array - items: - type: array - items: - type: string text/plain: schema: type: array @@ -285,9 +259,6 @@ paths: application/json: schema: type: string - application/protobuf: - schema: - type: string text/plain: schema: type: string @@ -301,9 +272,6 @@ paths: application/json: schema: type: string - application/protobuf: - schema: - type: string text/plain: schema: type: string diff --git a/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/mixupAnnotations.yaml b/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/mixupAnnotations.yaml index 121f96127..bf5794890 100644 --- a/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/mixupAnnotations.yaml +++ b/swagger/swagger-generator/generator-springmvc/src/test/resources/schemas/mixupAnnotations.yaml @@ -144,12 +144,6 @@ paths: "200": description: response of 200 content: - application/json: - schema: - type: string - application/protobuf: - schema: - type: string text/plain: schema: type: string @@ -369,13 +363,10 @@ paths: type: string requestBody: content: - application/json: - schema: - $ref: '#/components/schemas/User' - application/protobuf: + text/plain: schema: $ref: '#/components/schemas/User' - text/plain: + application/json: schema: $ref: '#/components/schemas/User' required: true @@ -384,13 +375,10 @@ paths: "200": description: response of 200 content: - application/json: - schema: - type: string - application/protobuf: + text/plain: schema: type: string - text/plain: + application/json: schema: type: string /usingGetMapping/{targetName}: @@ -414,13 +402,10 @@ paths: type: string requestBody: content: - application/json: - schema: - $ref: '#/components/schemas/User' - application/protobuf: + text/plain: schema: $ref: '#/components/schemas/User' - text/plain: + application/json: schema: $ref: '#/components/schemas/User' required: true @@ -429,13 +414,10 @@ paths: "200": description: response of 200 content: - application/json: - schema: - type: string - application/protobuf: + text/plain: schema: type: string - text/plain: + application/json: schema: type: string /usingPatchMapping/{targetName}: @@ -459,13 +441,10 @@ paths: type: string requestBody: content: - application/json: - schema: - $ref: '#/components/schemas/User' - application/protobuf: + text/plain: schema: $ref: '#/components/schemas/User' - text/plain: + application/json: schema: $ref: '#/components/schemas/User' required: true @@ -474,13 +453,10 @@ paths: "200": description: response of 200 content: - application/json: - schema: - type: string - application/protobuf: + text/plain: schema: type: string - text/plain: + application/json: schema: type: string /usingPostMapping/{targetName}: @@ -504,13 +480,10 @@ paths: type: string requestBody: content: - application/json: - schema: - $ref: '#/components/schemas/User' - application/protobuf: + text/plain: schema: $ref: '#/components/schemas/User' - text/plain: + application/json: schema: $ref: '#/components/schemas/User' required: true @@ -519,13 +492,10 @@ paths: "200": description: response of 200 content: - application/json: - schema: - type: string - application/protobuf: + text/plain: schema: type: string - text/plain: + application/json: schema: type: string /usingPutMapping/{targetName}: @@ -549,13 +519,10 @@ paths: type: string requestBody: content: - application/json: - schema: - $ref: '#/components/schemas/User' - application/protobuf: + text/plain: schema: $ref: '#/components/schemas/User' - text/plain: + application/json: schema: $ref: '#/components/schemas/User' required: true @@ -564,13 +531,10 @@ paths: "200": description: response of 200 content: - application/json: - schema: - type: string - application/protobuf: + text/plain: schema: type: string - text/plain: + application/json: schema: type: string /usingRequestMapping/{targetName}: @@ -594,13 +558,10 @@ paths: type: string requestBody: content: - application/json: - schema: - $ref: '#/components/schemas/User' - application/protobuf: + text/plain: schema: $ref: '#/components/schemas/User' - text/plain: + application/json: schema: $ref: '#/components/schemas/User' required: true @@ -609,13 +570,10 @@ paths: "200": description: response of 200 content: - application/json: - schema: - type: string - application/protobuf: + text/plain: schema: type: string - text/plain: + application/json: schema: type: string components:
