Showing results for 
Search instead for 
Did you mean: 

Creating OpenAPI definition from Java code

New Contributor

Creating OpenAPI definition from Java code

I have need to convert an API defintion to OpenAPI. The existing defintion is expressed as a Java class so I need to use the Java API to convert this.

Are there any examples of how to generate OpenAPI from plain Java?


Re: Creating OpenAPI definition from Java code



You can add annotations to your java classes, and then you will be able to generate the OpenAPI Specification. 

In this wiki address you will find some samples:


If you haven't integrated Swagger to your project you need to do it, but it will depend on the Api Implementation you are using, you can see this samples: 





If you have any questions, don't hesitate to contact us. 


Have a nice day!

New Contributor

Re: Creating OpenAPI definition from Java code

I don't think that's quite what I'm needing.

I have a Java class that describes an API, a bit like your io.swagger.v3.oas.models.OpenAPI class. This definition contains many of the attributes that are needed for an OpenAPI descriptor.

So what I need to do is translate from my descriptor to the OpenAPI descriptor. One instance of my descriptor would be translated into one instance of OpenAPI. And this would be done in Java code.

I've got a very basic initial example working, but was hoping there were examples available that describe how to create an OpenAPI instance in all its aspects.


Re: Creating OpenAPI definition from Java code

Technically, you can do what you're trying to achieve, but it would require some coding. You can follow a similar logic to what the Reader class does for reading the annotations and parsing them into an OpenAPI object, just create it with your own logic of converting your existing structure to the OpenAPI object.

Share Your Stories
Read Latest News
Top Kudoed Authors