Skip to content

Commit 664be6d

Browse files
Add support for deprecated properties (#23)
* feat: styling changes for deprecated properties, show warning label if deprecated * chore: change deprecated message * chore: add documentation, remove console.log * test: added tests for deprecated properties * chore(demo): add model * chore(demo): add new API to demo list, move Demo API to top * 4.2.11 * 4.2.12 * chore: update amf-helper-mixin * fix: changed warninig message style
1 parent b60fb87 commit 664be6d

File tree

9 files changed

+216
-26
lines changed

9 files changed

+216
-26
lines changed

demo/APIC-649/APIC-649.yaml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
openapi: "3.0.0"
2+
3+
info:
4+
description: This is a simple API
5+
version: "1.0.0"
6+
title: Simple Inventory API
7+
contact:
8+
email: you@your-company.com
9+
license:
10+
name: Apache 2.0
11+
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
12+
tags:
13+
- name: admins
14+
description: Secured Admin-only calls
15+
- name: developers
16+
description: Operations available to regular developers
17+
paths:
18+
/inventory:
19+
get:
20+
tags:
21+
- developers
22+
summary: searches inventory
23+
operationId: searchInventory
24+
description: |
25+
By passing in the appropriate options, you can search for
26+
available inventory in the system
27+
parameters:
28+
- in: query
29+
name: searchString
30+
description: pass an optional search string for looking up inventory
31+
required: false
32+
schema:
33+
type: string
34+
- in: query
35+
name: skip
36+
description: number of records to skip for pagination
37+
schema:
38+
type: integer
39+
format: int32
40+
minimum: 0
41+
- in: query
42+
name: limit
43+
description: maximum number of records to return
44+
schema:
45+
type: integer
46+
format: int32
47+
minimum: 0
48+
maximum: 50
49+
responses:
50+
'200':
51+
description: search results matching criteria
52+
content:
53+
application/json:
54+
schema:
55+
type: array
56+
items:
57+
$ref: '#/components/schemas/InventoryItem'
58+
'400':
59+
description: bad input parameter
60+
post:
61+
tags:
62+
- admins
63+
summary: adds an inventory item
64+
operationId: addInventory
65+
description: Adds an item to the system
66+
responses:
67+
'201':
68+
description: item created
69+
'400':
70+
description: 'invalid input, object invalid'
71+
'409':
72+
description: an existing item already exists
73+
requestBody:
74+
content:
75+
application/json:
76+
schema:
77+
$ref: '#/components/schemas/InventoryItem'
78+
description: Inventory item to add
79+
components:
80+
schemas:
81+
InventoryItem:
82+
type: object
83+
required:
84+
- id
85+
- name
86+
- manufacturer
87+
- releaseDate
88+
properties:
89+
id:
90+
type: string
91+
format: uuid
92+
example: d290f1ee-6c54-4b01-90e6-d701748f0851
93+
name:
94+
type: string
95+
example: Widget Adapter
96+
releaseDate:
97+
type: string
98+
format: date-time
99+
example: '2016-08-29T09:12:33.001Z'
100+
manufacturer:
101+
$ref: '#/components/schemas/Manufacturer'
102+
Manufacturer:
103+
required:
104+
- name
105+
properties:
106+
name:
107+
type: string
108+
example: ACME Corporation
109+
deprecated: true
110+
homePage:
111+
type: string
112+
format: url
113+
example: 'https://www.acme-corp.com'
114+
phone:
115+
type: string
116+
example: 408-867-5309
117+
deprecated: true
118+
type: object

demo/apis.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
"APIC-429/APIC-429.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1616
"SE-17897/SE-17897.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1717
"new-oas3-types/new-oas3-types.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
18-
"oas-api/read-only-properties.yaml": { "type": "OAS 3.0", "mime": "application/yaml" }
18+
"oas-api/read-only-properties.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
19+
"APIC-649/APIC-649.yaml": { "type": "OAS 3.0", "mime": "application/yaml" }
1920
}

demo/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ class ApiDemo extends ApiDemoPage {
9999

100100
_apiListTemplate() {
101101
return [
102-
['APIC-429', 'APIC 429'],
103102
['demo-api', 'Demo API'],
103+
['APIC-649', 'Deprecated properties'],
104+
['APIC-429', 'APIC 429'],
104105
['read-only-properties', 'Read Only Properties API'],
105106
['examples-api', 'Examples render demo'],
106107
['Petstore', 'OAS: Petstore'],

package-lock.json

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-type-document",
33
"description": "A documentation table for type (resource) properties. Works with AMF data model",
4-
"version": "4.2.11",
4+
"version": "4.2.12",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/PropertyShapeDocument.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
133133
* @attribute
134134
*/
135135
renderReadOnly: boolean;
136+
/**
137+
* Determines if shape's range is deprecated
138+
* @attribute
139+
*/
140+
deprecated: boolean
136141

137142
get complexToggleLabel(): string;
138143

src/PropertyShapeDocument.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
126126
* Computed value from the shape. True if the property is an anyOf
127127
*/
128128
isAnyOf: { type: Boolean },
129+
/**
130+
* Determines if shape's range is deprecated
131+
*/
132+
deprecated: { type: Boolean, reflect: true },
129133
};
130134
}
131135

@@ -208,6 +212,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
208212
this.hasPropertyDescription = false;
209213
this.narrow = false;
210214
this.renderReadOnly = false;
215+
this.deprecated = false;
211216
}
212217

213218
connectedCallback() {
@@ -268,6 +273,12 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
268273
this.propertyName
269274
);
270275
this.propertyDataType = this._computeObjectDataType(range, shape);
276+
const isDeprecated = Boolean(this._computeIsDeprecated(range));
277+
this.deprecated = isDeprecated;
278+
}
279+
280+
_computeIsDeprecated(range) {
281+
return this._getValue(range, this._getAmfKey(this.ns.aml.vocabularies.shapes.deprecated))
271282
}
272283

273284
_computeObjectDataType(range, shape) {
@@ -633,6 +644,13 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
633644
: ''}`;
634645
}
635646

647+
_deprecatedWarningTemplate() {
648+
if (!this.deprecated) {
649+
return '';
650+
}
651+
return html`<div class="deprecated-warning">Warning: Deprecated</div>`
652+
}
653+
636654
/**
637655
* @return {TemplateResult} Main render function.
638656
*/
@@ -665,6 +683,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
665683
>`
666684
: ''}
667685
</div>
686+
${this._deprecatedWarningTemplate()}
668687
${this._descriptionTemplate()}
669688
<property-range-document
670689
.amf="${this.amf}"

src/ShapeStyles.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,22 @@ export default css`
164164
background-color: var(--api-type-readonly-property-background-color, #ff9292);
165165
color: var(--api-type-readonly-property-color, black);
166166
}
167+
168+
:host([deprecated]) .property-title {
169+
color: gray;
170+
text-decoration: line-through;
171+
}
172+
173+
:host([deprecated]) .property-traits > span {
174+
background-color: var(--api-type-document-type-deprecated-background-color, gray);
175+
color: var(--api-type-document-type-deprecated-color, white);
176+
}
177+
178+
.deprecated-warning {
179+
background-color: var(--api-type-document-type-deprecated-background-color, gray);
180+
color: var(--api-type-document-type-deprecated-color, white);
181+
padding: var(--api-type-document-deprecated-warning-padding, 3px 6px);
182+
border-radius: var(--api-type-document-deprecated-warning-border-radius, 3px);
183+
display: inline-flex;
184+
}
167185
`;

test/property-shape-document.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,34 @@ describe('PropertyShapeDocument', () => {
676676
});
677677
});
678678

679+
describe('Deprecated properties', () => {
680+
[
681+
['Regular model', false],
682+
['Compact model', true],
683+
].forEach(([label, compact]) => {
684+
describe(String(label), () => {
685+
let amf;
686+
let type;
687+
688+
before(async () => {
689+
[amf, type] = await AmfLoader.loadType('Manufacturer', compact, 'APIC-649');
690+
});
691+
692+
it('should set `deprecated` property', async () => {
693+
const shape = AmfLoader.lookupPropertyShape(amf, type, 'name');
694+
const element = await modelFixture(amf, shape);
695+
assert.isTrue(element.deprecated);
696+
});
697+
698+
it('should set render deprecated warning message', async () => {
699+
const shape = AmfLoader.lookupPropertyShape(amf, type, 'name');
700+
const element = await modelFixture(amf, shape);
701+
assert.exists(element.shadowRoot.querySelector('.deprecated-warning'));
702+
});
703+
});
704+
});
705+
});
706+
679707
// this API does not produce amf_inline_type anymore
680708
// nor any inn the demos
681709
describe.skip('APIC-282', () => {

0 commit comments

Comments
 (0)