Maven plugin
Hello
This project looks excellent! Really good to see support for Bean validation.
Is there a maven plugin, that will allow schema generation using maven, eg mvn generate source?
Hi @magick93,
I‘m glad you like it. So far, there is no maven plugin to trigger the schema generation.
I‘ve never created one and wouldn’t know how to allow for the same level of configurability. If you have experience in that regard, I’d be happy to work on a Maven plugin with you.
Hi Carsten and Magick,
I have created a very first maven plugin today. This seems to work for my need, which is generating the schema based on Jackson and Addon annotations.
Following shows the configuration parameters I created:

@CarstenWickner What do you mean with your statement '..to allow for the same level of configurability...' @magick93 What is your expectation of the plugin?
Cheers,
Jan
Hi @JanLabrie,
Great you already had a look into this.
What I meant with configurability is the part where the user of the maven plugin decides which modules to use (e.g. @magick93 mentioned interest in the javax.validation module), what main Options to activate, what module options to enable/disable.
For special use cases, one might also want to add some individual configurations, unless you completely cover that part through the Addon module, which requires JSON Schema specific annotations in your code (which at least my personal motivation always was to keep to a minimum).
Hi @JanLabrie - wow! Nice work! Thanks.
- I think having a
packageoption would be good, as I would imagine a lot of users have all of their models / entities in a common package, and would like a schema generated for these. - And for the
addonsmaybe an array of implentations, egvictools/jsonschema-module-javax-validation,victools/jsonschema-module-swagger-1.5. @CarstenWickner - do these different addons have their own config options?
Hi @magick93,
Yes, each module may have its own (small) set of options to enable/disable certain parts. At least those standard modules have that at the moment. E.g. for backward-compatibility: new features are usually disabled but you can enable them then.
My first thought is to have it configurable like this:
<configuration>
<className>com.github.victools.jsonschema.plugin.maven.TestClass</className>
<outputDirectory>target/test-harness/basic-test</outputDirectory>
<options> <!-- Options for the generator -->
<option>DEFINITIONS_FOR_ALL_OBJECTS</option>
<option>OTHER_OPTION</option>
</options>
<modules><!-- Modules to use -->
<module>
<name>JacksonModule</name>
<!-- Options for the module -->
<option>FLATTENED_ENUMS_FROM_JSONVALUE</option>
</module>
<module>
<name>AddOnModule</name>
</module>
</modules>
</configuration>
- We could hardcode the known modules that there are now. But better would be to have a dynamic mechanism. Let's hardcode first.
- Hardcoding will also help now to set the options. There is no generic option mechanism for modules yet. i.e. the Generator uses a builder and a with() construction, the JacksonModule uses constructor arguments. I do not know about other modules.
What do you think?
@JanLabrie sounds very good.
- I'm also not sure about the configuration options of the
AddOnModuleas that's not maintained by me but @imIfOu. I'd assume it doesn't have any need for configuration options at this stage. - As to the other (what I call "standard") modules, i.e. the ones I maintain alongside the main generator library, those mostly use enum values to be provided in the constructor (like the
JacksonModule). Only thejavax.validationone also caters for particular validation groups to be specified, but that can probably be ignored here for now. - By design, the main generator library is much more complex. I hope to keep the configuration options for the modules as simple as possible. If someone doesn't like a particular module's behavior, there are still alternatives through the main generator to achieve most of what anybody could want.
- And everything the generator offers in terms of configurations can be bundled in a module. I.e. if you allow for any kind of module to be added (even without supporting it to be configured), the maven plugin would effectively allow any kind of configurations to be set. A user might just have to wrap their configurations into a
Module. - As to the configuration of the maven plugin:
- Maybe using the usual "groupId":"artifactId" combination instead of "name" would avoid having to maintain a hard-coded mapping within the plugin?
- On the other hand, if you look up implementations of the
Moduleinterface (e.g. via reflection) and only check for their simple class name, then the "name"JacksonModulewould be very appropriate. So maybe stick to your above plan for now. - Alternatively, you could expect a fully qualified class name that should be on the classpath. That way, it doesn't matter where the
Modulecomes from, e.g. local code or some dependency. - If it would make your life easier for this plugin if I harmonized those modules in some way (e.g. by introducing a common interface, extend the
Moduleinterface in some way or just offer another constructor accepting theStringnames of the respective options on each one), just let me know.
As far as I am concerned the maven-plugin branch is complete for first release, when issue #80 is merged.
The new Maven Plugin created by @JanLabrie has been released with version v4.11.0.