From 3c5f33f779d19d3726e7a80d521887b94c942095 Mon Sep 17 00:00:00 2001 From: Rob Date: Fri, 29 Aug 2025 14:05:31 +0100 Subject: [PATCH 1/2] fix missing schema details for arrays and objects under oneOf --- src/components/Fields/Field.tsx | 1 + src/components/Fields/FieldDetails.tsx | 4 +- src/components/Schema/OneOfSchema.tsx | 4 +- src/components/Schema/Schema.tsx | 60 ++++++++++++++++---------- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/components/Fields/Field.tsx b/src/components/Fields/Field.tsx index d142c9a5c4..819f915223 100644 --- a/src/components/Fields/Field.tsx +++ b/src/components/Fields/Field.tsx @@ -23,6 +23,7 @@ import type { FieldModel } from '../../services/models'; export interface FieldProps extends SchemaOptions { className?: string; isLast?: boolean; + noItemsType?: boolean; showExamples?: boolean; field: FieldModel; diff --git a/src/components/Fields/FieldDetails.tsx b/src/components/Fields/FieldDetails.tsx index d443c64f79..cb44df96dd 100644 --- a/src/components/Fields/FieldDetails.tsx +++ b/src/components/Fields/FieldDetails.tsx @@ -29,7 +29,7 @@ import { ArrayItemDetails } from './ArrayItemDetails'; export const FieldDetailsComponent = observer((props: FieldProps) => { const { enumSkipQuotes, hideSchemaTitles } = React.useContext(OptionsContext); - const { showExamples, field, renderDiscriminatorSwitch } = props; + const { showExamples, noItemsType, field, renderDiscriminatorSwitch } = props; const { schema, description, @@ -98,7 +98,7 @@ export const FieldDetailsComponent = observer((props: FieldProps) => { {schema.isCircular && {l('recursive')} } - {isArrayType && schema.items && } + {isArrayType && !noItemsType && schema.items && } {deprecated && (
diff --git a/src/components/Schema/OneOfSchema.tsx b/src/components/Schema/OneOfSchema.tsx index 73bd0b5fd1..7152cc60e3 100644 --- a/src/components/Schema/OneOfSchema.tsx +++ b/src/components/Schema/OneOfSchema.tsx @@ -8,7 +8,6 @@ import { } from '../../common-elements/schema'; import { Badge } from '../../common-elements/shelfs'; import { SchemaModel } from '../../services/models'; -import { ConstraintsView } from '../Fields/FieldConstraints'; import { Schema, SchemaProps } from './Schema'; import { DiscriminatorDropdown } from './DiscriminatorDropdown'; import { OptionsConsumer } from '../OptionsProvider'; @@ -81,8 +80,7 @@ export class OneOfSchema extends React.Component {
{oneOf[schema.activeOneOf].deprecated && Deprecated}
- - +
); } diff --git a/src/components/Schema/Schema.tsx b/src/components/Schema/Schema.tsx index c0d38b1ea8..deff381003 100644 --- a/src/components/Schema/Schema.tsx +++ b/src/components/Schema/Schema.tsx @@ -4,6 +4,7 @@ import * as React from 'react'; import { FieldDetails } from '../Fields/FieldDetails'; import { FieldModel, SchemaModel } from '../../services/models'; +import styled from '../../styled-components'; import { ArraySchema } from './ArraySchema'; import { ObjectSchema } from './ObjectSchema'; @@ -12,10 +13,16 @@ import { RecursiveSchema } from './RecursiveSchema'; import { isArray } from '../../utils/helpers'; +const Spacer = styled.div` + padding-top: ${({ theme }) => theme.spacing.unit * 2}px; +`; + export interface SchemaOptions { + noItemsType?: boolean; showTitle?: boolean; skipReadOnly?: boolean; skipWriteOnly?: boolean; + showFieldDetails?: boolean; level?: number; } @@ -38,6 +45,22 @@ export class Schema extends React.Component> { return ; } + // TODO: maybe adjust FieldDetails to accept schema + const field = { + schema, + name: '', + required: false, + description: schema.description, + externalDocs: schema.externalDocs, + deprecated: false, + toggle: () => null, + expanded: false, + } as any as FieldModel; // cast needed for hot-loader to not fail + + const types = isArray(type) ? type : [type]; + const showFieldDetails = + rest.showFieldDetails || (!types.includes('object') && !types.includes('array')); + if (discriminatorProp !== undefined) { if (!oneOf || !oneOf.length) { console.warn( @@ -65,30 +88,23 @@ export class Schema extends React.Component> { return ; } - const types = isArray(type) ? type : [type]; - if (types.includes('object')) { - if (schema.fields?.length) { - return ; - } - } else if (types.includes('array')) { - return ; - } - - // TODO: maybe adjust FieldDetails to accept schema - const field = { - schema, - name: '', - required: false, - description: schema.description, - externalDocs: schema.externalDocs, - deprecated: false, - toggle: () => null, - expanded: false, - } as any as FieldModel; // cast needed for hot-loader to not fail - return (
- + {showFieldDetails && } + {types.includes('object') ? ( + schema.fields?.length ? ( + + ) : ( + '' + ) + ) : types.includes('array') ? ( +
+ {showFieldDetails && } + +
+ ) : ( + '' + )}
); } From 7190438700d2b95864fc188f690f8b313fb8bcb3 Mon Sep 17 00:00:00 2001 From: Rob Date: Fri, 29 Aug 2025 14:08:17 +0100 Subject: [PATCH 2/2] show array items object schema details --- src/components/Schema/ArraySchema.tsx | 2 +- src/components/Schema/Schema.tsx | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/Schema/ArraySchema.tsx b/src/components/Schema/ArraySchema.tsx index 84bd716a56..8b31a1796b 100644 --- a/src/components/Schema/ArraySchema.tsx +++ b/src/components/Schema/ArraySchema.tsx @@ -37,7 +37,7 @@ export class ArraySchema extends React.PureComponent {
Array {minMaxItems} - +
diff --git a/src/components/Schema/Schema.tsx b/src/components/Schema/Schema.tsx index deff381003..9a39721aea 100644 --- a/src/components/Schema/Schema.tsx +++ b/src/components/Schema/Schema.tsx @@ -72,15 +72,18 @@ export class Schema extends React.Component> { return activeSchema.isCircular ? ( ) : ( - +
+ {showFieldDetails && } + +
); }