Skip to content

Commit 8c4fe27

Browse files
committed
fixes #330 - one-of arrays must be be indicated as arrays
1 parent a63bfb9 commit 8c4fe27

File tree

7 files changed

+134
-108
lines changed

7 files changed

+134
-108
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<head>
3+
<!-- Global site tag (gtag.js) - Google Analytics -->
4+
<script async src='https://www.googletagmanager.com/gtag/js?id=UA-132775238-1'></script>
5+
<script>
6+
window.dataLayer = window.dataLayer || [];
7+
function gtag(){dataLayer.push(arguments);}
8+
gtag('js', new Date());
9+
gtag('config', 'UA-132775238-1');
10+
</script>
11+
<meta charset='utf-8'>
12+
<meta name='viewport' content='width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes'>
13+
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;600&family=Roboto+Mono&display=swap" rel="stylesheet">
14+
<script type='text/javascript' src='../rapidoc-min.js'></script>
15+
</head>
16+
<body>
17+
<rapi-doc spec-url="../specs/oneof-combinations.yaml"
18+
allow-authentication = "false"
19+
show-info = "false"
20+
render-style = "read"
21+
allow-try = "false"
22+
regular-font = 'Open Sans'
23+
mono-font = "Roboto Mono"
24+
> </rapi-doc>
25+
</body>
26+
</html>

docs/list.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ <h2 style="font-weight:700"> Mix HTML content </h2>
457457
<a href="./examples/circular.html"> Circular references </a>
458458
</td>
459459
</tr>
460+
<tr>
461+
<td class="mono-bold">
462+
<a href="./examples/oneof-combinations.html"> one-of combinations </a>
463+
</td>
464+
</tr>
460465
<tr><td class="mono-bold">
461466
<a href="./tests/nested-allof-and-oneof.html"> Nested all-of & one-of </a>
462467
</td></tr>

docs/rapidoc-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/specs/oneof-combinations.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
openapi: 3.0.0
2+
info:
3+
title: One Of Test Cases
4+
version: '1.0'
5+
paths:
6+
/one-of-array-and-object:
7+
get:
8+
summary: One Of Array and Object
9+
responses:
10+
'200':
11+
description: OK
12+
content:
13+
application/json:
14+
schema:
15+
type: object
16+
properties:
17+
single:
18+
oneOf:
19+
- type: string
20+
- type: object
21+
properties:
22+
x:
23+
type: string
24+
y:
25+
type: string
26+
multiple:
27+
type: array
28+
items:
29+
oneOf:
30+
- type: string
31+
- type: object
32+
properties:
33+
x:
34+
type: string
35+
y:
36+
type: string
37+
/one-of-primitives-and-object:
38+
get:
39+
summary: One Of Object and premitives
40+
responses:
41+
'200':
42+
description: OK
43+
content:
44+
application/json:
45+
schema:
46+
type: object
47+
properties:
48+
a:
49+
type: string
50+
b:
51+
type: string
52+
c:
53+
oneOf:
54+
- type: boolean
55+
- type: number
56+
- type: string
57+
- type: object
58+
properties:
59+
x:
60+
type: string
61+
y:
62+
type: string
63+
d:
64+
type: string

docs/specs/temp.yaml

Lines changed: 30 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,42 @@
11
openapi: 3.0.0
22
info:
3-
title: Providing Examples
4-
description: Providing Examples
5-
version: 1.0.0
3+
title: sample-array-one
4+
version: '1.0'
5+
servers:
6+
- url: 'http://localhost'
67
paths:
7-
/single-example-by-response-type:
8+
/sample-array-one:
89
get:
9-
summary: Single Example at schema Level
10+
summary: sample-array-one
11+
tags: []
1012
responses:
1113
'200':
12-
description: Successful operation
14+
description: OK
1315
content:
1416
application/json:
1517
schema:
1618
type: object
1719
properties:
18-
age:
19-
description: Person Age
20-
type: integer
21-
fullName:
22-
description: Person Full name
23-
type: object
24-
properties:
25-
firstName:
26-
description: First name
27-
type: string
28-
lastName:
29-
description: Last name
30-
type: string
31-
example: |
32-
{
33-
age: 10,
34-
fullName: {
35-
firstName: Donald,
36-
lastName: Duck
37-
}
38-
}
39-
/single-example-by-response-type2:
40-
get:
41-
summary: Single Example at schema Level
42-
responses:
43-
'200':
44-
description: Successful operation
45-
content:
46-
application/json:
47-
schema:
48-
type: object
49-
properties:
50-
age:
51-
description: Person Age
52-
type: integer
53-
fullName:
54-
description: Person Full name
55-
type: object
56-
properties:
57-
firstName:
58-
description: First name
59-
type: string
60-
lastName:
61-
description: Last name
62-
type: string
63-
example:
64-
age: 10
65-
fullName:
66-
firstName: Donald
67-
lastName: Duck
20+
single:
21+
oneOf:
22+
- type: string
23+
- type: object
24+
properties:
25+
x:
26+
type: string
27+
y:
28+
type: string
29+
multiple:
30+
type: array
31+
items:
32+
oneOf:
33+
- type: string
34+
- type: object
35+
properties:
36+
x:
37+
type: string
38+
y:
39+
type: string
40+
operationId: get-sample-array-one
6841
components:
69-
schemas:
70-
cost:
71-
type: object
72-
properties:
73-
amount:
74-
type: integer
75-
description: Amount
76-
currency:
77-
description: Currency Code
78-
type: string
79-
currencies:
80-
type: array
81-
items:
82-
type: object
83-
properties:
84-
currencyCode:
85-
type: string
86-
evaluationDate:
87-
type: string
88-
format: date-time
89-
example:
90-
- currencyCode: USD
91-
evaluationDate: '2017-07-21T17:32:28Z'
92-
- currencyCode: INR
93-
evaluationDate: '2017-07-21T17:32:28Z'
94-
ArrayOfInt-1:
95-
type: array
96-
items:
97-
type: integer
98-
format: int64
99-
example: [1, 2, 3]
100-
ArrayOfInt-2:
101-
type: array
102-
items:
103-
type: integer
104-
format: int64
105-
example: 1
106-
PersonObject:
107-
type: object
108-
properties:
109-
name:
110-
type: string
111-
age:
112-
type: integer
113-
example:
114-
name: name-1
115-
age: 1
42+
schemas: {}

src/components/schema-tree.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ export default class SchemaTree extends LitElement {
150150
${data['::type'] === 'xxx-of-option' || prevKey.startsWith('::OPTION')
151151
? html`<span class='xxx-of-key'>${newPrevKey}</span>`
152152
: newPrevKey.endsWith('*')
153-
? html`${newPrevKey.substring(0, newPrevKey.length - 1)}<span style='color:var(--red);'>*</span>`
154-
: newPrevKey
155-
}${level > 0 ? ':' : ''}${openBracket}
153+
? html`${newPrevKey.substring(0, newPrevKey.length - 1)} ${prevDataType === 'array' ? 'ARRAY OF' : ''} <span style='color:var(--red);'>*</span>`
154+
: html`${newPrevKey}`
155+
}${level > 0 ? ':' : ''}
156+
${data['::type'] === 'xxx-of' && prevDataType === 'array' ? html`<span style="color:var(--primary-color)">ARRAY</span>` : ''}
157+
${openBracket}
156158
</div>
157159
<div class='td key-descr m-markdown-small'>${unsafeHTML(marked(prevDescr || ''))}</div>
158160
</div>

src/utils/schema-utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,10 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
355355
objWithAnyOfProps[`::OPTION~${index + 1}`] = partialObj;
356356
objWithAnyOfProps['::type'] = 'xxx-of-option';
357357
} else if (v.type === 'array' || v.items) {
358+
// This else-if block never seems to get executed
358359
const partialObj = [schemaInObjectNotation(v, {})];
359-
Object.assign(objWithAnyOfProps, partialObj);
360+
objWithAnyOfProps[`::OPTION~${index + 1}`] = partialObj;
361+
objWithAnyOfProps['::type'] = 'xxx-of-array';
360362
} else {
361363
const prop = `::OPTION~${index + 1}`;
362364
objWithAnyOfProps[prop] = `${getTypeInfo(v).html}`;

0 commit comments

Comments
 (0)