All Projects → schlothauer-wauer → jsoncodegen

schlothauer-wauer / jsoncodegen

Licence: MIT license
Groovy based generation tasks from JSON schema

Programming Languages

groovy
2714 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to jsoncodegen

jsonresume-theme-caffeine
Caffeine theme for the JSON Resume project
Stars: ✭ 78 (+178.57%)
Mutual labels:  json-schema
jsonSchema-to-uml
A tool to generate UML class diagrams from JSON schema documents
Stars: ✭ 33 (+17.86%)
Mutual labels:  json-schema
json-schema-core
A framework for building JSON Schema validators
Stars: ✭ 26 (-7.14%)
Mutual labels:  json-schema
json-validator
A json validator in PHP
Stars: ✭ 52 (+85.71%)
Mutual labels:  json-schema
express-json-validator-middleware
Express middleware for validating requests against JSON schema
Stars: ✭ 148 (+428.57%)
Mutual labels:  json-schema
jsonschema
A node package based on jsonschema-rs for performing JSON schema validation
Stars: ✭ 48 (+71.43%)
Mutual labels:  json-schema
express-objection-starter
an opinionated, production-ready, isomorphic express/knex/objection starter with centralized configuration
Stars: ✭ 19 (-32.14%)
Mutual labels:  json-schema
format-to-json
An algorithm that can format a string to json-like template. 字符串JSON格式化的算法。
Stars: ✭ 30 (+7.14%)
Mutual labels:  json-schema
typescript-to-json-schema
Generate JSON schema from your Typescript sources
Stars: ✭ 54 (+92.86%)
Mutual labels:  json-schema
nz-schema-form
ng-zorro-antd form generation based on JSON-Schema
Stars: ✭ 40 (+42.86%)
Mutual labels:  json-schema
helm-schema-gen
So that you don't have to write values.schema.json by hand from scratch for your Helm 3 charts. [CURRENTLY NOT MAINTAINED]
Stars: ✭ 104 (+271.43%)
Mutual labels:  json-schema
mock-json-schema
Simple utility to mock example objects based on JSON schema definitions
Stars: ✭ 23 (-17.86%)
Mutual labels:  json-schema
prisma-json-schema-generator
A generator for Prisma 2 to generate a valid JSON Schema (v7)
Stars: ✭ 145 (+417.86%)
Mutual labels:  json-schema
openapi4j
OpenAPI 3 parser, JSON schema and request validator.
Stars: ✭ 92 (+228.57%)
Mutual labels:  json-schema
robotframework-jsonvalidator
Robot Framework library for JSON validation
Stars: ✭ 21 (-25%)
Mutual labels:  json-schema
json-schema
Clojure library JSON Schema validation and generation - Draft-07 compatible
Stars: ✭ 52 (+85.71%)
Mutual labels:  json-schema
babl
JSON templating on steroids
Stars: ✭ 29 (+3.57%)
Mutual labels:  json-schema
react-jsonschema-formbuilder
No description or website provided.
Stars: ✭ 45 (+60.71%)
Mutual labels:  json-schema
check-jsonschema
A CLI and set of pre-commit hooks for jsonschema validation with built-in support for GitHub Workflows, Renovate, Azure Pipelines, and more!
Stars: ✭ 51 (+82.14%)
Mutual labels:  json-schema
graphql-to-json-schema
GraphQL Schema to JSON Schema
Stars: ✭ 146 (+421.43%)
Mutual labels:  json-schema

jsonCodeGen

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

Requirements

  • Java 8
  • Gradle v5.4*

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

# 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

Template Debugging

General Remarks

From version 0.13.0 it is also possible to debug code from templates. This is a common use case if the templates become more complicated. Unfortunately is it not possible to debug code that is included direct into the template, but with the '-gs' command line switch a external Groovy script can be injected into the code generation templates.

If the switch is used, then inside the template is a 'script' variable available. This variable points to the injected script and allows to call functions that are declared as clojure inside the generator-script.

// example usage of a generator script defined function
${script.generatorScriptDefinedFunction(possibleParameter)}
// example function definition in a generator script
def generatorScriptDefinedFunction(def someString) {
    return "Hello: $someString"
}

Code Examples

Steps to Debug template in IntelliJ

  1. Open the jsonCodeGen project in IntelliJ
  2. Open the generator library in the editor (example: ./src/test/resources/templates/handling_helper.groovy)
  3. Set a break point
  4. Configure remote debugging in IntelliJ listen on port 8100
  5. Run bin/debug_example.sh from command line
  6. Start remote debugging in IntelliJ
  7. Break-Point should be triggered in IDE

This approach can also be used for other projects.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].