@api-client/core 0.6.13 → 0.6.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.d.ts +9 -2
- package/build/browser.js +12 -2
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +9 -2
- package/build/index.js +12 -2
- package/build/index.js.map +1 -1
- package/build/src/amf/AmfMixin.d.ts +395 -0
- package/build/src/amf/AmfMixin.js +1146 -0
- package/build/src/amf/AmfMixin.js.map +1 -0
- package/build/src/amf/AmfSerializer.d.ts +136 -0
- package/build/src/amf/AmfSerializer.js +1913 -0
- package/build/src/amf/AmfSerializer.js.map +1 -0
- package/build/src/amf/AmfShapeGenerator.d.ts +85 -0
- package/build/src/amf/AmfShapeGenerator.js +385 -0
- package/build/src/amf/AmfShapeGenerator.js.map +1 -0
- package/build/src/amf/AmfTypes.d.ts +24 -0
- package/build/src/amf/AmfTypes.js +122 -0
- package/build/src/amf/AmfTypes.js.map +1 -0
- package/build/src/amf/ApiExampleGenerator.d.ts +36 -0
- package/build/src/amf/ApiExampleGenerator.js +109 -0
- package/build/src/amf/ApiExampleGenerator.js.map +1 -0
- package/build/src/amf/ApiMonacoSchemaGenerator.d.ts +67 -0
- package/build/src/amf/ApiMonacoSchemaGenerator.js +243 -0
- package/build/src/amf/ApiMonacoSchemaGenerator.js.map +1 -0
- package/build/src/amf/ApiSchemaGenerator.d.ts +55 -0
- package/build/src/amf/ApiSchemaGenerator.js +94 -0
- package/build/src/amf/ApiSchemaGenerator.js.map +1 -0
- package/build/src/amf/ApiSchemaValues.d.ts +98 -0
- package/build/src/amf/ApiSchemaValues.js +382 -0
- package/build/src/amf/ApiSchemaValues.js.map +1 -0
- package/build/src/amf/Utils.d.ts +41 -0
- package/build/src/amf/Utils.js +176 -0
- package/build/src/amf/Utils.js.map +1 -0
- package/build/src/amf/data-node/DataNodeBase.d.ts +31 -0
- package/build/src/amf/data-node/DataNodeBase.js +77 -0
- package/build/src/amf/data-node/DataNodeBase.js.map +1 -0
- package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts +15 -0
- package/build/src/amf/data-node/JsonDataNodeGenerator.js +24 -0
- package/build/src/amf/data-node/JsonDataNodeGenerator.js.map +1 -0
- package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts +13 -0
- package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js +42 -0
- package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js.map +1 -0
- package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts +21 -0
- package/build/src/amf/data-node/XmlDataNodeGenerator.js +30 -0
- package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +1 -0
- package/build/src/amf/definitions/Amf.d.ts +362 -0
- package/build/src/amf/definitions/Amf.js +2 -0
- package/build/src/amf/definitions/Amf.js.map +1 -0
- package/build/src/amf/definitions/Api.d.ts +381 -0
- package/build/src/amf/definitions/Api.js +2 -0
- package/build/src/amf/definitions/Api.js.map +1 -0
- package/build/src/amf/definitions/Base.d.ts +11 -0
- package/build/src/amf/definitions/Base.js +2 -0
- package/build/src/amf/definitions/Base.js.map +1 -0
- package/build/src/amf/definitions/Namespace.d.ts +311 -0
- package/build/src/amf/definitions/Namespace.js +330 -0
- package/build/src/amf/definitions/Namespace.js.map +1 -0
- package/build/src/amf/definitions/Shapes.d.ts +309 -0
- package/build/src/amf/definitions/Shapes.js +87 -0
- package/build/src/amf/definitions/Shapes.js.map +1 -0
- package/build/src/amf/models/AmfDataNode.d.ts +68 -0
- package/build/src/amf/models/AmfDataNode.js +188 -0
- package/build/src/amf/models/AmfDataNode.js.map +1 -0
- package/build/src/amf/shape/ShapeBase.d.ts +75 -0
- package/build/src/amf/shape/ShapeBase.js +90 -0
- package/build/src/amf/shape/ShapeBase.js.map +1 -0
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +46 -0
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +406 -0
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -0
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +84 -0
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +820 -0
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -0
- package/build/src/models/Thing.d.ts +17 -0
- package/build/src/models/Thing.js +19 -1
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/data/Bindings.d.ts +161 -0
- package/build/src/models/data/Bindings.js +2 -0
- package/build/src/models/data/Bindings.js.map +1 -0
- package/build/src/models/data/DataAssociation.d.ts +135 -14
- package/build/src/models/data/DataAssociation.js +154 -21
- package/build/src/models/data/DataAssociation.js.map +1 -1
- package/build/src/models/data/DataAssociationSchema.d.ts +36 -0
- package/build/src/models/data/DataEntity.d.ts +76 -4
- package/build/src/models/data/DataEntity.js +136 -9
- package/build/src/models/data/DataEntity.js.map +1 -1
- package/build/src/models/data/DataFile.d.ts +3 -0
- package/build/src/models/data/DataFile.js +3 -0
- package/build/src/models/data/DataFile.js.map +1 -1
- package/build/src/models/data/DataModel.d.ts +1 -1
- package/build/src/models/data/DataModel.js.map +1 -1
- package/build/src/models/data/DataNamespace.d.ts +6 -0
- package/build/src/models/data/DataNamespace.js +11 -1
- package/build/src/models/data/DataNamespace.js.map +1 -1
- package/build/src/models/data/DataProperty.d.ts +131 -36
- package/build/src/models/data/DataProperty.js +200 -17
- package/build/src/models/data/DataProperty.js.map +1 -1
- package/data/apis/oas-date/oas-date.yaml +28 -0
- package/data/apis/oas-types/oas-types.yaml +159 -0
- package/data/apis/oas-unions/oas-unions.yaml +75 -0
- package/data/apis/raml-date/raml-date.raml +28 -0
- package/data/apis/recursive/recursive.raml +14 -0
- package/data/apis/schema-api/examples/person.json +14 -0
- package/data/apis/schema-api/examples/person.raml +14 -0
- package/data/apis/schema-api/examples/person.url.encoded +1 -0
- package/data/apis/schema-api/examples/person.xml +14 -0
- package/data/apis/schema-api/library/demo-types.raml +43 -0
- package/data/apis/schema-api/schema-api.raml +644 -0
- package/data/apis/schema-api/schemas/person.json +104 -0
- package/data/apis/schema-api/schemas/person.xsd +26 -0
- package/data/apis/schema-api/types/DemoPerson.raml +67 -0
- package/data/model.js +106 -0
- package/data/models/oas-date.json +637 -0
- package/data/models/oas-types.json +5352 -0
- package/data/models/oas-unions.json +1881 -0
- package/data/models/raml-date.json +1096 -0
- package/data/models/recursive.json +610 -0
- package/data/models/schema-api.json +37319 -0
- package/package.json +9 -6
- package/src/amf/AmfMixin.ts +1623 -0
- package/src/amf/AmfSerializer.ts +2028 -0
- package/src/amf/AmfShapeGenerator.ts +400 -0
- package/src/amf/AmfTypes.ts +126 -0
- package/src/amf/ApiExampleGenerator.ts +112 -0
- package/src/amf/ApiMonacoSchemaGenerator.ts +296 -0
- package/src/amf/ApiSchemaGenerator.ts +108 -0
- package/src/amf/ApiSchemaValues.ts +411 -0
- package/src/amf/Utils.ts +182 -0
- package/src/amf/data-node/DataNodeBase.ts +81 -0
- package/src/amf/data-node/JsonDataNodeGenerator.ts +26 -0
- package/src/amf/data-node/README.md +3 -0
- package/src/amf/data-node/UrlEncodedDataNodeGenerator.ts +43 -0
- package/src/amf/data-node/XmlDataNodeGenerator.ts +38 -0
- package/src/amf/definitions/Amf.ts +443 -0
- package/src/amf/definitions/Api.ts +427 -0
- package/src/amf/definitions/Base.ts +13 -0
- package/src/amf/definitions/Namespace.ts +341 -0
- package/src/amf/definitions/Shapes.ts +414 -0
- package/src/amf/models/AmfDataNode.ts +200 -0
- package/src/amf/shape/README.md +4 -0
- package/src/amf/shape/ShapeBase.ts +160 -0
- package/src/amf/shape/ShapeJsonSchemaGenerator.ts +422 -0
- package/src/amf/shape/ShapeXmlSchemaGenerator.ts +876 -0
- package/src/models/Thing.ts +25 -1
- package/src/models/data/Bindings.ts +186 -0
- package/src/models/data/DataAssociation.ts +226 -29
- package/src/models/data/DataAssociationSchema.ts +38 -0
- package/src/models/data/DataEntity.ts +170 -13
- package/src/models/data/DataFile.ts +3 -0
- package/src/models/data/DataModel.ts +1 -1
- package/src/models/data/DataNamespace.ts +16 -1
- package/src/models/data/DataProperty.ts +250 -47
- package/build/src/models/data/DataPropertySchema.d.ts +0 -125
- package/build/src/models/data/DataPropertySchema.js +0 -33
- package/build/src/models/data/DataPropertySchema.js.map +0 -1
- package/src/models/data/DataPropertySchema.ts +0 -156
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
import { DataMock, ILoremWordInit, ITypeHashInit, ITypeNumberInit, Time } from '@pawel-up/data-mock';
|
|
2
|
+
import { AmfNamespace as ns } from "./definitions/Namespace.js";
|
|
3
|
+
import { JsonDataNodeGenerator } from "./data-node/JsonDataNodeGenerator.js";
|
|
4
|
+
import { parseBooleanInput, parseNumberInput, readTypedValue } from "./Utils.js";
|
|
5
|
+
import { ApiParameter } from './definitions/Api.js';
|
|
6
|
+
import { IAnyShape, IArrayNode, IArrayShape, IDataExample, IScalarNode, IScalarShape, IShapeUnion } from './definitions/Shapes.js';
|
|
7
|
+
|
|
8
|
+
export interface IApiSchemaReadOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Whether the value should be read only when the required property is set.
|
|
11
|
+
*/
|
|
12
|
+
requiredOnly?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to read the examples to generate the value.
|
|
15
|
+
*/
|
|
16
|
+
fromExamples?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A utility class with helper functions to read values from a schema definition
|
|
21
|
+
*/
|
|
22
|
+
export class ApiSchemaValues {
|
|
23
|
+
static mocking = new DataMock();
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Reads the value to be set on an input. This is for Scalar shapes only.
|
|
27
|
+
*
|
|
28
|
+
* @returns The value to set on the input. Note, it is not cast to the type.
|
|
29
|
+
*/
|
|
30
|
+
static readInputValue(parameter: ApiParameter, schema: IScalarShape, opts: IApiSchemaReadOptions = {}): any {
|
|
31
|
+
const { required } = parameter;
|
|
32
|
+
const { defaultValueStr, values } = schema;
|
|
33
|
+
if (!required && opts.requiredOnly === true) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
if (defaultValueStr) {
|
|
37
|
+
return ApiSchemaValues.readTypedValue(defaultValueStr, schema.dataType);
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(values) && values.length) {
|
|
40
|
+
const firstEnum = values[0] as IScalarNode;
|
|
41
|
+
return ApiSchemaValues.readTypedValue(firstEnum.value, firstEnum.dataType);
|
|
42
|
+
}
|
|
43
|
+
if (opts.fromExamples) {
|
|
44
|
+
let examples: IDataExample[] | undefined;
|
|
45
|
+
if (Array.isArray(parameter.examples) && parameter.examples.length) {
|
|
46
|
+
// just in case when an ApiParameter was passed.
|
|
47
|
+
examples = parameter.examples.filter(i => typeof i !== 'string');
|
|
48
|
+
} else if (Array.isArray(schema.examples) && schema.examples.length) {
|
|
49
|
+
examples = schema.examples;
|
|
50
|
+
}
|
|
51
|
+
if (examples && examples.length) {
|
|
52
|
+
return ApiSchemaValues.inputValueFromExamples(examples);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return ApiSchemaValues.generateDefaultValue(schema);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param parameter The parameter that has the array schema.
|
|
60
|
+
* @param schema The final schema to use to read the data from.
|
|
61
|
+
*/
|
|
62
|
+
static readInputValues(parameter: ApiParameter, schema: IShapeUnion, opts: IApiSchemaReadOptions={}): any {
|
|
63
|
+
if (!parameter.required && opts.requiredOnly === true) {
|
|
64
|
+
// for a non required array items just skip showing example values
|
|
65
|
+
// as they are not crucial to make an HTTP request.
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const { defaultValue } = schema;
|
|
69
|
+
if (defaultValue) {
|
|
70
|
+
const gen = new JsonDataNodeGenerator();
|
|
71
|
+
const result = gen.processNode(defaultValue);
|
|
72
|
+
if (Array.isArray(result)) {
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const anySchema = schema as IAnyShape;
|
|
77
|
+
if (opts.fromExamples) {
|
|
78
|
+
let examples: IDataExample[] | undefined;
|
|
79
|
+
if (Array.isArray(parameter.examples) && parameter.examples.length) {
|
|
80
|
+
// just in case when an ApiParameter was passed.
|
|
81
|
+
examples = parameter.examples.filter(i => typeof i !== 'string');
|
|
82
|
+
} else if (Array.isArray(anySchema.examples) && anySchema.examples.length) {
|
|
83
|
+
examples = anySchema.examples;
|
|
84
|
+
}
|
|
85
|
+
return ApiSchemaValues.arrayValuesFromExamples(examples);
|
|
86
|
+
}
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Reads the value for the form input(s) from examples.
|
|
92
|
+
*/
|
|
93
|
+
static inputValueFromExamples(examples: IDataExample[]): any | null | undefined {
|
|
94
|
+
if (!Array.isArray(examples) || !examples.length) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
const [example] = examples;
|
|
98
|
+
const { structuredValue } = example;
|
|
99
|
+
if (!structuredValue) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
if (structuredValue.types.includes(ns.aml.vocabularies.data.Scalar)) {
|
|
103
|
+
const value = structuredValue as IScalarNode;
|
|
104
|
+
return ApiSchemaValues.readTypedValue(value.value, value.dataType);
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Reads the array value from examples.
|
|
111
|
+
* @param examples Examples set on an array item.
|
|
112
|
+
*/
|
|
113
|
+
static arrayValuesFromExamples(examples?: IDataExample[]): any[] {
|
|
114
|
+
const defaultReturn: any[] = [];
|
|
115
|
+
if (!Array.isArray(examples) || !examples.length) {
|
|
116
|
+
return defaultReturn;
|
|
117
|
+
}
|
|
118
|
+
const [example] = examples;
|
|
119
|
+
if (!example.structuredValue || !example.structuredValue.types.includes(ns.aml.vocabularies.data.Array)) {
|
|
120
|
+
return defaultReturn;
|
|
121
|
+
}
|
|
122
|
+
const value = example.structuredValue as IArrayNode;
|
|
123
|
+
const { members } = value;
|
|
124
|
+
if (!Array.isArray(members) || !members.length) {
|
|
125
|
+
return defaultReturn;
|
|
126
|
+
}
|
|
127
|
+
const result: any[] = [];
|
|
128
|
+
members.forEach((item) => {
|
|
129
|
+
const scalar = item as IScalarNode;
|
|
130
|
+
if (!scalar.value) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const typedValue = ApiSchemaValues.readTypedValue(scalar.value, scalar.dataType);
|
|
134
|
+
if (typeof value !== 'undefined' && value !== null) {
|
|
135
|
+
result.push(typedValue);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Generates a default value from the schema type.
|
|
143
|
+
* For booleans it returns `false`, for numbers `0`, nulls `null`, etc.
|
|
144
|
+
* It does not generate a value for `string` types!
|
|
145
|
+
*/
|
|
146
|
+
static generateDefaultValue(schema: IScalarShape): any {
|
|
147
|
+
const { dataType } = schema;
|
|
148
|
+
switch (dataType) {
|
|
149
|
+
case ns.w3.xmlSchema.string: return this.generateStringValue(schema);
|
|
150
|
+
// XML schema, for DataNode
|
|
151
|
+
case ns.w3.xmlSchema.number:
|
|
152
|
+
case ns.w3.xmlSchema.integer:
|
|
153
|
+
case ns.w3.xmlSchema.float:
|
|
154
|
+
case ns.w3.xmlSchema.long:
|
|
155
|
+
case ns.w3.xmlSchema.double:
|
|
156
|
+
case ns.aml.vocabularies.shapes.number:
|
|
157
|
+
case ns.aml.vocabularies.shapes.integer:
|
|
158
|
+
case ns.aml.vocabularies.shapes.float:
|
|
159
|
+
case ns.aml.vocabularies.shapes.long:
|
|
160
|
+
case ns.aml.vocabularies.shapes.double: return this.generateNumberValue(schema);
|
|
161
|
+
case ns.aml.vocabularies.shapes.boolean:
|
|
162
|
+
case ns.w3.xmlSchema.boolean: return this.mocking.types.boolean();
|
|
163
|
+
case ns.aml.vocabularies.shapes.nil:
|
|
164
|
+
case ns.w3.xmlSchema.nil: return null;
|
|
165
|
+
case ns.w3.xmlSchema.date: return new Time().dateOnly();
|
|
166
|
+
case ns.w3.xmlSchema.dateTime: return new Time().dateTime((schema.format === 'date-time' ? 'rfc3339' : schema.format) as "rfc3339" | "rfc2616");
|
|
167
|
+
case ns.aml.vocabularies.shapes.dateTimeOnly: return new Time().dateTimeOnly();
|
|
168
|
+
case ns.w3.xmlSchema.time: return new Time().timeOnly();
|
|
169
|
+
default: return undefined;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Generates a random number value given the schema definition for a number scalar.
|
|
175
|
+
*/
|
|
176
|
+
static generateNumberValue(schema: IScalarShape): number {
|
|
177
|
+
const { minimum, maximum, format, multipleOf } = schema;
|
|
178
|
+
const init: ITypeNumberInit = {};
|
|
179
|
+
if (typeof minimum === 'number') {
|
|
180
|
+
init.min = minimum;
|
|
181
|
+
}
|
|
182
|
+
if (typeof maximum === 'number') {
|
|
183
|
+
init.max = maximum;
|
|
184
|
+
}
|
|
185
|
+
let generator: ((init?: number | ITypeNumberInit | undefined) => number) | undefined;
|
|
186
|
+
if (format && ['float', 'double'].includes(format)) {
|
|
187
|
+
generator = this.mocking.types.float.bind(this.mocking.types);
|
|
188
|
+
} else if (format && ['uint32', 'uint64', 'fixed32', 'fixed64'].includes(format)) {
|
|
189
|
+
// these are unsigned numbers, make sure the generate anything above 0
|
|
190
|
+
init.min = 0;
|
|
191
|
+
if (init.max && init.max < 0) {
|
|
192
|
+
delete init.max;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!generator) {
|
|
197
|
+
// by default generate an integer
|
|
198
|
+
generator = this.mocking.types.number.bind(this.mocking.types);
|
|
199
|
+
}
|
|
200
|
+
if (typeof multipleOf === 'number') {
|
|
201
|
+
init.precision = multipleOf;
|
|
202
|
+
}
|
|
203
|
+
return generator(init);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static generateStringValue(schema: IScalarShape): string {
|
|
207
|
+
const { minLength, maxLength, name='', format } = schema;
|
|
208
|
+
const lowerName = name.toLowerCase();
|
|
209
|
+
// we employ some heuristics to generate content based on the property name.
|
|
210
|
+
if (lowerName === 'description') {
|
|
211
|
+
return this.mocking.lorem.paragraph();
|
|
212
|
+
}
|
|
213
|
+
if (format === 'uuid') {
|
|
214
|
+
return this.mocking.types.uuid();
|
|
215
|
+
}
|
|
216
|
+
if (lowerName === 'id') {
|
|
217
|
+
const init: ITypeHashInit = { length: 12 };
|
|
218
|
+
const hasMin = typeof minLength === 'number';
|
|
219
|
+
if (hasMin) {
|
|
220
|
+
init.length = minLength;
|
|
221
|
+
} else if (!hasMin && typeof maxLength === 'number') {
|
|
222
|
+
init.length = maxLength;
|
|
223
|
+
}
|
|
224
|
+
return this.mocking.types.hash(init);
|
|
225
|
+
}
|
|
226
|
+
if (['name', 'fullname'].includes(lowerName)) {
|
|
227
|
+
return this.mocking.person.name();
|
|
228
|
+
}
|
|
229
|
+
if (lowerName === 'firstname') {
|
|
230
|
+
return this.mocking.person.firstName()
|
|
231
|
+
}
|
|
232
|
+
if (lowerName === 'lastname') {
|
|
233
|
+
return this.mocking.person.lastName()
|
|
234
|
+
}
|
|
235
|
+
// if (['zip', 'postcode', 'postalcode', 'zipcode'].includes(lowerName)) {
|
|
236
|
+
// return this.mocking.word
|
|
237
|
+
// }
|
|
238
|
+
|
|
239
|
+
const init: ILoremWordInit = {};
|
|
240
|
+
const hasMin = typeof minLength === 'number';
|
|
241
|
+
if (hasMin) {
|
|
242
|
+
init.length = minLength;
|
|
243
|
+
} else if (!hasMin && typeof maxLength === 'number') {
|
|
244
|
+
init.length = maxLength;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return this.mocking.lorem.word(init);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Casts the `value` to the corresponding data type
|
|
252
|
+
* @param type The w3 schema type
|
|
253
|
+
*/
|
|
254
|
+
static readTypedValue(value: any, type?: string): any {
|
|
255
|
+
return readTypedValue(value, type);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @param schemaType Data type encoded in the parameter schema.
|
|
260
|
+
* @returns One of the HTML input element type values.
|
|
261
|
+
*/
|
|
262
|
+
static readInputType(schemaType: string): 'number'|'boolean'|'date'|'time'|'datetime-local'|'text' {
|
|
263
|
+
switch (schemaType) {
|
|
264
|
+
case ns.aml.vocabularies.shapes.number:
|
|
265
|
+
case ns.aml.vocabularies.shapes.integer:
|
|
266
|
+
case ns.aml.vocabularies.shapes.float:
|
|
267
|
+
case ns.aml.vocabularies.shapes.long:
|
|
268
|
+
case ns.aml.vocabularies.shapes.double:
|
|
269
|
+
case ns.w3.xmlSchema.number:
|
|
270
|
+
case ns.w3.xmlSchema.integer:
|
|
271
|
+
case ns.w3.xmlSchema.float:
|
|
272
|
+
case ns.w3.xmlSchema.long:
|
|
273
|
+
case ns.w3.xmlSchema.double: return 'number';
|
|
274
|
+
case ns.w3.xmlSchema.date: return 'date';
|
|
275
|
+
case ns.w3.xmlSchema.time: return 'time';
|
|
276
|
+
case ns.w3.xmlSchema.dateTime:
|
|
277
|
+
case ns.aml.vocabularies.shapes.dateTimeOnly: return 'datetime-local';
|
|
278
|
+
case ns.aml.vocabularies.shapes.boolean:
|
|
279
|
+
case ns.w3.xmlSchema.boolean: return 'boolean';
|
|
280
|
+
default: return 'text';
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Processes a value that should be a number.
|
|
286
|
+
*/
|
|
287
|
+
static parseNumberInput(value: unknown, defaultValue?: number): number | undefined {
|
|
288
|
+
return parseNumberInput(value, defaultValue);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Processes a value that should be a number.
|
|
293
|
+
*/
|
|
294
|
+
static parseBooleanInput(value: unknown, defaultValue?: boolean): boolean | undefined {
|
|
295
|
+
return parseBooleanInput(value, defaultValue);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Processes a value that should be a date formatted as yyyy-MM-dd.
|
|
300
|
+
*/
|
|
301
|
+
static parseDateOnlyInput(value: any): string | undefined {
|
|
302
|
+
const d = new Date(value);
|
|
303
|
+
if (Number.isNaN(d.getTime())) {
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
const result = d.toJSON();
|
|
307
|
+
const timeSeparator = result.indexOf('T');
|
|
308
|
+
return result.substring(0, timeSeparator);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Processes a value that should be a date formatted as hh:mm:ss.
|
|
313
|
+
*/
|
|
314
|
+
static parseTimeOnlyInput(input: unknown): string|undefined {
|
|
315
|
+
const value = String(input).trim();
|
|
316
|
+
if (/^\d\d:\d\d$/.test(value)) {
|
|
317
|
+
return `${value}:00`;
|
|
318
|
+
}
|
|
319
|
+
if (/^\d\d:\d\d:\d\d$/.test(value)) {
|
|
320
|
+
return value;
|
|
321
|
+
}
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Processes a value that should be a date formatted in one of the supported formats:
|
|
327
|
+
* - rfc3339 (default): 2016-02-28T16:41:41.090Z
|
|
328
|
+
* - rfc2616: Sun, 28 Feb 2016 16:41:41 GMT
|
|
329
|
+
*/
|
|
330
|
+
static parseDateTimeInput(value: any, format: string = 'rfc3339'): string | undefined {
|
|
331
|
+
const d = new Date(value);
|
|
332
|
+
if (Number.isNaN(d.getTime())) {
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
if (format === 'rfc2616') {
|
|
336
|
+
return d.toUTCString();
|
|
337
|
+
}
|
|
338
|
+
// OAS has the `date-time` format describing rfc3339.
|
|
339
|
+
if (['rfc3339', 'date-time'].includes(format)) {
|
|
340
|
+
return d.toISOString();
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Processes a value that should be a date formatted as yyyy-MM-ddThh:mm
|
|
347
|
+
*/
|
|
348
|
+
static parseDateTimeOnlyInput(value: any): string | undefined {
|
|
349
|
+
const d = new Date(value);
|
|
350
|
+
if (Number.isNaN(d.getTime())) {
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
const jsonDate = d.toJSON(); // "yyyy-MM-ddThh:mm:ss.090Z"
|
|
354
|
+
const dot = jsonDate.indexOf('.');
|
|
355
|
+
return jsonDate.substring(0, dot);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Parses the the value according to array schema value.
|
|
360
|
+
*/
|
|
361
|
+
static parseArrayInput(value: any, schema: IArrayShape): string|number|boolean|null|undefined {
|
|
362
|
+
const { items } = schema;
|
|
363
|
+
if (!items) {
|
|
364
|
+
return String(value);
|
|
365
|
+
}
|
|
366
|
+
return ApiSchemaValues.parseUserInput(value, items);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Parses the user entered value according to the schema definition.
|
|
371
|
+
*/
|
|
372
|
+
static parseUserInput(value: any, schema: IShapeUnion): string|number|boolean|null|undefined {
|
|
373
|
+
if (!schema || value === undefined || value === null) {
|
|
374
|
+
return value;
|
|
375
|
+
}
|
|
376
|
+
const { types } = schema;
|
|
377
|
+
if (types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
|
|
378
|
+
return ApiSchemaValues.parseScalarInput(value, schema as IScalarShape);
|
|
379
|
+
}
|
|
380
|
+
if (types.includes(ns.aml.vocabularies.shapes.ArrayShape) || types.includes(ns.aml.vocabularies.shapes.MatrixShape)) {
|
|
381
|
+
return ApiSchemaValues.parseArrayInput(value, schema as IArrayShape);
|
|
382
|
+
}
|
|
383
|
+
return value;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Parses the user entered value as scalar value.
|
|
388
|
+
*/
|
|
389
|
+
static parseScalarInput(value: unknown, schema: IScalarShape): string|number|boolean|null|undefined {
|
|
390
|
+
switch (schema.dataType) {
|
|
391
|
+
// AML shapes, for Shape
|
|
392
|
+
case ns.aml.vocabularies.shapes.number:
|
|
393
|
+
case ns.aml.vocabularies.shapes.integer:
|
|
394
|
+
case ns.aml.vocabularies.shapes.float:
|
|
395
|
+
case ns.aml.vocabularies.shapes.long:
|
|
396
|
+
case ns.aml.vocabularies.shapes.double:
|
|
397
|
+
case ns.w3.xmlSchema.number:
|
|
398
|
+
case ns.w3.xmlSchema.integer:
|
|
399
|
+
case ns.w3.xmlSchema.float:
|
|
400
|
+
case ns.w3.xmlSchema.long:
|
|
401
|
+
case ns.w3.xmlSchema.double: return ApiSchemaValues.parseNumberInput(value);
|
|
402
|
+
case ns.aml.vocabularies.shapes.boolean:
|
|
403
|
+
case ns.w3.xmlSchema.boolean: return ApiSchemaValues.parseBooleanInput(value);
|
|
404
|
+
case ns.w3.xmlSchema.date: return ApiSchemaValues.parseDateOnlyInput(value);
|
|
405
|
+
case ns.w3.xmlSchema.time: return ApiSchemaValues.parseTimeOnlyInput(value);
|
|
406
|
+
case ns.w3.xmlSchema.dateTime: return ApiSchemaValues.parseDateTimeInput(value, schema.format);
|
|
407
|
+
case ns.aml.vocabularies.shapes.dateTimeOnly: return ApiSchemaValues.parseDateTimeOnlyInput(value);
|
|
408
|
+
default: return String(value);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
package/src/amf/Utils.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { UrlEncoder } from "../lib/parsers/UrlEncoder.js";
|
|
2
|
+
import { AmfNamespace } from "./definitions/Namespace.js";
|
|
3
|
+
import { INodeShape, IPropertyShape, IShapeUnion, IUnionShape } from "./definitions/Shapes.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param indent The current indent
|
|
7
|
+
*/
|
|
8
|
+
export function toXml(obj: any, indent=0): string {
|
|
9
|
+
if (typeof obj !== 'object') {
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
let xml = '';
|
|
13
|
+
const tabs = new Array(indent).fill(' ').join('');
|
|
14
|
+
Object.keys(obj).forEach((prop) => {
|
|
15
|
+
xml += Array.isArray(obj[prop]) ? '' : `${tabs}<${prop}>`;
|
|
16
|
+
if (Array.isArray(obj[prop])) {
|
|
17
|
+
(obj[prop] as any[]).forEach((item) => {
|
|
18
|
+
xml += `<${prop}>\n`;
|
|
19
|
+
xml += tabs;
|
|
20
|
+
xml += toXml({ ...item }, indent + 1);
|
|
21
|
+
xml += `</${prop}>\n`;
|
|
22
|
+
});
|
|
23
|
+
} else if (typeof obj[prop] === "object") {
|
|
24
|
+
xml += `\n`;
|
|
25
|
+
xml += toXml({ ...obj[prop] }, indent + 1);
|
|
26
|
+
} else {
|
|
27
|
+
xml += `${obj[prop]}`;
|
|
28
|
+
}
|
|
29
|
+
xml += Array.isArray(obj[prop]) ? '' : `</${prop}>\n`;
|
|
30
|
+
});
|
|
31
|
+
xml = xml.replace(/<\/?[0-9]{1,}>/g, '');
|
|
32
|
+
return xml
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param fill The fill value (spaces to put in front of the value)
|
|
37
|
+
* @param value The value to format
|
|
38
|
+
*/
|
|
39
|
+
export function formatXmlValue(fill: string, value: unknown): string {
|
|
40
|
+
const typed = String(value);
|
|
41
|
+
const parts = typed.split('\n').filter(i => !!i);
|
|
42
|
+
const formatted = parts.map(i => `${fill}${i}`).join('\n');
|
|
43
|
+
return formatted;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param str A key or value to encode as x-www-form-urlencoded.
|
|
48
|
+
* @param replacePlus When set it replaces `%20` with `+`.
|
|
49
|
+
* @deprecated Use `UrlEncoder.encodeQueryString()` instead.
|
|
50
|
+
*/
|
|
51
|
+
export function wwwFormUrlEncode(str: string, replacePlus?: boolean): string {
|
|
52
|
+
// Spec says to normalize newlines to \r\n and replace %20 spaces with +.
|
|
53
|
+
// jQuery does this as well, so this is likely to be widely compatible.
|
|
54
|
+
if (str === undefined) {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
return UrlEncoder.encodeQueryString(String(str), replacePlus);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Processes a value that should be a number.
|
|
62
|
+
*/
|
|
63
|
+
export function parseNumberInput(value: any, defaultValue?: number): number | undefined {
|
|
64
|
+
if (typeof value === 'number') {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
const n = Number(value);
|
|
68
|
+
if (Number.isNaN(n)) {
|
|
69
|
+
return defaultValue;
|
|
70
|
+
}
|
|
71
|
+
return n;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Processes a value that should be a number.
|
|
76
|
+
*/
|
|
77
|
+
export function parseBooleanInput(value: any, defaultValue?: boolean): boolean | undefined {
|
|
78
|
+
const type = typeof value;
|
|
79
|
+
if (type === 'boolean') {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
if (type === 'string') {
|
|
83
|
+
const trimmed = value.trim();
|
|
84
|
+
if (trimmed === 'true') {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
if (trimmed === 'false') {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return defaultValue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Casts the `value` to the corresponding data type
|
|
96
|
+
* @param type The w3 schema type
|
|
97
|
+
*/
|
|
98
|
+
export function readTypedValue(value: any, type?: string): string | null | number | boolean | undefined {
|
|
99
|
+
if (value === undefined || value === null) {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
switch (type) {
|
|
103
|
+
case AmfNamespace.aml.vocabularies.shapes.number:
|
|
104
|
+
case AmfNamespace.aml.vocabularies.shapes.integer:
|
|
105
|
+
case AmfNamespace.aml.vocabularies.shapes.float:
|
|
106
|
+
case AmfNamespace.aml.vocabularies.shapes.long:
|
|
107
|
+
case AmfNamespace.aml.vocabularies.shapes.double:
|
|
108
|
+
case AmfNamespace.w3.xmlSchema.number:
|
|
109
|
+
case AmfNamespace.w3.xmlSchema.integer:
|
|
110
|
+
case AmfNamespace.w3.xmlSchema.float:
|
|
111
|
+
case AmfNamespace.w3.xmlSchema.long:
|
|
112
|
+
case AmfNamespace.w3.xmlSchema.double: return parseNumberInput(value, 0);
|
|
113
|
+
case AmfNamespace.aml.vocabularies.shapes.boolean:
|
|
114
|
+
case AmfNamespace.w3.xmlSchema.boolean: return parseBooleanInput(value, false);
|
|
115
|
+
case AmfNamespace.aml.vocabularies.shapes.nil:
|
|
116
|
+
case AmfNamespace.w3.xmlSchema.nil:
|
|
117
|
+
return null;
|
|
118
|
+
default:
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Picks the union member to render.
|
|
125
|
+
* @param anyOf The list of union members
|
|
126
|
+
* @param selectedUnions Optional list of domain ids of currently selected unions. When set is returns a member that is "selected" or the first member otherwise.
|
|
127
|
+
*/
|
|
128
|
+
export function getUnionMember(anyOf: IShapeUnion[], selectedUnions: string[] = []): IShapeUnion {
|
|
129
|
+
let renderedItem: IShapeUnion | undefined;
|
|
130
|
+
if (Array.isArray(selectedUnions) && selectedUnions.length) {
|
|
131
|
+
renderedItem = anyOf.find((item) => selectedUnions.includes(item.id));
|
|
132
|
+
}
|
|
133
|
+
if (!renderedItem) {
|
|
134
|
+
[renderedItem] = anyOf;
|
|
135
|
+
}
|
|
136
|
+
return renderedItem;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param {ApiNodeShape} schema
|
|
141
|
+
* @param {string[]=} [selectedUnions=[]]
|
|
142
|
+
* @returns {ApiPropertyShape[]}
|
|
143
|
+
*/
|
|
144
|
+
export function collectNodeProperties(schema: INodeShape, selectedUnions?: string[]): IPropertyShape[] {
|
|
145
|
+
let result: IPropertyShape[] = [];
|
|
146
|
+
const { properties, inherits } = schema;
|
|
147
|
+
if (properties.length) {
|
|
148
|
+
result = [...properties];
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(inherits) && inherits.length) {
|
|
151
|
+
inherits.forEach((s) => {
|
|
152
|
+
let node = s;
|
|
153
|
+
if (node.types.includes(AmfNamespace.aml.vocabularies.shapes.UnionShape)) {
|
|
154
|
+
const union = node as IUnionShape;
|
|
155
|
+
const { anyOf=[] } = union;
|
|
156
|
+
node = getUnionMember(anyOf, selectedUnions);
|
|
157
|
+
}
|
|
158
|
+
if (!node.types.includes(AmfNamespace.w3.shacl.NodeShape)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const typed = node as INodeShape;
|
|
162
|
+
// const p = typed.properties;
|
|
163
|
+
// if (Array.isArray(p) && p.length) {
|
|
164
|
+
// result = result.concat(p);
|
|
165
|
+
// }
|
|
166
|
+
const upper = collectNodeProperties(typed);
|
|
167
|
+
if (upper.length) {
|
|
168
|
+
result = result.concat(upper)
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const merged: IPropertyShape[] = [];
|
|
173
|
+
result.forEach((item) => {
|
|
174
|
+
const existing = merged.find(i => i.name === item.name);
|
|
175
|
+
if (existing) {
|
|
176
|
+
// this should (?) merge properties from the two.
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
merged.push(item);
|
|
180
|
+
});
|
|
181
|
+
return merged;
|
|
182
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { AmfNamespace as ns } from "../definitions/Namespace.js";
|
|
2
|
+
import { IArrayNode, IDataNode, IObjectNode, IScalarNode } from "../definitions/Shapes.js";
|
|
3
|
+
import { readTypedValue } from '../Utils.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Base class for all schema generators based on AMF's DataNode which includes AMF's examples.
|
|
7
|
+
*/
|
|
8
|
+
export class DataNodeBase {
|
|
9
|
+
/**
|
|
10
|
+
* @param node The AMF data node to turn into a schema.
|
|
11
|
+
* @returns Undefined when passed non-DataNode domain element.
|
|
12
|
+
*/
|
|
13
|
+
processNode(node: IDataNode): any | undefined {
|
|
14
|
+
const { types } = node;
|
|
15
|
+
if (types.includes(ns.aml.vocabularies.data.Scalar)) {
|
|
16
|
+
return this.processScalarNode(node as IScalarNode);
|
|
17
|
+
}
|
|
18
|
+
if (types.includes(ns.aml.vocabularies.data.Array)) {
|
|
19
|
+
return this.processArrayNode(node as IArrayNode);
|
|
20
|
+
}
|
|
21
|
+
if (types.includes(ns.aml.vocabularies.data.Object)) {
|
|
22
|
+
return this.processObjectNode(node as IObjectNode);
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param scalar The scalar node to process.
|
|
29
|
+
* @returns The scalar value.
|
|
30
|
+
*/
|
|
31
|
+
processScalarNode(scalar: IScalarNode): any {
|
|
32
|
+
return readTypedValue(scalar.value, scalar.dataType);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param array The array node to process.
|
|
37
|
+
* @returns Array value.
|
|
38
|
+
*/
|
|
39
|
+
processArrayNode(array: IArrayNode): any[] {
|
|
40
|
+
const container: any[] = [];
|
|
41
|
+
array.members.forEach((member) => {
|
|
42
|
+
const result = this.processNode(member);
|
|
43
|
+
if (result !== undefined) {
|
|
44
|
+
container.push(result);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return container;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param object The object node to process.
|
|
52
|
+
* @returns Object value.
|
|
53
|
+
*/
|
|
54
|
+
processObjectNode(object: IObjectNode): any {
|
|
55
|
+
const container: any = {};
|
|
56
|
+
const { properties } = object;
|
|
57
|
+
Object.keys(properties).forEach((key) => {
|
|
58
|
+
const definition = properties[key];
|
|
59
|
+
const result = this.processNode(definition);
|
|
60
|
+
if (typeof result !== 'undefined') {
|
|
61
|
+
const name = this.normalizePropertyName(key);
|
|
62
|
+
container[name] = result;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return container;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Normalizes a property name. It decodes URL encoded values.
|
|
70
|
+
* @param name The property name to normalize
|
|
71
|
+
*/
|
|
72
|
+
normalizePropertyName(name: string): string {
|
|
73
|
+
let result = name;
|
|
74
|
+
try {
|
|
75
|
+
result = decodeURIComponent(result)
|
|
76
|
+
} catch (e) {
|
|
77
|
+
// ...
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IDataNode } from '../definitions/Shapes.js';
|
|
2
|
+
import { DataNodeBase } from './DataNodeBase.js';
|
|
3
|
+
|
|
4
|
+
/** @typedef {import('../../helpers/api').ApiDataNode} ApiDataNode */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A class that processes AMF's `structuredValue` into a JSON example.
|
|
8
|
+
*/
|
|
9
|
+
export class JsonDataNodeGenerator extends DataNodeBase {
|
|
10
|
+
/**
|
|
11
|
+
* Generates a JSON schema from the AMF's DataNode.
|
|
12
|
+
*
|
|
13
|
+
* @param node The AMF's data node to transform into a schema.
|
|
14
|
+
* @returns Undefined when passed non-DataNode domain element.
|
|
15
|
+
*/
|
|
16
|
+
generate(node: IDataNode): string | undefined {
|
|
17
|
+
const result = this.processNode(node);
|
|
18
|
+
if (!result) {
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
if (typeof result === 'string') {
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
return JSON.stringify(result, null, 2);
|
|
25
|
+
}
|
|
26
|
+
}
|