Skip to content

Commit

Permalink
Updated README and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
jefbarn committed Jul 28, 2021
1 parent 230a467 commit f4baa52
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.2.0] - 2021-07-28
### Added
- JSON Type Definition and Apache Avro support

## [0.1.0] - 2021-07-27
### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgx_json_schema"
version = "0.1.0"
version = "0.2.0"
edition = "2018"

[lib]
Expand Down
77 changes: 75 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Supported drafts:
* Draft 6
* Draft 4 (except optional bignum.json test case)

Bonus support added for:
* [JSON Type Definition (JTD)](https://jsontypedef.com/)
* [Apache Avro](https://avro.apache.org/)

### Installation:

```shell
Expand All @@ -40,6 +44,7 @@ create extension pgx_json_schema;

### How to use:

#### JSON Schema
```
select * from json_schema_is_valid('{"maxLength": 5}'::jsonb, '"foobar"'::jsonb);
Expand All @@ -48,7 +53,6 @@ json_schema_is_valid
f
```


```
select * from json_schema_get_errors('{"maxLength": 5}'::jsonb, '"foobar"'::jsonb);
Expand All @@ -57,13 +61,82 @@ error_value | description | details | in
"foobar" | "foobar" is longer than 5 characters | MaxLength { limit: 5 } | | /maxLength
```

#### JSON Type Definition
```
select jtd_is_valid('{
"properties": {
"name": { "type": "string" },
"age": { "type": "uint32" },
"phones": {
"elements": {
"type": "string"
}
}
}
}'::jsonb, '{
"age": "43",
"phones": ["+44 1234567", 442345678]
}'::jsonb);
jtd_is_valid
--------------
f
```

```
select instance_path, schema_path from jtd_get_errors('{
"properties": {
"name": { "type": "string" },
"age": { "type": "uint32" },
"phones": {
"elements": {
"type": "string"
}
}
}
}', '{
"age": "43",
"phones": ["+44 1234567", 442345678]
}'::jsonb);
instance_path | schema_path
---------------+----------------------------------
/age | /properties/age/type
| /properties/name
/phones/1 | /properties/phones/elements/type
```

> **_NOTE:_** The jtd library only reports the position of the validation errors, not a description.
#### Apache Avro
```
select avro_is_valid('{
"type": "record",
"name": "test",
"fields": [
{"name": "a", "type": "long", "default": 42},
{"name": "b", "type": "string"}
]
}'::jsonb, '{
"a": 27,
"b": "foo"
}'::jsonb);
avro_is_valid
---------------
t
```

> **_NOTE:_** The avro library only does complete validation, there is no way to list the errors.

### Things left to do:

- [ ] Use shared memory to store compiled validator (potential performance gain)
- [ ] More testing
- [ ] Benchmarking
- [ ] Add more schema types like [JTD](https://jsontypedef.com/) and [Avro](https://avro.apache.org/)
- [x] Add more schema types like [JTD](https://jsontypedef.com/) and [Avro](https://avro.apache.org/)
- [ ] Support newer JSON Schema drafts
- [x] Add Dockerfile with installation example

Expand Down

0 comments on commit f4baa52

Please sign in to comment.