Here was my process to generate XML schemas.
- Created Java classes annotated with XStream annotations
- Created example objects from the classes and marshalled them to XML via Spring's XStreamMarshaller
- Cut and pasted the XML into Freeformatter's XSD/XML Schema Generator
- Saved the generated .xsd file locally and tweaked it to so as to provide missing information such as:
- Enumerations
- set appropriate minOccurs and maxOccurs attributes on elements
- Validated my XML and my edited schema file by pasting them into Freeformatter's XML Validator - XSD (XML Schema)
- Tweaked the Java classes as necessary
- Rinse and Repeat until done
The process to generate JSON examples:
- The Java classes were annotated with Fasterxml's Jackson annotations
- Created example objects from the classes and serialized them using Jackson's ObjectMapper
To generate the documentation, I leveraged the code that generated the XML and JSON examples and wrote them to individual files on the filesystem. I then created AsciiDoctor .adoc templates that described the services and included the XSD, XML, and JSON files. Running Asciidoctor against the .adoc templates generates nice HTML that includes everything.