Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get latest code #1

Merged
merged 147 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
d939d16
Work around problems with file separators when running on windows.
SpeedsterF2 Apr 20, 2018
d1e58b7
remove creation of docker image from standard process
eikothomas Apr 23, 2018
11dc663
Merge pull request #13 from SpeedsterF2/windows_workarounds
OkieOth Apr 23, 2018
d28e5d4
basic mongodb generator
eikothomas May 13, 2018
9036b3d
some stuff on the way to the perfect mongo bean
eikothomas May 18, 2018
31aa0c5
nexus release 0.4.2
eikothomas May 18, 2018
88a8a0b
fix corrupt nexus release 0.4.2
eikothomas May 18, 2018
54ddeb8
fix error in start script
eikothomas May 18, 2018
4141101
fix error in start script
OkieOth May 18, 2018
10771a8
enforce camel-case names for java types
eikothomas May 24, 2018
8b6fd27
changes for run java command under windows os
eikothomas May 24, 2018
fb02a4c
fix error with tags in sub types
eikothomas Jun 4, 2018
6e1ad59
Merge branch 'master' into mongodb_beans
OkieOth Jun 4, 2018
be399e2
Merge pull request #15 from schlothauer-wauer/mongodb_beans
OkieOth Jun 4, 2018
8f40569
remove types that only base types from allOf constructs from model
eikothomas Jun 5, 2018
ed8c5af
print tags in plantuml diagrams
eikothomas Jun 6, 2018
8cdb8c9
fix type tags error for single file types
eikothomas Jun 6, 2018
5944c29
add check for name function for properties
eikothomas Jun 8, 2018
fa61ec9
optimize plantuml
eikothomas Jun 11, 2018
717069c
move Date and DateTime types to Java8 related types
Jul 10, 2018
04199d0
add extra parameter for java beans to get protected members
Jul 10, 2018
06ab07f
Moved enum TemplateType to file of its own
SpeedsterF2 Jul 11, 2018
a509cbb
Split model and types into more groovy files to help limited IDEs
SpeedsterF2 Jul 11, 2018
657dd36
Import the complete model package to workaround limited IDE
SpeedsterF2 Jul 11, 2018
614e646
Introduced presets for mapping of DateType and DateTimeType to Java c…
SpeedsterF2 Jul 11, 2018
2794cfc
Define preset for selecting Java classes for DateType and DateTimeType
SpeedsterF2 Jul 11, 2018
8db0f45
missing usage of preset
SpeedsterF2 Jul 11, 2018
6eec965
Merge pull request #16 from schlothauer-wauer/split_model_flexible_ja…
OkieOth Jul 11, 2018
c783977
Merge branch 'master' of github.com:schlothauer-wauer/jsoncodegen
Jul 11, 2018
25b7996
add ignoreTag parameter to MultiFileGenerator
Jul 16, 2018
8e6aaf1
increment project version
Jul 17, 2018
43c43da
Some more closures to use in templates. Get more control over format …
SpeedsterF2 Jul 18, 2018
ecc9545
Ignore files dedicated to perform closure experiments
SpeedsterF2 Jul 18, 2018
77e9d98
Comment pattern for exclusing type names via regex pattern
SpeedsterF2 Jul 18, 2018
38ce40c
Keep only closures with minimum typing
SpeedsterF2 Jul 18, 2018
90571b7
Merge pull request #17 from schlothauer-wauer/more-closures
OkieOth Jul 20, 2018
5370a41
Merge branch 'master' of github.com:schlothauer-wauer/jsoncodegen
Jul 20, 2018
256c2ae
remove the feature to strip the 'only base types' from the model - be…
Jul 20, 2018
3b4e9ef
enable real nexus publish
Jul 20, 2018
e2dd8df
complete publishing script
Jul 20, 2018
cecc2ce
Added possibility to filter for arbitrary tag
SpeedsterF2 Jul 25, 2018
f911c4b
Added possibility to filter for arbitrary tag not present
SpeedsterF2 Jul 25, 2018
e9002d3
Move closures for type and parameter name manipulation to extra class
SpeedsterF2 Jul 30, 2018
e175970
Removed the code, which was moved to TypeStringManipulation
SpeedsterF2 Jul 30, 2018
86de6c6
Fixed wrong package declaration
SpeedsterF2 Jul 30, 2018
8f99e42
GeneratorBase must extend TypeStringManipulation for closure visibility
SpeedsterF2 Jul 30, 2018
58ce4fc
Minor cosmetic changes
SpeedsterF2 Aug 2, 2018
e5e74cb
Added getDefaultValue()
SpeedsterF2 Aug 2, 2018
0cc672c
Bugfix: Do add indent to bindings
SpeedsterF2 Aug 14, 2018
e9be23f
Dirty hack for enabling the usage of mongoDB Index2d
SpeedsterF2 Aug 14, 2018
ede32fb
frist tests w/ apache xmlbeans - looks promising
Aug 17, 2018
856ab82
wip: XSDBuilder
Aug 20, 2018
a7043f9
Merge pull request #19 from schlothauer-wauer/extract_binding_closures
OkieOth Aug 20, 2018
edafbb8
first type import from XSD
Aug 21, 2018
1d80423
wip: begin to handle different content types
Aug 21, 2018
702cd7e
wip: begin to handle different content types
Aug 21, 2018
820e06e
basic xsd import seems to work
Aug 27, 2018
b840fb6
basic xsd export works
Aug 27, 2018
779f070
add jsonCodeGen comment to exported xsd
Aug 27, 2018
6198cb1
increment to version 0.7.0
Aug 28, 2018
41388ba
Merge pull request #21 from schlothauer-wauer/import_xsd
OkieOth Aug 28, 2018
62067ed
add comments to exported xsd
Aug 28, 2018
a684d12
Merge branch 'import_xsd'
Aug 28, 2018
a4cdde5
Merge branch 'master' of github.com:schlothauer-wauer/jsoncodegen
Aug 28, 2018
8033193
enable extraParams in sub templates
Aug 29, 2018
a061d08
increment version
Aug 29, 2018
8b2187d
Minor spelling fix
SpeedsterF2 Sep 11, 2018
e4d7724
Added closure convertForceSingle and cosmetics
SpeedsterF2 Sep 11, 2018
65b85fc
Added closure convertForceSingle to bindings
SpeedsterF2 Sep 11, 2018
97da961
Merge pull request #22 from schlothauer-wauer/mask_extensions
OkieOth Sep 11, 2018
eed4b46
increment version to 0.7.3
Sep 11, 2018
0815e8c
handle tags added to array types.
SpeedsterF2 Oct 15, 2018
57519ae
Merge pull request #24 from schlothauer-wauer/array_tags
OkieOth Oct 15, 2018
720d04b
repair last merge
Oct 15, 2018
3dc9965
fix error in tags for array properties
Oct 15, 2018
7abeb3a
add property attribs selfContainment and selfReference
Oct 15, 2018
aa4b7e5
increment to verion 0.7.4
Oct 15, 2018
c8ef428
Changed comments to JavaDocs
SpeedsterF2 Oct 16, 2018
3d3ef64
cosmetics
SpeedsterF2 Oct 16, 2018
3cf9a50
Added self reference check to closure filterProps
SpeedsterF2 Oct 16, 2018
f741fa1
Add the posibility to create a (deep) copy of the types
SpeedsterF2 Oct 17, 2018
22e975d
Added TODO: Check whether incomplete initialization is necessary / in…
SpeedsterF2 Oct 17, 2018
b7f08b3
DummyType: switched from def referencesToChange=[] to explicit List<B…
SpeedsterF2 Oct 17, 2018
bf06356
cosmetics
SpeedsterF2 Oct 17, 2018
d439447
remove test from xsd-builder
Oct 17, 2018
fcb515e
Merge branch 'master' of github.com:schlothauer-wauer/jsoncodegen
Oct 17, 2018
7b66452
add first array type
Oct 17, 2018
af6ab3b
Rework copy for handling circles in the type hierarchy
SpeedsterF2 Oct 17, 2018
aaac716
Cleaned up code
SpeedsterF2 Oct 17, 2018
6e12e05
Commented out debug output and more code cleanup
SpeedsterF2 Oct 17, 2018
7c22824
Merge pull request #25 from schlothauer-wauer/copy_types
OkieOth Oct 17, 2018
0977f22
Make Type.copyOf available in templates by adding it to the bindings
SpeedsterF2 Oct 17, 2018
91a01ff
Preserve flag isArray
SpeedsterF2 Oct 17, 2018
06e1f22
Merge pull request #26 from schlothauer-wauer/copy_types
OkieOth Oct 17, 2018
f2eb5fa
seems to work
Oct 17, 2018
74d3937
improve documentation
Oct 17, 2018
da99a32
Merge pull request #27 from schlothauer-wauer/add_pure_array_types
OkieOth Oct 17, 2018
d0a2286
type names to camel-case, add and remove tags from type per config
Oct 22, 2018
47457b5
add test for tag add via -at switch
Oct 22, 2018
7b8a4cb
add test for tag remove via -rt switch
Oct 22, 2018
b41738f
some improvements for plantuml
Oct 23, 2018
233cfb9
Merge pull request #28 from schlothauer-wauer/SWD-121_black_and_white…
OkieOth Oct 23, 2018
6fff2a6
improvements of main type printing
Oct 24, 2018
d235b7f
modify README
Oct 24, 2018
1c95311
increment project version
Oct 24, 2018
60f70fc
Merge pull request #29 from schlothauer-wauer/add_source_info_to_type
OkieOth Oct 24, 2018
3fdcc83
needed fix in pmts-switch handling
Oct 24, 2018
2946af6
add handling of switch lists for tag modification
Oct 24, 2018
f0e23e1
add command line switch for tagging mainTypes
Oct 26, 2018
bbe8026
improve plantuml generation
Nov 29, 2018
4962c84
Fix build.gradle for gradle v5.1 by moving tasks to the top
Feb 15, 2019
c3d3cbe
Added possibility to define suffix, too
Feb 15, 2019
4b4a77e
Incremented version to 0.8.5
Feb 15, 2019
49fee51
Default file names now use camel case, not '_' anymore. Adjusted path…
Feb 15, 2019
fbd2258
Merge pull request #30 from schlothauer-wauer/suffix
OkieOth Feb 15, 2019
86d0c13
improve java bean equal tests to match also with empty lists and null…
Feb 18, 2019
4bc801b
avoid null values for java bean attribs that contains a list
Feb 19, 2019
fd52f23
add version to model types
Mar 7, 2019
6707812
Merge pull request #31 from schlothauer-wauer/add_byte_type
OkieOth Mar 7, 2019
d7cadef
Use java.util.UUID for the UUIDType in the java code
Mar 12, 2019
5011e34
fix some errors in XSDBuilder
Mar 13, 2019
a8aac80
enable the loading of multiple model files
Mar 13, 2019
acf833a
v0.9.1, not deployed yet
Mar 13, 2019
b48758d
fix import error in java bean template
Mar 14, 2019
e029b7b
Merge pull request #32 from schlothauer-wauer/uuid_type
OkieOth Mar 14, 2019
756b476
go to version 0.10.0
Mar 14, 2019
ba0db27
introduce long type
Mar 15, 2019
2ade5c3
Merge pull request #33 from schlothauer-wauer/enable_long_values
OkieOth Mar 15, 2019
d41ab5e
improve byte declaration
Mar 15, 2019
569e0dd
import black- and whitelist handling for single file generators
Mar 17, 2019
0d26a4f
improve XSDBuilder
Mar 28, 2019
1a5dacc
update build.gradle
OkieOth May 1, 2019
d361e59
build docker image with jlink
OkieOth May 4, 2019
980d1c1
introduce EnumType and fix the tests to handle it
OkieOth Jun 8, 2019
a2c3e6b
add command line switch to activate enum handling
OkieOth Jun 9, 2019
71a67b7
add additional tests for enum handling
OkieOth Jun 9, 2019
b92d1dd
wip: start to implement java bean template
OkieOth Jun 9, 2019
e285fdc
done
OkieOth Jun 16, 2019
4d37098
Merge pull request #36 from schlothauer-wauer/enum_support
OkieOth Jun 19, 2019
bee0cff
manual merge with java_11 branch
Jun 19, 2019
284d1d7
edit README and make DoCodeGen function static
Jun 19, 2019
4b0c31d
add automated docker image tags from version
Jun 19, 2019
b662bd5
manual merge with java11 branch
Jul 6, 2019
b3da095
add template debugging example
Jul 7, 2019
928b94c
make external model references standard conform
Aug 9, 2019
866a32f
wip: tests are broken
Mar 23, 2020
b5c69b0
fix test
Mar 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.idea
*.log
.gradle
build
tmp
classes
out
*.swp
pushLatest.bat
src/main/groovy/de/lisaplus/atlas/DummyGenerator.groovy
src/main/groovy/de/lisaplus/atlas/TestStarter.groovy
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/java/jdk:11u3-zulu-alpine as build

RUN ["jlink", \
"--compress=2", \
"--strip-debug", \
"--no-header-files", \
"--no-man-pages", \
"--module-path", "/usr/lib/jvm/zulu-11-azure-jdk_11.31.11-11.0.3-linux_musl_x64/jmods", \
"--add-modules", "java.base,java.logging,java.desktop,java.naming,java.prefs,java.xml,java.scripting,java.sql", \
"--output", "/custom_jre"]

FROM alpine:latest
COPY --from=build /custom_jre /opt/jre/

RUN ln -s /opt/jre/bin/java /usr/bin/

ADD build/release /opt/jsonCodeGen/

ENTRYPOINT ["/opt/jsonCodeGen/jsonCodeGen.sh"]

CMD ["--help"]
94 changes: 91 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A simple Groovy based program to do generation tasks from a JSON schema.

## Requirements
* Java 8
* Gradle v4.*
* Gradle v5.4*

## Unsupported JSON schema features
* patternProperties - make no sense in model description
Expand Down Expand Up @@ -52,8 +52,6 @@ A simple Groovy based program to do generation tasks from a JSON schema.
## Handle with gradle
### Using with gradle
```bash
# do a complete release to configured maven repository
gradle publish

# builds a release with all dependencies
# release is built in PROJECT_DIR/build/release
Expand All @@ -80,6 +78,53 @@ gradle myRun -PmyArgs="-o,/tmp/test_beans,-m,src/test/resources/test_schemas/mul
-gp,destFileNameExt=java,-gp,packageName=de.sw.atlas.test"
```
### Usage of the release

```bash
./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
Expand Down Expand Up @@ -107,3 +152,46 @@ basic design.

## Usage
[see here](src/main/resources/docs/usage.md)

## Releases
[see here](Releases.md)

# 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.

```Groovy
// example usage of a generator script defined function
${script.generatorScriptDefinedFunction(possibleParameter)}
```

```Groovy
// example function definition in a generator script
def generatorScriptDefinedFunction(def someString) {
return "Hello: $someString"
}
```
## Code Examples
* [example additional generator script](./src/test/resources/templates/handling_helper.groovy)
* [example template that utilize the script](./src/test/resources/templates/handling.txt)
* [test that combines both](./src/test/groovy/de/lisaplus/atlas/codegen/test/MultiFileTemplates.groovy)
* [test in a shell script](./bin/debug_example.sh)

## 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.
66 changes: 66 additions & 0 deletions Releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## 0.13.1
- handle the right notation of external references: e.g. ./object_base.json#/definitions/ObjectBase

(Attention, the wrong reference style before that version, is still working)
## 0.8.4
- add additional generator parameters to improve plantuml view (ignoreAttribs,ignoreRefs,ignoreImplicitRefs, ignoreCompositions)

## 0.8.3
- ignoreTag, neededTag are handled now as lists for multi-file-generators
- rename 'pmta' command line switch to specify a required attribute for main types to 'mta'
- add 'tmt' command line switch to add automatically a 'mainType' tag to all main types

## 0.8.2
- needed fix in 'pmta' command line switch

## 0.8.1
- add to types schemaPath and schemaFileName attributes (to finally detect what are the interesting main types of a model)
- add a isMainType function to model type
- add command line switches pro print only main types

## 0.8.0
- command line switches for type black- and white-lists
- command line switch to add tags to types
- command line switch to remove a tag from types
- command line switch to remove a tag from all types
- enforce camel-case type names in models
- add guidTypeColor generator parameter for plantuml
- remove printTags generator parameter for plantuml
- add printTypeTags generator parameter for plantuml
- add printPropTags generator parameter for plantuml

## 0.7.5
- deep copy functions for types
- introduce pure array type to handle definitions where arrays contain only arrays, f.e. geoJson Polygons

```json
...
"FeatureAreaGeometry": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"coordinates": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
}
}
},
"projection": {
"type": "string"
}
},
"__tags": ["additional"]
},
...
```

## 0.7.4
- add attributes `selfReference` and `selfContainment` to model property type
20 changes: 20 additions & 0 deletions bin/debug_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# Example script to illustrate the template debugging option of jsonCodeGen

scriptPos=${0%/*}

debugStarterScript=$scriptPos/../build/release/jsonCodeGenDebug.sh
if ! [ -f "$debugStarterScript" ]; then
echo "debug starter script not found: $debugStarterScript"
echo "Maybe release is not created. Try to create a release at first and re-run the script"
echo "gradle clean buildRelease"
exit 1
fi

$debugStarterScript -g "multifiles=$scriptPos/../src/test/resources/templates/handling.txt" \
-gs "$scriptPos/../src/test/resources/templates/handling_helper.groovy" \
-m "$scriptPos/../src/test/resources/test_schemas/ds/incident.json" \
-o "$scriptPos/../tmp/handling" \
-gp "packageName=de.debug"


57 changes: 57 additions & 0 deletions bin/uploadReleaseToNexus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

scriptPos=${0%/*}

# retrieve the version from project file
version=`cat "$scriptPos/../build.gradle" | grep project.version | grep = | sed -e "s-.* '--" -e "s-'--"`
echo "version: $version"

pushd "$scriptPos/.." > /dev/null
if ! gradle publish; then
echo "error while publish jars to nexus"
popd > /dev/null
fi
popd > /dev/null

if [ -z "$NEXUS_USER" ]; then
echo "NEXUS_USER not defined"
exit 1
fi

if [ -z "$NEXUS_RAW_ARCHIVE" ]; then
echo "NEXUS_RAW_ARCHIVE not defined"
exit 1
fi

pushd "$scriptPos/.." > /dev/null
if ! gradle clean build; then
echo 'error while build'
exit 1
fi

if ! gradle buildRelease; then
echo 'error while build release'
exit 1
fi

cd build/release


releaseFile="jsonCodeGen_$version.tgz"

if [ -f "$releaseFile" ]; then
rm -f "$releaseFile"
fi

tar -czf "$releaseFile" *

if ! curl -v --user "$NEXUS_USER" --upload-file "$releaseFile" \
"$NEXUS_RAW_ARCHIVE/$releaseFile"
then
echo "error while upload release to nexus raw repo"
fi

git tag "$version"

popd > /dev/null

Loading