Reputation: 161
Swagger doesn't recognize a new interface of rest api.
This are swagger configuration file.
package trn06.administracion.api.configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import lombok.extern.slf4j.Slf4j;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Slf4j
@EnableSwagger2
@Configuration
public class TRN06SwaggerConfiguration {
@Value("${custom.host}")
private String hostValue;
private ApiInfo _apiInfo(final String version) {
return new ApiInfoBuilder()
.title("Administrative events")
.termsOfServiceUrl("")
.version(version)
.contact(new Contact("",
"",
""))
.build();
}
private Docket _configureVersion(final String version) {
// Get environment from java environment variables
return new Docket(DocumentationType.SWAGGER_2)
.host(hostValue)
.groupName("Version_" + version)
.select()
.apis(RequestHandlerSelectors.basePackage("trn06.administracion.api.controller.rest"))
.paths(PathSelectors.ant("/v" + version + "/**"))
.build()
.useDefaultResponseMessages(false)
.apiInfo(_apiInfo(version));
}
@Bean
Docket configureV1_0() {
return _configureVersion("1.0");
}
}
All interfaces defined on package trn06.administracion.api.controller.rest are ok, in fact I have two other interfaces mapped ok, except this one:
package trn06.administracion.api.controller.rest;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import trn06.administracion.api.model.dto.TRN06ErrorDto;
import trn06.administracion.api.model.dto.TRN06EventsAuthorityDto;
import trn06.administracion.api.model.dto.TRN06ValidationErrorDto;
import java.util.List;
@Api(value = "authorities", description = "Event's authorities ", tags = "Authorities")
public interface TRN06EventsAuthorityApiController {
@ApiOperation(value = "List of authorities", nickname = "findAuthorities", response = TRN06EventsAuthorityDto.class, responseContainer = "List", tags = {"Authorities,"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Operation performed", response = TRN06EventsAuthorityDto.class, responseContainer = "List"),
@ApiResponse(code = 400, message = "Validation error", response = TRN06ValidationErrorDto.class),
@ApiResponse(code = 404, message = "Not found"),
@ApiResponse(code = 500, message = "Error", response = TRN06ErrorDto.class)})
@GetMapping(value = "/v1.0/authorities",
produces = "application/json")
List<TRN06EventsAuthorityDto> findAuthorities();
}
Looks like database entity it's ok, I try making an error and was detected correctly. Try changing RequestHandlerSelectors to any(), same results.
No idea and no clue of whats appening.
Kind regards
Upvotes: 1
Views: 1603
Reputation: 161
In my case, was an annotation I forgot
public class TRN06EventsTypesApiControllerImpl
implements TRN06EventsTypesApiController {
....
After put anotation @RestController was fine
@RestController
public class TRN06EventsTypesApiControllerImpl
implements TRN06EventsTypesApiController {
....
Anyway, I take the note of @RequestMapping annotation.
Thanks @v-mokrecov and @mahesh-loya
Upvotes: 1
Reputation: 1084
You need to create an implementation of this interface and add @RestController and @RequestMapping annotations in the implementation.
For example:
@RestController
@RequestMapping("/findAuthorities")
public class TRN06EventsAuthorityApiControllerImpl implements TRN06EventsAuthorityApiController {
@Override
public List<String> findAuthorities() {
return null;
}
}
Upvotes: 1