@api-client/core 0.7.11 → 0.8.0
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/SECURITY.md +14 -0
- package/build/browser.d.ts +6 -0
- package/build/browser.js +6 -0
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +6 -0
- package/build/index.js +6 -0
- package/build/index.js.map +1 -1
- package/build/src/amf/AmfMixin.d.ts +55 -42
- package/build/src/amf/AmfMixin.js +9 -3
- package/build/src/amf/AmfMixin.js.map +1 -1
- package/build/src/amf/AmfSerializer.d.ts +72 -72
- package/build/src/amf/AmfSerializer.js +9 -4
- package/build/src/amf/AmfSerializer.js.map +1 -1
- package/build/src/amf/AmfShapeGenerator.d.ts +17 -17
- package/build/src/amf/AmfShapeGenerator.js +4 -4
- package/build/src/amf/AmfShapeGenerator.js.map +1 -1
- package/build/src/amf/AmfTypes.d.ts +16 -16
- package/build/src/amf/AmfTypes.js +16 -16
- package/build/src/amf/AmfTypes.js.map +1 -1
- package/build/src/amf/ApiExampleGenerator.d.ts +3 -3
- package/build/src/amf/ApiExampleGenerator.js.map +1 -1
- package/build/src/amf/ApiMonacoSchemaGenerator.d.ts +6 -6
- package/build/src/amf/ApiMonacoSchemaGenerator.js.map +1 -1
- package/build/src/amf/ApiSchemaGenerator.d.ts +2 -2
- package/build/src/amf/ApiSchemaGenerator.js.map +1 -1
- package/build/src/amf/ApiSchemaValues.d.ts +12 -12
- package/build/src/amf/ApiSchemaValues.js.map +1 -1
- package/build/src/amf/Parsing.d.ts +5 -5
- package/build/src/amf/Utils.d.ts +6 -6
- package/build/src/amf/Utils.js.map +1 -1
- package/build/src/amf/data-node/DataNodeBase.d.ts +5 -5
- package/build/src/amf/data-node/DataNodeBase.js.map +1 -1
- package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts +2 -2
- package/build/src/amf/data-node/JsonDataNodeGenerator.js.map +1 -1
- package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts +2 -2
- package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js.map +1 -1
- package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts +2 -2
- package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +1 -1
- package/build/src/amf/definitions/Amf.d.ts +339 -339
- package/build/src/amf/definitions/Api.d.ts +158 -158
- package/build/src/amf/definitions/Base.d.ts +5 -5
- package/build/src/amf/definitions/Shapes.d.ts +46 -46
- package/build/src/amf/definitions/Shapes.js +11 -11
- package/build/src/amf/definitions/Shapes.js.map +1 -1
- package/build/src/amf/models/AmfDataNode.d.ts +5 -5
- package/build/src/amf/models/AmfDataNode.js +4 -4
- package/build/src/amf/models/AmfDataNode.js.map +1 -1
- package/build/src/amf/shape/ShapeBase.d.ts +13 -13
- package/build/src/amf/shape/ShapeBase.js.map +1 -1
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +13 -13
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -1
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +16 -16
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +1 -1
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -1
- package/build/src/events/amf/AmfEvents.d.ts +4 -4
- package/build/src/events/amf/AmfEvents.js.map +1 -1
- package/build/src/models/data/Bindings.d.ts +2 -2
- package/build/src/models/data/DataAssociation.d.ts +4 -4
- package/build/src/models/data/DataAssociation.js.map +1 -1
- package/build/src/models/data/DataEntity.d.ts +2 -2
- package/build/src/models/data/DataProperty.d.ts +2 -2
- package/build/src/runtime/variables/VariablesProcessor.js.map +1 -1
- package/data/models/oas-date.json +1 -1
- package/data/models/oas-types.json +1 -1
- package/data/models/oas-unions.json +1 -1
- package/data/models/raml-date.json +1 -1
- package/data/models/recursive.json +1 -1
- package/data/models/schema-api.json +14 -6
- package/package.json +6 -6
- package/src/amf/AmfMixin.ts +124 -117
- package/src/amf/AmfSerializer.ts +245 -240
- package/src/amf/AmfShapeGenerator.ts +24 -24
- package/src/amf/AmfTypes.ts +16 -16
- package/src/amf/ApiExampleGenerator.ts +4 -4
- package/src/amf/ApiMonacoSchemaGenerator.ts +11 -11
- package/src/amf/ApiSchemaGenerator.ts +3 -3
- package/src/amf/ApiSchemaValues.ts +21 -21
- package/src/amf/Parsing.ts +5 -5
- package/src/amf/Utils.ts +15 -15
- package/src/amf/data-node/DataNodeBase.ts +8 -8
- package/src/amf/data-node/JsonDataNodeGenerator.ts +2 -2
- package/src/amf/data-node/UrlEncodedDataNodeGenerator.ts +2 -2
- package/src/amf/data-node/XmlDataNodeGenerator.ts +2 -2
- package/src/amf/definitions/Amf.ts +315 -314
- package/src/amf/definitions/Api.ts +158 -157
- package/src/amf/definitions/Base.ts +5 -5
- package/src/amf/definitions/Shapes.ts +60 -60
- package/src/amf/models/AmfDataNode.ts +17 -17
- package/src/amf/shape/ShapeBase.ts +16 -16
- package/src/amf/shape/ShapeJsonSchemaGenerator.ts +27 -27
- package/src/amf/shape/ShapeXmlSchemaGenerator.ts +44 -44
- package/src/events/amf/AmfEvents.ts +7 -7
- package/src/models/data/Bindings.ts +2 -2
- package/src/models/data/DataAssociation.ts +4 -4
- package/src/models/data/DataEntity.ts +2 -2
- package/src/models/data/DataProperty.ts +2 -2
- package/src/runtime/variables/VariablesProcessor.ts +2 -2
|
@@ -2,9 +2,9 @@ import { IPropertyBindings, IPropertySchema, IPropertyWebBindings } from "../mod
|
|
|
2
2
|
import { DataAssociation } from "../models/data/DataAssociation.js";
|
|
3
3
|
import { DataEntity } from "../models/data/DataEntity.js";
|
|
4
4
|
import { DataProperty } from "../models/data/DataProperty.js";
|
|
5
|
-
import {
|
|
5
|
+
import { IAmfExampleTypes, modelTypeToAmfDataType } from "./AmfTypes.js";
|
|
6
6
|
import { AmfNamespace } from "./definitions/Namespace.js";
|
|
7
|
-
import { anyShape, arrayShape, fileShape,
|
|
7
|
+
import { anyShape, arrayShape, fileShape, IApiAnyShape, IApiArrayShape, IApiDataExample, IApiFileShape, IApiNodeShape, IApiPropertyShape, IApiRecursiveShape, IApiScalarShape, IApiShape, IShapeUnion, nodeShape, propertyShape, recursiveShape, scalarShape, unionShape } from "./definitions/Shapes.js";
|
|
8
8
|
import { AmfDataNode } from "./models/AmfDataNode.js";
|
|
9
9
|
import v4 from '../lib/uuid.js';
|
|
10
10
|
|
|
@@ -18,7 +18,7 @@ export class AmfShapeGenerator {
|
|
|
18
18
|
* @param input The Property to serialize.
|
|
19
19
|
* @param generatedEntities The list keys of already generated entities. This prohibits recursive shape generation.
|
|
20
20
|
*/
|
|
21
|
-
entity(input: DataEntity, generatedEntities: string[] = []):
|
|
21
|
+
entity(input: DataEntity, generatedEntities: string[] = []): IApiNodeShape | IApiRecursiveShape {
|
|
22
22
|
// const adapted = input.readAdapted();
|
|
23
23
|
if (generatedEntities.includes(input.key)) {
|
|
24
24
|
// create a recursive shape.
|
|
@@ -59,7 +59,7 @@ export class AmfShapeGenerator {
|
|
|
59
59
|
*
|
|
60
60
|
* @param input The Property to serialize.
|
|
61
61
|
*/
|
|
62
|
-
property(input: DataProperty):
|
|
62
|
+
property(input: DataProperty): IApiPropertyShape {
|
|
63
63
|
const { required, key } = input;
|
|
64
64
|
const result = propertyShape(key);
|
|
65
65
|
result.path = `${AmfNamespace.aml.vocabularies.data.key}${input.info.name}`;
|
|
@@ -84,7 +84,7 @@ export class AmfShapeGenerator {
|
|
|
84
84
|
*
|
|
85
85
|
* @param input The Property to serialize.
|
|
86
86
|
*/
|
|
87
|
-
associationProperty(input: DataAssociation, generatedEntities: string[] = []):
|
|
87
|
+
associationProperty(input: DataAssociation, generatedEntities: string[] = []): IApiPropertyShape {
|
|
88
88
|
const { required, key } = input;
|
|
89
89
|
const result = propertyShape(key);
|
|
90
90
|
result.path = `${AmfNamespace.aml.vocabularies.data.key}${input.info.name}`;
|
|
@@ -104,7 +104,7 @@ export class AmfShapeGenerator {
|
|
|
104
104
|
*/
|
|
105
105
|
associationShape(input: DataAssociation, generatedEntities: string[] = []): IShapeUnion | undefined {
|
|
106
106
|
const adapted = input.readAdapted();
|
|
107
|
-
|
|
107
|
+
const schema = adapted && adapted.schema;
|
|
108
108
|
if (schema && schema.linked) {
|
|
109
109
|
// This is a link to the schema. In an API that would be the id
|
|
110
110
|
// of a resource to request the data from.
|
|
@@ -172,7 +172,7 @@ export class AmfShapeGenerator {
|
|
|
172
172
|
* @param input
|
|
173
173
|
* @returns
|
|
174
174
|
*/
|
|
175
|
-
protected _readPropertyRange(input: DataProperty):
|
|
175
|
+
protected _readPropertyRange(input: DataProperty): IApiArrayShape | IApiFileShape | IApiScalarShape {
|
|
176
176
|
const adapted = input.readAdapted();
|
|
177
177
|
let bindings: IPropertyWebBindings | undefined;
|
|
178
178
|
let schema: IPropertySchema | undefined;
|
|
@@ -188,7 +188,7 @@ export class AmfShapeGenerator {
|
|
|
188
188
|
return this._createAmfSchema(input, schema, bindings);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
protected _createAmfSchema(input: DataProperty, schema?: IPropertySchema, bindings?: IPropertyWebBindings):
|
|
191
|
+
protected _createAmfSchema(input: DataProperty, schema?: IPropertySchema, bindings?: IPropertyWebBindings): IApiArrayShape | IApiFileShape | IApiScalarShape {
|
|
192
192
|
const { multiple, type } = input;
|
|
193
193
|
if (multiple) {
|
|
194
194
|
return this._generateArrayShape(input, schema, bindings);
|
|
@@ -208,7 +208,7 @@ export class AmfShapeGenerator {
|
|
|
208
208
|
* @param type The data type of the parent property as set on the `range`
|
|
209
209
|
* @param isArray Whether the DataProperty is multiple
|
|
210
210
|
*/
|
|
211
|
-
protected _setShapeSchema(result:
|
|
211
|
+
protected _setShapeSchema(result: IApiAnyShape, schema: IPropertySchema, type: string, isArray?: boolean): void {
|
|
212
212
|
if (schema.defaultValue) {
|
|
213
213
|
const dt = AmfDataNode.scalar(schema.defaultValue, type);
|
|
214
214
|
result.defaultValue = dt.toJSON();
|
|
@@ -225,7 +225,7 @@ export class AmfShapeGenerator {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
protected _generateArrayShape(input: DataProperty, schema?: IPropertySchema, bindings?: IPropertyWebBindings):
|
|
228
|
+
protected _generateArrayShape(input: DataProperty, schema?: IPropertySchema, bindings?: IPropertyWebBindings): IApiArrayShape {
|
|
229
229
|
const result = arrayShape(input.key);
|
|
230
230
|
const { type } = input;
|
|
231
231
|
if (type === 'binary') {
|
|
@@ -235,13 +235,13 @@ export class AmfShapeGenerator {
|
|
|
235
235
|
result.items = this._generateScalarShape(input, undefined, bindings);
|
|
236
236
|
}
|
|
237
237
|
if (schema) {
|
|
238
|
-
const type = (result.items as
|
|
238
|
+
const type = (result.items as IApiScalarShape).dataType as string;
|
|
239
239
|
this._setShapeSchema(result, schema, type, input.multiple);
|
|
240
240
|
}
|
|
241
241
|
return result;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
protected _generateScalarShape(input: DataProperty, schema?: IPropertySchema, bindings?: IPropertyWebBindings):
|
|
244
|
+
protected _generateScalarShape(input: DataProperty, schema?: IPropertySchema, bindings?: IPropertyWebBindings): IApiScalarShape {
|
|
245
245
|
const result = scalarShape(input.key);
|
|
246
246
|
this._updateBaseProperties(input, result);
|
|
247
247
|
if (bindings) {
|
|
@@ -259,26 +259,26 @@ export class AmfShapeGenerator {
|
|
|
259
259
|
return result;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
protected _generateExamples(examples: string[], type: string):
|
|
262
|
+
protected _generateExamples(examples: string[], type: string): IApiDataExample[] {
|
|
263
263
|
return examples.map((current) => {
|
|
264
264
|
const value = AmfDataNode.scalar(current, type).toJSON();
|
|
265
|
-
const item:
|
|
265
|
+
const item: IApiDataExample = {
|
|
266
266
|
id: v4(),
|
|
267
267
|
customDomainProperties: [],
|
|
268
268
|
strict: true,
|
|
269
|
-
types:
|
|
269
|
+
types: IAmfExampleTypes,
|
|
270
270
|
structuredValue: value,
|
|
271
271
|
};
|
|
272
272
|
return item;
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
protected _generateArrayExamples(examples: string[], type: string):
|
|
277
|
-
const item:
|
|
276
|
+
protected _generateArrayExamples(examples: string[], type: string): IApiDataExample[] {
|
|
277
|
+
const item: IApiDataExample = {
|
|
278
278
|
id: v4(),
|
|
279
279
|
customDomainProperties: [],
|
|
280
280
|
strict: true,
|
|
281
|
-
types:
|
|
281
|
+
types: IAmfExampleTypes,
|
|
282
282
|
};
|
|
283
283
|
const value = new AmfDataNode('array');
|
|
284
284
|
examples.forEach((item) => {
|
|
@@ -289,7 +289,7 @@ export class AmfShapeGenerator {
|
|
|
289
289
|
return [item];
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
protected _generateFileShape(input: DataProperty, schema?: IPropertySchema, bindings?: IPropertyWebBindings):
|
|
292
|
+
protected _generateFileShape(input: DataProperty, schema?: IPropertySchema, bindings?: IPropertyWebBindings): IApiFileShape {
|
|
293
293
|
if (bindings && bindings.dataType === AmfNamespace.w3.xmlSchema.base64Binary) {
|
|
294
294
|
// this is a binary format of a string shape
|
|
295
295
|
}
|
|
@@ -304,7 +304,7 @@ export class AmfShapeGenerator {
|
|
|
304
304
|
return result;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
-
protected _fillScalarShapeCommonProperties(result:
|
|
307
|
+
protected _fillScalarShapeCommonProperties(result: IApiFileShape | IApiScalarShape, input: DataProperty, bindings: IPropertyWebBindings): void {
|
|
308
308
|
if (bindings.name) {
|
|
309
309
|
result.name = bindings.name;
|
|
310
310
|
}
|
|
@@ -346,7 +346,7 @@ export class AmfShapeGenerator {
|
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
protected _updateBaseProperties(input: DataProperty | DataAssociation | DataEntity, target:
|
|
349
|
+
protected _updateBaseProperties(input: DataProperty | DataAssociation | DataEntity, target: IApiShape): void {
|
|
350
350
|
const adopted = input.readAdapted();
|
|
351
351
|
if (adopted && adopted.info.name) {
|
|
352
352
|
target.name = adopted.info.name;
|
|
@@ -370,7 +370,7 @@ export class AmfShapeGenerator {
|
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
372
|
|
|
373
|
-
protected _recursiveShape(input: DataEntity):
|
|
373
|
+
protected _recursiveShape(input: DataEntity): IApiRecursiveShape {
|
|
374
374
|
return recursiveShape(input.key, input.key);
|
|
375
375
|
}
|
|
376
376
|
|
|
@@ -380,7 +380,7 @@ export class AmfShapeGenerator {
|
|
|
380
380
|
* @param array The source array.
|
|
381
381
|
* @returns The definition of the `items` of the array.
|
|
382
382
|
*/
|
|
383
|
-
refactorArrayToShape(array:
|
|
383
|
+
refactorArrayToShape(array: IApiArrayShape): IShapeUnion {
|
|
384
384
|
const { items } = array;
|
|
385
385
|
return items!;
|
|
386
386
|
}
|
|
@@ -392,7 +392,7 @@ export class AmfShapeGenerator {
|
|
|
392
392
|
* @param shape The shape to wrap as an array.
|
|
393
393
|
* @returns Array shape.
|
|
394
394
|
*/
|
|
395
|
-
refactorShapeToArray(id: string, shape: IShapeUnion):
|
|
395
|
+
refactorShapeToArray(id: string, shape: IShapeUnion): IApiArrayShape {
|
|
396
396
|
const result = arrayShape(id);
|
|
397
397
|
result.items = shape;
|
|
398
398
|
return result;
|
package/src/amf/AmfTypes.ts
CHANGED
|
@@ -2,67 +2,67 @@ import { DataPropertyType } from "../models/data/DataProperty.js";
|
|
|
2
2
|
import { IPropertyWebBindings } from "../models/data/Bindings.js";
|
|
3
3
|
import { AmfNamespace } from "./definitions/Namespace.js";
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const IAmfScalarTypes = [
|
|
6
6
|
AmfNamespace.aml.vocabularies.shapes.ScalarShape,
|
|
7
7
|
AmfNamespace.aml.vocabularies.shapes.AnyShape,
|
|
8
8
|
AmfNamespace.w3.shacl.Shape,
|
|
9
9
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
10
10
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
11
11
|
];
|
|
12
|
-
export const
|
|
12
|
+
export const IAmfArrayTypes = [
|
|
13
13
|
AmfNamespace.aml.vocabularies.shapes.ArrayShape,
|
|
14
14
|
AmfNamespace.aml.vocabularies.shapes.AnyShape,
|
|
15
15
|
AmfNamespace.w3.shacl.Shape,
|
|
16
16
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
17
17
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
18
18
|
];
|
|
19
|
-
export const
|
|
19
|
+
export const IAmfNodeTypes = [
|
|
20
20
|
AmfNamespace.w3.shacl.NodeShape,
|
|
21
21
|
AmfNamespace.aml.vocabularies.shapes.AnyShape,
|
|
22
22
|
AmfNamespace.w3.shacl.Shape,
|
|
23
23
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
24
24
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
25
25
|
];
|
|
26
|
-
export const
|
|
26
|
+
export const IAmfPropertyTypes = [
|
|
27
27
|
AmfNamespace.w3.shacl.PropertyShape,
|
|
28
28
|
AmfNamespace.w3.shacl.Shape,
|
|
29
29
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
30
30
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
31
31
|
];
|
|
32
|
-
export const
|
|
32
|
+
export const IAmfNilTypes = [
|
|
33
33
|
AmfNamespace.aml.vocabularies.shapes.NilShape,
|
|
34
34
|
AmfNamespace.w3.shacl.Shape,
|
|
35
35
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
36
36
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
37
37
|
];
|
|
38
|
-
export const
|
|
38
|
+
export const IAmfUnionTypes = [
|
|
39
39
|
AmfNamespace.aml.vocabularies.shapes.UnionShape,
|
|
40
40
|
AmfNamespace.aml.vocabularies.shapes.AnyShape,
|
|
41
41
|
AmfNamespace.w3.shacl.Shape,
|
|
42
42
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
43
43
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
44
44
|
];
|
|
45
|
-
export const
|
|
45
|
+
export const IAmfFileTypes = [
|
|
46
46
|
AmfNamespace.aml.vocabularies.shapes.FileShape,
|
|
47
47
|
AmfNamespace.aml.vocabularies.shapes.AnyShape,
|
|
48
48
|
AmfNamespace.w3.shacl.Shape,
|
|
49
49
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
50
50
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
51
51
|
];
|
|
52
|
-
export const
|
|
52
|
+
export const IAmfAnyTypes = [
|
|
53
53
|
AmfNamespace.aml.vocabularies.shapes.AnyShape,
|
|
54
54
|
AmfNamespace.w3.shacl.Shape,
|
|
55
55
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
56
56
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
57
57
|
];
|
|
58
|
-
export const
|
|
58
|
+
export const IAmfSchemaTypes = [
|
|
59
59
|
AmfNamespace.aml.vocabularies.shapes.SchemaShape,
|
|
60
60
|
AmfNamespace.aml.vocabularies.shapes.AnyShape,
|
|
61
61
|
AmfNamespace.w3.shacl.Shape,
|
|
62
62
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
63
63
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
64
64
|
];
|
|
65
|
-
export const
|
|
65
|
+
export const IAmfTupleTypes = [
|
|
66
66
|
AmfNamespace.aml.vocabularies.shapes.TupleShape,
|
|
67
67
|
AmfNamespace.aml.vocabularies.shapes.ArrayShape,
|
|
68
68
|
AmfNamespace.aml.vocabularies.shapes.AnyShape,
|
|
@@ -70,34 +70,34 @@ export const TupleTypes = [
|
|
|
70
70
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
71
71
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
72
72
|
];
|
|
73
|
-
export const
|
|
73
|
+
export const IAmfRecursiveTypes = [
|
|
74
74
|
AmfNamespace.aml.vocabularies.shapes.RecursiveShape,
|
|
75
75
|
AmfNamespace.w3.shacl.Shape,
|
|
76
76
|
AmfNamespace.aml.vocabularies.shapes.Shape,
|
|
77
77
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
78
78
|
];
|
|
79
|
-
export const
|
|
79
|
+
export const IAmfXmlSerializationTypes = [
|
|
80
80
|
AmfNamespace.aml.vocabularies.shapes.XMLSerializer,
|
|
81
81
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
82
82
|
];
|
|
83
83
|
|
|
84
|
-
export const
|
|
84
|
+
export const IAmfScalarNodeTypes = [
|
|
85
85
|
AmfNamespace.aml.vocabularies.data.Scalar,
|
|
86
86
|
AmfNamespace.aml.vocabularies.data.Node,
|
|
87
87
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
88
88
|
];
|
|
89
|
-
export const
|
|
89
|
+
export const IAmfArrayNodeTypes = [
|
|
90
90
|
AmfNamespace.aml.vocabularies.data.Array,
|
|
91
91
|
AmfNamespace.w3.rdfSchema.Seq,
|
|
92
92
|
AmfNamespace.aml.vocabularies.data.Node,
|
|
93
93
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
94
94
|
];
|
|
95
|
-
export const
|
|
95
|
+
export const IAmfObjectNodeTypes = [
|
|
96
96
|
AmfNamespace.aml.vocabularies.data.Object,
|
|
97
97
|
AmfNamespace.aml.vocabularies.data.Node,
|
|
98
98
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
99
99
|
];
|
|
100
|
-
export const
|
|
100
|
+
export const IAmfExampleTypes = [
|
|
101
101
|
AmfNamespace.aml.vocabularies.apiContract.Example,
|
|
102
102
|
AmfNamespace.aml.vocabularies.document.DomainElement,
|
|
103
103
|
];
|
|
@@ -3,7 +3,7 @@ import { JsonDataNodeGenerator } from './data-node/JsonDataNodeGenerator.js';
|
|
|
3
3
|
import { XmlDataNodeGenerator } from './data-node/XmlDataNodeGenerator.js';
|
|
4
4
|
import { UrlEncodedDataNodeGenerator } from './data-node/UrlEncodedDataNodeGenerator.js';
|
|
5
5
|
import { formatXmlValue } from './Utils.js';
|
|
6
|
-
import {
|
|
6
|
+
import { IApiArrayShape, IApiDataExample, IApiDataNode, IShapeUnion } from "./definitions/Shapes.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A class that processes AMF's Example object to read the example value
|
|
@@ -19,7 +19,7 @@ export class ApiExampleGenerator {
|
|
|
19
19
|
* @param shape The optional shape containing this example to use with the XML examples which needs wrapping into an element.
|
|
20
20
|
* @returns The read or generated example.
|
|
21
21
|
*/
|
|
22
|
-
read(example:
|
|
22
|
+
read(example: IApiDataExample, mime?: string, shape?: IShapeUnion): string | undefined {
|
|
23
23
|
const { value, structuredValue } = example;
|
|
24
24
|
if (!value && !structuredValue) {
|
|
25
25
|
return undefined;
|
|
@@ -67,7 +67,7 @@ export class ApiExampleGenerator {
|
|
|
67
67
|
* @param shape The optional shape containing this example to use with the XML examples which needs wrapping into an element.
|
|
68
68
|
* @returns The generated example or null if couldn't process the data.
|
|
69
69
|
*/
|
|
70
|
-
fromStructuredValue(mime: string, structuredValue:
|
|
70
|
+
fromStructuredValue(mime: string, structuredValue: IApiDataNode, shape?: IShapeUnion): string | undefined {
|
|
71
71
|
if (mime.includes('json')) {
|
|
72
72
|
const generator = new JsonDataNodeGenerator();
|
|
73
73
|
return generator.generate(structuredValue);
|
|
@@ -76,7 +76,7 @@ export class ApiExampleGenerator {
|
|
|
76
76
|
if (shape && shape.types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
|
|
77
77
|
shapeName = shape.name;
|
|
78
78
|
} else if (shape && shape.types.includes(ns.aml.vocabularies.shapes.ArrayShape)) {
|
|
79
|
-
const typed = shape as
|
|
79
|
+
const typed = shape as IApiArrayShape;
|
|
80
80
|
if (typed.items && typed.items.types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
|
|
81
81
|
shapeName = typed.items.name || shape.name;
|
|
82
82
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AmfNamespace as ns } from "./definitions/Namespace.js";
|
|
2
|
-
import {
|
|
2
|
+
import { IApiArrayShape, IApiNodeShape, IApiPropertyShape, IApiScalarNode, IApiScalarShape, IShapeUnion } from "./definitions/Shapes.js";
|
|
3
3
|
import { collectNodeProperties } from './Utils.js';
|
|
4
4
|
|
|
5
5
|
export interface IMonacoSchema {
|
|
@@ -73,7 +73,7 @@ export class ApiMonacoSchemaGenerator {
|
|
|
73
73
|
}
|
|
74
74
|
const { types } = schema;
|
|
75
75
|
if (types.includes(ns.w3.shacl.NodeShape)) {
|
|
76
|
-
return this.fromNodeShape(schema as
|
|
76
|
+
return this.fromNodeShape(schema as IApiNodeShape, parentUri);
|
|
77
77
|
}
|
|
78
78
|
return [];
|
|
79
79
|
}
|
|
@@ -81,7 +81,7 @@ export class ApiMonacoSchemaGenerator {
|
|
|
81
81
|
/**
|
|
82
82
|
* @param parentUri The URI for the fileMatch property.
|
|
83
83
|
*/
|
|
84
|
-
fromNodeShape(schema:
|
|
84
|
+
fromNodeShape(schema: IApiNodeShape, parentUri?: string): IMonacoSchema[] {
|
|
85
85
|
const { id, name } = schema;
|
|
86
86
|
const properties = collectNodeProperties(schema);
|
|
87
87
|
const content: IMonacoObjectProperty = {
|
|
@@ -105,7 +105,7 @@ export class ApiMonacoSchemaGenerator {
|
|
|
105
105
|
return this.schemas;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
appendSchemaProperty(content: IMonacoObjectProperty, property:
|
|
108
|
+
appendSchemaProperty(content: IMonacoObjectProperty, property: IApiPropertyShape): void {
|
|
109
109
|
const { name, range, minCount } = property;
|
|
110
110
|
if (!range) {
|
|
111
111
|
return;
|
|
@@ -122,18 +122,18 @@ export class ApiMonacoSchemaGenerator {
|
|
|
122
122
|
rangeToPropertySchema(range: IShapeUnion): IMonacoScalarProperty | IMonacoObjectProperty | IMonacoArrayProperty | undefined {
|
|
123
123
|
const { types } = range;
|
|
124
124
|
if (types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
|
|
125
|
-
return this.scalarRangeToPropertySchema(range as
|
|
125
|
+
return this.scalarRangeToPropertySchema(range as IApiScalarShape);
|
|
126
126
|
}
|
|
127
127
|
if (types.includes(ns.w3.shacl.NodeShape)) {
|
|
128
|
-
return this.nodeShapeRangeToPropertySchema(range as
|
|
128
|
+
return this.nodeShapeRangeToPropertySchema(range as IApiNodeShape);
|
|
129
129
|
}
|
|
130
130
|
if (types.includes(ns.aml.vocabularies.shapes.ArrayShape)) {
|
|
131
|
-
return this.arrayShapeRangeToPropertySchema(range as
|
|
131
|
+
return this.arrayShapeRangeToPropertySchema(range as IApiArrayShape);
|
|
132
132
|
}
|
|
133
133
|
return undefined;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
scalarRangeToPropertySchema(schema:
|
|
136
|
+
scalarRangeToPropertySchema(schema: IApiScalarShape): IMonacoScalarProperty {
|
|
137
137
|
const { values, description, name, displayName, defaultValueStr, exclusiveMaximum, exclusiveMinimum, minimum, maximum, minLength, maxLength, id, multipleOf, pattern, readOnly, writeOnly } = schema;
|
|
138
138
|
const type = this.schemaTypeToJsonDataType(schema.dataType);
|
|
139
139
|
const result: IMonacoScalarProperty = {
|
|
@@ -189,7 +189,7 @@ export class ApiMonacoSchemaGenerator {
|
|
|
189
189
|
values.forEach((value) => {
|
|
190
190
|
const { types } = value;
|
|
191
191
|
if (types.includes(ns.aml.vocabularies.data.Scalar)) {
|
|
192
|
-
const typed = value as
|
|
192
|
+
const typed = value as IApiScalarNode;
|
|
193
193
|
if (typed.value) {
|
|
194
194
|
result.enum!.push(typed.value);
|
|
195
195
|
}
|
|
@@ -222,7 +222,7 @@ export class ApiMonacoSchemaGenerator {
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
nodeShapeRangeToPropertySchema(schema:
|
|
225
|
+
nodeShapeRangeToPropertySchema(schema: IApiNodeShape): IMonacoObjectProperty {
|
|
226
226
|
const { description, name, displayName, id, readOnly, writeOnly, closed, minProperties, maxProperties } = schema;
|
|
227
227
|
const properties = collectNodeProperties(schema);
|
|
228
228
|
|
|
@@ -255,7 +255,7 @@ export class ApiMonacoSchemaGenerator {
|
|
|
255
255
|
return result;
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
arrayShapeRangeToPropertySchema(schema:
|
|
258
|
+
arrayShapeRangeToPropertySchema(schema: IApiArrayShape): IMonacoArrayProperty {
|
|
259
259
|
const { description, name, displayName, id, readOnly, writeOnly, items, minItems, maxItems, uniqueItems } = schema;
|
|
260
260
|
const result: IMonacoArrayProperty = {
|
|
261
261
|
'$id': id,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AmfNamespace as ns } from "./definitions/Namespace.js";
|
|
2
|
-
import {
|
|
2
|
+
import { IApiAnyShape, IApiDataExample, IShapeUnion } from "./definitions/Shapes.js";
|
|
3
3
|
import { ShapeBase, IShapeRenderOptions } from "./shape/ShapeBase.js";
|
|
4
4
|
import { ShapeJsonSchemaGenerator } from './shape/ShapeJsonSchemaGenerator.js';
|
|
5
5
|
import { ShapeXmlSchemaGenerator } from './shape/ShapeXmlSchemaGenerator.js';
|
|
6
6
|
|
|
7
|
-
export interface ISchemaExample extends
|
|
7
|
+
export interface ISchemaExample extends IApiDataExample {
|
|
8
8
|
/**
|
|
9
9
|
* The value to render as the example value.
|
|
10
10
|
*/
|
|
@@ -96,7 +96,7 @@ export class ApiSchemaGenerator {
|
|
|
96
96
|
renderValue,
|
|
97
97
|
customDomainProperties: [],
|
|
98
98
|
};
|
|
99
|
-
const typed = shape as
|
|
99
|
+
const typed = shape as IApiAnyShape;
|
|
100
100
|
if (Array.isArray(typed.examples) && typed.examples.length) {
|
|
101
101
|
const [example] = typed.examples;
|
|
102
102
|
if (example.value) {
|
|
@@ -2,8 +2,8 @@ import { DataMock, ILoremWordInit, ITypeHashInit, ITypeNumberInit, Time } from '
|
|
|
2
2
|
import { AmfNamespace as ns } from "./definitions/Namespace.js";
|
|
3
3
|
import { JsonDataNodeGenerator } from "./data-node/JsonDataNodeGenerator.js";
|
|
4
4
|
import { parseBooleanInput, parseNumberInput, readTypedValue } from "./Utils.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { IApiParameter } from './definitions/Api.js';
|
|
6
|
+
import { IApiAnyShape, IApiArrayNode, IApiArrayShape, IApiDataExample, IApiScalarNode, IApiScalarShape, IShapeUnion } from './definitions/Shapes.js';
|
|
7
7
|
|
|
8
8
|
export interface IApiSchemaReadOptions {
|
|
9
9
|
/**
|
|
@@ -27,7 +27,7 @@ export class ApiSchemaValues {
|
|
|
27
27
|
*
|
|
28
28
|
* @returns The value to set on the input. Note, it is not cast to the type.
|
|
29
29
|
*/
|
|
30
|
-
static readInputValue(parameter:
|
|
30
|
+
static readInputValue(parameter: IApiParameter, schema: IApiScalarShape, opts: IApiSchemaReadOptions = {}): any {
|
|
31
31
|
const { required } = parameter;
|
|
32
32
|
const { defaultValueStr, values } = schema;
|
|
33
33
|
if (!required && opts.requiredOnly === true) {
|
|
@@ -37,11 +37,11 @@ export class ApiSchemaValues {
|
|
|
37
37
|
return ApiSchemaValues.readTypedValue(defaultValueStr, schema.dataType);
|
|
38
38
|
}
|
|
39
39
|
if (Array.isArray(values) && values.length) {
|
|
40
|
-
const firstEnum = values[0] as
|
|
40
|
+
const firstEnum = values[0] as IApiScalarNode;
|
|
41
41
|
return ApiSchemaValues.readTypedValue(firstEnum.value, firstEnum.dataType);
|
|
42
42
|
}
|
|
43
43
|
if (opts.fromExamples) {
|
|
44
|
-
let examples:
|
|
44
|
+
let examples: IApiDataExample[] | undefined;
|
|
45
45
|
if (Array.isArray(parameter.examples) && parameter.examples.length) {
|
|
46
46
|
// just in case when an ApiParameter was passed.
|
|
47
47
|
examples = parameter.examples.filter(i => typeof i !== 'string');
|
|
@@ -59,7 +59,7 @@ export class ApiSchemaValues {
|
|
|
59
59
|
* @param parameter The parameter that has the array schema.
|
|
60
60
|
* @param schema The final schema to use to read the data from.
|
|
61
61
|
*/
|
|
62
|
-
static readInputValues(parameter:
|
|
62
|
+
static readInputValues(parameter: IApiParameter, schema: IShapeUnion, opts: IApiSchemaReadOptions = {}): any {
|
|
63
63
|
if (!parameter.required && opts.requiredOnly === true) {
|
|
64
64
|
// for a non required array items just skip showing example values
|
|
65
65
|
// as they are not crucial to make an HTTP request.
|
|
@@ -73,9 +73,9 @@ export class ApiSchemaValues {
|
|
|
73
73
|
return result;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
const anySchema = schema as
|
|
76
|
+
const anySchema = schema as IApiAnyShape;
|
|
77
77
|
if (opts.fromExamples) {
|
|
78
|
-
let examples:
|
|
78
|
+
let examples: IApiDataExample[] | undefined;
|
|
79
79
|
if (Array.isArray(parameter.examples) && parameter.examples.length) {
|
|
80
80
|
// just in case when an ApiParameter was passed.
|
|
81
81
|
examples = parameter.examples.filter(i => typeof i !== 'string');
|
|
@@ -90,7 +90,7 @@ export class ApiSchemaValues {
|
|
|
90
90
|
/**
|
|
91
91
|
* Reads the value for the form input(s) from examples.
|
|
92
92
|
*/
|
|
93
|
-
static inputValueFromExamples(examples:
|
|
93
|
+
static inputValueFromExamples(examples: IApiDataExample[]): any | null | undefined {
|
|
94
94
|
if (!Array.isArray(examples) || !examples.length) {
|
|
95
95
|
return undefined;
|
|
96
96
|
}
|
|
@@ -100,7 +100,7 @@ export class ApiSchemaValues {
|
|
|
100
100
|
return undefined;
|
|
101
101
|
}
|
|
102
102
|
if (structuredValue.types.includes(ns.aml.vocabularies.data.Scalar)) {
|
|
103
|
-
const value = structuredValue as
|
|
103
|
+
const value = structuredValue as IApiScalarNode;
|
|
104
104
|
return ApiSchemaValues.readTypedValue(value.value, value.dataType);
|
|
105
105
|
}
|
|
106
106
|
return undefined;
|
|
@@ -110,7 +110,7 @@ export class ApiSchemaValues {
|
|
|
110
110
|
* Reads the array value from examples.
|
|
111
111
|
* @param examples Examples set on an array item.
|
|
112
112
|
*/
|
|
113
|
-
static arrayValuesFromExamples(examples?:
|
|
113
|
+
static arrayValuesFromExamples(examples?: IApiDataExample[]): any[] {
|
|
114
114
|
const defaultReturn: any[] = [];
|
|
115
115
|
if (!Array.isArray(examples) || !examples.length) {
|
|
116
116
|
return defaultReturn;
|
|
@@ -119,14 +119,14 @@ export class ApiSchemaValues {
|
|
|
119
119
|
if (!example.structuredValue || !example.structuredValue.types.includes(ns.aml.vocabularies.data.Array)) {
|
|
120
120
|
return defaultReturn;
|
|
121
121
|
}
|
|
122
|
-
const value = example.structuredValue as
|
|
122
|
+
const value = example.structuredValue as IApiArrayNode;
|
|
123
123
|
const { members } = value;
|
|
124
124
|
if (!Array.isArray(members) || !members.length) {
|
|
125
125
|
return defaultReturn;
|
|
126
126
|
}
|
|
127
127
|
const result: any[] = [];
|
|
128
128
|
members.forEach((item) => {
|
|
129
|
-
const scalar = item as
|
|
129
|
+
const scalar = item as IApiScalarNode;
|
|
130
130
|
if (!scalar.value) {
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
@@ -143,7 +143,7 @@ export class ApiSchemaValues {
|
|
|
143
143
|
* For booleans it returns `false`, for numbers `0`, nulls `null`, etc.
|
|
144
144
|
* It does not generate a value for `string` types!
|
|
145
145
|
*/
|
|
146
|
-
static generateDefaultValue(schema:
|
|
146
|
+
static generateDefaultValue(schema: IApiScalarShape): any {
|
|
147
147
|
const { dataType } = schema;
|
|
148
148
|
return this.defaultValue(dataType);
|
|
149
149
|
}
|
|
@@ -153,7 +153,7 @@ export class ApiSchemaValues {
|
|
|
153
153
|
* For booleans it returns `false`, for numbers `0`, nulls `null`, etc.
|
|
154
154
|
* It does not generate a value for `string` types!
|
|
155
155
|
*/
|
|
156
|
-
static generateMockedValue(schema:
|
|
156
|
+
static generateMockedValue(schema: IApiScalarShape): any {
|
|
157
157
|
const { dataType } = schema;
|
|
158
158
|
switch (dataType) {
|
|
159
159
|
case ns.w3.xmlSchema.string: return this.generateStringValue(schema);
|
|
@@ -209,7 +209,7 @@ export class ApiSchemaValues {
|
|
|
209
209
|
/**
|
|
210
210
|
* Generates a random number value given the schema definition for a number scalar.
|
|
211
211
|
*/
|
|
212
|
-
static generateNumberValue(schema:
|
|
212
|
+
static generateNumberValue(schema: IApiScalarShape): number {
|
|
213
213
|
const { minimum, maximum, format, multipleOf } = schema;
|
|
214
214
|
const init: ITypeNumberInit = {};
|
|
215
215
|
if (typeof minimum === 'number') {
|
|
@@ -239,7 +239,7 @@ export class ApiSchemaValues {
|
|
|
239
239
|
return generator(init);
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
static generateStringValue(schema:
|
|
242
|
+
static generateStringValue(schema: IApiScalarShape): string {
|
|
243
243
|
const { minLength, maxLength, name = '', format } = schema;
|
|
244
244
|
const lowerName = name.toLowerCase();
|
|
245
245
|
// we employ some heuristics to generate content based on the property name.
|
|
@@ -394,7 +394,7 @@ export class ApiSchemaValues {
|
|
|
394
394
|
/**
|
|
395
395
|
* Parses the the value according to array schema value.
|
|
396
396
|
*/
|
|
397
|
-
static parseArrayInput(value: any, schema:
|
|
397
|
+
static parseArrayInput(value: any, schema: IApiArrayShape): string | number | boolean | null | undefined {
|
|
398
398
|
const { items } = schema;
|
|
399
399
|
if (!items) {
|
|
400
400
|
return String(value);
|
|
@@ -411,10 +411,10 @@ export class ApiSchemaValues {
|
|
|
411
411
|
}
|
|
412
412
|
const { types } = schema;
|
|
413
413
|
if (types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
|
|
414
|
-
return ApiSchemaValues.parseScalarInput(value, schema as
|
|
414
|
+
return ApiSchemaValues.parseScalarInput(value, schema as IApiScalarShape);
|
|
415
415
|
}
|
|
416
416
|
if (types.includes(ns.aml.vocabularies.shapes.ArrayShape) || types.includes(ns.aml.vocabularies.shapes.MatrixShape)) {
|
|
417
|
-
return ApiSchemaValues.parseArrayInput(value, schema as
|
|
417
|
+
return ApiSchemaValues.parseArrayInput(value, schema as IApiArrayShape);
|
|
418
418
|
}
|
|
419
419
|
return value;
|
|
420
420
|
}
|
|
@@ -422,7 +422,7 @@ export class ApiSchemaValues {
|
|
|
422
422
|
/**
|
|
423
423
|
* Parses the user entered value as scalar value.
|
|
424
424
|
*/
|
|
425
|
-
static parseScalarInput(value: unknown, schema:
|
|
425
|
+
static parseScalarInput(value: unknown, schema: IApiScalarShape): string | number | boolean | null | undefined {
|
|
426
426
|
return this.parseScalar(value, schema.dataType, schema.format);
|
|
427
427
|
}
|
|
428
428
|
|
package/src/amf/Parsing.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface IAmfServiceProcessingOptions {
|
|
2
2
|
/**
|
|
3
3
|
* When true it treats the source as a zip data. Files are unzipped to a temporary location before processing.
|
|
4
4
|
*/
|
|
@@ -15,7 +15,7 @@ export interface AmfServiceProcessingOptions {
|
|
|
15
15
|
mainFile?: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export interface
|
|
18
|
+
export interface IApiSearchCandidate {
|
|
19
19
|
/**
|
|
20
20
|
* Absolute path to the file
|
|
21
21
|
*/
|
|
@@ -26,7 +26,7 @@ export interface ApiSearchCandidate {
|
|
|
26
26
|
relative: string;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export interface
|
|
29
|
+
export interface IApiSearchTypeResult {
|
|
30
30
|
/**
|
|
31
31
|
* API type
|
|
32
32
|
*/
|
|
@@ -37,7 +37,7 @@ export interface ApiSearchTypeResult {
|
|
|
37
37
|
contentType: string;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export interface
|
|
40
|
+
export interface IApiParseResult {
|
|
41
41
|
/**
|
|
42
42
|
* The parsed API
|
|
43
43
|
*/
|
|
@@ -45,5 +45,5 @@ export interface ApiParseResult {
|
|
|
45
45
|
/**
|
|
46
46
|
* Api type info
|
|
47
47
|
*/
|
|
48
|
-
type:
|
|
48
|
+
type: IApiSearchTypeResult;
|
|
49
49
|
}
|