Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dmi3y/json-api-validator
JSON Schema based validator for JSON APIs
https://github.com/dmi3y/json-api-validator
api api-testing json-api json-schema validation
Last synced: 5 days ago
JSON representation
JSON Schema based validator for JSON APIs
- Host: GitHub
- URL: https://github.com/dmi3y/json-api-validator
- Owner: dmi3y
- Created: 2016-03-21T04:39:35.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-29T06:29:10.000Z (over 8 years ago)
- Last Synced: 2024-08-08T17:42:40.478Z (3 months ago)
- Topics: api, api-testing, json-api, json-schema, validation
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JsonSchema API validator [](https://circleci.com/gh/dmi3y/json-api-validator)
> Slightly opinionated view on [JsonSchema](http://json-schema.org/) API validation.
### Install
> json-api-validator
### Proposed usecase
> But not limited.
Let's say there is folder structure of json schemas.
````
api +
\schemas +
\request +
| \pathA
| get.json
| post.json
| put.json
| +
| \subpathA
| get.json
| .... etc ....
\response +
\pathA
get.json
post.json
put.json
+
\subpathA
get.json
.... etc ....
````This will be possible setup for validator.
`api/validator.js`
````js
var validator = require('api-validator')({
// from cwd
base: './schemas'
})// ... and later in the code
var result = validator(jsonToValidate, 'response/pashA/get.json')
// ... do something based on result
````See tests for better examples.
### API
This module is a wrapper over the [tv4](https://github.com/geraintluff/tv4) JsonSchema validator. The result returned from the call is direct pipeline from [`tv4.validateMultiple`](https://github.com/geraintluff/tv4#usage-3-multiple-errors) method.
There is options you can pass for initiation:
- `base` root folder from which schemas will be searched up, default to `cwd`.
- `globPattern` the pattern used to search schemas, default to `/**/*`.
- `formats` hash of the custom formats for [`tv4.addFormat`](https://github.com/geraintluff/tv4#addformatformat-validationfunction) multiple form.### Notes
As of now the all schemas are loaded in the memory, no matter will they be used or not. The lazy loading are considerably on the road map.