Skip to content

Commit 58dfd15

Browse files
BelfordZP0lip
andcommitted
fix: display title instead of any for combiners (#224)
* fix: display title instead of any for combiners * fix: remove as string in favor of string construction Co-authored-by: Jakub Rożek <[email protected]> --------- Co-authored-by: Jakub Rożek <[email protected]>
1 parent 5e72340 commit 58dfd15

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"title": "a",
3+
"oneOf": [
4+
{
5+
"title": "b",
6+
"type": "object",
7+
"properties": {
8+
"c": {
9+
"title": "d",
10+
"type": "string"
11+
},
12+
"e": {
13+
"title": "e",
14+
"type": "string"
15+
}
16+
}
17+
},
18+
{
19+
"title": "f",
20+
"type": "boolean"
21+
},
22+
{
23+
"title": "g",
24+
"oneOf": [
25+
{
26+
"title": "h",
27+
"type": "string"
28+
},
29+
{
30+
"title": "l",
31+
"type": "object",
32+
"properties": {
33+
"foo": {
34+
"title": "k",
35+
"oneOf": [
36+
{
37+
"title": "m",
38+
"type": "string"
39+
},
40+
{
41+
"title": "o",
42+
"type": "object",
43+
"properties": {
44+
"foo": { "type": "string" }
45+
}
46+
}
47+
]
48+
}
49+
}
50+
}
51+
]
52+
}
53+
]
54+
}

src/__stories__/Combiners.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const allOfSchema = require('../__fixtures__/combiners/allOfs/base.json');
99
const allOfComplexSchema = require('../__fixtures__/combiners/allOfs/complex.json');
1010
const oneOfWithArraySchema = require('../__fixtures__/combiners/oneof-with-array-type.json');
1111
const oneOfWithArraySchema2 = require('../__fixtures__/combiners/oneof-within-array-item.json');
12+
const oneOfWithMultiTypesSchema = require('../__fixtures__/combiners/oneof-with-multi-types.json');
1213
const anyOfObject = require('../__fixtures__/combiners/anyOf.json');
1314

1415
export default {
@@ -29,6 +30,9 @@ CircularAllOf.args = { schema: allOfComplexSchema as JSONSchema4 };
2930
export const ArrayOneOf = Template.bind({});
3031
ArrayOneOf.args = { schema: oneOfWithArraySchema as JSONSchema4, renderRootTreeLines: true };
3132

33+
export const OneOfMulti = Template.bind({});
34+
OneOfMulti.args = { schema: oneOfWithMultiTypesSchema, renderRootTreeLines: true };
35+
3236
export const ArrayOneOf2 = Template.bind({});
3337
ArrayOneOf2.args = { schema: oneOfWithArraySchema2 as JSONSchema4, renderRootTreeLines: true };
3438

src/components/SchemaRow/useChoices.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ function calculateChoiceTitle(node: SchemaNode, isPlural: boolean): string {
1818
if (realName) {
1919
return realName;
2020
}
21-
return node.primaryType !== null ? node.primaryType + primitiveSuffix : 'any';
21+
return node.primaryType !== null
22+
? node.primaryType + primitiveSuffix
23+
: String(node.originalFragment.title || 'any');
2224
}
2325
if (isReferenceNode(node)) {
2426
if (node.value) {

0 commit comments

Comments
 (0)