This project allows you to convert an XML file into OpenAPI 2.0 (Swagger 2.0) documentation in JSON format.
The module also contains all the implementation of the Swagger model in Java class.
You can thus :
- convert an XML file into Swagger Java objects
- convert XML file to Swagger Json Documentation
- convert Swagger Java objects to Swagger Json Documentation
You can find a very detailed documentation here.
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.
Version: 2.1
Allows you to transform the XML structure into a Java class
Version: 20210307
JSON Library is an open source Java library for serializing and deserializing Java objects in JSON
The module takes an XML file as input which it will convert into Java classes (thanks to JAXB). Once the Java classes have been obtained, the module will create the json swagger 2.0 using the JSON library. The module will return the JSON code.