Project

General

Profile

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

haketilo / common / jsonschema.js @ 1f9ccef9

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
#FROM common/entities.js IMPORT parse_schema_uri
61

    
62
#EXPORT scan
63
#EXPORT SchemaScanResult
64

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

    
71
const haketilo_schemas = [
72
    /* 1.x Hydrilla JSON schema series */
73
#INCLUDE schemas/1.x/api_query_result-1.0.1.schema.json
74
    ,
75
#INCLUDE schemas/1.x/api_mapping_description-1.0.1.schema.json
76
    ,
77
#INCLUDE schemas/1.x/api_resource_description-1.0.1.schema.json
78
    ,
79
#INCLUDE schemas/1.x/common_definitions-1.0.1.schema.json
80
    ,
81
    /* 2.x Hydrilla JSON schema series */
82
#INCLUDE schemas/2.x/api_query_result-2.schema.json
83
    ,
84
#INCLUDE schemas/2.x/api_mapping_description-2.schema.json
85
    ,
86
#INCLUDE schemas/2.x/api_resource_description-2.schema.json
87
    ,
88
#INCLUDE schemas/2.x/common_definitions-2.schema.json
89
].reduce((ac, s) => Object.assign(ac, {[s.$id]: s}), {});
90

    
91
for (const [$id, schema] of [...Object.entries(haketilo_schemas)]) {
92
    const parsed = parse_schema_uri($id);
93
    const schema_name = `${parsed.name_base}-${parsed.major}.schema.json`;
94
    haketilo_schemas[schema_name] = schema;
95
}
96

    
97
#EXPORT haketilo_schemas
98

    
99
const haketilo_validator = new Validator();
100
Object.values(haketilo_schemas)
101
    .forEach(s => haketilo_validator.addSchema(s, s.$id));
102
#EXPORT haketilo_validator
(5-5/11)