Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: displaying nested items with type string #2634

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/components/Fields/ArrayItemDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ export function ArrayItemDetails({ schema }: { schema: SchemaModel }) {
return null;
}

if (schema.type === 'string' && schema.pattern) {
return (
<Wrapper>
[<Pattern schema={schema} />]
</Wrapper>
);
}

return (
<Wrapper>
[ items
Expand Down
5 changes: 3 additions & 2 deletions src/components/Fields/FieldDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/components/__tests__/FieldDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('FieldDetailsComponent', () => {
items: {
type: 'string',
pattern: '^see regex[0-9]$',
constraints: [''],
constraints: ['<= 128 characters'],
externalDocs: undefined,
},
} as any as SchemaModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,21 @@ exports[`FieldDetailsComponent renders correctly when field items have string ty
<span
class="sc-kpDqfm sc-dAlyuH sc-dxcDKg cGRfjn gHomYR gXntsr"
>
[
[ items
<span>

<span
class="sc-kpDqfm sc-gFqAkR cGRfjn fYEICH"
>
&lt;= 128 characters
</span>
</span>
<span
class="sc-kpDqfm sc-eDPEul cGRfjn cCKYVD"
>
^see regex[0-9]$
</span>
]
]
</span>
</div>

Expand Down
Loading