Skip to content

Add support of swagger annotations @SecurityRequirement and @Tag on @Repository interface #837

Closed
@mtshane

Description

@mtshane

Describe the bug
No annotations that I add to @repository interfaces are used to guide the config creation

To Reproduce
Steps to reproduce the behavior:

  • new Spring Boot 2.2.9-RELEASE
  • springdoc-openapi-ui 1.4.4
  • springdoc-openapi-data-rest 1.4.4
  • Create a standard @RestController and annotate it with @tag and @securityrequirement
  • Apply the same annotations to a @repository interface
  • The generation for the controller works as expected, but the Repository interface annotations are ignored

`@RestController
@RequestMapping(
value = "/api/v1/integration/hawksearch",
produces = MediaType.APPLICATION_JSON_VALUE
)
@tag(name = "hawksearch-admin-controller", description = "Manage Hawksearch Data through the API")
@securityrequirement(name = "EntityAPIs")
public class HawksearchAdminController {

private final HawksearchFieldService fieldService;
private final HawksearchProductService hawksearchProductService;
private final HawksearchIndexService hawksearchIndexService;

@Autowired
public HawksearchAdminController(HawksearchFieldService fieldService,
HawksearchProductService hawksearchProductService,
HawksearchIndexService hawksearchIndexService) {
this.fieldService = fieldService;
this.hawksearchProductService = hawksearchProductService;
this.hawksearchIndexService = hawksearchIndexService;
}

@GetMapping( "/fields")
@operation(summary = "Get All Fields")
public ResponseEntity<?> getAllFields(@RequestParam Map<String, Object> parameters) {
try {
Preconditions.checkNotNull(parameters.get("instance"), "Parameter (instance) is required");
return new ResponseEntity<>(fieldService.getFields((String) parameters.get("instance")), HttpStatus.OK);
}
catch (Exception e) {
throw new RemoteServiceException(e.getMessage(), e);
}
}

@PostMapping( "/fields")
@operation(summary = "Create a new Field")
public ResponseEntity<?> createField(@RequestBody NewFieldRequest newFieldRequest) {
try {
Preconditions.checkArgument(StringUtils.isNotEmpty(newFieldRequest.getInstance()), "instance is required");
Preconditions.checkArgument(Objects.nonNull(newFieldRequest.getField()), "field is required");
return new ResponseEntity<>(fieldService.createField(newFieldRequest.getInstance(), newFieldRequest.getField()), HttpStatus.OK);
}
catch (Exception e) {
throw new RemoteServiceException(e.getMessage(), e);
}
}
}`

`@Tag(name = "Address Entity", description = "Address objects attached to Users")
@securityrequirement(name = "EntityAPIs")
@repository
public interface AddressRepository extends JpaRepository<Address, Long>, JpaSpecificationExecutor

{

Optional

findOneById(Long id);

@query("select ua from UserAddress ua JOIN FETCH ua.address a JOIN FETCH ua.user u where u = ?1")
Collection findAllAddressesByUser(User user);

}`

Expected behavior

  • The lock on the operation in swagger-ui should reference the correct authorization method to use for that path
  • The Tags array at the path/operation, and the global config should contain an entry with the annotation Tag name and description
  • The operation security array should contain the define security requirement

Screenshots

Screen Shot 2020-08-25 at 7 04 35 AM
Screen Shot 2020-08-25 at 7 04 49 AM

Additional context
Attached example of generated json from above two classes
springdoc.json.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions