diff --git a/datatypes-examples.xml b/datatypes-examples.xml
new file mode 100644
index 00000000..a54cee39
--- /dev/null
+++ b/datatypes-examples.xml
@@ -0,0 +1,347 @@
+
+
+
+ 2017-06-27T10:00:00+02:00
+ 2017-06-27T11:00:00+02:00
+ Oppmøte senest 15 minutter før timen
+ Oslo City Røntgen
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+ Undersøke smerter i ryggen
+
+ Informasjon om Oslo City Røntgen
+ Oslo City Røntgen er et spesialistsenter for avansert bildediagnostikk.
+
+
+
+
+
+
+ 23
+ Storgata
+ 0011
+ Oslo
+
+
+ 0301
+ 208
+ 630
+ 0
+ 0
+
+
+ externalId
+
+
+ Gunnar Gunnersen
+ gunnargunnar@gunn.ar
+
+ 59
+ 3
+ 4
+
+ 2017-07-27T10:00:00+02:00
+ Privat salg av sekundærbolig
+ Bill Isalg
+ Cooper Coopersen
+ 12345678
+
+ 123456789
+ H1337
+ 42
+
+ TNT ASA
+ Pantedokument
+ 3000000000
+
+
+ https://www.example.com
+ Gå til avsenders side for å gjøre en handling
+ Ta meg til handling!
+
+
+
+
+ Kommunestyre- og fylkestingvalg
+
+ 2019-05-23T10:00:00+02:00
+ 2019-05-23T16:00:00+02:00
+
+ Opening hours
+ Velkommen til valg! Husk legitimasjon.
+ Sagene skole
+ Election venue
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+
+ Forhåndsstemming
+ Du kan forhåndsstemme fra 10. august
+
+ Barcode for use on election day:
+
+ 1234567890
+ code-128
+ Show barcode for faster identification
+ true
+
+
+ https://valg.no
+ Les mer om valget på valg.no
+
+
+
+
+ https://www.oslo.kommune.no/barnehage/svar-pa-tilbud-om-plass/
+ 2017-09-30T13:37:00+02:00
+ Oslo Kommune ber deg akseptere eller avslå tilbudet om barnehageplass.
+ Svar på barnehageplass
+
+
+
+
+
+ KB432788293NO
+ 70300492517312675
+
+ 1234567890
+ CODE_128
+ Show barcode for faster identification
+ true
+
+ Klimanøytral Servicepakke
+ 2018-09-10T10:00:00+02:00
+ 2018-09-24T10:00:00+02:00
+
+ Test Testesen
+ test.testesen#0000
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+
+
+ Avsenderservice as
+ 13372500
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+
+
+ Coop Mega
+ RC89
+ Må hentes innen 010180
+ H32
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+
+
+ 120
+ 60
+ 60
+ 35000
+
+
+ 128.00
+ 1277.00
+ 162.00
+ FORENKLET TOLLBEHANDLING
+ 0
+ 0
+ 0
+ 0
+
+ READY_FOR_PICKUP
+ POSTEN
+
+
+
+ READY_FOR_PICKUP
+ 2019-01-10T10:10:00+01:00
+
+
+
+ Bekkestua Bibliotek
+ #e1e1e1
+ 2019-05-23T10:00:00+02:00
+
+
+ 2020
+ 2022
+
+ 1
+ 1
+
+
+ 12
+ 31
+ 0
+ 0
+ +01:00
+
+
+
+
+ Ola
+ Nordmann
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+
+ Lånekort
+ Lånekortnummer
+ a-132415124-xyzzy-21341
+
+ Kaffeklubb
+ Premium deluxe medlem
+
+
+ Regler
+ Det er ikke lov å rive ut sider i bøkene, eller søle med ketchup. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec aliquet urna condimentum, pulvinar neque ac, tempor tellus. Vestibulum ante ipsum primis in faucibus orci luctus et
+
+
+
+
+ F96B6805-2453-478A-B58B-CCDFA07E21ED
+ 364567
+ 2018-05-27T10:00:00+02:00
+ 59.80
+ 11.96
+ NOK
+ Benny
+ 15
+ 7F5A1EFF-ECAE-48A7-A07F-38D87576F815
+ Grünerløkka Hip Coffee
+ 12345678
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+ 123456789
+
+ 1234567890
+ code-128
+ Show barcode for faster identification
+ true
+
+
+ Bank Axept
+ ************1234
+ Visa
+ 100.00
+ NOK
+
+ USD
+ 15
+ 7.534567
+
+
+
+ Tall Cafe latte
+ Tall vanilla latte with extra sugar
+ 0000012
+ cup
+ 2.0
+ 29.90
+ 5.98
+ 59.80
+ 11.96
+ 5.50
+ XY12345325GF
+ 1345678
+
+
+ EK99999
+ 12341ASDF
+ 123456789
+ 2018-06-05T10:00:00+02:00
+ 2018-06-05T10:30:00+02:00
+ 8.00
+ 438.50
+ 2000
+ 8500
+ 6500
+ 320
+ 1220
+ 900
+
+
+ 400.00
+ 320.00
+ 80.00
+ 25.00
+
+ 64.90
+
+
+
+ Ola Nordmann
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+ Delivered to the doorstep
+
+
+ Ola Nordmann
+
+ Storgata 23
+ 0011
+ Oslo
+ Norge
+
+ Delivered to the doorstep
+
+ 123456
+ HG1234HH8778
+ Hip Coffee to the good citizens of Løkka
+
+
+
+
+ 23
+ Storgata
+ 0011
+ Oslo
+
+
+ 0301
+ 208
+ 630
+ 0
+ 0
+
+
+ externalId
+
+
+
+ Bedrift AS
+ Ansettelseskontrakt
+ 2018-07-11T10:00:00+02:00
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 7d98616a..b309fd50 100644
--- a/pom.xml
+++ b/pom.xml
@@ -298,7 +298,7 @@
package
no.digipost.api.datatypes.documentation.DocumentationGenerator
- ${basedir}/readme.md
+ ${basedir}/readme.md ${basedir}/datatypes-examples.xml
java
diff --git a/readme.md b/readme.md
index f5cf0b97..2b1cf7c8 100644
--- a/readme.md
+++ b/readme.md
@@ -43,7 +43,6 @@ Appointment represents a meeting set for a specific place and time
### XML
```xml
-
2017-06-27T10:00:00+02:00
2017-06-27T11:00:00+02:00
@@ -127,7 +126,6 @@ Details about a Residence, and may be joined with Residence to retrieve the core
### XML
```xml
-
@@ -218,7 +216,6 @@ Event represents an event that occurs over a time period or several days. Eg. a
### XML
```xml
-
Kommunestyre- og fylkestingvalg
@@ -269,7 +266,6 @@ An external URL, along with an optional description and deadline for resources s
### XML
```xml
-
https://www.oslo.kommune.no/barnehage/svar-pa-tilbud-om-plass/
2017-09-30T13:37:00+02:00
@@ -291,7 +287,6 @@ For treating documents as Payslips.
### XML
```xml
-
```
@@ -400,7 +395,6 @@ Valid values:
### XML
```xml
-
KB432788293NO
70300492517312675
@@ -490,7 +484,6 @@ Valid values:
### XML
```xml
-
READY_FOR_PICKUP
2019-01-10T10:10:00+01:00
@@ -571,7 +564,6 @@ Represents a legal document (Certificate, Licence, Permit, etc.) issued to a sin
### XML
```xml
-
Bekkestua Bibliotek
#e1e1e1
@@ -712,7 +704,6 @@ Receipt represents a document containing details about a purchase
### XML
```xml
-
F96B6805-2453-478A-B58B-CCDFA07E21ED
364567
@@ -850,7 +841,6 @@ Residence is a way of linking separate data for the same residence
### XML
```xml
-
23
@@ -885,7 +875,6 @@ Details about a signed document
### XML
```xml
-
Bedrift AS
Ansettelseskontrakt
diff --git a/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java b/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java
index 2b56753e..ef30a107 100644
--- a/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java
+++ b/src/main/java/no/digipost/api/datatypes/documentation/DocumentationGenerator.java
@@ -7,9 +7,7 @@
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.nio.file.*;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
@@ -20,7 +18,9 @@ public class DocumentationGenerator {
public static void main(String[] args) throws IOException, JAXBException {
final Path outputPath = Paths.get(args[0]);
+ final Path examplesOutputPath = Paths.get(args[1]);
DocumentationGenerator.generate(outputPath, DataTypeIdentifier.getAllClasses(), DocumentationGenerator::getDataTypeExample);
+ DocumentationGenerator.generateExamples(examplesOutputPath, DataTypeIdentifier.getAllClasses(), DocumentationGenerator::getDataTypeExample);
}
public static DataType getDataTypeExample(Class extends DataType> dataType) {
@@ -32,4 +32,18 @@ private static void generate(Path outputPath, Set> typesT
final String markdown = new MarkdownPrinter(DataTypesJAXBContext.getSingleton(), false).print(types.collect(toList()));
Files.write(outputPath, markdown.getBytes(StandardCharsets.UTF_8));
}
+
+ private static void generateExamples(Path outputPath, Set> typesToDocument, Function, T> getExample) throws IOException, JAXBException {
+ final Stream types = DocumentationStructureBuilder.buildTypeStructure(typesToDocument, getExample);
+
+ Files.write(outputPath, "".getBytes());
+ Files.write(outputPath, ("" + System.lineSeparator() + "" + System.lineSeparator()).getBytes(), StandardOpenOption.APPEND);
+
+ for (ComplexType complexType : types.collect(toList())) {
+ final String xml = new MarkdownPrinter(DataTypesJAXBContext.getSingleton(), false).getXmlExample(complexType.getExample());
+ Files.write(outputPath, xml.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
+ }
+
+ Files.write(outputPath, "".getBytes(), StandardOpenOption.APPEND);
+ }
}
diff --git a/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java b/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java
index 6ba0fb1a..dc93173d 100644
--- a/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java
+++ b/src/main/java/no/digipost/api/datatypes/documentation/MarkdownPrinter.java
@@ -69,13 +69,17 @@ private String printComplementedByInformation(ComplexType type) {
}
private String printXmlExample(Object example) {
+ return heading(3, "XML") + LLF + code("xml", getXmlExample(example).trim());
+ }
+
+ public String getXmlExample(Object example) {
try {
final StringWriter writer = new StringWriter();
final Marshaller marshaller = jaxb.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
marshaller.marshal(example, writer);
- return heading(3, "XML") + LLF +
- code("xml", writer.toString().trim());
+ return writer.toString() + LLF;
} catch (JAXBException e) {
throw new RuntimeException(e);
}
diff --git a/src/test/resources/no/digipost/api/datatypes/documentation/testdoc.md b/src/test/resources/no/digipost/api/datatypes/documentation/testdoc.md
index 269fe1e2..9d09fc49 100644
--- a/src/test/resources/no/digipost/api/datatypes/documentation/testdoc.md
+++ b/src/test/resources/no/digipost/api/datatypes/documentation/testdoc.md
@@ -39,7 +39,6 @@
### XML
```xml
-
Dette er en kort melding til deg