Skip to content

feat: Implement parsing and generation of OpenAPI security schemes and security requirements#342

Open
NicolasThierion wants to merge 4 commits intokbuntrock:devfrom
NicolasThierion:dev
Open

feat: Implement parsing and generation of OpenAPI security schemes and security requirements#342
NicolasThierion wants to merge 4 commits intokbuntrock:devfrom
NicolasThierion:dev

Conversation

@NicolasThierion
Copy link

Use this checklist to help us review and merge your contribution quickly and smoothly:

  • Ensure your pull request focuses on a single issue and does not introduce unrelated changes.
  • Provide a clear and detailed enough description explaining what the pull request does, how, and why.
  • Add unit tests that reflect any behavioral changes, making sure they fail when the corresponding runtime modifications are not applied.
  • Run mvn verify to confirm that the basic checks pass.
    A more thorough validation will be executed automatically on your pull request.
  • Update the documentation if required (at least the English version).
    English documentation files can be found in docs/docs.

Disclamer: I’m not very familiar with this project yet, so I used some AI assistance to help implement this feature. I have thoroughly tested the results and everything looks good on my end, but please let me know if any parts of the code seem out of place or inconsistent with the project's standards.

Copy link
Owner

@kbuntrock kbuntrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, this MR looks pretty good to me!

I left a few comments on your MR, but nothing significant! 😉

| | `required` | `boolean` | Whether the parameter is required |
| | `schema` | `Schema` | Parameter schema |
| | `example` | `String` | Example value |
| `SecurityScheme` | `name` | `String` | Security Scheme name |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want you can also add this in the french version here :
docs/i18n/fr/docusaurus-plugin-content-docs/current/advanced_topics/swagger_annotations.md

(since I suspect you're also pretty fluent in french 😊)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en effet :)

// in is an enum, so we use its toString() method
// only set it if it's not the DEFAULT or empty enum value
String inStr = inOpt.get().toString();
if(!StringUtils.isEmpty(inStr) && !"DEFAULT".equals(inStr)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the implementation of the enumeration (v2.2.30), the enum DEFAULT is linked to the empty string value.
Unless you are aware of a different implementation in another version, "DEFAULT" will never be equal to the value returned by toString(). Better to choose here one of the two method : comparaison of the value or the name.

.filter(e -> methodIdentifier.equals(e.getIdentifier()))
.collect(Collectors.toList());
for(Endpoint endpoint : endpointsForMethod) {
readSecurityRequirements(mergedAnnotations, endpoint.getSecurityRequirements());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid matching things a posteriori, I would prefer that the reading of securityRequirement be done at the same time the other endpoint information are collected.

I suggest moving the readSecurityRequirements function to the AbstractLibraryReader class so that it can be called for the class from JavaClassAnalyser (as it is now), and inside the readers for each endpoint.

I think its call could be added to the AbstractLibraryReader#setSwaggerAnnotatedEndpointProperties function.

And this block would disappear.

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class SecurityScheme {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SecurityScheme is use in a couple of Set but do not define an equals function.
I guess comparing instance on the name is what we want?

Or let it like this but use List instead of Set in the readSecuritySchemes functions.

}

private void readSecuritySchemes(MergedAnnotations mergedAnnotations, Set<SecurityScheme> securitySchemes) {
Map<String, SecurityScheme> map = new LinkedHashMap<>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this function, you silently secure the addition of multiple SecurityScheme with the same name. But later you throw a runtime exception on merging the schemes.
Better to homogenise how we handle this.

But an exception is a bit extreme for this functionality in my opinion. I would prefer a warning log since I guess Spring do not care and launch the app anyway.

You can still use the result of the map addition to log a warn, or use directly the destination Set addition if you opted to implement the equals function on SecurityScheme.


public void addSecurityScheme(SecurityScheme scheme) {
if(securitySchemes.containsKey(scheme.getName())) {
throw new RuntimeException("Multiple SecurityScheme with the same name (" + scheme.getName() + ") are defined.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a warning log here instead of the exception.

@kbuntrock
Copy link
Owner

Hello @NicolasThierion

Would you happen to know when you might have time to continue this MR? (No pressure at all. 😅)
It’s just that I’m considering making a release and possibly including this feature.

@NicolasThierion
Copy link
Author

NicolasThierion commented Mar 17, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants