Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SCB-989]scan RestController to to make springmvc controller publish …
…as ServiceComb Rest easier
- Loading branch information
Showing
11 changed files
with
263 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestRestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.servicecomb.it.testcase; | ||
|
||
import org.apache.servicecomb.it.extend.engine.ITSCBRestTemplate; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class TestRestController { | ||
private static ITSCBRestTemplate restControllerSchemaClient = new ITSCBRestTemplate | ||
("org.apache.servicecomb.it.schema.RestControllerSchema"); | ||
|
||
private static ITSCBRestTemplate restControllerEmptyMappingSchemaClient = new ITSCBRestTemplate | ||
("org.apache.servicecomb.it.schema.RestControllerEmptyMappingSchema"); | ||
|
||
private static ITSCBRestTemplate restControllerWithRequestMappingSchemaClient = new ITSCBRestTemplate | ||
("org.apache.servicecomb.it.schema.RestControllerWithRequestMappingSchema"); | ||
|
||
private static ITSCBRestTemplate restControllerWithRestSchemaSchemaClient = new ITSCBRestTemplate | ||
("RestControllerWithRestSchemaSchema"); | ||
|
||
@Test | ||
public void restControllerSchemaClient() { | ||
Assert.assertEquals("/", restControllerSchemaClient.getBasePath()); | ||
int result = restControllerSchemaClient.getForObject("/restControllerSchemaQuery?input=2", int.class); | ||
Assert.assertEquals(2, result); | ||
} | ||
|
||
@Test | ||
public void restControllerEmptyMappingSchemaClient() { | ||
// empty path default to class name(@RequestMapping(path = "")). Shall we change this behavior in future? | ||
Assert.assertEquals("/RestControllerEmptyMappingSchema", restControllerEmptyMappingSchemaClient.getBasePath()); | ||
int result = restControllerEmptyMappingSchemaClient | ||
.getForObject("/restControllerEmptyMappingSchemaQuery?input=2", int.class); | ||
Assert.assertEquals(2, result); | ||
} | ||
|
||
@Test | ||
public void restControllerWithRequestMappingSchemaClient() { | ||
Assert.assertEquals("/restControllerWithRequest", restControllerWithRequestMappingSchemaClient.getBasePath()); | ||
int result = restControllerWithRequestMappingSchemaClient | ||
.getForObject("/restControllerWithRequestMappingSchemaQuery?input=2", int.class); | ||
Assert.assertEquals(2, result); | ||
} | ||
|
||
@Test | ||
public void restControllerWithRestSchemaSchemaClient() { | ||
Assert.assertEquals("/restControllerWithRestSchemaSchema", restControllerWithRestSchemaSchemaClient.getBasePath()); | ||
int result = restControllerWithRestSchemaSchemaClient | ||
.getForObject("/restControllerWithRestSchemaSchemaQuery?input=2", int.class); | ||
Assert.assertEquals(2, result); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ucer/src/main/java/org/apache/servicecomb/it/schema/RestControllerEmptyMappingSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.it.schema; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping(path = "") | ||
public class RestControllerEmptyMappingSchema { | ||
@GetMapping(path = "restControllerEmptyMappingSchemaQuery") | ||
public int intQuery(@RequestParam(name = "input", required = false, defaultValue = "13") int input) { | ||
return input; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ests/it-producer/src/main/java/org/apache/servicecomb/it/schema/RestControllerSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.it.schema; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class RestControllerSchema { | ||
@GetMapping(path = "restControllerSchemaQuery") | ||
public int intQuery(@RequestParam(name = "input", required = false, defaultValue = "13") int input) { | ||
return input; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...rc/main/java/org/apache/servicecomb/it/schema/RestControllerWithRequestMappingSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.it.schema; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping(path = "/restControllerWithRequest") | ||
public class RestControllerWithRequestMappingSchema { | ||
@GetMapping(path = "restControllerWithRequestMappingSchemaQuery") | ||
public int intQuery(@RequestParam(name = "input", required = false, defaultValue = "13") int input) { | ||
return input; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...er/src/main/java/org/apache/servicecomb/it/schema/RestControllerWithRestSchemaSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.it.schema; | ||
|
||
import org.apache.servicecomb.provider.rest.common.RestSchema; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RestSchema(schemaId = "RestControllerWithRestSchemaSchema") | ||
@RequestMapping(path = "/restControllerWithRestSchemaSchema") | ||
public class RestControllerWithRestSchemaSchema { | ||
@GetMapping(path = "restControllerWithRestSchemaSchemaQuery") | ||
public int intQuery(@RequestParam(name = "input", required = false, defaultValue = "13") int input) { | ||
return input; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...gger/generator/springmvc/processor/annotation/RestControllerClassAnnotationProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.springmvc.processor.annotation; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.servicecomb.swagger.generator.core.ClassAnnotationProcessor; | ||
import org.apache.servicecomb.swagger.generator.core.SwaggerGenerator; | ||
|
||
import io.swagger.models.Swagger; | ||
|
||
public class RestControllerClassAnnotationProcessor implements ClassAnnotationProcessor { | ||
|
||
@Override | ||
public void process(Object annotation, SwaggerGenerator swaggerGenerator) { | ||
Swagger swagger = swaggerGenerator.getSwagger(); | ||
if (StringUtils.isEmpty(swagger.getBasePath())) { | ||
swagger.setBasePath("/"); | ||
} | ||
} | ||
} |