Project

General

Profile

Download (3.04 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / common / jsonschema.js @ 74bbdd9a

1
/* SPDX-License-Identifier: MIT AND CC0-1.0
2
 *
3
 * License text of the original lib/index.js from jsonschema library:
4
 *
5
 ***************************************
6
 *
7
 * jsonschema is licensed under MIT license.
8
 *
9
 * Copyright (C) 2012-2015 Tom de Grunt <tom@degrunt.nl>
10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
12
 * this software and associated documentation files (the "Software"), to deal in
13
 * the Software without restriction, including without limitation the rights to
14
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
15
 * of the Software, and to permit persons to whom the Software is furnished to do
16
 * so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in all
19
 * copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
 * SOFTWARE.
28
 *
29
 *******************************************************************************
30
 *
31
 * License notice for the adaptation to use in Haketilo:
32
 *
33
 ***************************************
34
 *
35
 * Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
36
 *
37
 * This program is free software: you can redistribute it and/or modify
38
 * it under the terms of the CC0 1.0 Universal License as published by
39
 * the Creative Commons Corporation.
40
 *
41
 * This program is distributed in the hope that it will be useful,
42
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44
 * CC0 1.0 Universal License for more details.
45
 */
46

    
47
#FROM common/jsonschema/validator.js IMPORT Validator
48
#EXPORT Validator
49

    
50
#FROM common/jsonschema/helpers.js IMPORT ValidatorResult, ValidationError, \
51
                                          ValidatorResultError, SchemaError
52

    
53
#EXPORT ValidatorResult
54
#EXPORT ValidationError
55
#EXPORT ValidatorResultError
56
#EXPORT SchemaError
57

    
58
#FROM common/jsonschema/scan.js IMPORT SchemaScanResult, scan
59

    
60
#EXPORT scan
61
#EXPORT SchemaScanResult
62

    
63
function validate(instance, schema, options) {
64
    var v = new Validator();
65
    return v.validate(instance, schema, options);
66
};
67
#EXPORT validate
68

    
69
const haketilo_schemas = [
70
#INCLUDE schemas/api_query_result-1.0.1.schema.json
71
    ,
72
#INCLUDE schemas/api_mapping_description-1.0.1.schema.json
73
    ,
74
#INCLUDE schemas/api_resource_description-1.0.1.schema.json
75
    ,
76
#INCLUDE schemas/common_definitions-1.0.1.schema.json
77
].reduce((ac, s) => Object.assign(ac, {[s.$id]: s}), {});
78
#EXPORT haketilo_schemas
79

    
80
const haketilo_validator = new Validator();
81
Object.values(haketilo_schemas)
82
    .forEach(s => haketilo_validator.addSchema(s, s.$id));
83
#EXPORT haketilo_validator
(5-5/11)