@api-components/api-type-document 4.2.12 → 4.2.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/README.md +8 -10
- package/package.json +18 -18
- package/src/ApiTypeDocument.d.ts +11 -1
- package/src/ApiTypeDocument.js +63 -54
- package/src/PropertyDocumentMixin.d.ts +11 -0
- package/src/PropertyDocumentMixin.js +12 -0
- package/src/PropertyShapeDocument.d.ts +10 -0
- package/src/PropertyShapeDocument.js +28 -3
package/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# DEPRECATED
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
This component is being deprecated. The code base has been moved to [api-documentation](https://github.com/advanced-rest-client/api-documentation) module. This module will be archived when [PR 37](https://github.com/advanced-rest-client/api-documentation/pull/37) is merged.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## <api-type-document>
|
|
5
|
+
-----
|
|
8
6
|
|
|
9
7
|
A documentation table for RAML type / OAS schema properties. Works with AMF data model.
|
|
10
8
|
|
|
@@ -19,7 +17,7 @@ For compatibility with previous model version use `3.x.x` version of the compone
|
|
|
19
17
|
|
|
20
18
|
Custom property | Description | Default
|
|
21
19
|
----------------|-------------|----------
|
|
22
|
-
`--api-type-document` | Mixin applied to this
|
|
20
|
+
`--api-type-document` | Mixin applied to this element | `{}`
|
|
23
21
|
`--api-type-document-union-button-background-color` | Background color of union selector button | `#fff`
|
|
24
22
|
`--api-type-document-union-button-color` | Color of union selector button | `#000`
|
|
25
23
|
`--api-type-document-union-button-active-background-color` | Background color of active union selector button | `#CDDC39`
|
|
@@ -29,7 +27,7 @@ From `property-shape-document`
|
|
|
29
27
|
|
|
30
28
|
Custom property | Description | Default
|
|
31
29
|
----------------|-------------|----------
|
|
32
|
-
`--property-shape-document` | Mixin applied each
|
|
30
|
+
`--property-shape-document` | Mixin applied each property element | `{}`
|
|
33
31
|
`--property-shape-document-array-color` | Property border color when type is an array | `#8BC34A`
|
|
34
32
|
`--property-shape-document-object-color` | Property border color when type is an object | `#FF9800`
|
|
35
33
|
`--property-shape-document-union-color` | Property border color when type is an union | `#FFEB3B`
|
|
@@ -41,17 +39,17 @@ Custom property | Description | Default
|
|
|
41
39
|
`--api-type-document-type-color` | Color of the "type" trait | `white`
|
|
42
40
|
`--api-type-document-type-background-color` | Background color of the "type" trait | `#2196F3`
|
|
43
41
|
`--api-type-document-trait-background-color` | Background color to main range trait (type, required, enum) | `#EEEEEE`,
|
|
44
|
-
`--api-type-document-trait-border-radius` | Border
|
|
42
|
+
`--api-type-document-trait-border-radius` | Border radius of a main property traits like type, required, enum | `3px`
|
|
45
43
|
|
|
46
44
|
From `property-range-document`
|
|
47
45
|
|
|
48
46
|
Custom property | Description | Default
|
|
49
47
|
----------------|-------------|----------
|
|
50
|
-
`--property-range-document` | Mixin applied to this
|
|
48
|
+
`--property-range-document` | Mixin applied to this element | `{}`
|
|
51
49
|
`--api-type-document-type-attribute-color` | Color of each attribute that describes a property | `#616161`
|
|
52
50
|
`--api-type-document-examples-title-color` | Color of examples section title | ``
|
|
53
51
|
`--api-type-document-examples-border-color` | Example section border color | `transparent`
|
|
54
|
-
`--code-background-color` | Background color of the examples section
|
|
52
|
+
`--code-background-color` | Background color of the examples section |``
|
|
55
53
|
`--arc-font-body1` | Mixin applied to an example name label | `{}`
|
|
56
54
|
`--arc-font-body2` | Mixin applied to the examples section title | `{}`
|
|
57
55
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@api-components/api-type-document",
|
|
3
3
|
"description": "A documentation table for type (resource) properties. Works with AMF data model",
|
|
4
|
-
"version": "4.2.
|
|
4
|
+
"version": "4.2.16",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "index.js",
|
|
@@ -27,31 +27,31 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@advanced-rest-client/arc-marked": "^1.1.0",
|
|
29
29
|
"@advanced-rest-client/markdown-styles": "^3.1.4",
|
|
30
|
-
"@anypoint-web-components/anypoint-button": "^1.2.
|
|
31
|
-
"@api-components/amf-helper-mixin": "^4.
|
|
30
|
+
"@anypoint-web-components/anypoint-button": "^1.2.3",
|
|
31
|
+
"@api-components/amf-helper-mixin": "^4.5.6",
|
|
32
32
|
"@api-components/api-annotation-document": "^4.1.0",
|
|
33
|
-
"@api-components/api-resource-example-document": "^4.
|
|
33
|
+
"@api-components/api-resource-example-document": "^4.3.3",
|
|
34
34
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
35
35
|
"lit-element": "^2.4.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@advanced-rest-client/arc-demo-helper": "^
|
|
39
|
-
"@anypoint-web-components/anypoint-checkbox": "^1.
|
|
40
|
-
"@anypoint-web-components/anypoint-styles": "^1.0.
|
|
41
|
-
"@api-components/api-model-generator": "^0.2.
|
|
42
|
-
"@commitlint/cli": "^
|
|
43
|
-
"@commitlint/config-conventional": "^
|
|
38
|
+
"@advanced-rest-client/arc-demo-helper": "^3.0.3",
|
|
39
|
+
"@anypoint-web-components/anypoint-checkbox": "^1.2.2",
|
|
40
|
+
"@anypoint-web-components/anypoint-styles": "^1.0.2",
|
|
41
|
+
"@api-components/api-model-generator": "^0.2.14",
|
|
42
|
+
"@commitlint/cli": "^13.2.0",
|
|
43
|
+
"@commitlint/config-conventional": "^13.2.0",
|
|
44
44
|
"@open-wc/eslint-config": "^4.2.0",
|
|
45
45
|
"@open-wc/testing": "^2.5.15",
|
|
46
|
-
"@web/dev-server": "^0.1.
|
|
47
|
-
"@web/test-runner": "^0.
|
|
48
|
-
"@web/test-runner-playwright": "^0.8.
|
|
49
|
-
"eslint": "^7.
|
|
46
|
+
"@web/dev-server": "^0.1.24",
|
|
47
|
+
"@web/test-runner": "^0.13.18",
|
|
48
|
+
"@web/test-runner-playwright": "^0.8.8",
|
|
49
|
+
"eslint": "^7.32.0",
|
|
50
50
|
"eslint-config-prettier": "^8.1.0",
|
|
51
|
-
"husky": "^
|
|
52
|
-
"lint-staged": "^
|
|
53
|
-
"sinon": "^
|
|
54
|
-
"typescript": "^4.
|
|
51
|
+
"husky": "^7.0.2",
|
|
52
|
+
"lint-staged": "^11.1.2",
|
|
53
|
+
"sinon": "^11.1.2",
|
|
54
|
+
"typescript": "^4.4.3",
|
|
55
55
|
"typescript-lit-html-plugin": "^0.9.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
package/src/ApiTypeDocument.d.ts
CHANGED
|
@@ -166,11 +166,21 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
166
166
|
*/
|
|
167
167
|
renderReadOnly?: boolean;
|
|
168
168
|
|
|
169
|
+
/**
|
|
170
|
+
* When enabled, media selector will not be rendered.
|
|
171
|
+
* Should be used in cases where media types are not
|
|
172
|
+
* applicable.
|
|
173
|
+
* @attribute
|
|
174
|
+
*/
|
|
175
|
+
noMediaSelector: boolean;
|
|
176
|
+
|
|
177
|
+
get shouldRenderMediaSelector(): boolean;
|
|
178
|
+
|
|
169
179
|
constructor();
|
|
170
180
|
|
|
171
181
|
connectedCallback(): void;
|
|
172
182
|
|
|
173
|
-
_computeRenderMainExample(noMainExample: boolean, hasExamples: boolean): boolean;
|
|
183
|
+
_computeRenderMainExample(noMainExample: boolean, hasExamples: boolean, isScalar: boolean): boolean;
|
|
174
184
|
|
|
175
185
|
/**
|
|
176
186
|
* Called when resolved type or amf changed.
|
package/src/ApiTypeDocument.js
CHANGED
|
@@ -160,6 +160,13 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
160
160
|
_renderMainExample: { type: Boolean },
|
|
161
161
|
|
|
162
162
|
renderReadOnly: { type: Boolean },
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* When enabled, media selector will not be rendered.
|
|
166
|
+
* Should be used in cases where media types are not
|
|
167
|
+
* applicable.
|
|
168
|
+
*/
|
|
169
|
+
noMediaSelector: { type: Boolean },
|
|
163
170
|
};
|
|
164
171
|
}
|
|
165
172
|
|
|
@@ -282,12 +289,22 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
282
289
|
}
|
|
283
290
|
this.__hasExamples = value;
|
|
284
291
|
this.requestUpdate('_hasExamples', old);
|
|
292
|
+
const scalarType = this._hasType(this.type, this.ns.aml.vocabularies.shapes.ScalarShape);
|
|
285
293
|
this._renderMainExample = this._computeRenderMainExample(
|
|
286
294
|
this.noMainExample,
|
|
287
|
-
value
|
|
295
|
+
value,
|
|
296
|
+
scalarType
|
|
288
297
|
);
|
|
289
298
|
}
|
|
290
299
|
|
|
300
|
+
get shouldRenderMediaSelector() {
|
|
301
|
+
const { renderMediaSelector, noMediaSelector } = this;
|
|
302
|
+
if (noMediaSelector) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
return renderMediaSelector;
|
|
306
|
+
}
|
|
307
|
+
|
|
291
308
|
constructor() {
|
|
292
309
|
super();
|
|
293
310
|
this.hasParentType = false;
|
|
@@ -308,6 +325,7 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
308
325
|
this.renderReadOnly = false;
|
|
309
326
|
|
|
310
327
|
this._isPropertyReadOnly = this._isPropertyReadOnly.bind(this);
|
|
328
|
+
this.noMediaSelector = false;
|
|
311
329
|
}
|
|
312
330
|
|
|
313
331
|
connectedCallback() {
|
|
@@ -321,8 +339,8 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
321
339
|
}
|
|
322
340
|
}
|
|
323
341
|
|
|
324
|
-
_computeRenderMainExample(noMainExample, hasExamples) {
|
|
325
|
-
return !!(!noMainExample && hasExamples);
|
|
342
|
+
_computeRenderMainExample(noMainExample, hasExamples, isScalar = false) {
|
|
343
|
+
return isScalar ? false : !!(!noMainExample && hasExamples);
|
|
326
344
|
}
|
|
327
345
|
|
|
328
346
|
/**
|
|
@@ -637,57 +655,48 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
637
655
|
/**
|
|
638
656
|
* @return {TemplateResult} Templates for object properties
|
|
639
657
|
*/
|
|
640
|
-
|
|
658
|
+
_arrayTemplate() {
|
|
641
659
|
const items = this._computeArrayProperties(this._resolvedType) || [];
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
?compatibility="${this.compatibility}"
|
|
683
|
-
.mediaType="${this.mediaType}"
|
|
684
|
-
?graph="${this.graph}"
|
|
685
|
-
></api-type-document>`
|
|
686
|
-
: ''}
|
|
687
|
-
`
|
|
688
|
-
)}
|
|
689
|
-
</div>
|
|
690
|
-
`;
|
|
660
|
+
const documents = items.map(
|
|
661
|
+
(item) => html`
|
|
662
|
+
${item.isShape
|
|
663
|
+
? html`<property-shape-document
|
|
664
|
+
class="array-document"
|
|
665
|
+
.amf="${this.amf}"
|
|
666
|
+
.shape="${item}"
|
|
667
|
+
parentTypeName="${this._computeArrayParentName(this.parentTypeName)}"
|
|
668
|
+
?narrow="${this.narrow}"
|
|
669
|
+
?noExamplesActions="${this.noExamplesActions}"
|
|
670
|
+
?compatibility="${this.compatibility}"
|
|
671
|
+
.mediaType="${this.mediaType}"
|
|
672
|
+
?graph="${this.graph}"
|
|
673
|
+
></property-shape-document>`
|
|
674
|
+
: ''}
|
|
675
|
+
${item.isType
|
|
676
|
+
? html`<api-type-document
|
|
677
|
+
class="union-document"
|
|
678
|
+
.amf="${this.amf}"
|
|
679
|
+
.parentTypeName="${this.parentTypeName}"
|
|
680
|
+
.type="${item}"
|
|
681
|
+
?narrow="${this.narrow}"
|
|
682
|
+
?noExamplesActions="${this.noExamplesActions}"
|
|
683
|
+
?noMainExample="${this._renderMainExample}"
|
|
684
|
+
?compatibility="${this.compatibility}"
|
|
685
|
+
.mediaType="${this.mediaType}"
|
|
686
|
+
?graph="${this.graph}"
|
|
687
|
+
></api-type-document>`
|
|
688
|
+
: ''}
|
|
689
|
+
`
|
|
690
|
+
);
|
|
691
|
+
if (!this.hasParentType) {
|
|
692
|
+
return html`
|
|
693
|
+
<span>Array of:</span>
|
|
694
|
+
<div class="array-children">
|
|
695
|
+
${documents}
|
|
696
|
+
</div>
|
|
697
|
+
`;
|
|
698
|
+
}
|
|
699
|
+
return html`${documents}`;
|
|
691
700
|
}
|
|
692
701
|
|
|
693
702
|
/**
|
|
@@ -819,7 +828,7 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
819
828
|
const mediaTypes = (this.mediaTypes || []);
|
|
820
829
|
return html`<style>${this.styles}</style>
|
|
821
830
|
<section class="examples" ?hidden="${!this._renderMainExample}">
|
|
822
|
-
${this.
|
|
831
|
+
${this.shouldRenderMediaSelector
|
|
823
832
|
? html`<div class="media-type-selector">
|
|
824
833
|
<span>Media type:</span>
|
|
825
834
|
${mediaTypes.map((item, index) => {
|
|
@@ -115,6 +115,17 @@ interface PropertyDocumentMixin extends AmfHelperMixin {
|
|
|
115
115
|
*/
|
|
116
116
|
_computeIsAnyOf(range: Object): boolean
|
|
117
117
|
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Computes value for `isAllOf` property.
|
|
121
|
+
* AllOf type is identified as `http://www.w3.org/ns/shacl#and`
|
|
122
|
+
* Returns true if `and` property is present in shape. Otherwise returns false.
|
|
123
|
+
*
|
|
124
|
+
* @param {Object} range Range object of current shape.
|
|
125
|
+
* @returns {boolean}
|
|
126
|
+
*/
|
|
127
|
+
_computeIsAllOf(range: Object): boolean
|
|
128
|
+
|
|
118
129
|
/**
|
|
119
130
|
* Computes list of type labels to render.
|
|
120
131
|
*
|
|
@@ -345,6 +345,18 @@ const mxFunction = (base) => {
|
|
|
345
345
|
return this._hasProperty(range, this.ns.w3.shacl.or);
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Computes value for `isAllOf` property.
|
|
351
|
+
* Returns true if `and` property is present in shape. Otherwise returns false.
|
|
352
|
+
*
|
|
353
|
+
* @param {Object} range Range object of current shape.
|
|
354
|
+
* @returns {boolean}
|
|
355
|
+
*/
|
|
356
|
+
_computeIsAllOf(range) {
|
|
357
|
+
return this._hasProperty(range, this.ns.w3.shacl.and);
|
|
358
|
+
}
|
|
359
|
+
|
|
348
360
|
/**
|
|
349
361
|
* Computes list of type labels to render.
|
|
350
362
|
*
|
|
@@ -50,6 +50,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
50
50
|
* @attribute
|
|
51
51
|
*/
|
|
52
52
|
isScalarArray: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Computed value, true if current property is one of.
|
|
55
|
+
* @attribute
|
|
56
|
+
*/
|
|
57
|
+
isOneOf: boolean;
|
|
53
58
|
/**
|
|
54
59
|
* Computed value, true if this property contains a complex
|
|
55
60
|
* structure. It is computed when the property is and array,
|
|
@@ -212,6 +217,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
212
217
|
*/
|
|
213
218
|
_computeIsComplex(isUnion: boolean, isObject: boolean, isArray: boolean): boolean;
|
|
214
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Computes value `IsOneOf` property.
|
|
222
|
+
*/
|
|
223
|
+
_computeIsOneOf(range): boolean;
|
|
224
|
+
|
|
215
225
|
_evaluateGraph(): void;
|
|
216
226
|
|
|
217
227
|
_getType(amf: object, id: string): Object;
|
|
@@ -56,6 +56,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
56
56
|
* is a scalar.
|
|
57
57
|
*/
|
|
58
58
|
isScalarArray: { type: Boolean, reflect: true },
|
|
59
|
+
/**
|
|
60
|
+
* Computed value, true if current property is one of.
|
|
61
|
+
*/
|
|
62
|
+
isOneOf: { type: Boolean, reflect: true, },
|
|
59
63
|
/**
|
|
60
64
|
* Computed value, true if this property contains a complex
|
|
61
65
|
* structure. It is computed when the property is and array,
|
|
@@ -242,6 +246,20 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
242
246
|
);
|
|
243
247
|
}
|
|
244
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Computes value `IsOneOf` property.
|
|
251
|
+
* @param {Object} range Current `range` object
|
|
252
|
+
* @return {Boolean}
|
|
253
|
+
*/
|
|
254
|
+
_computeIsOneOf(range) {
|
|
255
|
+
if (!range) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const oneOfKey = this._getAmfKey(this.ns.w3.shacl.xone);
|
|
260
|
+
return oneOfKey in range;
|
|
261
|
+
}
|
|
262
|
+
|
|
245
263
|
_rangeChanged(range) {
|
|
246
264
|
this.propertyDescription = this._computeDescription(range);
|
|
247
265
|
this.hasPropertyDescription = this._computeHasStringValue(
|
|
@@ -253,11 +271,15 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
253
271
|
this.isEnum = this._computeIsEnum(range, this.isArray);
|
|
254
272
|
this.isReadOnly = this._isReadOnly(range);
|
|
255
273
|
this.isAnyOf = this._computeIsAnyOf(range);
|
|
274
|
+
this.isOneOf = this._computeIsOneOf(range);
|
|
275
|
+
this.isAllOf = this._computeIsAllOf(range);
|
|
256
276
|
this.isComplex = this._computeIsComplex(
|
|
257
277
|
this.isUnion,
|
|
258
278
|
this.isObject,
|
|
259
279
|
this.isArray,
|
|
260
|
-
this.isAnyOf
|
|
280
|
+
this.isAnyOf,
|
|
281
|
+
this.isOneOf,
|
|
282
|
+
this.isAllOf
|
|
261
283
|
);
|
|
262
284
|
this.isScalarArray = this.isArray
|
|
263
285
|
? this._computeIsScalarArray(range)
|
|
@@ -445,10 +467,13 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
|
|
|
445
467
|
* @param {boolean} isUnion
|
|
446
468
|
* @param {boolean} isObject
|
|
447
469
|
* @param {boolean} isArray
|
|
470
|
+
* @param {boolean} isAnyOf
|
|
471
|
+
* @param {boolean} isOneOf
|
|
472
|
+
* @param {boolean} isAllOf
|
|
448
473
|
* @return {boolean}
|
|
449
474
|
*/
|
|
450
|
-
_computeIsComplex(isUnion, isObject, isArray, isAnyOf) {
|
|
451
|
-
return isUnion || isObject || isArray || isAnyOf;
|
|
475
|
+
_computeIsComplex(isUnion, isObject, isArray, isAnyOf, isOneOf, isAllOf) {
|
|
476
|
+
return isUnion || isObject || isArray || isAnyOf || isOneOf || isAllOf;
|
|
452
477
|
}
|
|
453
478
|
|
|
454
479
|
_evaluateGraph() {
|