Skip to content

Commit

Permalink
fix: display title instead of any for combiners (#224)
Browse files Browse the repository at this point in the history
* fix: display title instead of any for combiners

* fix: remove as string in favor of string construction

Co-authored-by: Jakub Rożek <jakub@rozek.tech>

---------

Co-authored-by: Jakub Rożek <jakub@rozek.tech>
  • Loading branch information
BelfordZ and P0lip committed May 30, 2023
1 parent 5e72340 commit 58dfd15
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
54 changes: 54 additions & 0 deletions src/__fixtures__/combiners/oneof-with-multi-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"title": "a",
"oneOf": [
{
"title": "b",
"type": "object",
"properties": {
"c": {
"title": "d",
"type": "string"
},
"e": {
"title": "e",
"type": "string"
}
}
},
{
"title": "f",
"type": "boolean"
},
{
"title": "g",
"oneOf": [
{
"title": "h",
"type": "string"
},
{
"title": "l",
"type": "object",
"properties": {
"foo": {
"title": "k",
"oneOf": [
{
"title": "m",
"type": "string"
},
{
"title": "o",
"type": "object",
"properties": {
"foo": { "type": "string" }
}
}
]
}
}
}
]
}
]
}
4 changes: 4 additions & 0 deletions src/__stories__/Combiners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const allOfSchema = require('../__fixtures__/combiners/allOfs/base.json');
const allOfComplexSchema = require('../__fixtures__/combiners/allOfs/complex.json');
const oneOfWithArraySchema = require('../__fixtures__/combiners/oneof-with-array-type.json');
const oneOfWithArraySchema2 = require('../__fixtures__/combiners/oneof-within-array-item.json');
const oneOfWithMultiTypesSchema = require('../__fixtures__/combiners/oneof-with-multi-types.json');
const anyOfObject = require('../__fixtures__/combiners/anyOf.json');

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

export const OneOfMulti = Template.bind({});
OneOfMulti.args = { schema: oneOfWithMultiTypesSchema, renderRootTreeLines: true };

export const ArrayOneOf2 = Template.bind({});
ArrayOneOf2.args = { schema: oneOfWithArraySchema2 as JSONSchema4, renderRootTreeLines: true };

Expand Down
4 changes: 3 additions & 1 deletion src/components/SchemaRow/useChoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function calculateChoiceTitle(node: SchemaNode, isPlural: boolean): string {
if (realName) {
return realName;
}
return node.primaryType !== null ? node.primaryType + primitiveSuffix : 'any';
return node.primaryType !== null
? node.primaryType + primitiveSuffix
: String(node.originalFragment.title || 'any');
}
if (isReferenceNode(node)) {
if (node.value) {
Expand Down

0 comments on commit 58dfd15

Please sign in to comment.