-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Access HttpServletRequest in Spring Controller that implements generated interface
- Loading branch information
Aleksandar Stojsavljevic
committed
Dec 7, 2018
1 parent
fe21d9e
commit ee36735
Showing
9 changed files
with
224 additions
and
1 deletion.
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
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
24 changes: 24 additions & 0 deletions
24
src/test/java/com/phoenixnap/oss/ramlplugin/raml2code/github/Issue163RulesTest.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,24 @@ | ||
package com.phoenixnap.oss.ramlplugin.raml2code.github; | ||
|
||
import org.junit.Test; | ||
|
||
import com.phoenixnap.oss.ramlplugin.raml2code.plugin.TestConfig; | ||
import com.phoenixnap.oss.ramlplugin.raml2code.rules.GitHubAbstractRuleTestBase; | ||
import com.phoenixnap.oss.ramlplugin.raml2code.rules.Spring4ControllerDecoratorRule; | ||
|
||
/** | ||
* @author aleksandars | ||
* @since 2.0.5 | ||
*/ | ||
public class Issue163RulesTest extends GitHubAbstractRuleTestBase { | ||
|
||
@Test | ||
public void check_http_request_as_method_parameter() throws Exception { | ||
TestConfig.setInjectHttpRequestParameter(true); | ||
loadRaml("issue-163.raml"); | ||
rule = new Spring4ControllerDecoratorRule(); | ||
rule.apply(getControllerMetadata(), jCodeModel); | ||
verifyGeneratedCode("Issue163Spring4ControllerDecoratorRule"); | ||
TestConfig.setInjectHttpRequestParameter(false); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#%RAML 1.0 | ||
title: Access HttpServletRequest in Spring Controller that implements generated interface #163 | ||
|
||
/test: | ||
get: | ||
queryParameters: | ||
color: string | ||
post: | ||
body: | ||
application/json: | ||
type: string | ||
/{testId}: | ||
uriParameters: | ||
testId: number | ||
put: | ||
body: | ||
application/json: | ||
type: string | ||
delete: | ||
responses: | ||
201: | ||
|
129 changes: 129 additions & 0 deletions
129
src/test/resources/validations/github/Issue163Spring4ControllerDecoratorRule.java.txt
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,129 @@ | ||
-----------------------------------com.gen.test.TestController.java----------------------------------- | ||
|
||
package com.gen.test; | ||
|
||
import java.math.BigDecimal; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.validation.Valid; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
|
||
/** | ||
* No description | ||
* (Generated with springmvc-raml-parser [email protected]@) | ||
* | ||
*/ | ||
public interface TestController { | ||
|
||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
public ResponseEntity<?> getObjectByColor(java.lang.String color, HttpServletRequest httpRequest); | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
public ResponseEntity<?> createString( | ||
@Valid | ||
String string, HttpServletRequest httpRequest); | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
public ResponseEntity<?> updateString(BigDecimal testId, | ||
@Valid | ||
String string, HttpServletRequest httpRequest); | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
public ResponseEntity<?> deleteTestByTestId(BigDecimal testId, HttpServletRequest httpRequest); | ||
|
||
} | ||
-----------------------------------com.gen.test.TestControllerDecorator.java----------------------------------- | ||
|
||
package com.gen.test; | ||
|
||
import java.math.BigDecimal; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.validation.Valid; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
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.RestController; | ||
|
||
|
||
/** | ||
* No description | ||
* (Generated with springmvc-raml-parser [email protected]@) | ||
* | ||
*/ | ||
@RestController | ||
@RequestMapping("/api/test") | ||
@Validated | ||
public class TestControllerDecorator | ||
implements TestController | ||
{ | ||
|
||
@Autowired | ||
private TestController testControllerDelegate; | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
@RequestMapping(value = "", method = RequestMethod.GET) | ||
public ResponseEntity<?> getObjectByColor( | ||
@RequestParam | ||
java.lang.String color, HttpServletRequest httpRequest) { | ||
return this.testControllerDelegate.getObjectByColor(color, httpRequest); | ||
} | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
@RequestMapping(value = "", method = RequestMethod.POST) | ||
public ResponseEntity<?> createString( | ||
@Valid | ||
@RequestBody | ||
String string, HttpServletRequest httpRequest) { | ||
return this.testControllerDelegate.createString(string, httpRequest); | ||
} | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
@RequestMapping(value = "/{testId}", method = RequestMethod.PUT) | ||
public ResponseEntity<?> updateString( | ||
@PathVariable | ||
BigDecimal testId, | ||
@Valid | ||
@RequestBody | ||
String string, HttpServletRequest httpRequest) { | ||
return this.testControllerDelegate.updateString(testId, string, httpRequest); | ||
} | ||
|
||
/** | ||
* No description | ||
* | ||
*/ | ||
@RequestMapping(value = "/{testId}", method = RequestMethod.DELETE) | ||
public ResponseEntity<?> deleteTestByTestId( | ||
@PathVariable | ||
BigDecimal testId, HttpServletRequest httpRequest) { | ||
return this.testControllerDelegate.deleteTestByTestId(testId, httpRequest); | ||
} | ||
|
||
} |