1

I want to create a soap endpoint but have my kotlin data classes as single point of truth (I do not have an XSD to hand and I want to use spring which just supports contract-first)

I hardly found anything about generating an xsd from java classes, just the other way around.

Does someone have experience with how to generate an XSD from kotlin data classes in gradle?

Many thanks

Ruth
  • 856
  • 2
  • 13
  • 26
  • Maybe [schemagen](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/schemagen.html) is what you are looking for... Alternatively you can also generate the schema using [`JAXBContext#generateSchema`](https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/JAXBContext.html#generateSchema-javax.xml.bind.SchemaOutputResolver-)... – Roland Oct 29 '19 at 12:27
  • @Roland thank you for your message. I had a look and tried that already. with java classes it works exactly as expected. but the kotlin data classes seem to be ignored. Any idea what I could do? Cannot find anythin in the internet unfortunately :( – Ruth Oct 29 '19 at 15:20
  • ah, I see... missed that `schemagen` takes `java`-files as input... do you use `JAXB`-annotations or do you only want the `data class`(es) to transform into a schema file? – Roland Oct 29 '19 at 15:49
  • I did add the annotations that were generated on the java classes as a trial. you can see my data from the sample project [here](https://github.com/huehnerlady/gs-producing-web-service/blob/kotlin/complete/src/main/kotlin/hello/api/Api.kt) – Ruth Oct 31 '19 at 14:40
  • just wondering... did you also try to write out the schema ~manually using `JAXBContext.generateSchema`? [This answer contains some sample code](https://stackoverflow.com/a/24041280/6202869) – Roland Oct 31 '19 at 15:27

1 Answers1

0

I suggest that you convert the Kotlin classes to Java classes like described here: https://www.baeldung.com/kotlin/convert-to-java .

Then use schemagen from your local Java home. E.g.:

.\schemagen.exe -d "C:\xsd\" *.java
Tom Reineke
  • 332
  • 4
  • 6