Skip to content

Commit 34775cd

Browse files
Merge pull request #33 from saasquatch/dev
Dev
2 parents 0d75629 + 85d813a commit 34775cd

33 files changed

+686
-356
lines changed

.github/workflows/JavaCI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ jobs:
44
build:
55
runs-on: ubuntu-latest
66
steps:
7-
- uses: actions/checkout@v3
8-
- uses: actions/setup-java@v3
7+
- uses: actions/checkout@v4
8+
- uses: actions/setup-java@v4
99
with:
10-
java-version: "8"
10+
java-version: 8
1111
distribution: adopt
1212
- name: Setup Gradle
1313
uses: gradle/gradle-build-action@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ buildNumber.properties
3232
.gradle
3333
.gradletasknamecache
3434
.m2
35+
build/

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## [Unreleased]
44

5+
## [0.2.1] - 2024-01-05
6+
7+
### Added
8+
9+
- (Beta) Added support for JSON Path.
10+
11+
### Changed
12+
13+
- Internal dependency version bumps.
14+
515
## [0.2.0] - 2023-04-24
616

717
### Changed
@@ -42,7 +52,9 @@
4252

4353
## [0.1.1] - 2020-02-27
4454

45-
[Unreleased]: https://github.com/saasquatch/json-schema-inferrer/compare/0.2.0...HEAD
55+
[Unreleased]: https://github.com/saasquatch/json-schema-inferrer/compare/0.2.1...HEAD
56+
57+
[0.2.1]: https://github.com/saasquatch/json-schema-inferrer/compare/0.2.0...0.2.1
4658

4759
[0.2.0]: https://github.com/saasquatch/json-schema-inferrer/compare/0.1.5...0.2.0
4860

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ Maven
175175
<dependency>
176176
<groupId>com.github.saasquatch</groupId>
177177
<artifactId>json-schema-inferrer</artifactId>
178-
<version>0.2.0</version>
178+
<version>0.2.1</version>
179179
</dependency>
180180
```
181181

182182
Gradle
183183

184184
```gradle
185-
implementation 'com.github.saasquatch:json-schema-inferrer:0.2.0'
185+
implementation 'com.github.saasquatch:json-schema-inferrer:0.2.1'
186186
```
187187

188188
### Transitive Dependencies

build.gradle

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ repositories {
2020
}
2121

2222
dependencies {
23-
testImplementation platform('org.junit:junit-bom:5.9.2')
24-
testImplementation 'org.junit.jupiter:junit-jupiter'
23+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
24+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
2525
implementation 'com.google.code.findbugs:jsr305:3.0.2'
26-
api 'com.fasterxml.jackson.core:jackson-databind:2.15.0'
27-
builtInFormatInferrerSupportImplementation 'commons-validator:commons-validator:1.7'
28-
testImplementation 'com.networknt:json-schema-validator:1.0.80'
29-
testImplementation 'com.google.guava:guava:31.1-jre'
26+
api 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
27+
builtInFormatInferrerSupportImplementation 'commons-validator:commons-validator:1.8.0'
28+
testImplementation 'com.networknt:json-schema-validator:1.1.0'
29+
testImplementation 'com.google.guava:guava:33.0.0-jre'
3030
}
3131

3232
tasks.test {
3333
useJUnitPlatform()
3434
}
35+
36+
java {
37+
toolchain {
38+
languageVersion.set(JavaLanguageVersion.of(8))
39+
}
40+
}

gradle/wrapper/gradle-wrapper.jar

468 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

gradlew

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ done
8585
APP_BASE_NAME=${0##*/}
8686
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
8787

88-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89-
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90-
9188
# Use the maximum available, or set MAX_FD != -1 to use that value.
9289
MAX_FD=maximum
9390

@@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
197194
done
198195
fi
199196

197+
198+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
199+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
200+
200201
# Collect all arguments for the java command;
201202
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
202203
# shell script including quotes and variable substitutions, so put them in

gradlew.bat

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
1-
@rem
2-
@rem Copyright 2015 the original author or authors.
3-
@rem
4-
@rem Licensed under the Apache License, Version 2.0 (the "License");
5-
@rem you may not use this file except in compliance with the License.
6-
@rem You may obtain a copy of the License at
7-
@rem
8-
@rem https://www.apache.org/licenses/LICENSE-2.0
9-
@rem
10-
@rem Unless required by applicable law or agreed to in writing, software
11-
@rem distributed under the License is distributed on an "AS IS" BASIS,
12-
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
@rem See the License for the specific language governing permissions and
14-
@rem limitations under the License.
15-
@rem
16-
17-
@if "%DEBUG%"=="" @echo off
18-
@rem ##########################################################################
19-
@rem
20-
@rem Gradle startup script for Windows
21-
@rem
22-
@rem ##########################################################################
23-
24-
@rem Set local scope for the variables with windows NT shell
25-
if "%OS%"=="Windows_NT" setlocal
26-
27-
set DIRNAME=%~dp0
28-
if "%DIRNAME%"=="" set DIRNAME=.
29-
@rem This is normally unused
30-
set APP_BASE_NAME=%~n0
31-
set APP_HOME=%DIRNAME%
32-
33-
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
34-
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35-
36-
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37-
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38-
39-
@rem Find java.exe
40-
if defined JAVA_HOME goto findJavaFromJavaHome
41-
42-
set JAVA_EXE=java.exe
43-
%JAVA_EXE% -version >NUL 2>&1
44-
if %ERRORLEVEL% equ 0 goto execute
45-
46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
51-
52-
goto fail
53-
54-
:findJavaFromJavaHome
55-
set JAVA_HOME=%JAVA_HOME:"=%
56-
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57-
58-
if exist "%JAVA_EXE%" goto execute
59-
60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
65-
66-
goto fail
67-
68-
:execute
69-
@rem Setup the command line
70-
71-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72-
73-
74-
@rem Execute Gradle
75-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76-
77-
:end
78-
@rem End local scope for the variables with windows NT shell
79-
if %ERRORLEVEL% equ 0 goto mainEnd
80-
81-
:fail
82-
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83-
rem the _cmd.exe /c_ return code!
84-
set EXIT_CODE=%ERRORLEVEL%
85-
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86-
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87-
exit /b %EXIT_CODE%
88-
89-
:mainEnd
90-
if "%OS%"=="Windows_NT" endlocal
91-
92-
:omega
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem https://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
17+
@if "%DEBUG%"=="" @echo off
18+
@rem ##########################################################################
19+
@rem
20+
@rem Gradle startup script for Windows
21+
@rem
22+
@rem ##########################################################################
23+
24+
@rem Set local scope for the variables with windows NT shell
25+
if "%OS%"=="Windows_NT" setlocal
26+
27+
set DIRNAME=%~dp0
28+
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
30+
set APP_BASE_NAME=%~n0
31+
set APP_HOME=%DIRNAME%
32+
33+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
34+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35+
36+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38+
39+
@rem Find java.exe
40+
if defined JAVA_HOME goto findJavaFromJavaHome
41+
42+
set JAVA_EXE=java.exe
43+
%JAVA_EXE% -version >NUL 2>&1
44+
if %ERRORLEVEL% equ 0 goto execute
45+
46+
echo.
47+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48+
echo.
49+
echo Please set the JAVA_HOME variable in your environment to match the
50+
echo location of your Java installation.
51+
52+
goto fail
53+
54+
:findJavaFromJavaHome
55+
set JAVA_HOME=%JAVA_HOME:"=%
56+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57+
58+
if exist "%JAVA_EXE%" goto execute
59+
60+
echo.
61+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62+
echo.
63+
echo Please set the JAVA_HOME variable in your environment to match the
64+
echo location of your Java installation.
65+
66+
goto fail
67+
68+
:execute
69+
@rem Setup the command line
70+
71+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72+
73+
74+
@rem Execute Gradle
75+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76+
77+
:end
78+
@rem End local scope for the variables with windows NT shell
79+
if %ERRORLEVEL% equ 0 goto mainEnd
80+
81+
:fail
82+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83+
rem the _cmd.exe /c_ return code!
84+
set EXIT_CODE=%ERRORLEVEL%
85+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87+
exit /b %EXIT_CODE%
88+
89+
:mainEnd
90+
if "%OS%"=="Windows_NT" endlocal
91+
92+
:omega

src/main/java/com/saasquatch/jsonschemainferrer/AdditionalPropertiesPolicies.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ public static AdditionalPropertiesPolicy noOp() {
3131

3232
/**
3333
* @return A singleton {@link AdditionalPropertiesPolicy} that always sets
34-
* {@code additionalProperties} to true
34+
* {@code additionalProperties} to true
3535
*/
3636
public static AdditionalPropertiesPolicy allowed() {
3737
return input -> JsonNodeFactory.instance.booleanNode(true);
3838
}
3939

4040
/**
4141
* @return A singleton {@link AdditionalPropertiesPolicy} that always sets
42-
* {@code additionalProperties} to false
42+
* {@code additionalProperties} to false
4343
*/
4444
public static AdditionalPropertiesPolicy notAllowed() {
4545
return input -> JsonNodeFactory.instance.booleanNode(false);
4646
}
4747

4848
/**
4949
* @return A singleton {@link AdditionalPropertiesPolicy} that sets {@code additionalProperties}
50-
* to existing types on the schema
50+
* to existing types on the schema
5151
*/
5252
@Beta
5353
public static AdditionalPropertiesPolicy existingTypes() {

src/main/java/com/saasquatch/jsonschemainferrer/BuiltInFormatInferrer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.time.LocalDate;
44
import java.time.ZonedDateTime;
5+
import java.util.regex.Pattern;
56
import javax.annotation.Nonnull;
67
import org.apache.commons.validator.routines.EmailValidator;
78
import org.apache.commons.validator.routines.InetAddressValidator;
@@ -23,6 +24,10 @@ public String inferFormat(@Nonnull FormatInferrerInput input) {
2324
},
2425

2526
DATE_TIME {
27+
28+
private final Pattern timePattern = Pattern.compile(
29+
"^(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.\\d+)?(?:Z|[+-](?:0[0-9]|2[0-3]):[0-5][0-9])$");
30+
2631
@Override
2732
public String inferFormat(@Nonnull FormatInferrerInput input) {
2833
final String textValue = input.getSample().textValue();
@@ -45,8 +50,7 @@ public String inferFormat(@Nonnull FormatInferrerInput input) {
4550
// Ignore
4651
}
4752
// The time format is not the same as Java's LocalTime and OffsetTime
48-
if (textValue.matches(
49-
"^(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.\\d+)?(?:Z|[+-](?:0[0-9]|2[0-3]):[0-5][0-9])$")) {
53+
if (timePattern.matcher(textValue).matches()) {
5054
return Consts.Formats.TIME;
5155
}
5256
}

src/main/java/com/saasquatch/jsonschemainferrer/Consts.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface Consts {
1616
* Field names
1717
*/
1818
interface Fields {
19+
1920
String TYPE = "type";
2021
String ITEMS = "items";
2122
String ANY_OF = "anyOf";
@@ -46,6 +47,7 @@ interface Fields {
4647
* Type names
4748
*/
4849
interface Types {
50+
4951
String OBJECT = "object";
5052
String ARRAY = "array";
5153
String STRING = "string";
@@ -61,6 +63,7 @@ interface Types {
6163
* Format names
6264
*/
6365
interface Formats {
66+
6467
String EMAIL = "email";
6568
String IPV4 = "ipv4";
6669
String IPV6 = "ipv6";
@@ -69,4 +72,9 @@ interface Formats {
6972
String TIME = "time";
7073
}
7174

75+
interface JsonPath {
76+
77+
String ROOT = "$";
78+
}
79+
7280
}

0 commit comments

Comments
 (0)