Skip to content

schlothauer-wauer/jsoncodegen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonCodeGen

A simple Groovy based program to do generation tasks from a JSON schema.

Requirements

  • Java 8
  • Gradle v4.*

Unsupported JSON schema features

  • patternProperties - make no sense in model description
  • only references in the local document and local file system are supported

Additional features

  • easier version markup in model
  • mark attributes as aggregation types (references) with suffix '_id'
  • additional property attribute 'aggregationType' to set the specific attribute information
  • allOf - to implement inheritance
    // How to mark different aggregation types in the model
    // Attention, this works only for "$ref" types!
    ...
    "Greens": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "green_id": {
            // aggregation
            "$ref": "#/definitions/GreenType"
        },
        "green_obj": {
            // composition
            "$ref": "#/definitions/GreenType"
        },
        "green_obj": {
            // aggregation
            "__aggregationType": "aggregation",
            "$ref": "#/definitions/GreenType"
        },
        "greens": {
          // composotion
          "type": "array",
          "items": {
            "$ref": "#/definitions/GreenType"
          }
        }
      }
    },
    ...

Handle with gradle

Using with gradle

# do a complete release to configured maven repository
gradle publish

# builds a release with all dependencies
# release is built in PROJECT_DIR/build/release
# before a release is build the tests are executed - skip not possible
gradle buildRelease

# builds release and copy artifacts to docker image dir as preparation for the image build
gradle copyReleaseToDockerImage

# run program without any arguments from project
gradle myRun

# run program with arguments ... opens test schema
gradle myRun -PmyArgs="-m,src/test/resources/schemas/ProcessDataEvent.json"

# complex example for debug mode run
gradle myRun -PDEBUG -PmyArgs="-o,/tmp/test_beans,-m,src/test/resources/test_schemas/multiType.json,\
-g,multifiles=src/main/resources/templates/java/java_bean.txt,\
-gp,destFileNameExt=java,-gp,packageName=de.sw.atlas.test"

# complex example without debug mode run
gradle myRun -PmyArgs="-o,/tmp/test_beans,-m,src/test/resources/test_schemas/multiType.json,\
-g,multifiles=src/main/resources/templates/java/java_bean.txt,\
-gp,destFileNameExt=java,-gp,packageName=de.sw.atlas.test"

Usage of the release

./jsonCodeGen.sh
Usage: de.lisaplus.atlas.DoCodeGen [options]
  Options:
    -at, --add-tag
      add a text as tag to a specific type, f.e. -at User=unused
      Default: []
    -b, --black-list
      black listed type, multiple usage possible
      Default: []
    -g, --generator
      generator that are used with the model. This parameter can be used 
      multiple times
      Default: []
    -gp, --generator-parameter
      special parameter that are passed to template via maps
      Default: []
    -h, --help

  * -m, --model
      Path to JSON schema to parse
    -o, --outputBase
      Base directory for the output
    -pmt, --print-main-types
      don't do any code generation, simply loads the model and print the 
      main-types of it
      Default: false
    -pmta, --print-main-types-attrib
      don't do any code generation, simply loads the model and print the 
      main-types of it
    -pmti, --print-main-types-info
      print with info header
      Default: false
    -pmts, --print-main-types-separator
      separator to use for printing main types
    -rt, --remove-tag
      remove a tag from a specific type, f.e. -rt User=unused
      Default: []
    -rta, --remove-tag-all
      remove a tag from all model types, f.e. -rta rest
      Default: []
    -w, --white-list
      white listed type, multiple usage possible
      Default: []

After you built a release with gradle or you download a release bundle you can start the program with the contained start script. If you start it with the help option you get a full description of the possible parameters

# or a similar path
cd build/release
# start program in bash environment
./jsonCodeGen.sh

# show help in bash environment
./jsonCodeGen.sh --help

# example swagger call
build/release/jsonCodeGen.sh -g swagger -o ~/tmp -m src/test/resources/test_schemas/ds/user.json \
  -gp removeEmptyLines=true -gp host=api.lisaplus.de

To get a better understanding how the program works see here

Program design

Basic class design

Diagram source (main structure) describes the basic design.

Usage

see here

Releases

see here

About

Groovy based generation tasks from JSON schema

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •