Maven plugin - Generating schemas for multiple classes
The current Maven plugin only allows to generate the schema for one class. This should be extended to specify multiple classes. Either by mentioning them or by mentioning a package.
As per comment on #78, I'd propose a structure like this:
<configuration>
<targetTypes>
<targetType>
<className>a.b.c.YourClass</className>
</targetType>
<targetType>
<className>a.b.c.MyClass</className>
<schemaFileName>MyClass_schema.json</schemaFileName>
</targetType>
</targetTypes>
<targetPackages>
<targetPackage>
<packageName>x.y.z</packageName>
</targetPackage>
</targetPackages>
<schemaFilePath>src/main/resources/schema</schemaFilePath>
</configuration>
I'll go for a slightly different approach:
<configuration>
<targetTypes>
<className>a.b.c.YourClass</className>
<className>a.b.c.MyClass</className>
</targetTypes>
<targetPackages>
<packageName>x.y.z</packageName>
</targetPackages>
<schemaFilePath>src/main/resources/schema</schemaFilePath>
<schemaFileNamePattern>schema-%s.json</schemaFileNamePattern>
</configuration>
The filename pattern is applied to all generated files, and uses the syntax of String.format, where the class name is the one parameter.
Should be good enough for now, but will be harder to extend later on if the request comes for setting individual names and naming patterns per type/package.
Let's build it and gain experience. I am always a fan of defining a pattern and sticking to it.
One other topic on the schema files for packages: shall we generate them in a subfolder that matches the package name? Mainly to prevent name collisions.
That subfolder would only be necessary if the same type names are present in two packages. Possible, but probably not very likely that someone would want to generate schemas for both types then.
Maybe we can use MessageFormat.format() instead of String.format() and thereby offer multiple numbered placeholder values.
{0}would be the simple class name{1}would be the package name
We would be flexible to add more values later on and the user could simply include the package name in the file name themselves, if there are any conflicts otherwise.
Agreed. The default can then be: {0}-schema.json
I already included the discussed naming pattern in #88, but not the ability to configure multiple classes though.
The work is done. PR submitted. The xml turned out with some different names, but the same structure. Have your go at it.