Skip to content

Commit

Permalink
Merge pull request #33 from saasquatch/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
slisaasquatch authored Jan 5, 2024
2 parents 0d75629 + 85d813a commit 34775cd
Show file tree
Hide file tree
Showing 33 changed files with 686 additions and 356 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/JavaCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: "8"
java-version: 8
distribution: adopt
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ buildNumber.properties
.gradle
.gradletasknamecache
.m2
build/
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## [Unreleased]

## [0.2.1] - 2024-01-05

### Added

- (Beta) Added support for JSON Path.

### Changed

- Internal dependency version bumps.

## [0.2.0] - 2023-04-24

### Changed
Expand Down Expand Up @@ -42,7 +52,9 @@

## [0.1.1] - 2020-02-27

[Unreleased]: https://github.com/saasquatch/json-schema-inferrer/compare/0.2.0...HEAD
[Unreleased]: https://github.com/saasquatch/json-schema-inferrer/compare/0.2.1...HEAD

[0.2.1]: https://github.com/saasquatch/json-schema-inferrer/compare/0.2.0...0.2.1

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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ Maven
<dependency>
<groupId>com.github.saasquatch</groupId>
<artifactId>json-schema-inferrer</artifactId>
<version>0.2.0</version>
<version>0.2.1</version>
</dependency>
```

Gradle

```gradle
implementation 'com.github.saasquatch:json-schema-inferrer:0.2.0'
implementation 'com.github.saasquatch:json-schema-inferrer:0.2.1'
```

### Transitive Dependencies
Expand Down
18 changes: 12 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ repositories {
}

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

tasks.test {
useJUnitPlatform()
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 4 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
184 changes: 92 additions & 92 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ public static AdditionalPropertiesPolicy noOp() {

/**
* @return A singleton {@link AdditionalPropertiesPolicy} that always sets
* {@code additionalProperties} to true
* {@code additionalProperties} to true
*/
public static AdditionalPropertiesPolicy allowed() {
return input -> JsonNodeFactory.instance.booleanNode(true);
}

/**
* @return A singleton {@link AdditionalPropertiesPolicy} that always sets
* {@code additionalProperties} to false
* {@code additionalProperties} to false
*/
public static AdditionalPropertiesPolicy notAllowed() {
return input -> JsonNodeFactory.instance.booleanNode(false);
}

/**
* @return A singleton {@link AdditionalPropertiesPolicy} that sets {@code additionalProperties}
* to existing types on the schema
* to existing types on the schema
*/
@Beta
public static AdditionalPropertiesPolicy existingTypes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import org.apache.commons.validator.routines.EmailValidator;
import org.apache.commons.validator.routines.InetAddressValidator;
Expand All @@ -23,6 +24,10 @@ public String inferFormat(@Nonnull FormatInferrerInput input) {
},

DATE_TIME {

private final Pattern timePattern = Pattern.compile(
"^(?:[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])$");

@Override
public String inferFormat(@Nonnull FormatInferrerInput input) {
final String textValue = input.getSample().textValue();
Expand All @@ -45,8 +50,7 @@ public String inferFormat(@Nonnull FormatInferrerInput input) {
// Ignore
}
// The time format is not the same as Java's LocalTime and OffsetTime
if (textValue.matches(
"^(?:[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])$")) {
if (timePattern.matcher(textValue).matches()) {
return Consts.Formats.TIME;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/saasquatch/jsonschemainferrer/Consts.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Consts {
* Field names
*/
interface Fields {

String TYPE = "type";
String ITEMS = "items";
String ANY_OF = "anyOf";
Expand Down Expand Up @@ -46,6 +47,7 @@ interface Fields {
* Type names
*/
interface Types {

String OBJECT = "object";
String ARRAY = "array";
String STRING = "string";
Expand All @@ -61,6 +63,7 @@ interface Types {
* Format names
*/
interface Formats {

String EMAIL = "email";
String IPV4 = "ipv4";
String IPV6 = "ipv6";
Expand All @@ -69,4 +72,9 @@ interface Formats {
String TIME = "time";
}

interface JsonPath {

String ROOT = "$";
}

}
Loading

0 comments on commit 34775cd

Please sign in to comment.