joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

Possible to run with separate settings for different files? #1228

Open dan-lind opened 3 years ago

dan-lind commented 3 years ago

This is a duplicate of a request that I added to the jsonschema2dataclass repo back when it was referred to as the "official" version of the gradle plugin for jsonschema2json.

Link to the issue: https://github.com/jsonschema2dataclass/js2d-gradle/issues/31#issue-810782997

My understanding is that the gradle plugin of this repo has since come back to life, so I wanted to add this request here as well as it looks like the two repos will continue to be separate projects.

More of a question than an actual issue:

I was wondering if it is somehow possible to run with separate settings for different files? In my example, I have schemas that look a little bit different, but have overlapping names. As such, I need to prefix each of the generate pojos a bit differently.

I have currenly resolved to using a bash script and the CLI like this

jsonschema2pojo -y Create -fdt -r -ut -tv 11 -303 -b -R -s src/main/resources/schemas/CREATE-Payload_Schema.json -t build/generated/sources/js2p -p com.example
jsonschema2pojo -y Update -fdt -r -ut -tv 11 -303 -b -s src/main/resources/schemas/UPDATE_Payload_Schema.json -t build/generated/sources/js2p -p com.example
jsonschema2pojo -y Read -fdt -r -ut -tv 11 -303 -b -s src/main/resources/schemas/READ_Response_Schema.json -t build/generated/sources/js2p -p com.example

This works but is giving us some headache as some developers or on a Windows machine.

joelittlejohn commented 3 years ago

I think there are a number of options here:

  1. Create a multi-module Gradle project, you can have a different configuration per module
  2. Use Maven, it allows multiple executions of a plugin, each with a different configuration
  3. Ask the developers that use Windows to use WSL and bash. I'm sure this is not the only time you will want to run more than one command and create a script.
  4. Replace your bash script with a Python script - it's simple to run these executions from python and it is portable across Linux and Windows
dan-lind commented 3 years ago

I think there are a number of options here:

  1. Create a multi-module Gradle project, you can have a different configuration per module

Not sure what you mean here. We have 13 different schemas, I don't think it makes sense to have a separate module for each schema when they are all used by the same module.

  1. Use Maven, it allows multiple executions of a plugin, each with a different configuration

Not an option for us, we use Gradle for all projects and will not convert this specific project.

  1. Ask the developers that use Windows to use WSL and bash. I'm sure this is not the only time you will want to run more than one command and create a script.

This is what I'm doing myself, but the main reason is that I come from Mac and like Linux better than Windows. However this is not the case for all devs in our team, and we probably have to live with the fact that not everyone prefers running WSL over powershell or whatever (not that I could every understand why....)

  1. Replace your bash script with a Python script - it's simple to run these executions from python and it is portable across Linux and Windows

Hmm, I guess this might be an option to look into.

Though I would still prefer to have gradle support :-)