JAXB Swagger Plugin - my first contribution to the Open Source world
Tags: java, swagger, xsd, jaxb
Published: 2020-02-23 18:22:04

---
title: JAXB Swagger Plugin - my first contribution to the Open Source world
published: true
description: I have been waiting for this time to make my first contribution to the Open Source world and after a few weeks of investigation and development work finally it is here :)
tags: #java #swagger #xsd #jaxb
---

# Introduction

Hello everybody and welcome to my very first post on dev.to :)
I have been almost here for one year now (joined: Feb 24, 2019, just checked it now :D)
I have been a developer since 2016 but I always liked computer and programming, so basically after my official job I come home and I work on side-project with friends or just for fun. My main interests are Java related topics, I like both Spring and Java EE world and I think #Hibernate is my favorite third party framework (kudos to the boys/girls at JBoss).

I live and work in Debrecen, in Hungary, this is the second largest city in the country and there are a lot of opportunities for developers, the university is here for the upcoming devs, but I prefer coding related schools with more practical stuff :)

# What did I bring to you?
At my last job we were preferring XSD2Java class based DTO class generation with a lot of reasons and we were building microservice architecture based applications and we were providing functionalities for clients (both internal (internal applications) and external clients).

The documentation for these classes and API endpoints were mandatory and we were experimenting with [Swagger](https://swagger.io/), at this time we were a using Java EE related framework called [Thorntail](https://thorntail.io/) (a.k.a Wildfly Swarm), and it came really handy to just put some annotation on the classes and API endpoints to document them.

The problem was the following: 
- All of our DTOs, which were part of the communication, were generated by the 
**maven-jaxb2-plugin**
 and we were not able to annotate our generated classes because on the next generation the whole stuff would go to the trash can (/dev/null).

Solution: JAXB2 plugin supports external dependencies to take part in the class generation and we found a few options to extend our class generation phase.
This [Redlab Swagger JAXB Plugin](https://github.com/redlab/swagger-jaxb) helped us a lot but it just hepled us to annotate our fields with the proper Swagger annotations like [@ApiModel](https://github.com/swagger-api/swagger-core/blob/1.5/modules/swagger-annotations/src/main/java/io/swagger/annotations/ApiModel.java) and [@ApiModelProperty](https://github.com/swagger-api/swagger-core/blob/1.5/modules/swagger-annotations/src/main/java/io/swagger/annotations/ApiModelProperty.java), nothing special, if you take a closer look at these annotations you will see that there are a lot of configuration options like, the **required**, **allowableValues**, **description** attributes.

As I quited the company, they moved to the [OpenAPI](https://www.openapis.org/) specification which is a way more rich specification, I stayed with Swagger at my side-projects and at my job.
There is no problem with Swagger, OpenAPI just got a few new ways to express schemas.

I started to look around the internet, GitHub and I found that there is a lot of fork of the mentioned JAXB Plugin, and there is one which is way more expressive than the original one.
{% github Andreas-Maier-NTT/swagger-jaxb %}

This one deals with a lot of my concerns and does its job but I was still not satisfied with the solution, so I forked this repository and made my changes on it.


# The contribution

Here is the repository with my changes:
{% github nandorholozsnyak/swagger-jaxb %}

A detailed README.MD and some examples are provided, most of the features are covered by unit tests, but not all, the codes by redlab and by Andreas were a bit reworked but not all.

In my projects right now I use [Springfox](https://github.com/springfox/springfox) for Swagger functionality and with this little plugin all of my DTOs which take part in the communication with the clients are detailed.

If you are interested in a extended XSD2Java class generation with Swagger then this is your time to pull this dependency into your **pom.xml** and start generating :)


# Summary
Thank you for everybody who read my first blog post, I really appreciate it, and because I'm really new to writing I'm eager for some feedback in the comment section.

I'm curious if anybody is still using XSD schemas to generate their Java classes or maybe JSON schemas took over (btw I validate the incoming request against these schemas, so there is no surprise in the business logic ;))

Let me know what do you guys think about that and feel free to open issues or PR's.

I try to maintain the code, the code quality is not the best, I'm still wondering on a lof of refactor options but for know, it is okay to use, as I will use it from now ;)