mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-10 19:06:34 +03:00
fix: default value as object in request body (#2437)
This commit is contained in:
parent
ba7cd0a130
commit
b36a6e27bb
|
@ -51,8 +51,8 @@ export const FieldDetailsComponent = observer((props: FieldProps) => {
|
|||
|
||||
return null;
|
||||
}, [field, showExamples]);
|
||||
|
||||
const defaultValue = isObject(schema.default)
|
||||
const defaultValue =
|
||||
isObject(schema.default) && field.in
|
||||
? getSerializedValue(field, schema.default).replace(`${field.name}=`, '')
|
||||
: schema.default;
|
||||
|
||||
|
|
|
@ -44,4 +44,36 @@ describe('FieldDetailsComponent', () => {
|
|||
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('renders correctly when default value is object in request body', () => {
|
||||
const mockFieldProps = {
|
||||
showExamples: true,
|
||||
field: {
|
||||
schema: {
|
||||
type: 'object',
|
||||
default: { properties: {} },
|
||||
displayType: 'object',
|
||||
title: 'test title',
|
||||
externalDocs: undefined,
|
||||
constraints: [''],
|
||||
} as SchemaModel,
|
||||
example: 'example',
|
||||
name: 'name',
|
||||
expanded: false,
|
||||
required: false,
|
||||
kind: '',
|
||||
deprecated: false,
|
||||
collapse: jest.fn(),
|
||||
toggle: jest.fn(),
|
||||
explode: false,
|
||||
expand: jest.fn(),
|
||||
description: 'test description',
|
||||
in: undefined,
|
||||
},
|
||||
renderDiscriminatorSwitch: jest.fn(),
|
||||
};
|
||||
const wrapper = shallow(withTheme(<FieldDetails {...mockFieldProps} />));
|
||||
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -37,7 +37,73 @@ exports[`FieldDetailsComponent renders correctly 1`] = `
|
|||
<span
|
||||
class="sc-kpDqfm sc-eldPxv cGRfjn ehWiAn"
|
||||
>
|
||||
""
|
||||
[]
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span
|
||||
class="sc-kpDqfm cGRfjn"
|
||||
>
|
||||
Example:
|
||||
</span>
|
||||
|
||||
<span
|
||||
class="sc-kpDqfm sc-eldPxv cGRfjn ehWiAn"
|
||||
>
|
||||
"example"
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<div
|
||||
class="sc-lcIPJg sc-hknOHE gBHqkN jFBMaE"
|
||||
>
|
||||
<p>
|
||||
test description
|
||||
</p>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`FieldDetailsComponent renders correctly when default value is object in request body 1`] = `
|
||||
<div>
|
||||
<div>
|
||||
<span
|
||||
class="sc-kpDqfm sc-dAlyuH cGRfjn gHomYR"
|
||||
/>
|
||||
<span
|
||||
class="sc-kpDqfm sc-jlZhew cGRfjn dYtiIA"
|
||||
>
|
||||
object
|
||||
</span>
|
||||
<span
|
||||
class="sc-kpDqfm sc-cwHptR cGRfjn gyVIPr"
|
||||
>
|
||||
(test title)
|
||||
</span>
|
||||
<span>
|
||||
|
||||
<span
|
||||
class="sc-kpDqfm sc-gFqAkR cGRfjn fYEICH"
|
||||
>
|
||||
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span
|
||||
class="sc-kpDqfm cGRfjn"
|
||||
>
|
||||
Default:
|
||||
</span>
|
||||
|
||||
<span
|
||||
class="sc-kpDqfm sc-eldPxv cGRfjn ehWiAn"
|
||||
>
|
||||
{"properties":{}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user