1 /******************************************************************************
2 * Copyright (c) 2000-2015 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
9 // This module compares two JSON schemas generated by the TITAN compiler
10 module CompareSchemas {
12 //////////////////////////////////////
13 // JSON schema container data types //
14 //////////////////////////////////////
17 type record JsonSchema {
22 // definitions section:
23 type set of DefSchema DefSchemas;
25 type record DefSchema {
26 charstring moduleName,
31 type set of TypeSchemaElement TypeSchema;
33 type record TypeSchemaElement {
38 type enumerated ElemKey {
39 Ref, Type, SubType, Pattern, OriginalName, UnusedAlias, MinItems, MaxItems, MinLength, MaxLength, Minimum, Maximum, // strVal
40 AdditionalProperties, OmitAsNull, exclusiveMinimum, exclusiveMaximum, // boolVal
41 Default, // strVal or boolVal
42 NumericValues, Required, FieldOrder, // strArrayVal
45 AnyOf, AllOf, // typeArrayVal
46 Properties, // fieldSetVal
50 type union ElemValue {
53 record of charstring strArrayVal,
55 record of TypeSchema typeArrayVal,
56 set of FieldValue fieldSetVal,
57 ExtensionValue extVal,
61 type record FieldValue {
66 type record ExtensionValue {
72 charstring strVal, // number, string or null
74 ObjectValue objectVal,
78 type record ObjectSegment {
83 type set of ObjectSegment ObjectValue;
85 type record of AnyValue ArrayValue;
87 // references/functions section:
88 type set of RefSchema RefSchemas;
90 type record RefSchema {
92 EncDecData enc optional,
93 EncDecData dec optional
96 type record EncDecData {
97 PrototypeData prototype,
98 ErrorBehaviorData eb optional,
99 charstring printing optional
102 type record of charstring PrototypeData;
104 type record of ErrorBehaviorElem ErrorBehaviorData;
106 type record ErrorBehaviorElem {
107 charstring errorType,
108 charstring errorBehavior
111 //////////////////////////////////
112 // Import and compare functions //
113 //////////////////////////////////
115 // Imports a JSON schema from the given file and stores it in the specified container.
116 // Throws a Dynamic Testcase Error if the file cannot be read or does not have the correct format.
117 // The resulting JsonSchema should not have any unbound fields.
118 external function f_ext_import_schema(in charstring file, out JsonSchema schema);
120 // Compares the two schemas found in the files specified by the parameters.
121 // Returns true if they are equal.
122 function f_compare_schemas(in charstring schema_file1, in charstring schema_file2) return boolean
124 // read the schemas from the files
125 var JsonSchema schema1;
126 f_ext_import_schema(schema_file1, schema1);
127 var JsonSchema schema2;
128 f_ext_import_schema(schema_file2, schema2);
130 // log both schemas (good luck digging through these...)
131 //log("Generated (", schema_file1, "): ", schema1);
132 //log("Expected (", schema_file2, "): ", schema2);
134 // set the verdict depending on their equality
135 if (match(schema1, schema2)) {
138 log(match(schema1, schema2));