简体   繁体   中英

Swagger 2.0 (Open Api 3.0) with Play Framework 2.6 (Java)

There is swagger-play plugin, that says to support Swagger 2.0, however actually it uses swagger annotations 1.5.x , not 2.0, thus, not supporting Open Api 3.0.

Has anyone managed to wire Open Api 3 with Play Framework using code-first interface declaration?

I tried to declare explicit swagger-core dependency as

"io.swagger.core.v3" % "swagger-core" % "2.0.5"

but with no success, ie I get errors at initializing plugin:

[error] 1) Error injecting constructor, java.lang.NoClassDefFoundError: Could not initialize class io.swagger.converter.ModelConverters
[error]   at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:35)
[error]   while locating play.modules.swagger.SwaggerPluginImpl
[error]   at play.modules.swagger.SwaggerModule.bindings(SwaggerModule.scala:11):
[error] Binding(interface play.modules.swagger.SwaggerPlugin to ConstructionTarget(class play.modules.swagger.SwaggerPluginImpl) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
[error]   while locating play.modules.swagger.SwaggerPlugin

It seems the Open API 3.0 support in swagger-play is not planned in immediate future as per this - Swagger/OpenAPI 3.0 support? .

An alternate solution for this can be iheartradio/play-swagger . Reference to this alternative is also mentioned in the swagger-play But with this alternate api you can specify the Open API 3.0 Specs as comments in the form of JSON or YAML inside your play Route file and not as an annotation in controller.

Alternatively the specs can be maintained (using swagger-editor ) in a separate JSON / YAML file and can be viewed/exposed via swagger-ui or other Open API spec supporting viewer like OpenAPI-GUI .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM