Skip to content

Commit b725e6b

Browse files
authored
Merge pull request #36 from advanced-rest-client/fix/description-missing
Fix/description missing
2 parents 8a92b69 + 519c567 commit b725e6b

File tree

7 files changed

+119
-3
lines changed

7 files changed

+119
-3
lines changed

demo/APIC-758/APIC-758.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
openapi: "3.0.0"
2+
externalDocs:
3+
url: petstore.com
4+
description: Pet Store website
5+
info:
6+
version: 1.0.0
7+
title: OpenAPI Spec 3.0 Petstore
8+
9+
components:
10+
schemas:
11+
Pet:
12+
type: object
13+
required:
14+
- id
15+
- name
16+
properties:
17+
id:
18+
type: integer
19+
format: int64
20+
name:
21+
type: string
22+
tag:
23+
type: string
24+
Error:
25+
type: object
26+
required:
27+
- code
28+
- message
29+
properties:
30+
code:
31+
type: integer
32+
format: int32
33+
message:
34+
type: string
35+
paths:
36+
/pets:
37+
post:
38+
summary: Create a pet
39+
requestBody:
40+
description: Pet to add
41+
content:
42+
application/json:
43+
schema:
44+
$ref: "#/components/schemas/Pet"
45+
responses:
46+
"201":
47+
description: Null response
48+
default:
49+
description: unexpected error
50+
content:
51+
application/json:
52+
schema:
53+
$ref: "#/components/schemas/Error"

demo/apis.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"APIC-463/APIC-463.raml": "RAML 1.0",
1010
"SE-12291/SE-12291.json": "OAS 2.0",
1111
"anyOf/anyOf.yaml": "ASYNC 2.0",
12-
"steveTest-1/stevetest.json": "OAS 2.0"
12+
"steveTest-1/stevetest.json": "OAS 2.0",
13+
"APIC-758/APIC-758.yaml": "OAS 3.0"
1314
}

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-body-document",
33
"description": "A component to render HTTP method body documentation based on AMF model",
4-
"version": "4.4.4",
4+
"version": "4.4.5",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiBodyDocumentElement.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export declare class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
2929
* type.
3030
*/
3131
body: any[];
32+
/**
33+
* requestBody description for OAS 3.0 specs
34+
*/
35+
bodyDescription: string;
36+
/**
37+
* requestBody description for OAS 3.0 specs
38+
*/
39+
_bodyDescription: string;
3240
/**
3341
* List of discovered media types in the `body`.
3442
*/

src/ApiBodyDocumentElement.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
4141
* type.
4242
*/
4343
body: { type: Array },
44+
/**
45+
* requestBody description for OAS 3.0 specs
46+
*/
47+
bodyDescription: { type: String },
4448
/**
4549
* List of discovered media types in the `body`.
4650
*/
@@ -203,6 +207,19 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
203207
this._bodyChanged();
204208
}
205209

210+
get bodyDescription() {
211+
return this._bodyDescription;
212+
}
213+
214+
set bodyDescription(value) {
215+
const old = this._bodyDescription;
216+
if (old === value) {
217+
return;
218+
}
219+
this._bodyDescription = value;
220+
this.requestUpdate('bodyDescription', old);
221+
}
222+
206223
get toggleActionLabel() {
207224
const { opened } = this;
208225
return opened ? 'Hide' : 'Show';
@@ -478,10 +495,12 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
478495
amf,
479496
narrow,
480497
renderReadOnly,
498+
bodyDescription
481499
} = this;
482500
const hasBodyName = !!_bodyName;
483501
const hasDescription = !!_description;
484502
const hasTypeName = _typeName && _typeName !== 'default';
503+
const hasBodyDescription = !!bodyDescription
485504

486505
return html`
487506
<div class="media-type-selector">
@@ -490,6 +509,10 @@ export class ApiBodyDocumentElement extends AmfHelperMixin(LitElement) {
490509
this._mediaTypesTemplate() :
491510
html`<span class="media-type-label">${_selectedMediaType}</span>`}
492511
</div>
512+
${hasBodyDescription ? html`
513+
<arc-marked .markdown="${bodyDescription}" sanitize>
514+
<div slot="markdown-html" class="markdown-html" part="markdown-html"></div>
515+
</arc-marked>` : ''}
493516
${hasBodyName ? html`<div class="body-name type-title">${_bodyName}</div>` : ''}
494517
${hasTypeName ? html`<div class="type-title">${_typeName}</div>` : ''}
495518
${hasDescription ? html`

test/api-body-document.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,35 @@ describe('ApiBodyDocumentElement', () => {
560560
});
561561
});
562562
});
563+
564+
describe('OAS 3.0', () => {
565+
[
566+
['Full AMF model', false],
567+
['Compact AMF model', true]
568+
].forEach(([label, compact]) => {
569+
describe(String(label), () => {
570+
let element = /** @type ApiBodyDocumentElement */ (null);
571+
let amf;
572+
let payload;
573+
574+
before(async () => {
575+
amf = await AmfLoader.load(compact, 'APIC-758');
576+
payload = AmfLoader.lookupReturnsPayload(amf, '/pets', 'post', 201);
577+
});
578+
579+
beforeEach(async () => {
580+
element = await openedFixture();
581+
element.amf = amf;
582+
element.body = payload;
583+
element.bodyDescription = 'Pet to add';
584+
await nextFrame();
585+
await aTimeout(0);
586+
});
587+
588+
it('Sets body description value', async () => {
589+
assert.equal(element._bodyDescription, 'Pet to add');
590+
});
591+
});
592+
});
593+
});
563594
});

0 commit comments

Comments
 (0)