Skip to content

support @SecurityScheme #163

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

Closed
wants to merge 3 commits into from
Closed

support @SecurityScheme #163

wants to merge 3 commits into from

Conversation

kevin70
Copy link
Contributor

@kevin70 kevin70 commented Feb 17, 2023

Hello.
I added support for @SecurityScheme and @SecurityRequirement.

Use the following method to automatically convert security authentication to the corresponding OpenAPI.
e.g.

@Controller
@Path("/security")
class SecurityController {

  @Get("/first")
  @SecurityRequirement(name = "JWT")
  String first() {
    return "simple";
  }

  @Get("/second")
  @SecurityRoles
  String second() {
    return "simple";
  }
}

There seems to be a lot of source files that I changed this time. Please help me review them if you have time. If there is any problem, I will modify it in time. Thank you.

@SentryMan
Copy link
Collaborator

ok so clearly my custom openAPI serializer doesn't cut it anymore. Instead of pulling all of swagger core, can you only add jackson databind and do something like how we had it before?

@kevin70
Copy link
Contributor Author

kevin70 commented Feb 18, 2023

swagger code has a large number of optimization implementations for serialization. Using swagger-code can better maintain compatibility with the OpenAPI specification. This is helpful for generating better OpenAPI documents, so I hope to introduce swigger-code to better help us solve this problem.

@SentryMan
Copy link
Collaborator

swagger code has a large number of optimization implementations for serialization.

If a regular ObectMapper can serialize correctly, do we need all of the optimizations? I guess I'm hesitating to add all the transitive dependencies to the shaded jar (jakarta.xml.bind, commons-lang, snakeyaml, etc.) if we don't actually need them.

@kevin70
Copy link
Contributor Author

kevin70 commented Feb 20, 2023

I removed the swagger core dependency and replaced it with jackson. The generated OpenAPI document looks good at present.

Copy link
Collaborator

@SentryMan SentryMan left a comment

Choose a reason for hiding this comment

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

LGTM

@SentryMan
Copy link
Collaborator

Wait a second, we do have an issue it seems, when I use avaje-http(your changes installed to my local maven) as a provided dependency I get this error.

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Failed on call to `getDeclaredMethods()` on class `io.swagger.v3.oas.models.OpenAPI`, problem: (java.lang.NoClassDefFoundError) io/swagger/v3/oas/models/security/SecurityRequirement

We'll have to figure out why it can't find the model class

@SentryMan
Copy link
Collaborator

I get this error with or without the @SecurityRequirement annotation, I also tried reverting to use swagger core deserialization and it still doesn't work. To reproduce, mvn clean install your changes, then clone https://github.com/SentryMan/avaje-javalin-api-example and bump the version in the POM.

@SentryMan
Copy link
Collaborator

also it seems using the ObjectMapper by default outputs invalid openAPI when validated by https://apitools.dev/swagger-parser/online/

@kevin70
Copy link
Contributor Author

kevin70 commented Feb 21, 2023

also it seems using the ObjectMapper by default outputs invalid openAPI when validated by https://apitools.dev/swagger-parser/online/

Yes, thank you for your repair. I ignored this problem at the beginning.

@SentryMan
Copy link
Collaborator

we can close this since the changes will be added in #164 (when it gets reviewed)

@kevin70 kevin70 closed this Mar 1, 2023
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