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, // strVal
40 AdditionalProperties, OmitAsNull, // boolVal
41 Default, // strVal or boolVal
42 Enum, NumericValues, Required, FieldOrder, // strArrayVal
44 AnyOf, // typeArrayVal
45 Properties // fieldSetVal
48 type union ElemValue {
51 record of charstring strArrayVal,
53 record of TypeSchema typeArrayVal,
54 set of FieldValue fieldSetVal
57 type record FieldValue {
62 // references/functions section:
63 type set of RefSchema RefSchemas;
65 type record RefSchema {
67 EncDecData enc optional,
68 EncDecData dec optional
71 type record EncDecData {
72 PrototypeData prototype,
73 ErrorBehaviorData eb optional,
74 charstring printing optional
77 type record of charstring PrototypeData;
79 type record of ErrorBehaviorElem ErrorBehaviorData;
81 type record ErrorBehaviorElem {
83 charstring errorBehavior
86 //////////////////////////////////
87 // Import and compare functions //
88 //////////////////////////////////
90 // Imports a JSON schema from the given file and stores it in the specified container.
91 // Throws a Dynamic Testcase Error if the file cannot be read or does not have the correct format.
92 // The resulting JsonSchema should not have any unbound fields.
93 external function f_ext_import_schema(in charstring file, out JsonSchema schema);
95 // Compares the two schemas found in the files specified by the parameters.
96 // Returns true if they are equal.
97 function f_compare_schemas(in charstring schema_file1, in charstring schema_file2) return boolean
99 // read the schemas from the files
100 var JsonSchema schema1;
101 f_ext_import_schema(schema_file1, schema1);
102 var JsonSchema schema2;
103 f_ext_import_schema(schema_file2, schema2);
105 // log both schemas (good luck digging through these...)
106 //log("Generated (", schema_file1, "): ", schema1);
107 //log("Expected (", schema_file2, "): ", schema2);
109 // set the verdict depending on their equality
110 if (match(schema1, schema2)) {
113 log(match(schema1, schema2));