Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mtshane opened this issue Aug 25, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@mtshane
Copy link

mtshane commented Aug 25, 2020

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

@bnasslahsen
Copy link
Contributor

@mtshane,

It's already answered here: #777 and here #644.

@mtshane
Copy link
Author

mtshane commented Aug 25, 2020

Thank you @bnasslahsen .. sorry, I searched for @SecurityRequirement and went through the first two pages of issues and didn't see anything relevant. Appreciate the response

@bnasslahsen bnasslahsen changed the title Annotations don't seem to have any effect on @Repository interface Add support of swagger annotations on @Repository interface Aug 26, 2020
@bnasslahsen
Copy link
Contributor

bnasslahsen commented Aug 26, 2020

Great @mtshane,

We hopefully will add the support for @SecurityRequirement and @Tags (on the Repository level) for the next release v1.4.5;

@bnasslahsen bnasslahsen changed the title Add support of swagger annotations on @Repository interface Add support of swagger annotations @SecurityRequirement and @Tag on @Repository interface Aug 26, 2020
@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants