@api-client/core 0.8.1 → 0.8.2
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 +3 -3
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +3 -3
- package/build/index.js.map +1 -1
- package/build/oauth-popup.html +29 -0
- package/build/src/amf/AmfShapeGenerator.d.ts +2 -0
- package/build/src/amf/AmfShapeGenerator.js +2 -0
- package/build/src/amf/AmfShapeGenerator.js.map +1 -1
- package/build/src/amf/ApiSchemaValues.d.ts +4 -4
- package/build/src/amf/ApiSchemaValues.js.map +1 -1
- package/build/src/amf/Utils.js +3 -1
- package/build/src/amf/Utils.js.map +1 -1
- package/build/src/amf/data-node/XmlDataNodeGenerator.js +2 -1
- package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +1 -1
- package/build/src/amf/shape/ShapeBase.d.ts +1 -1
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +4 -2
- package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -1
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +13 -13
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +25 -7
- package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -1
- package/build/src/authorization/OAuth2Authorization.d.ts +4 -4
- package/build/src/authorization/OAuth2Authorization.js +7 -7
- package/build/src/authorization/OAuth2Authorization.js.map +1 -1
- package/build/src/authorization/OidcAuthorization.js +0 -1
- package/build/src/authorization/OidcAuthorization.js.map +1 -1
- package/build/src/data/XmlReader.js +2 -0
- package/build/src/data/XmlReader.js.map +1 -1
- package/build/src/events/CustomEvent.d.ts +1 -1
- package/build/src/events/CustomEvent.js +1 -1
- package/build/src/lib/logging/DefaultLogger.js +1 -0
- package/build/src/lib/logging/DefaultLogger.js.map +1 -1
- package/build/src/lib/parsers/UriTemplate.js +1 -1
- package/build/src/lib/parsers/UrlEncoder.js +1 -0
- package/build/src/lib/parsers/UrlEncoder.js.map +1 -1
- package/build/src/mocking/LegacyInterfaces.d.ts +1 -2
- package/build/src/mocking/LegacyMock.js +0 -1
- package/build/src/mocking/LegacyMock.js.map +1 -1
- package/build/src/mocking/legacy/Http.js +1 -1
- package/build/src/mocking/legacy/Http.js.map +1 -1
- package/build/src/models/data/DataNamespace.d.ts +0 -1
- package/build/src/models/data/DataNamespace.js +1 -1
- package/build/src/models/data/DataNamespace.js.map +1 -1
- package/build/src/models/store/Permission.js.map +1 -1
- package/build/src/models/transformers/ArcLegacyTransformer.js +1 -0
- package/build/src/models/transformers/ArcLegacyTransformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.d.ts +1 -2
- package/build/src/models/transformers/PostmanV21Transformer.js +2 -0
- package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js +2 -0
- package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
- package/build/src/runtime/store/AuthSdk.js +1 -0
- package/build/src/runtime/store/AuthSdk.js.map +1 -1
- package/build/src/runtime/store/SdkBase.js.map +1 -1
- package/build/src/testing/TestCliHelper.js.map +1 -1
- package/data/apis/APIC-187/APIC-187.raml +21 -0
- package/data/apis/APIC-187/dataType.raml +132 -0
- package/data/apis/APIC-187/example.raml +84 -0
- package/data/apis/APIC-188/APIC-188.raml +21 -0
- package/data/apis/APIC-188/dataType.raml +132 -0
- package/data/apis/APIC-188/example.raml +84 -0
- package/data/apis/APIC-233/APIC-233.raml +15 -0
- package/data/apis/APIC-391/APIC-391.raml +44 -0
- package/data/apis/APIC-391/examples/post-body-request-example.raml +7 -0
- package/data/apis/APIC-487/APIC-487.raml +36 -0
- package/data/apis/APIC-655/APIC-655.raml +44 -0
- package/data/apis/APIC-655/delivery.json +12 -0
- package/data/apis/APIC-689/APIC-689.raml +20 -0
- package/data/apis/APIC-690/APIC-690.raml +17 -0
- package/data/apis/APIC-690/datatypes/Address.raml +10 -0
- package/data/apis/APIC-690/datatypes/Customer.raml +17 -0
- package/data/apis/APIC-690/examples/CustomerExample2.raml +17 -0
- package/data/apis/APIC-690/examples/CustomersExample.raml +34 -0
- package/data/apis/SE-10469/Purchase-Order-oagis-id-dd32f9c6c01048a19e15c423c9c741ae.json +1383 -0
- package/data/apis/SE-10469/SE-10469.raml +11 -0
- package/data/apis/SE-13092/Examples/PersonExample.raml +7 -0
- package/data/apis/SE-13092/SE-13092.raml +37 -0
- package/data/apis/SE-13092/datatypes/Address.raml +5 -0
- package/data/apis/SE-13092/datatypes/InlineType.raml +5 -0
- package/data/apis/SE-13092/datatypes/Person.raml +15 -0
- package/data/apis/SE-22063/SE-22063.raml +14 -0
- package/data/apis/SE-22063/stock.raml +41 -0
- package/data/apis/example-generator-api/contact-email-example.raml +6 -0
- package/data/apis/example-generator-api/contact-example.raml +5 -0
- package/data/apis/example-generator-api/contact-fax-example.raml +5 -0
- package/data/apis/example-generator-api/contact-website-example.raml +2 -0
- package/data/apis/example-generator-api/example-1.raml +6 -0
- package/data/apis/example-generator-api/example-2.raml +9 -0
- package/data/apis/example-generator-api/example-3.raml +4 -0
- package/data/apis/example-generator-api/example-4.raml +2 -0
- package/data/apis/example-generator-api/example-5.raml +4 -0
- package/data/apis/example-generator-api/example-6.raml +2 -0
- package/data/apis/example-generator-api/example-7.raml +5 -0
- package/data/apis/example-generator-api/example-generator-api.raml +423 -0
- package/data/apis/example-generator-api/example.json +14 -0
- package/data/apis/example-generator-api/example.xml +15 -0
- package/data/apis/example-generator-api/example.xsd +26 -0
- package/data/apis/example-generator-api/examples/employee.raml +7 -0
- package/data/apis/example-generator-api/examples/employees.raml +7 -0
- package/data/apis/example-generator-api/linked-named-example.raml +21 -0
- package/data/apis/example-generator-api/named-example-with-link.raml +5 -0
- package/data/apis/example-generator-api/named-example.raml +9 -0
- package/data/apis/example-generator-api/user-json-example.raml +17 -0
- package/data/apis/example-generator-api/user-raml-example.raml +37 -0
- package/data/apis/example-generator-api/user.json +8 -0
- package/data/apis/example-generator-api/user.raml +18 -0
- package/data/apis/example-generator-api/users-json-example.raml +17 -0
- package/data/apis/example-generator-api/users-raml-example.raml +32 -0
- package/data/apis/example-generator-api/users.json +8 -0
- package/data/apis/schema-api/schema-api.raml +13 -1
- package/data/apis/tracked-examples/datatypes/employee.raml +5 -0
- package/data/apis/tracked-examples/examples/employee.raml +4 -0
- package/data/apis/tracked-examples/examples/employees.raml +8 -0
- package/data/apis/tracked-examples/tracked-to-linked.raml +28 -0
- package/data/model.js +14 -0
- package/data/models/APIC-187.json +11398 -0
- package/data/models/APIC-188.json +11398 -0
- package/data/models/APIC-233.json +539 -0
- package/data/models/APIC-391.json +1872 -0
- package/data/models/APIC-487.json +1225 -0
- package/data/models/APIC-655.json +3109 -0
- package/data/models/APIC-689.json +761 -0
- package/data/models/APIC-690.json +5992 -0
- package/data/models/SE-10469.json +22882 -0
- package/data/models/SE-13092.json +2715 -0
- package/data/models/SE-22063.json +2276 -0
- package/data/models/example-generator-api.json +44978 -0
- package/data/models/schema-api.json +436 -428
- package/data/models/tracked-to-linked.json +1790 -0
- package/package.json +6 -5
- package/src/amf/AmfShapeGenerator.ts +5 -3
- package/src/amf/ApiSchemaValues.ts +5 -5
- package/src/amf/Utils.ts +6 -4
- package/src/amf/data-node/XmlDataNodeGenerator.ts +2 -1
- package/src/amf/shape/ShapeBase.ts +1 -1
- package/src/amf/shape/ShapeJsonSchemaGenerator.ts +4 -2
- package/src/amf/shape/ShapeXmlSchemaGenerator.ts +85 -66
- package/src/authorization/OAuth2Authorization.ts +33 -32
- package/src/authorization/OidcAuthorization.ts +3 -4
- package/src/data/XmlReader.ts +7 -5
- package/src/events/CustomEvent.ts +1 -1
- package/src/lib/logging/DefaultLogger.ts +1 -0
- package/src/lib/parsers/UriTemplate.ts +1 -1
- package/src/lib/parsers/UrlEncoder.ts +1 -0
- package/src/mocking/LegacyInterfaces.ts +1 -2
- package/src/mocking/LegacyMock.ts +0 -1
- package/src/mocking/legacy/Http.ts +1 -1
- package/src/models/data/DataNamespace.ts +2 -2
- package/src/models/store/Permission.ts +1 -1
- package/src/models/transformers/ArcLegacyTransformer.ts +1 -0
- package/src/models/transformers/PostmanV21Transformer.ts +3 -2
- package/src/models/transformers/PostmanV2Transformer.ts +2 -0
- package/src/runtime/store/AuthSdk.ts +1 -0
- package/src/runtime/store/SdkBase.ts +1 -0
- package/src/testing/TestCliHelper.ts +1 -0
|
@@ -12,7 +12,7 @@ interface IProcessNodeOptions {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface ICollectExamplesOptions {
|
|
15
|
-
nodeName?: string;
|
|
15
|
+
nodeName?: string;
|
|
16
16
|
indent?: number;
|
|
17
17
|
isWrapped?: boolean;
|
|
18
18
|
tagFill?: string;
|
|
@@ -28,7 +28,7 @@ export const normalizeXmlTagName = (name: string): string => name.replace(/[^a-z
|
|
|
28
28
|
const UNKNOWN_TYPE = 'unknown-type';
|
|
29
29
|
|
|
30
30
|
export function shapeToXmlTagName(shape: IApiAnyShape): string {
|
|
31
|
-
const { name, inherits=[], xmlSerialization } = shape;
|
|
31
|
+
const { name, inherits = [], xmlSerialization } = shape;
|
|
32
32
|
let label: string | undefined = xmlSerialization && xmlSerialization.name ? xmlSerialization.name : name || UNKNOWN_TYPE;
|
|
33
33
|
if (label === 'schema' && inherits.length) {
|
|
34
34
|
const n = inherits.find(i => i.name && i.name !== 'schema');
|
|
@@ -45,15 +45,15 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
45
45
|
*
|
|
46
46
|
* @param schema The Shape definition
|
|
47
47
|
*/
|
|
48
|
-
generate(schema: IShapeUnion): string {
|
|
49
|
-
const value = this.processNode(schema);
|
|
48
|
+
generate(schema: IShapeUnion): string | undefined {
|
|
49
|
+
const value = this.processNode(schema, {}, true);
|
|
50
50
|
return value;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Processes the Shape definition and returns a JavaScript object or array.
|
|
55
55
|
*/
|
|
56
|
-
processNode(schema: IShapeUnion, options: IProcessNodeOptions = {}): string {
|
|
56
|
+
processNode(schema: IShapeUnion, options: IProcessNodeOptions = {}, isRoot = false): string | undefined {
|
|
57
57
|
const { types } = schema;
|
|
58
58
|
if (types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
|
|
59
59
|
return this._scalarShapeObject(schema as IApiScalarShape, options);
|
|
@@ -74,7 +74,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
74
74
|
return this._tupleShapeObject();
|
|
75
75
|
}
|
|
76
76
|
if (types.includes(ns.aml.vocabularies.shapes.ArrayShape) || types.includes(ns.aml.vocabularies.shapes.MatrixShape)) {
|
|
77
|
-
return this._arrayShapeObject(schema as IApiArrayShape, options);
|
|
77
|
+
return this._arrayShapeObject(schema as IApiArrayShape, options, isRoot);
|
|
78
78
|
}
|
|
79
79
|
return this._anyShapeObject(schema as IApiAnyShape);
|
|
80
80
|
}
|
|
@@ -82,8 +82,8 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
82
82
|
/**
|
|
83
83
|
* Serializes generated JS value according to the mime type.
|
|
84
84
|
*/
|
|
85
|
-
serialize(value:
|
|
86
|
-
return value;
|
|
85
|
+
serialize(value: unknown): string | undefined {
|
|
86
|
+
return value as string;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -99,9 +99,9 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
99
99
|
return collectNodeProperties(schema, selectedUnions);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
protected _nodeShapeObject(schema: IApiNodeShape, options: IProcessNodeOptions={}): string {
|
|
102
|
+
protected _nodeShapeObject(schema: IApiNodeShape, options: IProcessNodeOptions = {}): string {
|
|
103
103
|
const label = options.forceName || shapeToXmlTagName(schema);
|
|
104
|
-
const parts = [];
|
|
104
|
+
const parts: string[] = [];
|
|
105
105
|
const currentIndent = (options.indent || 0);
|
|
106
106
|
const exampleValue = this._collectExamples(schema, {
|
|
107
107
|
tagFill: new Array(currentIndent * 2 + 0).fill(' ').join(''),
|
|
@@ -114,7 +114,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
114
114
|
const attributes: string[] = [];
|
|
115
115
|
const properties = this._collectProperties(schema);
|
|
116
116
|
properties.forEach((property) => {
|
|
117
|
-
const { range, minCount=0 } = property;
|
|
117
|
+
const { range, minCount = 0 } = property;
|
|
118
118
|
if (minCount === 0 && !this.opts.renderOptional || !range) {
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
@@ -135,10 +135,14 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
135
135
|
}
|
|
136
136
|
const value = this._propertyShapeObject(property, { indent: currentIndent });
|
|
137
137
|
if (typeof value !== 'undefined') {
|
|
138
|
-
const
|
|
138
|
+
const offset = options.noWrap ? 0 : 2;
|
|
139
|
+
const fill = new Array(currentIndent * 2 + offset).fill(' ').join('');
|
|
139
140
|
parts.push(formatXmlValue(fill, value));
|
|
140
141
|
}
|
|
141
142
|
});
|
|
143
|
+
if (options.noWrap) {
|
|
144
|
+
return parts.join('\n');
|
|
145
|
+
}
|
|
142
146
|
|
|
143
147
|
let opening = `<${label}`;
|
|
144
148
|
if (attributes.length) {
|
|
@@ -146,12 +150,12 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
146
150
|
opening += attributes.join(' ');
|
|
147
151
|
}
|
|
148
152
|
parts.unshift(`${opening}>`);
|
|
149
|
-
const fill = new Array(currentIndent*2).fill(' ').join('');
|
|
153
|
+
const fill = new Array(currentIndent * 2).fill(' ').join('');
|
|
150
154
|
parts.push(`${fill}</${label}>`);
|
|
151
155
|
return parts.join('\n');
|
|
152
156
|
}
|
|
153
157
|
|
|
154
|
-
protected _scalarShapeObject(schema: IApiScalarShape, options: IProcessNodeOptions={}):
|
|
158
|
+
protected _scalarShapeObject(schema: IApiScalarShape, options: IProcessNodeOptions = {}): string {
|
|
155
159
|
const { xmlSerialization, defaultValue } = schema;
|
|
156
160
|
let content;
|
|
157
161
|
if (defaultValue) {
|
|
@@ -182,11 +186,11 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
182
186
|
parts.push(opening);
|
|
183
187
|
parts.push(content);
|
|
184
188
|
parts.push(`</${label}>`);
|
|
185
|
-
|
|
189
|
+
|
|
186
190
|
return parts.join('');
|
|
187
191
|
}
|
|
188
192
|
|
|
189
|
-
protected _nilShapeObject(schema: IApiScalarShape, options: IProcessNodeOptions={}):
|
|
193
|
+
protected _nilShapeObject(schema: IApiScalarShape, options: IProcessNodeOptions = {}): string | undefined {
|
|
190
194
|
const { xmlSerialization } = schema;
|
|
191
195
|
const content = '';
|
|
192
196
|
let label = options.forceName || shapeToXmlTagName(schema);
|
|
@@ -211,24 +215,24 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
211
215
|
parts.push(opening);
|
|
212
216
|
parts.push(content);
|
|
213
217
|
parts.push(`</${label}>`);
|
|
214
|
-
|
|
218
|
+
|
|
215
219
|
return parts.join('');
|
|
216
220
|
}
|
|
217
221
|
|
|
218
222
|
/**
|
|
219
223
|
* @returns The value for the property or undefined when cannot generate the value.
|
|
220
224
|
*/
|
|
221
|
-
protected _propertyShapeObject(schema: IApiPropertyShape, options: IProcessNodeOptions = {}): string|undefined {
|
|
222
|
-
const { range, minCount=0 } = schema;
|
|
225
|
+
protected _propertyShapeObject(schema: IApiPropertyShape, options: IProcessNodeOptions = {}): string | undefined {
|
|
226
|
+
const { range, minCount = 0 } = schema;
|
|
223
227
|
if (minCount === 0 && !this.opts.renderOptional || !range) {
|
|
224
228
|
return undefined;
|
|
225
229
|
}
|
|
226
230
|
const { types } = range;
|
|
227
|
-
const name = shapeToXmlTagName(schema as IApiAnyShape);
|
|
228
231
|
if (types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
|
|
229
232
|
return this._scalarShapeObject(range as IApiScalarShape, { ...options });
|
|
230
|
-
}
|
|
233
|
+
}
|
|
231
234
|
if (types.includes(ns.aml.vocabularies.shapes.NilShape)) {
|
|
235
|
+
const name = shapeToXmlTagName(schema as IApiAnyShape);
|
|
232
236
|
return this._nilShapeObject(range as IApiScalarShape, { ...options, forceName: name });
|
|
233
237
|
}
|
|
234
238
|
if (types.includes(ns.aml.vocabularies.shapes.RecursiveShape)) {
|
|
@@ -240,6 +244,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
240
244
|
if (types.includes(ns.aml.vocabularies.shapes.ArrayShape) || types.includes(ns.aml.vocabularies.shapes.MatrixShape)) {
|
|
241
245
|
return this._nodePropertyArray(schema as IApiPropertyShape<IApiArrayShape>, options);
|
|
242
246
|
}
|
|
247
|
+
const name = shapeToXmlTagName(schema as IApiAnyShape);
|
|
243
248
|
return this.processNode(range, { ...options, forceName: name });
|
|
244
249
|
}
|
|
245
250
|
|
|
@@ -247,15 +252,15 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
247
252
|
if (!this.opts.renderExamples) {
|
|
248
253
|
return undefined;
|
|
249
254
|
}
|
|
250
|
-
const { isWrapped, nodeName, tagFill='', indent = 0
|
|
251
|
-
let { examples=[] } = (schema as IApiAnyShape);
|
|
255
|
+
const { isWrapped, nodeName, tagFill = '', indent = 0 } = opts;
|
|
256
|
+
let { examples = [] } = (schema as IApiAnyShape);
|
|
252
257
|
const { inherits } = schema;
|
|
253
258
|
if (Array.isArray(inherits) && inherits.length) {
|
|
254
259
|
inherits.forEach((parent) => {
|
|
255
260
|
let node = parent;
|
|
256
261
|
if (node.types.includes(ns.aml.vocabularies.shapes.UnionShape)) {
|
|
257
262
|
const union = node as IApiUnionShape;
|
|
258
|
-
const { anyOf=[] } = union;
|
|
263
|
+
const { anyOf = [] } = union;
|
|
259
264
|
node = this._readCurrentUnion(anyOf);
|
|
260
265
|
}
|
|
261
266
|
const anyShape = node as IApiAnyShape;
|
|
@@ -264,18 +269,19 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
264
269
|
}
|
|
265
270
|
});
|
|
266
271
|
}
|
|
267
|
-
|
|
272
|
+
|
|
268
273
|
const validExamples = examples.filter(item => !!item.structuredValue);
|
|
269
274
|
if (!validExamples.length) {
|
|
270
275
|
return undefined;
|
|
271
276
|
}
|
|
277
|
+
|
|
272
278
|
const parts: string[] = [];
|
|
273
279
|
if (isWrapped) {
|
|
274
280
|
parts.push(`${tagFill}<${nodeName}>`);
|
|
275
281
|
}
|
|
276
282
|
const generator = new XmlDataNodeGenerator();
|
|
277
283
|
validExamples.forEach((item) => {
|
|
278
|
-
const value = generator.generate(item.structuredValue
|
|
284
|
+
const value = generator.generate(item.structuredValue as IApiDataNodeUnion, nodeName, {
|
|
279
285
|
indent: indent + 1,
|
|
280
286
|
});
|
|
281
287
|
if (value !== undefined) {
|
|
@@ -285,6 +291,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
285
291
|
if (isWrapped) {
|
|
286
292
|
parts.push(`${tagFill}</${nodeName}>`);
|
|
287
293
|
}
|
|
294
|
+
|
|
288
295
|
return parts.join('\n');
|
|
289
296
|
}
|
|
290
297
|
|
|
@@ -295,7 +302,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
295
302
|
protected _nodePropertyObject(schema: IApiPropertyShape<IApiNodeShape>, options: IProcessNodeOptions = {}): string {
|
|
296
303
|
const parts: string[] = [];
|
|
297
304
|
const name = normalizeXmlTagName(String(schema.name));
|
|
298
|
-
const { indent=0 } = options;
|
|
305
|
+
const { indent = 0 } = options;
|
|
299
306
|
const baseTabs = this._createTabs(indent);
|
|
300
307
|
let value: string;
|
|
301
308
|
const range = schema.range as IApiNodeShape;
|
|
@@ -310,14 +317,14 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
310
317
|
} else {
|
|
311
318
|
const propertyParts: string[] = [];
|
|
312
319
|
const properties = this._collectProperties(range);
|
|
313
|
-
|
|
320
|
+
|
|
314
321
|
properties.forEach((property) => {
|
|
315
|
-
const { range, minCount=0 } = property;
|
|
322
|
+
const { range, minCount = 0 } = property;
|
|
316
323
|
if (minCount === 0 && !this.opts.renderOptional) {
|
|
317
324
|
return;
|
|
318
325
|
}
|
|
319
326
|
const anyRange = range as IApiAnyShape;
|
|
320
|
-
|
|
327
|
+
|
|
321
328
|
if (anyRange.xmlSerialization) {
|
|
322
329
|
const { prefix, attribute } = anyRange.xmlSerialization;
|
|
323
330
|
if (attribute && anyRange.types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
|
|
@@ -351,7 +358,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
351
358
|
}
|
|
352
359
|
|
|
353
360
|
protected _nodePropertyArray(schema: IApiPropertyShape<IApiArrayShape>, options: IProcessNodeOptions = {}): string {
|
|
354
|
-
const range = schema.range as IApiArrayShape;
|
|
361
|
+
const range = schema.range as IApiArrayShape;
|
|
355
362
|
const parts: string[] = [];
|
|
356
363
|
let name: string;
|
|
357
364
|
if (range.xmlSerialization && range.xmlSerialization.name) {
|
|
@@ -359,7 +366,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
359
366
|
} else {
|
|
360
367
|
name = normalizeXmlTagName(String(schema.name));
|
|
361
368
|
}
|
|
362
|
-
const { indent=0 } = options;
|
|
369
|
+
const { indent = 0 } = options;
|
|
363
370
|
const isScalarItems = !!range.items && range.items.types.includes(ns.aml.vocabularies.shapes.ScalarShape);
|
|
364
371
|
|
|
365
372
|
const baseTabs = this._createTabs(indent);
|
|
@@ -375,7 +382,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
375
382
|
return parts.join('\n');
|
|
376
383
|
}
|
|
377
384
|
|
|
378
|
-
protected _arrayShapeObject(schema: IApiArrayShape, options: IProcessNodeOptions={}): string {
|
|
385
|
+
protected _arrayShapeObject(schema: IApiArrayShape, options: IProcessNodeOptions = {}, isRoot = false): string {
|
|
379
386
|
const { items } = schema;
|
|
380
387
|
const isScalarItems = !!items && items.types.includes(ns.aml.vocabularies.shapes.ScalarShape);
|
|
381
388
|
// the name is either from the XML serialization info, or the parent property.
|
|
@@ -388,21 +395,30 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
388
395
|
// nodeName = normalizeXmlTagName(items.name);
|
|
389
396
|
// }
|
|
390
397
|
|
|
391
|
-
if (
|
|
398
|
+
if (isRoot && schema.xmlSerialization && schema.xmlSerialization.name) {
|
|
399
|
+
nodeName = normalizeXmlTagName(schema.xmlSerialization.name);
|
|
400
|
+
} else if (isRoot && schema.name) {
|
|
401
|
+
nodeName = normalizeXmlTagName(schema.name);
|
|
402
|
+
} else if (!isScalarItems && items?.name) {
|
|
392
403
|
nodeName = normalizeXmlTagName(items.name);
|
|
393
404
|
} else if (schema.name) {
|
|
394
405
|
nodeName = normalizeXmlTagName(schema.name);
|
|
395
406
|
}
|
|
407
|
+
|
|
396
408
|
// wrapping can only be defined on the array shape and it "wraps" the generated
|
|
397
409
|
// content into an element that has the same name as the items
|
|
410
|
+
let hasWrapped = false;
|
|
411
|
+
if (schema.xmlSerialization && typeof schema.xmlSerialization.wrapped === 'boolean') {
|
|
412
|
+
hasWrapped = true;
|
|
413
|
+
}
|
|
398
414
|
const isWrapped = !!schema.xmlSerialization && !!schema.xmlSerialization.wrapped;
|
|
399
|
-
|
|
415
|
+
|
|
400
416
|
const currentIndent = (options.indent || 0);
|
|
401
417
|
const tagFill = new Array((currentIndent) * 2 + 0).fill(' ').join('');
|
|
402
418
|
const valueFill = new Array((currentIndent) * 2 + (isWrapped ? 2 : 0)).fill(' ').join('');
|
|
403
419
|
// let's start with examples
|
|
404
420
|
if (this.opts.renderExamples) {
|
|
405
|
-
const { examples=[] } = schema;
|
|
421
|
+
const { examples = [] } = schema;
|
|
406
422
|
const validExamples = examples.filter(item => !!item.structuredValue);
|
|
407
423
|
if (validExamples.length) {
|
|
408
424
|
const parts: string[] = [];
|
|
@@ -414,7 +430,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
414
430
|
if (!nodeName && items?.name) {
|
|
415
431
|
nodeName = normalizeXmlTagName(items.name);
|
|
416
432
|
}
|
|
417
|
-
const value = generator.generate(example.structuredValue
|
|
433
|
+
const value = generator.generate(example.structuredValue as IApiDataNodeUnion, nodeName, {
|
|
418
434
|
indent: currentIndent,
|
|
419
435
|
});
|
|
420
436
|
if (value !== undefined) {
|
|
@@ -422,7 +438,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
422
438
|
}
|
|
423
439
|
} else if (isScalarItems && isWrapped) {
|
|
424
440
|
const [example] = validExamples;
|
|
425
|
-
const value = generator.generate(example.structuredValue
|
|
441
|
+
const value = generator.generate(example.structuredValue as IApiDataNodeUnion, nodeName, {
|
|
426
442
|
indent: currentIndent,
|
|
427
443
|
});
|
|
428
444
|
parts.push(`${tagFill}<${nodeName}>`);
|
|
@@ -434,7 +450,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
434
450
|
// when wrapped we wrap each example into the "name", else we render all examples under the "name".
|
|
435
451
|
validExamples.forEach((item) => {
|
|
436
452
|
parts.push(`${tagFill}<${nodeName}>`);
|
|
437
|
-
const value = generator.generate(item.structuredValue
|
|
453
|
+
const value = generator.generate(item.structuredValue as IApiDataNodeUnion, /* nodeName */ undefined, {
|
|
438
454
|
indent: currentIndent + 2,
|
|
439
455
|
});
|
|
440
456
|
if (value !== undefined) {
|
|
@@ -444,7 +460,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
444
460
|
});
|
|
445
461
|
} else {
|
|
446
462
|
validExamples.forEach((item) => {
|
|
447
|
-
const value = generator.generate(item.structuredValue
|
|
463
|
+
const value = generator.generate(item.structuredValue as IApiDataNodeUnion, /* nodeName */ undefined, {
|
|
448
464
|
indent: currentIndent,
|
|
449
465
|
});
|
|
450
466
|
if (value !== undefined) {
|
|
@@ -455,7 +471,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
455
471
|
return parts.join('\n');
|
|
456
472
|
}
|
|
457
473
|
}
|
|
458
|
-
|
|
474
|
+
|
|
459
475
|
if (isScalarItems && schema.defaultValue) {
|
|
460
476
|
const gen = new XmlDataNodeGenerator();
|
|
461
477
|
const value = gen.generate(schema.defaultValue);
|
|
@@ -476,6 +492,9 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
476
492
|
if (nodeName) {
|
|
477
493
|
init.forceName = nodeName;
|
|
478
494
|
}
|
|
495
|
+
if (!isRoot && (!hasWrapped || (hasWrapped && !isWrapped))) {
|
|
496
|
+
init.noWrap = true;
|
|
497
|
+
}
|
|
479
498
|
const value = this.processNode(items, init);
|
|
480
499
|
if (value !== undefined) {
|
|
481
500
|
parts.push(`${valueFill}${value}`);
|
|
@@ -497,7 +516,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
497
516
|
// return this._nodeItems(schema as IArrayShape<INodeShape>, options);
|
|
498
517
|
// }
|
|
499
518
|
// }
|
|
500
|
-
|
|
519
|
+
|
|
501
520
|
// let label = shapeToXmlTagName(schema);
|
|
502
521
|
// if (label === UNKNOWN_TYPE && isScalarItems) {
|
|
503
522
|
// // label = shapeToXmlTagName(items as IScalarShape);
|
|
@@ -593,7 +612,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
593
612
|
// parts.push(`${fill}${value}`);
|
|
594
613
|
// }
|
|
595
614
|
// }
|
|
596
|
-
|
|
615
|
+
|
|
597
616
|
// parts.push(`${rootFill}</${label}>`);
|
|
598
617
|
// return parts.join('\n');
|
|
599
618
|
}
|
|
@@ -605,7 +624,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
605
624
|
* @param schema The array schema
|
|
606
625
|
* @param options Processing options.
|
|
607
626
|
*/
|
|
608
|
-
protected _scalarItems(schema: IApiArrayShape<IApiScalarShape>, options: IProcessNodeOptions={}): string {
|
|
627
|
+
protected _scalarItems(schema: IApiArrayShape<IApiScalarShape>, options: IProcessNodeOptions = {}): string {
|
|
609
628
|
const items = schema.items as IApiScalarShape;
|
|
610
629
|
const currentIndent = (options.indent || 0);
|
|
611
630
|
const tagFill = new Array(currentIndent * 2).fill(' ').join('');
|
|
@@ -619,7 +638,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
619
638
|
|
|
620
639
|
// let's start with examples
|
|
621
640
|
if (this.opts.renderExamples) {
|
|
622
|
-
let { examples=[] } = schema;
|
|
641
|
+
let { examples = [] } = schema;
|
|
623
642
|
if (Array.isArray(items.examples)) {
|
|
624
643
|
examples = examples.concat(items.examples);
|
|
625
644
|
}
|
|
@@ -628,7 +647,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
628
647
|
const parts: string[] = [];
|
|
629
648
|
const generator = new XmlDataNodeGenerator();
|
|
630
649
|
validExamples.forEach((item) => {
|
|
631
|
-
const value = generator.generate(item.structuredValue
|
|
650
|
+
const value = generator.generate(item.structuredValue as IApiDataNodeUnion, nodeName);
|
|
632
651
|
if (value !== undefined) {
|
|
633
652
|
parts.push(`${tagFill}${value}`);
|
|
634
653
|
}
|
|
@@ -636,7 +655,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
636
655
|
return parts.join('\n');
|
|
637
656
|
}
|
|
638
657
|
}
|
|
639
|
-
|
|
658
|
+
|
|
640
659
|
// then the default value
|
|
641
660
|
if (schema.defaultValue) {
|
|
642
661
|
const generator = new XmlDataNodeGenerator();
|
|
@@ -645,7 +664,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
645
664
|
return `${tagFill}${value}`;
|
|
646
665
|
}
|
|
647
666
|
}
|
|
648
|
-
|
|
667
|
+
|
|
649
668
|
// finally we generate stuff.
|
|
650
669
|
const opts: IProcessNodeOptions = {
|
|
651
670
|
indent: currentIndent + 1,
|
|
@@ -661,7 +680,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
661
680
|
* @param schema The array shape with item that is NodeShape.
|
|
662
681
|
* @param options Rendering options.
|
|
663
682
|
*/
|
|
664
|
-
protected _nodeItems(schema: IApiArrayShape<IApiNodeShape>, options: IProcessNodeOptions={}): string {
|
|
683
|
+
protected _nodeItems(schema: IApiArrayShape<IApiNodeShape>, options: IProcessNodeOptions = {}): string {
|
|
665
684
|
const items = schema.items as IApiNodeShape;
|
|
666
685
|
const currentIndent = (options.indent || 0);
|
|
667
686
|
const tagFill = new Array(currentIndent * 2).fill(' ').join('');
|
|
@@ -685,7 +704,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
685
704
|
|
|
686
705
|
// let's start with examples
|
|
687
706
|
if (this.opts.renderExamples) {
|
|
688
|
-
let { examples=[] } = schema;
|
|
707
|
+
let { examples = [] } = schema;
|
|
689
708
|
if (Array.isArray(items.examples)) {
|
|
690
709
|
examples = examples.concat(items.examples);
|
|
691
710
|
}
|
|
@@ -694,7 +713,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
694
713
|
const parts: string[] = [];
|
|
695
714
|
const generator = new XmlDataNodeGenerator();
|
|
696
715
|
validExamples.forEach((item) => {
|
|
697
|
-
const value = generator.generate(item.structuredValue
|
|
716
|
+
const value = generator.generate(item.structuredValue as IApiDataNodeUnion, nodeName);
|
|
698
717
|
if (value !== undefined) {
|
|
699
718
|
parts.push(`${tagFill}${value}`);
|
|
700
719
|
}
|
|
@@ -710,7 +729,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
710
729
|
parts.push(`${tagFill}${value}`);
|
|
711
730
|
rendered = true;
|
|
712
731
|
}
|
|
713
|
-
}
|
|
732
|
+
}
|
|
714
733
|
if (!rendered) {
|
|
715
734
|
const properties = this._collectProperties(items);
|
|
716
735
|
properties.forEach((prop) => {
|
|
@@ -729,7 +748,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
729
748
|
/**
|
|
730
749
|
* @param example The example to turn into a JS object
|
|
731
750
|
*/
|
|
732
|
-
protected _exampleToObject(example?: IApiDataExample):
|
|
751
|
+
protected _exampleToObject(example?: IApiDataExample): string | undefined {
|
|
733
752
|
if (example && example.structuredValue) {
|
|
734
753
|
const generator = new XmlDataNodeGenerator();
|
|
735
754
|
return generator.generate(example.structuredValue);
|
|
@@ -737,8 +756,8 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
737
756
|
return undefined;
|
|
738
757
|
}
|
|
739
758
|
|
|
740
|
-
protected _unionShapeObject(schema: IApiUnionShape, options: IProcessNodeOptions={}):
|
|
741
|
-
let { anyOf=[], examples=[] } = schema;
|
|
759
|
+
protected _unionShapeObject(schema: IApiUnionShape, options: IProcessNodeOptions = {}): string | undefined {
|
|
760
|
+
let { anyOf = [], examples = [] } = schema;
|
|
742
761
|
if (Array.isArray(schema.inherits) && schema.inherits) {
|
|
743
762
|
schema.inherits.forEach((parent) => {
|
|
744
763
|
const anyParent = parent as IApiAnyShape;
|
|
@@ -763,7 +782,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
763
782
|
if (value !== undefined) {
|
|
764
783
|
const label = shapeToXmlTagName(schema);
|
|
765
784
|
const currentIndent = (options.indent || 0);
|
|
766
|
-
const rootFill = new Array(currentIndent*2).fill(' ').join('');
|
|
785
|
+
const rootFill = new Array(currentIndent * 2).fill(' ').join('');
|
|
767
786
|
const valueFill = new Array(currentIndent * 2 + 2).fill(' ').join('');
|
|
768
787
|
const parts = [];
|
|
769
788
|
parts.push(`${rootFill}<${label}>`);
|
|
@@ -787,13 +806,13 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
787
806
|
* @param schema The schema with unions
|
|
788
807
|
* @param defaultValue The definition of a default value.
|
|
789
808
|
*/
|
|
790
|
-
protected _unionDefaultValue(schema: IShapeUnion, defaultValue: IApiDataNodeUnion, options: IProcessNodeOptions = {}):
|
|
809
|
+
protected _unionDefaultValue(schema: IShapeUnion, defaultValue: IApiDataNodeUnion, options: IProcessNodeOptions = {}): string | undefined {
|
|
791
810
|
const gen = new XmlDataNodeGenerator();
|
|
792
811
|
const value = gen.generate(defaultValue);
|
|
793
812
|
const anySchema = schema as IApiAnyShape;
|
|
794
813
|
const label = shapeToXmlTagName(anySchema);
|
|
795
814
|
const currentIndent = (options.indent || 0);
|
|
796
|
-
const rootFill = new Array(currentIndent*2).fill(' ').join('');
|
|
815
|
+
const rootFill = new Array(currentIndent * 2).fill(' ').join('');
|
|
797
816
|
const parts = [
|
|
798
817
|
`${rootFill}<${label}>`
|
|
799
818
|
];
|
|
@@ -803,20 +822,20 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
803
822
|
return parts.join('\n');
|
|
804
823
|
}
|
|
805
824
|
|
|
806
|
-
protected _fileShapeObject():
|
|
825
|
+
protected _fileShapeObject(): string | undefined {
|
|
807
826
|
return undefined;
|
|
808
827
|
}
|
|
809
828
|
|
|
810
|
-
protected _schemaShapeObject():
|
|
829
|
+
protected _schemaShapeObject(): string | undefined {
|
|
811
830
|
return undefined;
|
|
812
831
|
}
|
|
813
832
|
|
|
814
|
-
protected _tupleShapeObject():
|
|
833
|
+
protected _tupleShapeObject(): string | undefined {
|
|
815
834
|
return undefined;
|
|
816
835
|
}
|
|
817
836
|
|
|
818
|
-
|
|
819
|
-
const { and=[], xone=[], or=[] } = schema;
|
|
837
|
+
protected _anyShapeObject(schema: IApiAnyShape): string | undefined {
|
|
838
|
+
const { and = [], xone = [], or = [] } = schema;
|
|
820
839
|
if (and.length) {
|
|
821
840
|
// we combine all properties together under `schema` with changed properties
|
|
822
841
|
const copy = JsonCore.clone(schema) as IApiNodeShape;
|
|
@@ -840,7 +859,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
840
859
|
return this._nodeShapeObject(copy);
|
|
841
860
|
}
|
|
842
861
|
if (xone.length) {
|
|
843
|
-
const { selectedUnions=[] } = this.opts;
|
|
862
|
+
const { selectedUnions = [] } = this.opts;
|
|
844
863
|
let selected = xone.find(i => selectedUnions.includes(i.id));
|
|
845
864
|
if (!selected) {
|
|
846
865
|
// select firs available
|
|
@@ -849,7 +868,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
849
868
|
return this.processNode(selected);
|
|
850
869
|
}
|
|
851
870
|
if (or.length) {
|
|
852
|
-
const { selectedUnions=[] } = this.opts;
|
|
871
|
+
const { selectedUnions = [] } = this.opts;
|
|
853
872
|
let selected = or.find(i => selectedUnions.includes(i.id));
|
|
854
873
|
if (!selected) {
|
|
855
874
|
// select firs available
|
|
@@ -857,7 +876,7 @@ export class ShapeXmlSchemaGenerator extends ShapeBase {
|
|
|
857
876
|
}
|
|
858
877
|
return this.processNode(selected);
|
|
859
878
|
}
|
|
860
|
-
const { examples=[] } = schema;
|
|
879
|
+
const { examples = [] } = schema;
|
|
861
880
|
const label = shapeToXmlTagName(schema);
|
|
862
881
|
if (this.opts.renderExamples && examples && examples.length) {
|
|
863
882
|
const example = examples.find((item) => !!item.structuredValue);
|