Skip to content

Commit

Permalink
Merge pull request #52 from korzio/release/1.2.0
Browse files Browse the repository at this point in the history
Release/1.2.0
  • Loading branch information
korzio authored Sep 27, 2017
2 parents 47935f6 + afaab0c commit a98cb5d
Show file tree
Hide file tree
Showing 19 changed files with 491 additions and 283 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ log.log
*.log

.vscode
test/
test/
docs/
75 changes: 75 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
#### 1.2.0 (2017-09-25)

##### Documentation Changes

* **npm:** Remove docs folder from npm files #51 ([d5d2a8de](https://github.com/korzio/djv/commit/d5d2a8decd75db3351734ba25175b98533ca2d75))
* **readme:** Update v6 support #51 ([2ec9d7f0](https://github.com/korzio/djv/commit/2ec9d7f0abe53edb5b0e0c2d23b0747dd1cafbca))
* **const:** Add const documentation #51 ([b7f0355d](https://github.com/korzio/djv/commit/b7f0355d61e048d88ee485007d006f47831de0c9))
* **state:**
* Fix state documentation #51 ([7a000072](https://github.com/korzio/djv/commit/7a000072b038bf6ffa3a4d0c98252c739fecd7c3))
* Add resolution exampes #41 ([a89658c0](https://github.com/korzio/djv/commit/a89658c07dfb65848920425404e278b5c099eaa7))
* Add state description #41 ([ff1b7a75](https://github.com/korzio/djv/commit/ff1b7a75392e807098c29d0a719b99cdb1f596d6))
* **todo:** Add todo for draft-06 #41 ([4fa64971](https://github.com/korzio/djv/commit/4fa64971c550fa558fda3031c93bd62ef061a7aa))
* **contribute:** Change tests debug description ([b0d03069](https://github.com/korzio/djv/commit/b0d03069c24c462cee82c8c6b5c78baeb4cc4f41))
* **contributing:**
* Fix version ([351a8eb8](https://github.com/korzio/djv/commit/351a8eb88648b2939ecc7e6a87c9c6ce1f762f1d))
* Fix typo ([66b62f3e](https://github.com/korzio/djv/commit/66b62f3eab75768403eae9682bb49ebf859f99eb))
* Add release branch MR description ([faf53856](https://github.com/korzio/djv/commit/faf538564894a47d386e621b7de8a21602020052))
* **release:** Add table of contents, update release contributing #35 ([2f69a166](https://github.com/korzio/djv/commit/2f69a1660c3d882bc783e42dbd8ea45e7173d824))
* Update api docs, format utils ([11cae181](https://github.com/korzio/djv/commit/11cae1815de6f786abc24a71616eb50e18b2beaf))

##### New Features

* **id:** Add $id, examples keywords #44 ([1ef4745f](https://github.com/korzio/djv/commit/1ef4745f1658857c6c132264b8319fdaa73ccbcc))
* **format:** Add uri formats #44 ([79802269](https://github.com/korzio/djv/commit/79802269650e530228f2719497ddda165acfba81))
* **validator:**
* Add json-pointer format #44 ([7a522f8a](https://github.com/korzio/djv/commit/7a522f8a9da29504190140329d12faf0aa29d4c5))
* Add propertyNames validator #44 ([5ad9d343](https://github.com/korzio/djv/commit/5ad9d343575558be0e6a69bd2420b958e1d4dc00))
* Add const validator #44 ([1d4fa106](https://github.com/korzio/djv/commit/1d4fa10656d4bb7caffd2fd9b598ecfccf1d71eb))
* Add contains validator #44 ([8ecf27d8](https://github.com/korzio/djv/commit/8ecf27d81621b7638e6199c75c1ab623f47561ec))
* **validators:** Add useVersion method to change environment version; Add exlusive maximum/minimum properties #44 ([f57f9116](https://github.com/korzio/djv/commit/f57f9116204ad0f9f4126a81e6ead89bbce25f58))

##### Bug Fixes

* **test:**
* Add name json mock data to test environment #41 ([c1d0e13b](https://github.com/korzio/djv/commit/c1d0e13bb50ccab189e88b7f6d6e2568c47a3770))
* **rename:** Rename template resolve to link as in state #41 ([34fc6e4d](https://github.com/korzio/djv/commit/34fc6e4d3f378a82378244a354817cd9ec4a6e3e))
* **format:** Add regex, fix uri formatters #44 ([757397d7](https://github.com/korzio/djv/commit/757397d7fb1a698a92953596804cf37d28b325d1))
* **draft-06:**
* Move validators to patch environment #44 ([9f7412bc](https://github.com/korzio/djv/commit/9f7412bc3ed8148d119b729cf30b6f8d4c7fbb82))
* Fix properties strict type check #44 ([f663f7ba](https://github.com/korzio/djv/commit/f663f7ba6285ed04575050ac9d27eb4509420c01))
* **boolean:** Fix transform default schema ([69488621](https://github.com/korzio/djv/commit/694886218a5f1330d5c49671d88932b645185b95))
* **tests:** Add isSchema, transformSchema utilities for boolean schema presentation #44 ([cb48a2a1](https://github.com/korzio/djv/commit/cb48a2a1da27a7a9c1c373a412b2c0624b8f8f7d))
* **validator:** Add not array required check #44 ([83b01279](https://github.com/korzio/djv/commit/83b01279824698d783aedc8c39b0b434c404f22b))

##### Other Changes

* **state:** Fix skip describe for jasmine #41 ([52ffd0c7](https://github.com/korzio/djv/commit/52ffd0c7f500bf793dfd26df6b46a6551b7ef328))
* **debug:** Add console output if error is thrown ([6b61a465](https://github.com/korzio/djv/commit/6b61a4657668fbee616acf1a7092cfc4a9c53a4c))
* Add draft-06 tests; Switch to json schema test package #44 ([1a9ce7e7](https://github.com/korzio/djv/commit/1a9ce7e77b200fb475735997928edc378e9caf19))

##### Refactors

* **files:**
* Clean code; Remove deprecated #51 ([b815f6dc](https://github.com/korzio/djv/commit/b815f6dcafa1b40f13895b1ffb3d348dff4ed2b4))
* Clean code; Split utils to uri and schema; Move transforms to environment #51 ([7c497fb5](https://github.com/korzio/djv/commit/7c497fb50613680afec2b011a1a46012c0c7b247))
* **performance:** Clean code; Change uri keys utils; Rewrite state resolution id algorithm to not use multiple functions calls #51 ([1fe9339d](https://github.com/korzio/djv/commit/1fe9339d4fefdcbaf75b54e3df53c9c1b5a08f06))
* **state:**
* Clean code; Change cleanId to head #51 ([465749a4](https://github.com/korzio/djv/commit/465749a4c48bab74d34158b15abaacdd44ffdb17))
* Add draft-06 meta schema to tests; Add uriKeys variable to contain id/$id changes; Fix boolean schema descend resolution #41 ([01b37316](https://github.com/korzio/djv/commit/01b37316529752a1fe982f3028bf9065b5a5fbc1))
* Move descend to state; Fix intermediate ids resolution #41 ([ad70e8e7](https://github.com/korzio/djv/commit/ad70e8e775a6834034a1e17a6052eeb9c3b2b47b))
* Fix uri utils regexps #41 ([0df12100](https://github.com/korzio/djv/commit/0df121002385e679a9dfe339f7c2ce66a5e2d86c))
* Fix ignore other properties in $ref schemas; Clean schemas stack after visit #41 ([fe85a55b](https://github.com/korzio/djv/commit/fe85a55b49b8acb6a9013f452a6cb4554a03dd07))
* Add reference schema resolution; Add resolution by id #41 ([64d9ba5e](https://github.com/korzio/djv/commit/64d9ba5e1dacc4b61c2e561290564bbb372c6635))
* Simplify resolution; Rename descend utils #41 ([c55f3af6](https://github.com/korzio/djv/commit/c55f3af6cc96e11909c28648164e105e450866c5))
* **validators:**
* Change hasOwnProperty usage; Add checks for boolean schemas #44 ([af5fcc75](https://github.com/korzio/djv/commit/af5fcc755788215b9c6f26f09a3aee7ae72c760d))

##### Code Style Changes

* **state:** Normalize if-else utils clauses #41 ([b9b11e29](https://github.com/korzio/djv/commit/b9b11e2996607ffe566f33ecd5ab4409bec9f280))

##### Tests

* **properties:** Add check for object type #44 ([3fb8bcbb](https://github.com/korzio/djv/commit/3fb8bcbb56b8915bef2e492524eb1bc8387d75aa))

#### 1.1.1 (2017-07-20)

##### Documentation Changes
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ git checkout -b release/$VERSION
```
- [ ] Update package.json version to $VERSIONALPHA and commit
```sh
git commit -m "release: Update package version to $VERSIONALPHA #ISSUE"
git commit -m "release: Update package version to $VERSIONALPHA #$ISSUE"
```
- [ ] Tag with the alpha version
```sh
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Dynamic JSON Schema Validator

Current package supports **JSON Schema v4** and it contains utils for validating objects against schemas.
Current package supports **JSON Schema v6 and v4**. It contains utils to validate objects against schemas.
This is a part of **djv** packages aimed to work with json-schema.

- [djv](https://github.com/korzio/djv) validate object against schemas
Expand Down Expand Up @@ -192,6 +192,7 @@ npm test

## References <a name="references"></a>

* [JSON-Schema Specification](http://json-schema.org/)
* [JSON Schema Benchmark](https://github.com/ebdrup/json-schema-benchmark)

<!---
Expand Down
2 changes: 1 addition & 1 deletion djv.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion djv.js.map

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions docs/const.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# const <a name="title"></a>

The keyword [const](https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.24) has appeared in draft-06,
meaning the comparison to exact value of a given json-schema const property.

## Table of contents <a name="content"></a>

* [const](#title)
* [Table of contents](#content)
* [Overview](#overview)
* [Examples](#examples)
* [Summary](#summary)

## Overview <a name="overview"></a>

In a current implementation there were already a special constant property defined. However it was under "TODO" comment, and apparently was never tested before. I could not find any tests regarding it in [json-schema-benchmark](https://github.com/ebdrup/json-schema-benchmark/search?utf8=%E2%9C%93&q=constant&type=) as well. Anyways, the current implementation was not good enough to use it in a new specification. If you look into the definition of [instance equality](https://tools.ietf.org/html/draft-wright-json-schema-01#section-4.3) for objects it says

> both are objects, and each property in one has exactly one property with a key equal to the other's, and that other property has an equal value.
And a `JSON.stringify` uses the [sort of "random"](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in) properties order, so it cannot be applied here. The other solution is to use a `deep equal comparison` function, as the others validators do. It is easy work in simple data cases, when a string or number are being compared. However if the `const` value is an array or an object, things there are coming tougher - you have to iterate all keys of *array/object*, compare to the same values on the second *array/object* and sometimes go recursively. However this approach is pretty straightforward, I still assume there could be a better solution. And it is quite relative to the json schema validator tecnhique.

The solution is to preprocess the object given by a `const` keyword in a way normally a validator does it - gets all valuable information on the pre-processing phase and then creates a `function` (or it could be a inline-implementation as well) to check that the object corresponds to const definition of it. Of course there should be a combination of both techniques - if simple objects are not the same, then obviously the utility should return false. To implement the `const` utility first we generate the schema by the object, generate the validator for it, and then on the runtime we call it against the data object as usual.

## Examples <a name="examples"></a>

The tests [examples](https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/05fdba41bd7844de1d527455e208addd50d41a01/tests/draft6/const.json#L24)

```json
{ "const": 2 }
// =>
{
"enum": [2]
}
```

Objects

```json
...
"description": "const with object",
"schema": {"const": {"foo": "bar", "baz": "bax"}},
... // -> schema
{
properties: {
"foo": { enum: "bar" },
"baz": { enum: "bax" }
},
required: ["foo", "baz"],
additionalProperties: false // other properties should be valid by `false` schema, aka do not exist at all
}
```

Arrays (created [a PR](https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/191) to json schema test suite)
```json
...
"description": "const with object",
"schema": {"const": [{ foo: "bar" }]},
... // -> schema
{
items: [{
"properties": {
"foo": { enum: "bar" },
},
required: ["foo"]
}],
additionalItems: false // other items should be valid by `false` schema, aka do not exist at all
}
```

So for simple objects we could use only `required`, `enum` and `additionalProperties` validation. The same for arrays - adding `items` and `additionalItems`.

Do we need anything else? The key difference between schema and instances is that there is no need to define a group or class of objects by schema, there only one object that should be checked against this schema.

## Summary <a name="summary"></a>

- A created package could be a start point for the *generate schema by instance* library
Loading

0 comments on commit a98cb5d

Please sign in to comment.