Skip to content

Commit

Permalink
Reorganised date/time validations, added isURITemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
pwall567 committed Nov 2, 2024
1 parent b87c33f commit 51d4a2b
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 126 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build

on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '**.md'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '8'
cache: maven
- name: Build with mvn package
run: mvn -B --no-transfer-progress package
29 changes: 29 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploy

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '8'
cache: maven
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Set up signing key
run: |
# there's probably a better way of doing this!
echo -e "${{ secrets.MAVEN_GPG_PRIVATE_KEY_E }}" | gpg --batch --import
- name: Build and deploy with mvn deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
run: mvn -B --no-transfer-progress deploy
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

The format is based on [Keep a Changelog](http://keepachangelog.com/).

## [2.0] - 2024-11-02
### Added
- `build.yml`, `deploy.yml`: converted project to GitHub Actions
### Changed
- updated all functions to take `CharSequence` instead of `String`
- added `validations` table
- reorganised date/time validations, added `isLocalDateTime()`, `isLocalTime()`
- added `isURITemplate()`
- `pom.xml`, tests: reverted from Junit 5 to Junit 4 (more stable)
### Removed
- `.travis.yml`

## [1.5] - 2022-11-06
### Changed
- simplified and improved efficiency (by loop unrolling) of `isUUID`
Expand Down
125 changes: 110 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# json-validation

[![Build Status](https://travis-ci.com/pwall567/json-validation.svg?branch=main)](https://app.travis-ci.com/github/pwall567/json-validation)
[![Build Status](https://github.com/pwall567/json-validation/actions/workflows/build.yml/badge.svg)](https://github.com/pwall567/json-validation/actions/workflows/build.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Maven Central](https://img.shields.io/maven-central/v/net.pwall.json/json-validation?label=Maven%20Central)](https://search.maven.org/search?q=g:%22net.pwall.json%22%20AND%20a:%22json-validation%22)

Expand Down Expand Up @@ -29,85 +29,180 @@ They return `true` if the value matches the requirements of the specification (t
```java
boolean valid = JSONValidation.isDateTime(str);
```
Test for conformity to the `date-time` format type.
A string is valid if it conforms to the `date-time` production in
[RFC 3339, section 5.6](https://tools.ietf.org/html/rfc3339#section-5.6).

### `local-date-time` validation

```java
boolean valid = JSONValidation.isLocalDateTime(str);
```
Test for conformity to an unofficial `local-date-time` type (not part of the JSON Schema Validation Specification).
A string is valid if it conforms to a new production `[full-date "T" partial-time]` based on
[RFC 3339, section 5.6](https://tools.ietf.org/html/rfc3339#section-5.6).

### `date` validation

```java
boolean valid = JSONValidation.isDate(str);
```

Test for conformity to the `date` format type.
A string is valid if it conforms to the `full-date` production in
[RFC 3339, section 5.6](https://tools.ietf.org/html/rfc3339#section-5.6).

### `time` validation

```java
boolean valid = JSONValidation.isTime(str);
```

### `duration` validation
Test for conformity to the `time` format type.
A string is valid if it conforms to the `full-time` production in
[RFC 3339, section 5.6](https://tools.ietf.org/html/rfc3339#section-5.6).

```java
boolean valid = JSONValidation.isDuration(str);
```

### `email` validation
### `local-time` validation

```java
boolean valid = JSONValidation.isEmail(str);
boolean valid = JSONValidation.isLocalTime(str);
```

### `hostname` validation
Test for conformity to an unofficial `local-time` type (not part of the JSON Schema Validation Specification).
A string is valid if it conforms to the `partial-time` production in
[RFC 3339, section 5.6](https://tools.ietf.org/html/rfc3339#section-5.6).

### `duration` validation

```java
boolean valid = JSONValidation.isHostname(str);
boolean valid = JSONValidation.isDuration(str);
```

Test for conformity to the `duration` format type.
A string is valid if it conforms to the `duration` production in
[RFC 3339, Appendix A](https://tools.ietf.org/html/rfc3339#appendix-A).

### `uri` validation

```java
boolean valid = JSONValidation.isURI(str);
```

Test for conformity to the `uri` format type.
A string is valid if it conforms to [RFC 3986](https://tools.ietf.org/html/rfc3986).

### `uri-reference` validation

```java
boolean valid = JSONValidation.isURIReference(str);
```

Test for conformity to the `uri-reference` format type.
A string is valid if it conforms to [RFC 3986](https://tools.ietf.org/html/rfc3986) (either a URI or a
relative-reference).

### `uri-template` validation

```java
boolean valid = JSONValidation.isURI(str);
```

Test for conformity to the `uri-template` format type.
A string is valid if it conforms to [RFC 6570](https://www.rfc-editor.org/rfc/rfc6570.html).

### `uuid` validation

```java
boolean valid = JSONValidation.isUUID(str);
```

Test for conformity to the `uuid` format type.
A string is valid if it conforms to [RFC 4122](https://tools.ietf.org/html/rfc4122).

### `hostname` validation

```java
boolean valid = JSONValidation.isHostname(str);
```

Test for conformity to the `hostname` format type.
A string is valid if it conforms to [RFC 1123, section 2.1](https://tools.ietf.org/html/rfc1123#section-2.1).

### `email` validation

```java
boolean valid = JSONValidation.isEmail(str);
```

Test for conformity to the `email` format type.

Validation of email addresses is difficult, largely because the specification in
[RFC 5322](https://www.ietf.org/rfc/rfc5322.html) makes reference to earlier “obsolete” forms of email
addresses that are expected to be accepted as valid.
This function does not attempt to cover the entire range of obsolete addresses; instead, it implements a form of
validation derived from the regular expression at the web site [`emailregex.com`](http://emailregex.com/) for the
“local-part” (the addressee or mailbox name), and it uses the `hostname` validation from
[RFC 1123](https://tools.ietf.org/html/rfc1123) for the “domain”.

### `ipv4` validation

```java
boolean valid = JSONValidation.isIPV4(str);
```

Test for conformity to the `ipv4` format type.
A string is valid if it conforms to [RFC 2673, section 3.2](https://tools.ietf.org/html/rfc2673#section-3.2).

### `ipv6` validation

```java
boolean valid = JSONValidation.isIPV6(str);
```

Test for conformity to the `ipv6` format type.
A string is valid if it conforms to [RFC 4291, section 2.2](https://tools.ietf.org/html/rfc4291#section-2.2).

**NOTE:** The [JSON Schema Validation](https://json-schema.org/draft/2019-09/json-schema-validation.html) specification
says (§ 7.3.4) that a string conforming to the `ipv6` format must be an “IPv6 address as defined in
[RFC 4291, section 2.2](https://tools.ietf.org/html/rfc4291)”.
Subsequent to RFC 4291, [RFC 5952](https://tools.ietf.org/html/rfc5952) recommended tighter restrictions on the
representation of IPV6 addresses, including mandating the use of lower case for all alpha characters, and prohibiting
the use of “`::`” to compress a single zero 16-bit field.
Because the JSON Schema Validation specification refers only to RFC 4291, not RFC 5952, this function does not implement
the tighter restrictions of the later document.

### `json-pointer` validation

```java
boolean valid = JSONValidation.isJSONPointer(str);
```

Test for conformity to the `json-pointer` format type.
A string is valid if it conforms to [RFC 6901, section 5](https://tools.ietf.org/html/rfc6901#section-5).

### `relative-json-pointer` validation

```java
boolean valid = JSONValidation.isRelativeJSONPointer(str);
```

Test for conformity to the `relative-json-pointer` format type.
A string is valid if it conforms to
[Relative JSON Pointers](https://json-schema.org/draft/2020-12/relative-json-pointer.html).

### `regex` validation

```java
boolean valid = JSONValidation.isRegex(str);
```

Test for conformity to the `regex` format type.
A string is valid if it conforms to the [ECMA 262](https://www.ecma-international.org/ecma-262/11.0) regular expression
dialect.

Since the Java `Pattern` class used here implements a dialect very close to, but not identical to the ECMA 262 variant,
it is possible that in rare cases there may be subtle inconsistencies in the results of this function.

## Additional Functions

In order to perform date validations, the library contains additional static functions related to dates.
Expand Down Expand Up @@ -139,25 +234,25 @@ long list of transitive dependencies.

## Dependency Specification

The latest version of the library is 1.5, and it may be obtained from the Maven Central repository.
The latest version of the library is 2.0, and it may be obtained from the Maven Central repository.

### Maven
```xml
<dependency>
<groupId>net.pwall.json</groupId>
<artifactId>json-validation</artifactId>
<version>1.5</version>
<version>2.0</version>
</dependency>
```
### Gradle
```groovy
implementation 'net.pwall.json:json-validation:1.5'
implementation 'net.pwall.json:json-validation:2.0'
```
### Gradle (kts)
```kotlin
implementation("net.pwall.json:json-validation:1.5")
implementation("net.pwall.json:json-validation:2.0")
```

Peter Wall

2022-11-06
2024-11-02
36 changes: 9 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.pwall.json</groupId>
<artifactId>json-validation</artifactId>
<version>1.5</version>
<version>2.0</version>
<name>JSON Validation</name>
<description>Validation functions for JSON Schema validation</description>
<packaging>jar</packaging>
Expand All @@ -14,7 +14,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit.jupiter.version>5.9.1</junit.jupiter.version>
</properties>

<licenses>
Expand Down Expand Up @@ -55,9 +54,9 @@
<dependencies>
<!-- IMPORTANT - do not add transitive dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -67,33 +66,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<version>3.7.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -109,7 +91,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -122,7 +104,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -133,7 +115,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<version>3.2.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
Loading

0 comments on commit 51d4a2b

Please sign in to comment.