Giter VIP home page Giter VIP logo

Comments (9)

dzikoysk avatar dzikoysk commented on June 2, 2024

Currently, the security scheme section can be configured via OpenApiPluginConfiguration. Take a look at the example module:

// Based on official example: https://swagger.io/docs/specification/authentication/oauth2/
.withSecurity(new SecurityComponentConfiguration()
.withSecurityScheme("BasicAuth", new BasicAuth())
.withSecurityScheme("BearerAuth", new BearerAuth())
.withSecurityScheme("ApiKeyAuth", new ApiKeyAuth())
.withSecurityScheme("CookieAuth", new CookieAuth("JSESSIONID"))
.withSecurityScheme("OpenID", new OpenID("https://example.com/.well-known/openid-configuration"))
.withSecurityScheme("OAuth2", new OAuth2("This API uses OAuth 2 with the implicit grant flow.")
.withFlow(new ImplicitFlow("https://api.example.com/oauth2/authorize")
.withScope("read_pets", "read your pets")
.withScope("write_pets", "modify pets in your account")
)
.withFlow(new ClientCredentials("https://api.example.com/credentials/authorize"))
)
.withGlobalSecurity(new Security("OAuth2")
.withScope("write_pets")
.withScope("read_pets"))
)

from javalin-openapi.

franck-malka avatar franck-malka commented on June 2, 2024

from javalin-openapi.

dzikoysk avatar dzikoysk commented on June 2, 2024

I think I need more information, because the example works properly. When you'll visit the OpenApi scheme, the following properties are added to the scheme & Swagger UI picks them up.

Could you provide an example with highlighted difference between generated scheme and expected result?

from javalin-openapi.

franck-malka avatar franck-malka commented on June 2, 2024

from javalin-openapi.

dzikoysk avatar dzikoysk commented on June 2, 2024

The code you gave:

.withSecurity(new SecurityComponentConfiguration()
  .withSecurityScheme("OAuth2", new OAuth2("This API uses OAuth 2 with the implicit grant flow.")
      .withFlow(new ImplicitFlow("https://api.example.com/oauth2/authorize")
      .withScope("read_pets", "read your pets")
      .withScope("write_pets", "modify pets in your account")
  )
  .withFlow(new ClientCredentials("https://api.example.com/credentials/authorize"))
)
.withGlobalSecurity(new Security("OAuth2")
  .withScope("write_pets")
  .withScope("read_pets"))
)

Produces valid scheme:

obraz

Make sure that you use the latest version of OpenAPI plugin & annotation processor runs on updated sources (clean package / clean build)

from javalin-openapi.

franck-malka avatar franck-malka commented on June 2, 2024

from javalin-openapi.

dzikoysk avatar dzikoysk commented on June 2, 2024

Could you prepare a small example repository that I can clone & run to reproduce your issue?

from javalin-openapi.

franck-malka avatar franck-malka commented on June 2, 2024

from javalin-openapi.

dzikoysk avatar dzikoysk commented on June 2, 2024

For configuration:

For annotations:

That's basically all we have, and it reflects 1:1 the OpenAPI specification, so that's the best source of truth there.

from javalin-openapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.