# Creating OpenAPI definition from Java code

**URL:** <https://community.smartbear.com/t/creating-openapi-definition-from-java-code/220>\
**Category:** Swagger OS\
**Tags:** api, migrated, swagger-oss, swagger-core\
**Created:** [December 3, 2018, 12:37pm UTC](https://community.smartbear.com/t/creating-openapi-definition-from-java-code/220 "2018-12-03T12:37:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [December 3, 2018, 12:37pm UTC](https://community.smartbear.com/t/creating-openapi-definition-from-java-code/220/1 "2018-12-03T12:37:41Z")

</div>

> Originally posted by **tdudgeon** on December 03, 2018

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?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [December 3, 2018, 1:04pm UTC](https://community.smartbear.com/t/creating-openapi-definition-from-java-code/220/2 "2018-12-03T13:04:57Z")

</div>

> Originally posted by **ralphdoe** on December 03, 2018

Hello.

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:

[https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations](https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations)

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:

Resteasy: [https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-RESTEasy-2.X-Project-Setup-1.5](https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-RESTEasy-2.X-Project-Setup-1.5)

Jersey: [https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-RESTEasy-2.X-Project-Setup-1.5](https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-RESTEasy-2.X-Project-Setup-1.5)

Spring: [https://github.com/ralphdoe/opentech](https://github.com/ralphdoe/opentech)

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

Have a nice day!

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [December 3, 2018, 1:41pm UTC](https://community.smartbear.com/t/creating-openapi-definition-from-java-code/220/3 "2018-12-03T13:41:13Z")

</div>

> Originally posted by **tdudgeon** on December 03, 2018

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.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [December 3, 2018, 6:25pm UTC](https://community.smartbear.com/t/creating-openapi-definition-from-java-code/220/4 "2018-12-03T18:25:03Z")

</div>

> Originally posted by **RonRatovsky** on December 03, 2018

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](https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java) 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.

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [October 7, 2026, 5:13pm UTC](https://community.smartbear.com/t/creating-openapi-definition-from-java-code/220/5 "2026-10-07T17:13:44Z")

</div>

Closed on October 7, 2026, 5:13pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
