How to add swagger annotation for rest endpoint @GetMapping(“/**”)?
I wanted to add swagger implementation for below snippet. But couldn't find exact annotation to read url input from swagger.
Tried using,
@ApiOperation(httpMethod = "GET",value = "Get Value",response = String.class)
@ApiImplicitParams({@ApiImplicitParam(name="basePath",paramType = "path")
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
above code didn't help.
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
Expectation is to get a url as input via swagger-ui and return the same as response.
web-services spring-boot servlets swagger-ui
add a comment |
I wanted to add swagger implementation for below snippet. But couldn't find exact annotation to read url input from swagger.
Tried using,
@ApiOperation(httpMethod = "GET",value = "Get Value",response = String.class)
@ApiImplicitParams({@ApiImplicitParam(name="basePath",paramType = "path")
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
above code didn't help.
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
Expectation is to get a url as input via swagger-ui and return the same as response.
web-services spring-boot servlets swagger-ui
add a comment |
I wanted to add swagger implementation for below snippet. But couldn't find exact annotation to read url input from swagger.
Tried using,
@ApiOperation(httpMethod = "GET",value = "Get Value",response = String.class)
@ApiImplicitParams({@ApiImplicitParam(name="basePath",paramType = "path")
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
above code didn't help.
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
Expectation is to get a url as input via swagger-ui and return the same as response.
web-services spring-boot servlets swagger-ui
I wanted to add swagger implementation for below snippet. But couldn't find exact annotation to read url input from swagger.
Tried using,
@ApiOperation(httpMethod = "GET",value = "Get Value",response = String.class)
@ApiImplicitParams({@ApiImplicitParam(name="basePath",paramType = "path")
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
above code didn't help.
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
Expectation is to get a url as input via swagger-ui and return the same as response.
web-services spring-boot servlets swagger-ui
web-services spring-boot servlets swagger-ui
edited Jan 3 at 14:18
TinyOS
99011130
99011130
asked Jan 3 at 10:15
KaviKavi
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Let suppose that your controller look like :
package com.sample.controller;
@RestController
@RequestMapping
@Api(value = "GreetingsController", tags = {"Just for greetings"})
Public class GreetingsController{
@ApiOperation(httpMethod = "GET", value = "Get value",notes = "description")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK !"),
@ApiResponse(code = 500, message = "Internal Error")
})
@GetMapping(value = "/")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
}
The Dependency:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
Configurations:
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configurable
public class AppConfig{
public @Bean Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("GroupeName").apiInfo(apiInfo())
.select().paths(PathSelectors.regex(".*controller.*")).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("App title").description("App description")
.termsOfServiceUrl("").license("©Licence").licenseUrl("").version("1.0").build();
}
}
Application.yml:
server:
port: 8111
servlet:
context-path: /exampleApp
Access url : http://localhost:8111/exampleApp/swagger-ui.html
My question is for @GetMapping(value = "/**") not for @GetMapping(value = "/").. please support with relevant answers..
– Kavi
Jan 7 at 13:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020224%2fhow-to-add-swagger-annotation-for-rest-endpoint-getmapping%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Let suppose that your controller look like :
package com.sample.controller;
@RestController
@RequestMapping
@Api(value = "GreetingsController", tags = {"Just for greetings"})
Public class GreetingsController{
@ApiOperation(httpMethod = "GET", value = "Get value",notes = "description")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK !"),
@ApiResponse(code = 500, message = "Internal Error")
})
@GetMapping(value = "/")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
}
The Dependency:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
Configurations:
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configurable
public class AppConfig{
public @Bean Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("GroupeName").apiInfo(apiInfo())
.select().paths(PathSelectors.regex(".*controller.*")).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("App title").description("App description")
.termsOfServiceUrl("").license("©Licence").licenseUrl("").version("1.0").build();
}
}
Application.yml:
server:
port: 8111
servlet:
context-path: /exampleApp
Access url : http://localhost:8111/exampleApp/swagger-ui.html
My question is for @GetMapping(value = "/**") not for @GetMapping(value = "/").. please support with relevant answers..
– Kavi
Jan 7 at 13:15
add a comment |
Let suppose that your controller look like :
package com.sample.controller;
@RestController
@RequestMapping
@Api(value = "GreetingsController", tags = {"Just for greetings"})
Public class GreetingsController{
@ApiOperation(httpMethod = "GET", value = "Get value",notes = "description")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK !"),
@ApiResponse(code = 500, message = "Internal Error")
})
@GetMapping(value = "/")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
}
The Dependency:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
Configurations:
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configurable
public class AppConfig{
public @Bean Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("GroupeName").apiInfo(apiInfo())
.select().paths(PathSelectors.regex(".*controller.*")).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("App title").description("App description")
.termsOfServiceUrl("").license("©Licence").licenseUrl("").version("1.0").build();
}
}
Application.yml:
server:
port: 8111
servlet:
context-path: /exampleApp
Access url : http://localhost:8111/exampleApp/swagger-ui.html
My question is for @GetMapping(value = "/**") not for @GetMapping(value = "/").. please support with relevant answers..
– Kavi
Jan 7 at 13:15
add a comment |
Let suppose that your controller look like :
package com.sample.controller;
@RestController
@RequestMapping
@Api(value = "GreetingsController", tags = {"Just for greetings"})
Public class GreetingsController{
@ApiOperation(httpMethod = "GET", value = "Get value",notes = "description")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK !"),
@ApiResponse(code = 500, message = "Internal Error")
})
@GetMapping(value = "/")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
}
The Dependency:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
Configurations:
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configurable
public class AppConfig{
public @Bean Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("GroupeName").apiInfo(apiInfo())
.select().paths(PathSelectors.regex(".*controller.*")).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("App title").description("App description")
.termsOfServiceUrl("").license("©Licence").licenseUrl("").version("1.0").build();
}
}
Application.yml:
server:
port: 8111
servlet:
context-path: /exampleApp
Access url : http://localhost:8111/exampleApp/swagger-ui.html
Let suppose that your controller look like :
package com.sample.controller;
@RestController
@RequestMapping
@Api(value = "GreetingsController", tags = {"Just for greetings"})
Public class GreetingsController{
@ApiOperation(httpMethod = "GET", value = "Get value",notes = "description")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK !"),
@ApiResponse(code = 500, message = "Internal Error")
})
@GetMapping(value = "/")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
}
The Dependency:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
Configurations:
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configurable
public class AppConfig{
public @Bean Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("GroupeName").apiInfo(apiInfo())
.select().paths(PathSelectors.regex(".*controller.*")).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("App title").description("App description")
.termsOfServiceUrl("").license("©Licence").licenseUrl("").version("1.0").build();
}
}
Application.yml:
server:
port: 8111
servlet:
context-path: /exampleApp
Access url : http://localhost:8111/exampleApp/swagger-ui.html
answered Jan 3 at 14:09
TinyOSTinyOS
99011130
99011130
My question is for @GetMapping(value = "/**") not for @GetMapping(value = "/").. please support with relevant answers..
– Kavi
Jan 7 at 13:15
add a comment |
My question is for @GetMapping(value = "/**") not for @GetMapping(value = "/").. please support with relevant answers..
– Kavi
Jan 7 at 13:15
My question is for @GetMapping(value = "/**") not for @GetMapping(value = "/").. please support with relevant answers..
– Kavi
Jan 7 at 13:15
My question is for @GetMapping(value = "/**") not for @GetMapping(value = "/").. please support with relevant answers..
– Kavi
Jan 7 at 13:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54020224%2fhow-to-add-swagger-annotation-for-rest-endpoint-getmapping%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown