Skip to content

Commit 355a497

Browse files
committed
Add support for the optional SchemaFragment#objectRefType property
1 parent e939434 commit 355a497

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
.cache-loader
2828
.cache
2929
.rpt2_cache
30+
.publish
3031

3132
# logs
3233
*.log*

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stoplight/json-schema-viewer",
3-
"version": "0.0.0",
3+
"version": "4.16.401",
44
"description": "A beautiful React component for viewing JSON Schema",
55
"keywords": [],
66
"sideEffects": false,
@@ -26,7 +26,7 @@
2626
"commit": "git-cz",
2727
"lint": "eslint 'src/**/*.{ts,tsx}'",
2828
"lint.fix": "yarn lint --fix",
29-
"release": "sl-scripts release",
29+
"release": "rm -rf .publish && mkdir .publish && cp package.json README.md LICENSE .publish/ && cp -r dist/* .publish/ && cd .publish && yarn pack && yarn publish ./stoplight-json-schema-viewer* --registry https://bin.ti8m.ch/artifactory/api/npm/channelsuite-npm-release/",
3030
"release.docs": "sl-scripts release:docs",
3131
"release.dryRun": "sl-scripts release --dry-run --debug",
3232
"storybook": "start-storybook -p 6006",

src/components/shared/Types.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ export const Types: React.FunctionComponent<{ schemaNode: SchemaNode }> = ({ sch
7171

7272
printedName ??= type + (formats === null || formats[0] !== type ? '' : `<${formats[1]}>`);
7373

74+
// It addresses https://github.com/stoplightio/elements/issues/2762.
75+
// Abstract: instead of displaying "object" or "array[object]" we want to display the actual type of 'object'.
76+
//
77+
// The optional 'objectRefType' property is what ti&m Stoplight Elements core supplies for $ref types.
78+
// We cannot redefine the SchemaFragment type as it's defined outside the scope of this project.
79+
// -> sprinkle with '@ts-ignore'
80+
//
81+
// @ts-ignore
82+
if (type === 'array' && schemaNode.fragment?.items?.objectRefType) {
83+
// @ts-ignore
84+
printedName = `array[${schemaNode.fragment.items.objectRefType}]`;
85+
// @ts-ignore
86+
} else if (type === 'object' && schemaNode.fragment?.objectRefType) {
87+
// @ts-ignore
88+
printedName = schemaNode.fragment.objectRefType;
89+
}
90+
7491
return (
7592
<React.Fragment key={type}>
7693
<Box as="span" textOverflow="truncate" color="muted" data-test="property-type">

0 commit comments

Comments
 (0)