Skip to content

Commit

Permalink
rapidoc/components/schema: allow JSON schema content data
Browse files Browse the repository at this point in the history
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
  • Loading branch information
proppy committed Jul 6, 2020
1 parent e6e5a6a commit 2900ee0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/schema-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import marked from 'marked';
import { unsafeHTML } from 'lit-html/directives/unsafe-html';
import FontStyles from '@/styles/font-styles';
import SchemaStyles from '@/styles/schema-styles';
import { schemaInObjectNotation } from '@/utils/schema-utils';

export default class SchemaTable extends LitElement {
static get properties() {
Expand All @@ -17,6 +18,9 @@ export default class SchemaTable extends LitElement {
super.connectedCallback();
if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) { this.schemaExpandLevel = 99999; }
if (!this.schemaDescriptionExpanded || !'true false'.includes(this.schemaDescriptionExpanded)) { this.schemaDescriptionExpanded = 'false'; }
if (!this.data) {
this.data = schemaInObjectNotation(JSON.parse(this.querySelector('pre').textContent), {});
}
}

static get styles() {
Expand Down
4 changes: 4 additions & 0 deletions src/components/schema-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { unsafeHTML } from 'lit-html/directives/unsafe-html';
import FontStyles from '@/styles/font-styles';
import SchemaStyles from '@/styles/schema-styles';
import BorderStyles from '@/styles/border-styles';
import { schemaInObjectNotation } from '@/utils/schema-utils';

export default class SchemaTree extends LitElement {
static get properties() {
Expand All @@ -18,6 +19,9 @@ export default class SchemaTree extends LitElement {
super.connectedCallback();
if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) { this.schemaExpandLevel = 99999; }
if (!this.schemaDescriptionExpanded || !'true false'.includes(this.schemaDescriptionExpanded)) { this.schemaDescriptionExpanded = 'false'; }
if (!this.data) {
this.data = schemaInObjectNotation(JSON.parse(this.querySelector('pre').textContent), {});
}
}

static get styles() {
Expand Down

0 comments on commit 2900ee0

Please sign in to comment.