From 84ca1b12796e77ac4c7b6155ab5a915a25ea4883 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Mon, 30 Dec 2024 15:50:06 +0100 Subject: [PATCH 1/2] fix: displaying nested items with type string --- src/components/Fields/ArrayItemDetails.tsx | 8 -------- src/components/Fields/FieldDetails.tsx | 5 +++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/components/Fields/ArrayItemDetails.tsx b/src/components/Fields/ArrayItemDetails.tsx index bbae19911d..b45f56a8b8 100644 --- a/src/components/Fields/ArrayItemDetails.tsx +++ b/src/components/Fields/ArrayItemDetails.tsx @@ -18,14 +18,6 @@ export function ArrayItemDetails({ schema }: { schema: SchemaModel }) { return null; } - if (schema.type === 'string' && schema.pattern) { - return ( - - [] - - ); - } - return ( [ items diff --git a/src/components/Fields/FieldDetails.tsx b/src/components/Fields/FieldDetails.tsx index 40c1122f01..570c382f6f 100644 --- a/src/components/Fields/FieldDetails.tsx +++ b/src/components/Fields/FieldDetails.tsx @@ -8,7 +8,7 @@ import { TypePrefix, TypeTitle, } from '../../common-elements/fields'; -import { getSerializedValue, isObject } from '../../utils'; +import { getSerializedValue, isArray, isObject } from '../../utils'; import { ExternalDocumentation } from '../ExternalDocumentation/ExternalDocumentation'; import { Markdown } from '../Markdown/Markdown'; import { EnumValues } from './EnumValues'; @@ -30,7 +30,8 @@ export const FieldDetailsComponent = observer((props: FieldProps) => { const { showExamples, field, renderDiscriminatorSwitch } = props; const { schema, description, deprecated, extensions, in: _in, const: _const } = field; - const isArrayType = schema.type === 'array'; + const isArrayType = + schema.type === 'array' || (isArray(schema.type) && schema.type.includes('array')); const rawDefault = enumSkipQuotes || _in === 'header'; // having quotes around header field default values is confusing and inappropriate From 780caf1ef42b9ed94a4ba5e4c79ebc9bfea77fb3 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Mon, 30 Dec 2024 16:01:09 +0100 Subject: [PATCH 2/2] chore: improve tests --- src/components/__tests__/FieldDetails.test.tsx | 2 +- .../__snapshots__/FieldDetails.test.tsx.snap | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/__tests__/FieldDetails.test.tsx b/src/components/__tests__/FieldDetails.test.tsx index 0d70fe55cd..03331ed828 100644 --- a/src/components/__tests__/FieldDetails.test.tsx +++ b/src/components/__tests__/FieldDetails.test.tsx @@ -90,7 +90,7 @@ describe('FieldDetailsComponent', () => { items: { type: 'string', pattern: '^see regex[0-9]$', - constraints: [''], + constraints: ['<= 128 characters'], externalDocs: undefined, }, } as any as SchemaModel, diff --git a/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap b/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap index a8b1a44fac..5d6e6811c8 100644 --- a/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap @@ -161,13 +161,21 @@ exports[`FieldDetailsComponent renders correctly when field items have string ty - [ + [ items + + + + <= 128 characters + + ^see regex[0-9]$ - ] + ]