Skip to content
Thomas Lapierre edited this page Jun 8, 2021 · 17 revisions

xml2swagger Wiki

You will be able to find the explanation of the project and its functioning.

Introduction

The developed Java module allows to convert an XML file into JsonSwagger 2.0. The XML file specified as input has a very specific form: see here.

The XML input file is based on the simplified swagger conventions that you can find here.

Warning: Not everything has been implemented

Pull requests are welcome!

As for the output Json Swagger 2.0 file, it corresponds to the Swagger 2.0 standard (OpenAPI 2.0) which you can find here.

General Functioning

The module will first convert the XML file into Java classes via the JAXB library. Once the Java classes are obtained, the module will feed a Json file which will become the OpenAPI 2.0 file (Swagger 2.0).

Usage

There are two ways to use the module depending on your needs.

In any case, you will need to download the ".jar" file: swagger2xml.jar

Use the module via the command prompt:

To do this you must:

  • Place yourself in the directory of the ".jar" file downloaded above
  • Type the command

java -jar xml2swagger.jar -f <file-name.xml>

for example java -jar xml2swagger.jar -f desktop/perso/example1.xml

-------------or-------------

java -jar xml2swagger.jar -s "<xml-string>"

for example java -jar xml2swagger.jar -s "<global> <rest>...</rest> </global>"

Note:

-s option allows to specify an xml string -s means string input

-f option allows to specify an .xml file address -f means file input

Use the module in the Java source code:

You can also use the module directly in the code.

To do so, you just have to import the .jar file downloaded above in the buildpath of your project.

Then you will benefit from four methods :

Method Description
XmlParser.xmlFileToSwaggerJson(File file); Convert xml file into swagger Json
XmlParser.xmlStringToSwaggerJson(String xml); Convert xml string into swagger Json
XmlParser.xmlFileToJavaClass(File file) Convert xml file into Java class
XmlParser.xmlStringToJavaClass(String xml) Convert xml string into Java class
XmlParser.javaClassToSwaggerJson(Global globalObject) Convert a Global object into a swagger json documentation

The Java class conversion methods are there to increase the development possibilities for people using the module and to offer export methods in YAML instead of Json or the generation of PDF, HTML, etc.

Dependancies

JAXB (Java Architecture for XML Binding)

Version: 2.1

Allows you to transform the XML structure into a Java class

JSON Library

Version: 20210307

JSON Library is an open source Java library for serializing and deserializing Java objects in JSON

Clone this wiki locally