Skip to content

Commit 8822e9d

Browse files
committed
fixes #592 - Array Min and Max Items are rendered. fixes #626 Render Titles in schema
1 parent 179f5e8 commit 8822e9d

File tree

8 files changed

+316
-13
lines changed

8 files changed

+316
-13
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<!-- Global site tag (gtag.js) - Google Analytics -->
5+
<script async src='https://www.googletagmanager.com/gtag/js?id=UA-132775238-1'></script>
6+
<script>
7+
window.dataLayer = window.dataLayer || [];
8+
function gtag(){dataLayer.push(arguments);}
9+
gtag('js', new Date());
10+
gtag('config', 'UA-132775238-1');
11+
</script>
12+
<meta charset='utf-8'>
13+
<meta name='viewport' content='width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes'>
14+
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;600&family=Roboto+Mono&display=swap" rel="stylesheet">
15+
<link href='../index.css' rel='stylesheet'>
16+
<script type='module' src='../rapidoc-min.js'></script>
17+
</head>
18+
<body>
19+
<rapi-doc spec-url="../specs/schema-title-and-descriptions.yaml"
20+
id = "thedoc"
21+
allow-authentication = "false"
22+
allow-search = "false"
23+
show-info = "false"
24+
show-header = "false"
25+
render-style = "read"
26+
allow-try = "false"
27+
regular-font = 'Open Sans'
28+
mono-font = "Roboto Mono"
29+
theme = "dark"
30+
schema-style='table'
31+
>
32+
<div slot="nav-logo" style="width:100%; display: flex; flex-direction:column;">
33+
<div style="text-align: center; padding: 0 0 12px 0; color:#47AFE8"> Schema Display Style </div>
34+
<div style="display: flex;justify-content: center; margin: 2px 0">
35+
<button class='btn medium' onclick="document.getElementById('thedoc').setAttribute('schema-style', 'tree')" >Tree</button>
36+
<button class='btn medium' onclick="document.getElementById('thedoc').setAttribute('schema-style', 'table')" >Table</button>
37+
</div>
38+
39+
<div style="text-align: center; padding: 20px 0 12px 0; color:#47AFE8"> Font Size </div>
40+
<div style="display: flex;justify-content: center; margin: 2px 0"">
41+
<button class='btn medium' onclick="document.getElementById('thedoc').setAttribute('font-size', 'default')" >Default</button>
42+
<button class='btn medium' onclick="document.getElementById('thedoc').setAttribute('font-size', 'large')" >Large</button>
43+
<button class='btn medium' onclick="document.getElementById('thedoc').setAttribute('font-size', 'largest')" >Largest</button>
44+
</div>
45+
</div>
46+
</rapi-doc>
47+
</body>
48+
</html>

docs/list.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ <h2 style="font-weight:700"> Mix HTML content </h2>
511511
<a href="./examples/data-types.html"> Data types </a>
512512
</td></tr>
513513

514+
<tr><td class="mono-bold">
515+
<a href="./examples/schema-title-and-descriptions.html"> Schema Title and Descriptions </a>
516+
</td></tr>
517+
514518
<tr><td class="mono-bold">
515519
<a href="./examples/readwrite.html"> Read and Write annotations </a>
516520
</td></tr>

docs/specs/events.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ info:
5757
servers:
5858
- url: https://reqres.in/api/
5959
paths:
60-
/users:
60+
/users?delay=2:
6161
get:
6262
description: List of users (paginated)
6363
parameters:
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Schema Titles and Description Testcase
4+
description: More detailed description of the titles example API
5+
version: '1'
6+
paths:
7+
/object:
8+
get:
9+
summary: Object
10+
responses:
11+
default:
12+
description: Response description.
13+
content:
14+
application/json:
15+
schema:
16+
title: Root Object Title
17+
description: Root Object Description
18+
type: object
19+
properties:
20+
propString:
21+
title: Prop 1 Title
22+
description: Property 1 description
23+
type: string
24+
propArrayOfString:
25+
type: array
26+
title: Array Title
27+
description: Array Description
28+
items:
29+
title: Array Item Title
30+
description: Array Item Description (premitive)
31+
type: string
32+
propArrayOfObject:
33+
type: array
34+
title: Array Title
35+
description: Array Description
36+
items:
37+
type: object
38+
title: Array Item Title
39+
description: Array Item Description (object)
40+
properties:
41+
name:
42+
type: string
43+
title: Title
44+
description: description
45+
age:
46+
type: integer
47+
title: Title
48+
description: description
49+
50+
/array-of-string:
51+
get:
52+
summary: Array Of String
53+
responses:
54+
default:
55+
description: Response description.
56+
content:
57+
application/json:
58+
schema:
59+
title: Root Array Title
60+
description: Root Array Description
61+
type: array
62+
items:
63+
title: Array Item Title
64+
description: Array Item Description (premitive)
65+
type: string
66+
/array-of-object:
67+
get:
68+
summary: Array Of Object
69+
responses:
70+
default:
71+
description: Response description.
72+
content:
73+
application/json:
74+
schema:
75+
type: object
76+
title: Root Object Title
77+
description: Root Object Description
78+
properties:
79+
array_attribute:
80+
type: array
81+
minItems: 10
82+
maxItems: 20
83+
title: Array Title
84+
description: Array Description
85+
items:
86+
type: object
87+
title: Array Item Title
88+
minProperties: 2
89+
maxProperties: 2
90+
description: Array Item Description
91+
properties:
92+
key:
93+
type: string
94+
value:
95+
type: integer
96+
minimum: 20

docs/specs/titles.txt

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Titles example (title)",
5+
"description": "More detailed description of the titles example API",
6+
"version": "1"
7+
},
8+
"paths": {
9+
"/inline/object": {
10+
"get": {
11+
"summary": "Example with inline schemas, object",
12+
"responses": {
13+
"default": {
14+
"description": "Response description.",
15+
"content": {
16+
"*/*": {
17+
"schema": {
18+
"title": "Inline object (title)",
19+
"description": "Detailed description of inline object.",
20+
"type": "object",
21+
"properties": {
22+
"prop": {
23+
"title": "Inline property in inline object (title)",
24+
"description": "Detailed description of inline property in inline object.",
25+
"type": "string"
26+
}
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
},
35+
"/inline/array": {
36+
"get": {
37+
"summary": "Example with inline schemas, array",
38+
"responses": {
39+
"default": {
40+
"description": "Response description.",
41+
"content": {
42+
"*/*": {
43+
"schema": {
44+
"title": "Inline array (title)",
45+
"description": "Detailed description of inline array.",
46+
"type": "array",
47+
"items": {
48+
"title": "Inline item in inline array (title)",
49+
"description": "Detailed description of inline item in inline array.",
50+
"type": "string"
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
},
59+
"/components/object": {
60+
"get": {
61+
"summary": "Example with schemas in components, object",
62+
"responses": {
63+
"default": {
64+
"description": "Response description.",
65+
"content": {
66+
"*/*": {
67+
"schema": { "$ref": "#/components/schemas/Object" }
68+
}
69+
}
70+
}
71+
}
72+
}
73+
},
74+
"/components/array": {
75+
"get": {
76+
"summary": "Example with schemas in components, array",
77+
"responses": {
78+
"default": {
79+
"description": "Response description.",
80+
"content": {
81+
"*/*": {
82+
"schema": { "$ref": "#/components/schemas/ArrayOfString" }
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
89+
},
90+
"components": {
91+
"schemas": {
92+
"String": {
93+
"title": "Schema String (title)",
94+
"description": "Detailed description of schema String.",
95+
"type": "string"
96+
},
97+
"ArrayOfString": {
98+
"title": "Schema ArrayOfString (title)",
99+
"description": "Detailed description of schema ArrayOfString.",
100+
"type": "array",
101+
"items": { "$ref": "#/components/schemas/String" }
102+
},
103+
"Object": {
104+
"title": "Schema Object (title)",
105+
"description": "Detailed description of schema Object.",
106+
"type": "object",
107+
"properties": {
108+
"componentString": { "$ref": "#/components/schemas/String" },
109+
"inlineString": {
110+
"title": "Inline string property in schema Object (title)",
111+
"description": "Detailed description of inline string property in schema Object.",
112+
"type": "string"
113+
},
114+
"componentArray": { "$ref": "#/components/schemas/ArrayOfString" },
115+
"inlineArray": {
116+
"title": "Inline array property in schema Object (title)",
117+
"description": "Detailed description of inline array property in schema Object.",
118+
"type": "array",
119+
"items": {
120+
"title": "Inline item in inline array property in schema Object (title)",
121+
"description": "Detailed description of inline item in inline array property in schema Object.",
122+
"type": "string"
123+
}
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}

src/components/schema-table.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default class SchemaTable extends LitElement {
234234
? html`${this.generateTree(data[0], 'xxx-of-option', '', '::ARRAY~OF', '', newSchemaLevel, newIndentLevel, '')}`
235235
: html`
236236
${Object.keys(data).map((dataKey) => html`
237-
${['::description', '::type', '::props', '::deprecated', '::array-type', '::readwrite'].includes(dataKey)
237+
${['::title', '::description', '::type', '::props', '::deprecated', '::array-type', '::readwrite'].includes(dataKey)
238238
? data[dataKey]['::type'] === 'array' || data[dataKey]['::type'] === 'object'
239239
? html`${this.generateTree(
240240
data[dataKey]['::type'] === 'array' ? data[dataKey]['::props'] : data[dataKey],
@@ -303,7 +303,7 @@ export default class SchemaTable extends LitElement {
303303
${defaultValue ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px;'> <span class='bold-text'>Default: </span>${defaultValue}</div>` : ''}
304304
${allowedValues ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px;'> <span class='bold-text'>Allowed: </span>${allowedValues}</div>` : ''}
305305
${pattern ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px;'> <span class='bold-text'>Pattern: </span>${pattern}</div>` : ''}
306-
${schemaDescription ? html`<span class="m-markdown-small">${unsafeHTML(marked(schemaDescription))}</span>` : ''}
306+
${schemaDescription ? html`<span class="m-markdown-small">${unsafeHTML(marked(`${schemaTitle ? `**${schemaTitle}:**` : ''} ${schemaDescription}`))}</span>` : ''}
307307
</div>
308308
</div>
309309
`;

src/components/schema-tree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export default class SchemaTree extends LitElement {
227227
? html`${this.generateTree(data[0], 'xxx-of-option', '', '::ARRAY~OF', '', newSchemaLevel, newIndentLevel, data[0]['::readwrite'])}`
228228
: html`
229229
${Object.keys(data).map((dataKey) => html`
230-
${['::description', '::type', '::props', '::deprecated', '::array-type', '::readwrite'].includes(dataKey)
230+
${['::title', '::description', '::type', '::props', '::deprecated', '::array-type', '::readwrite'].includes(dataKey)
231231
? data[dataKey]['::type'] === 'array' || data[dataKey]['::type'] === 'object'
232232
? html`${this.generateTree(
233233
data[dataKey]['::type'] === 'array' ? data[dataKey]['::props'] : data[dataKey],
@@ -263,7 +263,7 @@ export default class SchemaTree extends LitElement {
263263
}
264264

265265
// For Primitive types and array of Primitives
266-
const [type, primitiveReadOrWrite, constraint, defaultValue, allowedValues, pattern, schemaDescription, , deprecated] = data.split('~|~');
266+
const [type, primitiveReadOrWrite, constraint, defaultValue, allowedValues, pattern, schemaDescription, schemaTitle, deprecated] = data.split('~|~');
267267
if (primitiveReadOrWrite === '🆁' && this.schemaHideReadOnly === 'true') {
268268
return;
269269
}
@@ -310,7 +310,7 @@ export default class SchemaTree extends LitElement {
310310
${defaultValue ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Default: </span>${defaultValue}</div>` : ''}
311311
${allowedValues ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Allowed: </span>${allowedValues}</div>` : ''}
312312
${pattern ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Pattern: </span>${pattern}</div>` : ''}
313-
${schemaDescription ? html`<span class="m-markdown-small">${unsafeHTML(marked(schemaDescription))}</span>` : ''}
313+
${schemaDescription ? html`<span class="m-markdown-small">${unsafeHTML(marked(`${schemaTitle ? `**${schemaTitle}:**` : ''} ${schemaDescription}`))}</span>` : ''}
314314
</div>
315315
</div>
316316
`;

0 commit comments

Comments
 (0)