cancel
Showing results for 
Search instead for 
Did you mean: 

Need help enabling OpenAPI into non-spring java project

anirtek
Occasional Contributor

Need help enabling OpenAPI into non-spring java project

I am using jetty server that is initiated with a port and threadconnectionpool. I add the handlers to the contexts object and then all my APIs are in the com.example.handler package. 

 

I am very very new to the OpenAPI and I want to document all my above apis. How do I get started from scratch? I mean what kind of dependencies do I need and also what should I do to hook up my project with openApi? 

8 REPLIES 8
joejoyce
Staff

Re: Need help enabling OpenAPI into non-spring java project

Hey @anirtek; have you looked into using swagger-core? It's a Java implementation of the OpenAPI Specification. The documentation in the link should help you get started with your new project.

 

 

anirtek
Occasional Contributor

Re: Need help enabling OpenAPI into non-spring java project

@joejoyce this is a great suggestion. Infact I am looking for solution in Jakarta namespace only. I will try to use this. But would this automatically generate the OpenAPI yaml after code annotation? Or I will have to use some tool to get the yaml first? I am trying to generate yaml from code annotations. Can you provide something about this confusion? 

hugomario
Staff

Re: Need help enabling OpenAPI into non-spring java project

Hello @anirtek 

 

I recommend you to use https://editor.swagger.io/

 

From there, you can work with yours open api definitions and generate code for multiples language/frameworks, no only spring.

 

Hope that helps.

joejoyce
Staff

Re: Need help enabling OpenAPI into non-spring java project

@anirtek yes indeed; using the swagger-core method, the Swagger/OAS contract is generated from an API based on the meta-data added against the various resources, methods and controllers. This meta-data will generate the contract, client-side code, and other artifacts during runtime. Typically, this meta-data will be in the form of code annotations. 

 

You'll find some more useful documentation on this here.

 

Hope this helps!

anirtek
Occasional Contributor

Re: Need help enabling OpenAPI into non-spring java project

@hugomario the reason I can not do that is I have an existing project that runs on Jetty 11.

anirtek
Occasional Contributor

Re: Need help enabling OpenAPI into non-spring java project

@joejoyce I think swagger core project is what I am looking for. But I need some more help about this.

 

In the Where to start section, it says - 

since version 2.0.5, swagger-core project also provides maven and gradle plugins to resolve an OpenAPI definition at build time. As these are based on the same resolving and configuration mechanisms, most information in the wiki applies also in this case.

 

I have added the swagger-core Gradle plugin in the id section and other dependencies in the Jakarta namespace in dependencies. 

 

Now if my code is annotated, should I see the swagger-ui directly when I run my project or I need to configure swagger-ui in my main method? 

anirtek
Occasional Contributor

Re: Need help enabling OpenAPI into non-spring java project

@joejoyce @hugomario I am trying to user swagger-core-gradle-plugin. But I am confused about 1 thing - whether I need to specify jakarta artifact.  I have set my gradle plugin as follows: 

id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.9"

But since I am using Jetty 11 which works with jakarta namespace only, do I need to set buildClasspath = classpath so that my gradle dependencies will refer to jakarta based builds?  If I use the plugin with suffix `jakarta`, that does not seem to have fetching the packages. Can someone please help? 

anirtek
Occasional Contributor

Re: Need help enabling OpenAPI into non-spring java project

How do I configure swagger-core into jersey3.0.2?

New Here?
Join us and watch the welcome video:
Top Kudoed Authors