Coder Social home page Coder Social logo

reaster / schema-gen Goto Github PK

View Code? Open in Web Editor NEW
28.0 4.0 7.0 425 KB

XML Schema code generator outputting Swift, Kotlin and Java

License: Apache License 2.0

Groovy 100.00%
xml-schema kotlin swift java json schema-gen schema-generation code-generation jackson-json-processor jackson

schema-gen's Introduction

schema-gen

schema-gen is a multi-language, interoperable, XML Schema code generator. The generated code allows reading, writing, manipulating, and transmitting data in the two most widely used industry formats: XML and JSON. Currently supported languages are Java 8, Kotlin 1, Swift 4 and Dart 2.1. The code is interoperable, meaning it's well suited for developing cross-language, mobile, client-server applications.

Producing concise, readable code is a top schema-gen priority, providing a high level of flexibility and configurability.

This software is written in Groovy and is packaged as a Gradle plugin.

Build Status

Currently Supported Languages

Java

Features: Generated POJOs contain Jackson annotations supporting reading and writing both JSON and XML documents. XML Schema restrictions are translated into Bean Validation 2.0 annotations. Equals, hashCode and toString methods are also generated to facilitate testing. See the java-gpx sample project.

Usage: The main entry point is com.javagen.schema.java.JavaGen which can be invoked directly or via the gradle plugin. By default, the generated code is placed in the src/main/java-gen folder to keep it separate from hand-written code.

Limitations: A limitation of the Java langauge is that it does not support the extension features of more recent languages, making it harder to maintain a clean separation between hand-written and generated code. You may be forced to put your business logic in the generated files with the downside being, if you ever have to regenerate, you'll have to manually merge your code back in.

Kotlin

Features: By leveraging data classes, Kotlin generated code is very concise. Classes contain Jackson annotations supporting reading and writing both JSON and XML documents. XML Schema restrictions are translated into Bean Validation 2.0 annotations. Extending generated code with business logic can be achieved using extensions. See the kotlin-gpx sample project.

Usage: The main entry point is com.javagen.schema.kotlin.KotlinGen which can be invoked directly or via the gradle plugin. By default, the generated code is placed in the src/main/kotlin-gen folder to keep it separate from hand-written code.

Limitations: The code generator attempts to create no-argument constructors by setting default values on every property, which in some cases can cause problems. To minimize unessasary annotations, the generated code requires Java 8 parameter name support. See the build.gradle and unit tests in kotlin-gpx for proper setup and configuration.

Swift

Features: schema-gen generates code utilizing the built-in Encodable and Decodable JSON support introduced in Swift 4. Extending generated code with business logic can be achieved using Extensions. See the swift-gpx sample project.

Usage: The main entry point is com.javagen.schema.swift.SwiftGen which can be invoked directly or via the gradle plugin. By default, the generated code is placed in the src/swift-gen folder to keep it separate from hand-written code.

Limitations: Swift only supports JSON serialization. Assuming you're server is written in Kotlin or Java, communication with a Swift client can utilize JSON, even if the documents are stored as XML, thanks to Jackson's support of both. However, given a good XMLEncoder, XML support should be straight forward to add. The author wrote saxy in Objective-C the last time around and it's somebody else's turn to do this for Swift ;-)

Dart

Features: schema-gen generates model code decorated with json_annotation JSON directives. Extending generated code with business logic can be achieved using Dart's part support.

Usage: The main entry point is com.javagen.schema.dart.DartGen which can be invoked directly or via the gradle plugin. By default, the generated code is placed in the lib folder.

Limitations: Dart only supports JSON serialization. Assuming you're server is written in Kotlin or Java, communication with a Dart client can utilize JSON, even if the documents are stored as XML, thanks to Jackson's support of both.

Usage

Gradle Plugin

Note: currently not being supported.

schema-gen includes a Gradle Plugin which can be added to your gradle.build file by including it in your buildscript, and applying and configuring it:

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.javagen:schema-gen:0.9.1'
    }
}

apply plugin: 'com.javagen.schema-gen'

schemaGen {
    swift {
        schemaURL = new URL('http://www.topografix.com/gpx/1/1/gpx.xsd')
    }
}

To generate code use the gen task:

swift-gpx> gradle gen

To remove the generated code, use the genClean task:

swift-gpx> gradle genClean

To install the Gradle plugin locally, use the maven install task:

schema-gen> gradle install

A good starting point is to download the schema-gen-examples project, regenerate the code and run the tests:

schema-gen-examples> gradle genClean gen test

Running the Generators in your IDE

For code generator development work, you'll want to run the target language gen class (JavaGen, KotlinGen, SwiftGen) directly. There are three main launcher classes you can adpot for this purpose (JavaGenMain, KotlinGenMain, SwiftGenMain). If you place your project (say, java-atom) in the same parent directory as schema-gen, you can hard-code your configuration in the JavaGenMain class as follows:

class JavaGenMain extends JavaGen
{
    def initAtom()
    {
        schemaURL = new URL('file:../java-atom/src/main/resources/atom.xsd')
        srcDir = new File('../java-atom/src/main/java-gen')
        packageName = 'org.w3.atom.java'
        addSuffixToEnumClass = null
        anyPropertyName = 'text'
    }

    JavaGenMain()
    {
        super()
        initAtom()
    }

    static void main(String[] args) {
        new JavaGenMain().gen()
    }
}

Then you can point your IDE at JavaGenMain in the schema-gen project and the generated code will be put in your java-atom project. See schema-gen-examples/java-atom for working atom.xsd and xml.xsd files.

Configuration

The code generator is designed to be highly customizable. In particular, how it names classes, properties, and enumerations is all encoded in configurable properties and lambdas. Here is a sampling of the properties that can be overridden in the Gen base class:

URL schemaURL = new URL('http://www.topografix.com/gpx/1/1/gpx.xsd')
File srcDir = new File('src/main/java-gen')
List<MVisitor> pipeline = []
PluralService pluralService = new PluralService()
def customPluralMappings = [:] //needed for irregular nouns: tooth->teeth, person->people
boolean useOptional = false //just effects Java code: Integer vs Optional<Integer>
String packageName = null
String addSuffixToEnumClass = 'Enum'
String removeSuffixFromType = 'Type'
String fileExtension = 'java'

Function<String,String> packageNameFunction = { ns -> packageName ?: ns ? GlobalFunctionsUtil.javaPackageFromNamespace(ns, true) : 'com.javagen.model' }
Function<String,String> enumNameFunction = { text -> GlobalFunctionsUtil.javaEnumName(text, false) }
Function<String,String> enumValueFunction = { text -> text }
Function<String,String> enumClassNameFunction = { text -> GlobalFunctionsUtil.enumClassName(text, addSuffixToEnumClass) }
Function<String,String> classNameFunction = { text -> GlobalFunctionsUtil.className(text, removeSuffixFromType) }
Function<String,String> propertyNameFunction = { text -> GlobalFunctionsUtil.legalJavaName(lowerCase(text)) }
Function<String,String> constantNameFunction = { text -> GlobalFunctionsUtil.javaConstName(text) }
Function<String,String> collectionNameFunction = { singular -> customPluralMappings[singular] ?: pluralService.toPlural(singular) }
Function<String,String> simpleXmlTypeToPropertyType
BiFunction<Gen,MClass,File> classOutputFileFunction = { gen,clazz -> new File(gen.srcDir, GlobalFunctionsUtil.pathFromPackage(clazz.fullName(),fileExtension))} //default works for Java

These properties can be set in the Gradle plugin for each of the target languages:

schemaGen {
    kotlin {
        srcDir = new File('../kotlin-gpx/src/main/kotlin')
    }
    swift{
        srcDir = new File('../swift-gpx/src/swift-gen')
    }
    java {
        srcDir = new File('src/main/java')
        packageName = 'com.javagen.model'
    }

 }

Status

Although the design went through three iterations and is now stable as of 2017, the code is still being cleaned up. It has yet to be tested against a wide variety of schemas, so issues should be expected when trying new schemas.

Limitations

Xml Schema

Mixed Content

This code generator is not intended to support document-centric (versus data-centric) code like HTML. In particular, mixed content (mixed tags and text) is not well supported and will often be mapped to a single string property.

AttributeGroup

Currently, AttributeGroup are in-lined (i.e. expaned where they are referenced) and not mapped to a specific, re-usable entity (interface, class, trait, etc.)

Group

Currently, Group elements are in-lined (i.e. expanded where they are referenced) and not mapped to a specific, re-usable entity (interface, class, trait, etc.)

Union

Unions often consist of 2 or more TextOnlyTypes merged together with their attached restrictions. If these restrictions are all enumerations, the union of unique values will be modeled properly. However, in other cases - say mixing numeric and string values - you will get a warning and probably an incorrect mapping.


Architecture

For developers wishing to extend this framework, here is a quick overview of how it's put together.

XmlSchemaNormalizer

To simplify the schema-to-code translation process, the XML schema is normalized (references removed, etc.) as the first step in the code generation process. The results are stored in a Schema instance which tracks schema types (TestOnlyType, SimpleType and ComplextType), elements, attributes and other needed constructs. QNames support mixed namespace schemas.

Gen

The translation classes (JavaGen, KotlinGen, SwiftGen, etc.) walk the normalized schema and generate an abstract code model: MModule, MClass, MProperty, etc.

Callbacks

Code generation for supported third party libraries is handled via callback classes that typically set annotations and interfaces expected by the library. See KotlinJacksonCallback for an example.

Emitters

An emitter exists for each supported language and takes the abstact model and converts it into the target computer langauge. See JavaEmitter as an example.

PreEmitters

These do the grunt work of generating boiler-plate code for methods such as equals, hashCode and toString. The developer can simply add a method with the proper stereotype and the PreEmitter will generate the rest. See SwiftPreEmitter as an example.

TypeRegistry

Each langauge needs a type registry, specific to it's supported types along with how to translate these from XML schema types.


Change Log

0.9.1

At the schema level, add suport for compositors (all, sequence, choice), support for substitutionGroup, add double and float types, and proper targetNamespace vs default namespace handling. Kotlin reserved words now handled properly. Java inheritance support added.

0.9.0

First release. Language support: Java, Kotlin and Swift 4. Tested XML schemas: GPX, Atom.


Support

Pull requests are welcome! Professional support is available from the Outsource Cafe, Inc.

schema-gen's People

Contributors

pierrickrouxel avatar proton72 avatar reaster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

schema-gen's Issues

[Question]: Run without plugin

Hello!

I've encountered issue described here #10 but with different scheme. I ran schema-gen with gradle plugin. As far as I understand the problem has been fixed but I need to run schema-gen "directly" (since plugin is not supported any more).

I'm not familiar with groovy, gradle etc. Could you please elaborate what does it mean "The main entry point is com.javagen.schema.swift.SwiftGen which can be invoked directly"?

What tools I need to install?
How to build schema-gen itself?
How run schema-gen without gradle plugin?

TODO -> IllegalStateException

I want to generate kotlin code from a xsd schema that is "well formed and valid". There is no registered namespace, so the XmlSlurper constructor is called with true, false. The error messages suggest that the code generation does not cover all use cases:

Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
set, which is probably not what is desired. Parser will use a default
ErrorHandler to print the first 10 errors. Please call
the 'setErrorHandler' method to fix this.
Error: URI=null Line=2: Document root element "xs:schema", must match DOCTYPE root "null".
Error: URI=null Line=2: Document is invalid: no grammar found.
TODO add support to traverseElements() for node type: xs:element
Exception in thread "main" java.lang.IllegalStateException: TODO add support to gatherElements() for node type: xs:element
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:250)
at com.javagen.schema.xml.XmlSchemaNormalizer.traverseElements(XmlSchemaNormalizer.groovy:373)
at com.javagen.schema.xml.XmlSchemaNormalizer$traverseElements$2.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:157)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:169)
at com.javagen.schema.xml.XmlSchemaNormalizer.buildSchema(XmlSchemaNormalizer.groovy:704)
at com.javagen.schema.xml.XmlSchemaNormalizer$buildSchema$0.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:157)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:177)
at com.javagen.schema.xml.XmlSchemaNormalizer.buildSchema(XmlSchemaNormalizer.groovy:652)
at com.javagen.schema.xml.XmlSchemaNormalizer.buildSchema(XmlSchemaNormalizer.groovy)
at com.javagen.schema.xml.XmlSchemaNormalizer$buildSchema.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at com.javagen.schema.kotlin.KotlinGen.gen(KotlinGen.groovy:188)
at com.javagen.schema.kotlin.KotlinGen$gen.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at com.javagen.schema.kotlin.KotlinGenMain.main(KotlinGenMain.groovy:65)

class com.javagen.schema.java.JavaGen, unresolved supertypes: FieldHelper

When building the build.gradle.kts file I get an exception:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.3.0"
    id("com.javagen.schema-gen") version "0.9.1"
}

repositories {
    mavenCentral()
}

dependencies {
    compile(kotlin("stdlib-jdk8"))

    implementation("com.github.ajalt:clikt:1.3.0")
    implementation("io.github.config4k:config4k:0.4.1")
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

schemaGen {
    kotlin {
        srcDir = File("")
    }
}

The exception that is thrown is:

Script compilation error:

  Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
      class com.javagen.schema.java.JavaGen, unresolved supertypes: FieldHelper
  

1 error

Could you explain how this issue van be solved?

Invalid enum and variable names

When generating Kotlin classes from the following schema:
https://edavki.durs.si/Documents/Schemas/Doh_KDVP_9.xsd

I encountered the following issues:

  1. TypeInventoryEnum.Unknown is used but not generated, which causes syntax error.
  2. This seems to be Jackson related, but can also be 'fixed' here: If variable has name with inverse case, for example kDVP, it is serialized to lowercase XML tag 'kdvp' regardless of property localname='KDVP'. Solution: rename var in generated code to lower case ('kdvp'). Note: It seems that XML tag is serialized as lowercase by Jackson if the first letter of var name is lower case, and the second is upper case. The rest is not important.
  3. @JsonPropertyOrder annotation is missing for sequences of XML elements to preserve element order on

serialization.
4. Property @JacksonXmlProperty(namespace=...) is not generated for elements with namespace.

StackOverflowError (no error message): Don't re-load and parse a file previously loaded and parsed.

gradle gen
Parallel execution is an incubating feature.

> Task :gen FAILED
schemaGen.java.srcDir=/home/michael/git/WoS-Schema/src/main/java-gen, schemaURL=file:/home/michael/git/WoS-Schema/src/main/resources/com/clarivate/xsd/clarivate.com.schema.wok5.27.rawxml.xsd
<xs:schema targetNamespace='http://clarivate.com/schema/wok5.27/public/FullRecord'>
<xs:schema targetNamespace='http://clarivate.com/schema/wok5.27/public/FullRecord'>
 ... [bunches and bunches of times]
<xs:schema targetNamespace='http://clarivate.com/schema/wok5.27/public/FullRecord'>
<xs:schema targetNamespace='http://clarivate.com/schema/wok5.27/public/FullRecord'>

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gen'.
> java.lang.StackOverflowError (no error message)

This is from trying to process "clarivate.com.schema.wok5.27.rawxml.xsd" and its children XSDs.

The output reads like the FullRecord xsd is trigguring something to pull itself in again as a new file for processing ... ad infitum till stack out of space.

The file only has an "include" for "common_types.rawxml.xsd" which includes "EWUID.rawxml.xsd" which back references "common_types.rawxml.xsd" as an include ...

<?xml version="1.0" encoding="UTF-8"?>
<!-- WoK 5.27 Raw Data Public schema -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
	<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
	<xs:include schemaLocation="common_types.rawxml.xsd"/>
	<xs:element name="fullrecord_metadata" type="fullrecord_metadata"/>
	<xs:complexType name="fullrecord_metadata">
 ...
<?xml version="1.0" encoding="UTF-8"?>
<!-- WoK 5.27 Raw Data Public schema -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
	<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
	<xs:include schemaLocation="EWUID.rawxml.xsd"/>
	<xs:element name="item" type="ItemType" abstract="false"/>
	<xs:element name="abstract" type="abstract">
 ...

So I set the gen source to "common_types ... xsd" and get the same error.

Support for multiple xsd

The plugin support configuration of providing the single xsd file. Is there a way to provide a folder which has more than one xsds to be processed?

Cannot get property 'imports' on null object

I'm trying to generate Kotlin classes for my XSDs. This is the calling code:

class CodeGen extends KotlinGen {
    CodeGen(File schemaFile, File targetDir, String targetPackage) {
        super()
        schemaURL = schemaFile.toURI().toURL()
        srcDir = targetDir
        packageName = targetPackage
        addSuffixToEnumClass = null
        anyPropertyName = 'text'
    }
}

The XSD file is valid (and was used to create Java Beans via xjc before), the targetDir is valid as well and exists, the package name is non-empty. When I execute this code in my custom task, I receive the following crash:

java.lang.NullPointerException: Cannot get property 'imports' on null object
        at com.javagen.schema.model.MSource$Imports.leftShift(MSource.groovy:83)
        at com.javagen.schema.model.MSource$Imports$leftShift.call(Unknown Source)
        at com.javagen.schema.kotlin.KotlinJacksonCallback$_gen_closure1.doCall(KotlinJacksonCallback.groovy:116)              at com.javagen.schema.kotlin.KotlinJacksonCallback.gen(KotlinJacksonCallback.groovy:113)
        at com.javagen.schema.kotlin.KotlinJacksonCallback$gen.call(Unknown Source)
        at com.javagen.schema.java.JavaGen.visit(JavaGen.groovy:357)
        at com.javagen.schema.xml.XmlSchemaVisitor$visit$2.call(Unknown Source)
        at com.javagen.schema.xml.XmlSchemaVisitor$Trait$Helper.visit(XmlSchemaVisitor.groovy:37)
        at com.javagen.schema.xml.XmlSchemaVisitor$Trait$Helper$visit$1.call(Unknown Source)
        at com.javagen.schema.java.JavaGen.visit(JavaGen.groovy:143)
        at com.javagen.schema.java.JavaGen$visit.callCurrent(Unknown Source)
        at com.javagen.schema.kotlin.KotlinGen.gen(KotlinGen.groovy:186)
        at com.javagen.schema.kotlin.KotlinGen$gen.call(Unknown Source)

My Groovy-foo is not good enough to figure out whats going on here, so maybe you have an idea?

Complex element with choice is not generated correct anymore

This worked in V 0.9.1.

Xsd-snippet:

<xsd:complexType name="KontoForTilbakebetaling">
	<xsd:sequence>
		<xsd:choice>
			<xsd:sequence>
				<xsd:element name="norskKontonummer" type="Kontonummer"/>
			</xsd:sequence>
			<xsd:sequence>
				<xsd:element name="swiftBIC" type="Tekst"/>
				<xsd:element name="valuta" type="Valutakode"/>
				<xsd:element name="IBAN" type="Tekst"/>
			</xsd:sequence>
		</xsd:choice>
	</xsd:sequence>

used to generate (Kotlin):

  data class KontoForTilbakebetaling(
      val norskKontonummer:String? = null, 
      val swiftBIC:String? = null, 
      val valuta:String? = null, 
      val IBAN:String? = null
  )
  {
  }

And the latest code generates:

  data class KontoForTilbakebetaling(
  val norskKontonummer:String? = null, 
  )	

Unable to execute DartGenMain.groovy

I have been struggling for several days to get this running. Here is what I have tried so far:

platform: Debian GNU/Linux 10
Groovy Version: 3.0.8 JVM: 1.8.0_292 Vendor: AdoptOpenJDK OS: Linux
working directory: .../schema-gen/src/main/groovy

Direct execution

groovy -cp=com/ com/javagen/schema/dart/DartGenMain.groovy

21 Errors org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 34: unable to resolve class com.javagen.schema.model.MMethod.IncludeProperties @ line 34, column 1. import static com.javagen.schema.model.MMethod.IncludeProperties.allProperties ^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 35: unable to resolve class com.javagen.schema.model.MMethod.Stereotype
@ line 35, column 1.
import static com.javagen.schema.model.MMethod.Stereotype.*
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 129: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 129, column 25.
XmlSchemaVisitor.super.preVisit(schema) //visit global elements, pre-create classes for type reference lookups
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 130: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 130, column 25.
XmlSchemaVisitor.super.visit(schema)
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 298: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 298, column 25.
XmlSchemaVisitor.super.visit(complexType)
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 365: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 365, column 25.
XmlSchemaVisitor.super.visit(all)
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 430: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 430, column 33.
XmlSchemaVisitor.super.visit(choice)
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 438: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 438, column 25.
XmlSchemaVisitor.super.visit(sequence)
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 467: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 467, column 37.
XmlSchemaVisitor.super.visit(group)
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 492: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 492, column 37.
XmlSchemaVisitor.super.visit(group)
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/java/JavaGen.groovy: 517: The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner classes.
@ line 517, column 25.
XmlSchemaVisitor.super.visit(simpleType)
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartToJsonCallback.groovy: 26: unable to resolve class com.javagen.schema.xml.node.Restriction.RType
@ line 26, column 1.
import static com.javagen.schema.xml.node.Restriction.RType.*
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartPreEmitter.groovy: 26: unable to resolve class com.javagen.schema.model.MMethod.IncludeProperties
@ line 26, column 1.
import static com.javagen.schema.model.MMethod.IncludeProperties.allProperties
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartPreEmitter.groovy: 27: unable to resolve class com.javagen.schema.model.MMethod.IncludeProperties
@ line 27, column 1.
import static com.javagen.schema.model.MMethod.IncludeProperties.finalProperties
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartPreEmitter.groovy: 28: unable to resolve class com.javagen.schema.model.MMethod.Stereotype
@ line 28, column 1.
import static com.javagen.schema.model.MMethod.Stereotype.*
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartJsonEmitter.groovy: 23: unable to resolve class com.javagen.schema.model.MMethod.IncludeProperties
@ line 23, column 1.
import static com.javagen.schema.model.MMethod.IncludeProperties.allProperties
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartJsonEmitter.groovy: 24: unable to resolve class com.javagen.schema.model.MMethod.IncludeProperties
@ line 24, column 1.
import static com.javagen.schema.model.MMethod.IncludeProperties.finalProperties
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartJsonEmitter.groovy: 25: unable to resolve class com.javagen.schema.model.MMethod.Stereotype
@ line 25, column 1.
import static com.javagen.schema.model.MMethod.Stereotype.*
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartSupportEmitter.groovy: 23: unable to resolve class com.javagen.schema.model.MMethod.Stereotype
@ line 23, column 1.
import static com.javagen.schema.model.MMethod.Stereotype.fromJson
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartSupportEmitter.groovy: 24: unable to resolve class com.javagen.schema.model.MMethod.Stereotype
@ line 24, column 1.
import static com.javagen.schema.model.MMethod.Stereotype.toJson
^

file:/workspaces/schema-gen/src/main/groovy/com/javagen/schema/dart/DartEmitter.groovy: 21: unable to resolve class com.javagen.schema.model.MMethod.Stereotype
@ line 21, column 1.
import com.javagen.schema.model.MMethod.Stereotype
^

21 errors

Compiled

I figured out (via googling) that to fix these errors I had to compile the classes 'bottom up' to a 'bin' folder which I then used as the classpath. This fixed the 'unable to resolve' and 'class.this' / 'class.super' errors.

groovyc -d=./bin com/javagen/schema/model/*
groovyc -d=./bin com/javagen/schema/common/*
groovyc -cp=./bin -d=./bin com/javagen/schema/xml/node/*
groovyc -cp=./bin -d=./bin com/javagen/schema/xml/*.groovy

All seems ok until I try to compile java

groovyc -cp=./bin -d=./bin com/javagen/schema/java/*.groovy
1 Error ``` org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Compilation incomplete: expected to find the class com.javagen.schema.xml.node.LIST in com/javagen/schema/java/Java14Emitter.groovy, but the file contains the classes: com.javagen.schema.java.Java14Emitter

1 error

</details>

Invalid `static` keyword for nested Kotlin classes

The generated Kotlin code gets the keyword static added to inner Kotlin classes. This keyword does not exist. In Kotlin, all inner classes are by default static; to have a non-static inner class, Kotlin requires the developer to add the inner keyword in front of the inner class.

fractionDigits facet is not recognized

First of all, thanks for the great tool.

I have imported a rather large schema and I have encountered one issue:

The fractionDigits facet throws an exception.

XML Schema

<xsd:schema attributeFormDefault="unqualified"
            elementFormDefault="qualified"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="envelope">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="nest_volume" nillable="true">
                    <!-- [NV] Nest volume. The additional amount of volume for nested articles. -->
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:decimal">
                            <xsd:totalDigits value="16"/>
                            <xsd:fractionDigits value="6"/>
                            <xsd:minInclusive value="0"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

Gradle output

15:22:39: Executing task 'gen'...


> Task :gen FAILED
schemaGen.kotlin.srcDir=/home/user/projects/project/src/main/kotlin-gen, schemaURL=file:/home/user/projects/project/src/main/resources/xmlschemas/test.xsd

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':gen'.
> no namespace registered for prefix 'null' for name: envelope

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed
Cause: no namespace registered for prefix 'null' for name: envelope
15:22:40: Task execution finished 'gen'.

still usable?

Hi,

I am trying to use this service, but I cannot find a working example.

When I try to use the dependency in gradle, I always get

Searched in the following locations:
       - https://repo.maven.apache.org/maven2/com/javagen/schema-gen/0.9.1/schema-gen-0.9.1.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.

I cannot see anything pointing to a dependency in this repository and the gradle plugin seems not supported.
So is this still being used?

No namespace registered for prefix

Hello,

I'm trying to use your work to generate Swift code from AIXM XSD (standard file format to define airspaces).

I'm facing the error no namespace registered for prefix 'null' for name: alpha for every single object definition in the published document.

Here is a sample part of the XSD that generate the error.

Am I doing something wrong? How should I solve this issue?

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsd:annotation>
		<xsd:documentation>Version: 4.5-r2</xsd:documentation>
	</xsd:annotation>
	<!-- AIXM predefined simple data types -->
	<xsd:simpleType name="alpha">
		<xsd:restriction base="xsd:string">
			<xsd:pattern value="[A-Z]*"/>
		</xsd:restriction>
	</xsd:simpleType>
	<xsd:simpleType name="alphanumeric">
		<xsd:restriction base="xsd:string">
			<xsd:pattern value="([A-Z]|\d)*"/>
		</xsd:restriction>
	</xsd:simpleType>
	<xsd:simpleType name="character1">
		<xsd:restriction base="xsd:string">
			<xsd:pattern value="([A-Z]|[0-9])+([ \+\-/]*([A-Z]|[0-9])+)*"/>
		</xsd:restriction>
	</xsd:simpleType>
	<xsd:simpleType name="character2">
		<xsd:restriction base="xsd:string"/>
	</xsd:simpleType>
	<xsd:simpleType name="character3">
		<xsd:restriction base="xsd:string">
			<xsd:pattern value="([A-Z]|[0-9]|[, !&quot;&amp;#$%&apos;\(\)\*\+\-\./:;&lt;=&gt;\?@\[\\\]\^_\|\{\}])*"/>
		</xsd:restriction>
	</xsd:simpleType>
	<xsd:simpleType name="codeAcftEngineNoBase">
		<xsd:restriction base="xsd:string">
			<xsd:enumeration value="1"/>
			<xsd:enumeration value="2"/>
			<xsd:enumeration value="3"/>
			<xsd:enumeration value="4"/>
			<xsd:enumeration value="6"/>
			<xsd:enumeration value="8"/>
			<xsd:enumeration value="C"/>
			<xsd:enumeration value="OTHER"/>
		</xsd:restriction>
	</xsd:simpleType>
	<xsd:complexType name="codeAcftEngineNo">
		<xsd:annotation>
			<xsd:documentation>A coded indication for the number of engines of an aircraft.</xsd:documentation>
		</xsd:annotation>
		<xsd:simpleContent>
			<xsd:extension base="codeAcftEngineNoBase">
				<xsd:attributeGroup ref="Changes"/>
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>
	<xsd:simpleType name="codeActivityBase">
		<xsd:restriction base="xsd:string">
			<xsd:enumeration value="TFC-AD"/>
			<xsd:enumeration value="TFC-HELI"/>
			<xsd:enumeration value="TRG"/>
			<xsd:enumeration value="ACROBAT"/>
			<xsd:enumeration value="AIRSHOW"/>
			<xsd:enumeration value="SPORT"/>
			<xsd:enumeration value="ULM"/>
			<xsd:enumeration value="GLIDER"/>
			<xsd:enumeration value="PARAGLIDER"/>
			<xsd:enumeration value="HANGGLIDER"/>
			<xsd:enumeration value="PARACHUTE"/>
			<xsd:enumeration value="DROP"/>
			<xsd:enumeration value="BALLOON"/>
			<xsd:enumeration value="ASCENT"/>
			<xsd:enumeration value="SPACEFLT"/>
			<xsd:enumeration value="UAV"/>
			<xsd:enumeration value="WORK"/>
			<xsd:enumeration value="DUSTING"/>
			<xsd:enumeration value="FIRE"/>
			<xsd:enumeration value="MILOPS"/>
			<xsd:enumeration value="REFUEL"/>
			<xsd:enumeration value="JETCLIMB"/>
			<xsd:enumeration value="EXERCISE"/>
			<xsd:enumeration value="TOWING"/>
			<xsd:enumeration value="NAVAL"/>
			<xsd:enumeration value="MISSILES"/>
			<xsd:enumeration value="AIRGUN"/>
			<xsd:enumeration value="ARTILERY"/>
			<xsd:enumeration value="SHOOT"/>
			<xsd:enumeration value="BLAST"/>
			<xsd:enumeration value="WATERBLAST"/>
			<xsd:enumeration value="ANTIHAIL"/>
			<xsd:enumeration value="BIRD"/>
			<xsd:enumeration value="BIRD-MGR"/>
			<xsd:enumeration value="FIREWORK"/>
			<xsd:enumeration value="HI-RADIO"/>
			<xsd:enumeration value="HI-LIGHT"/>
			<xsd:enumeration value="LASER"/>
			<xsd:enumeration value="NATURE"/>
			<xsd:enumeration value="FAUNA"/>
			<xsd:enumeration value="NO-NOISE"/>
			<xsd:enumeration value="ACCIDENT"/>
			<xsd:enumeration value="POPULATION"/>
			<xsd:enumeration value="VIP"/>
			<xsd:enumeration value="VIP-PRES"/>
			<xsd:enumeration value="VIP-VICE"/>
			<xsd:enumeration value="OIL"/>
			<xsd:enumeration value="GAZ"/>
			<xsd:enumeration value="IND-OIL"/>
			<xsd:enumeration value="IND-CHEM"/>
			<xsd:enumeration value="IND-NUCLEAR"/>
			<xsd:enumeration value="TECHNICAL"/>
			<xsd:enumeration value="ATS"/>
			<xsd:enumeration value="EQUIPMENT"/>
			<xsd:enumeration value="EQUIPMENT-RVSM"/>
			<xsd:enumeration value="EQUIPMENT-RNAV"/>
			<xsd:enumeration value="EQUIPMENT-833"/>
			<xsd:enumeration value="PROCEDURE"/>
			<xsd:enumeration value="OTHER"/>
		</xsd:restriction>
	</xsd:simpleType>
</xsd:schema>

Sample for Kotlin/JS?

Hi Richard,
I would like to use schema-gen for a Kotlin/JS project.
Do you know of any projects/samples?

Thanks in advance
-j

When i upgrade the gradle version to 6, below error is coming

When i upgrade the gradle version to 6, below error is coming. The samples in https://github.com/reaster/schema-gen-examples are also failing with the same error.

at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[hash, toString, equals, setter, getter, toStringBuilder, adder]' with class 'java.util.ImmutableCollections$SetN' to class 'java.util.EnumSet' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.EnumSet(com.javagen.schema.model.MMethod$Stereotype, com.javagen.schema.model.MMethod$Stereotype, com.javagen.schema.model.MMethod$Stereotype, com.javagen.schema.model.MMethod$Stereotype, com.javagen.schema.model.MMethod$Stereotype, com.javagen.schema.model.MMethod$Stereotype, com.javagen.schema.model.MMethod$Stereotype)
at com.javagen.schema.java.JavaPreEmitter.(JavaPreEmitter.groovy:54)

schemaGen {
java {
schemaURL = new URL('file:src/main/resources/atom.xsd')
packageName = 'com.sap.java'
addSuffixToEnumClass = null
anyPropertyName = 'text'
}
}

when i remove the above code, it works!!! But we need this configuration. Any help???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.