Skip to content

Commit 2900ee0

Browse files
committed
rapidoc/components/schema: allow JSON schema content data
This change allow usage of <schema-tree> and <schema-table> custom element with a child <pre> block containing a JSON schema. Fixes rapi-doc#253
1 parent e6e5a6a commit 2900ee0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/components/schema-table.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import marked from 'marked';
33
import { unsafeHTML } from 'lit-html/directives/unsafe-html';
44
import FontStyles from '@/styles/font-styles';
55
import SchemaStyles from '@/styles/schema-styles';
6+
import { schemaInObjectNotation } from '@/utils/schema-utils';
67

78
export default class SchemaTable extends LitElement {
89
static get properties() {
@@ -17,6 +18,9 @@ export default class SchemaTable extends LitElement {
1718
super.connectedCallback();
1819
if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) { this.schemaExpandLevel = 99999; }
1920
if (!this.schemaDescriptionExpanded || !'true false'.includes(this.schemaDescriptionExpanded)) { this.schemaDescriptionExpanded = 'false'; }
21+
if (!this.data) {
22+
this.data = schemaInObjectNotation(JSON.parse(this.querySelector('pre').textContent), {});
23+
}
2024
}
2125

2226
static get styles() {

src/components/schema-tree.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { unsafeHTML } from 'lit-html/directives/unsafe-html';
44
import FontStyles from '@/styles/font-styles';
55
import SchemaStyles from '@/styles/schema-styles';
66
import BorderStyles from '@/styles/border-styles';
7+
import { schemaInObjectNotation } from '@/utils/schema-utils';
78

89
export default class SchemaTree extends LitElement {
910
static get properties() {
@@ -18,6 +19,9 @@ export default class SchemaTree extends LitElement {
1819
super.connectedCallback();
1920
if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) { this.schemaExpandLevel = 99999; }
2021
if (!this.schemaDescriptionExpanded || !'true false'.includes(this.schemaDescriptionExpanded)) { this.schemaDescriptionExpanded = 'false'; }
22+
if (!this.data) {
23+
this.data = schemaInObjectNotation(JSON.parse(this.querySelector('pre').textContent), {});
24+
}
2125
}
2226

2327
static get styles() {

0 commit comments

Comments
 (0)