Skip to content

Commit 1f67d66

Browse files
Fix parameter description for OAS 3 (#20)
* fix: save description from shape, use if no description in property * test: add test for shape description * test: fix test * 4.2.10
1 parent c811324 commit 1f67d66

File tree

7 files changed

+78
-4
lines changed

7 files changed

+78
-4
lines changed

demo/SE-17897/SE-17897.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
openapi: '3.0.2'
2+
info:
3+
title: 'SE-17897'
4+
version: 1.0.0
5+
6+
paths:
7+
/default:
8+
post:
9+
parameters:
10+
- in: query
11+
name: conversationId
12+
required: false
13+
description: >
14+
The ConversationId uniquely identifies the message sent from the sender to the receiver.
15+
schema:
16+
type: string
17+
format: uuid
18+
example: '242ab55c-de2b-4822-a411-945e85882b60'
19+
responses:
20+
'201':
21+
description: Created

demo/apis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"APIC-631/APIC-631.raml": "RAML 1.0",
1313
"SE-19500/SE-19500.raml": "RAML 1.0",
1414
"APIC-429/APIC-429.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
15+
"SE-17897/SE-17897.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1516
"new-oas3-types/new-oas3-types.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1617
"oas-api/read-only-properties.yaml": { "type": "OAS 3.0", "mime": "application/yaml" }
1718
}

package-lock.json

Lines changed: 1 addition & 1 deletion
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.9",
4+
"version": "4.2.10",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/PropertyShapeDocument.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,21 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
9393
* @attribute
9494
*/
9595
propertyDescription: string;
96+
/**
97+
* A description of the shape to render.
98+
* @attribute
99+
*/
100+
shapeDescription: string;
96101
/**
97102
* Computed value, true if description is set.
98103
* @attribute
99104
*/
100105
hasPropertyDescription: boolean;
106+
/**
107+
* Computed value, true if description is set.
108+
* @attribute
109+
*/
110+
hasShapeDescription: boolean;
101111
/**
102112
* A property to set when the component is rendered in the narrow
103113
* view. To be used with mobile rendering or when the

src/PropertyShapeDocument.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,18 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
9191
* A description of the property to render.
9292
*/
9393
propertyDescription: { type: String },
94+
/**
95+
* A description of the shape to render.
96+
*/
97+
shapeDescription: { type: String },
9498
/**
9599
* Computed value, true if description is set.
96100
*/
97101
hasPropertyDescription: { type: Boolean },
102+
/**
103+
* Computed value, true if description is set.
104+
*/
105+
hasShapeDescription: { type: Boolean },
98106
/**
99107
* A property to set when the component is rendered in the narrow
100108
* view. To be used with mobile rendering or when the
@@ -223,6 +231,10 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
223231
}
224232
this.range = this._computeRange(shape);
225233
this.isRequired = this._computeIsRequired(shape);
234+
this.shapeDescription = this._computeDescription(shape);
235+
this.hasShapeDescription = this._computeHasStringValue(
236+
this.shapeDescription
237+
);
226238
}
227239

228240
_rangeChanged(range) {
@@ -564,11 +576,11 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
564576
* @return {TemplateResult|string} Template for the description
565577
*/
566578
_descriptionTemplate() {
567-
if (!this.hasPropertyDescription) {
579+
if (!(this.hasPropertyDescription || this.hasShapeDescription)) {
568580
return '';
569581
}
570582
return html`
571-
<arc-marked .markdown="${this.propertyDescription}" sanitize>
583+
<arc-marked .markdown="${this.propertyDescription || this.shapeDescription}" sanitize>
572584
<div slot="markdown-html" class="markdown-body"></div>
573585
</arc-marked>
574586
`;

test/property-shape-document.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,36 @@ describe('PropertyShapeDocument', () => {
646646
});
647647
});
648648

649+
describe('SE-17897', () => {
650+
[
651+
['Regular model', false],
652+
['Compact model', true],
653+
].forEach((item) => {
654+
describe(String(item[0]), () => {
655+
let element = /** @type PropertyShapeDocument */ (null);
656+
let amf;
657+
658+
before(async () => {
659+
amf = await AmfLoader.load(item[1], 'SE-17897')
660+
});
661+
662+
beforeEach(async () => {
663+
element = await basicFixture();
664+
element.amf = amf;
665+
});
666+
667+
it('sets shape description when schema does not have one', async () => {
668+
const [parameter] = AmfLoader.lookupParameters(amf, '/default', 'post');
669+
element.shape = parameter;
670+
await nextFrame();
671+
assert.isFalse(element.hasPropertyDescription);
672+
assert.isTrue(element.hasShapeDescription);
673+
assert.isTrue(element.shapeDescription.startsWith('The ConversationId uniquely identifies the message sent from the sender to the receiver.'));
674+
});
675+
});
676+
});
677+
});
678+
649679
// this API does not produce amf_inline_type anymore
650680
// nor any inn the demos
651681
describe.skip('APIC-282', () => {

0 commit comments

Comments
 (0)