diff --git a/src/components/Fields/FieldDetails.tsx b/src/components/Fields/FieldDetails.tsx index 7bdab8a186..40c1122f01 100644 --- a/src/components/Fields/FieldDetails.tsx +++ b/src/components/Fields/FieldDetails.tsx @@ -51,10 +51,10 @@ export const FieldDetailsComponent = observer((props: FieldProps) => { return null; }, [field, showExamples]); - - const defaultValue = isObject(schema.default) - ? getSerializedValue(field, schema.default).replace(`${field.name}=`, '') - : schema.default; + const defaultValue = + isObject(schema.default) && field.in + ? getSerializedValue(field, schema.default).replace(`${field.name}=`, '') + : schema.default; return (
diff --git a/src/components/__tests__/FieldDetails.test.tsx b/src/components/__tests__/FieldDetails.test.tsx index 703dc3eabb..04982bb93c 100644 --- a/src/components/__tests__/FieldDetails.test.tsx +++ b/src/components/__tests__/FieldDetails.test.tsx @@ -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()); + + expect(wrapper.render()).toMatchSnapshot(); + }); }); diff --git a/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap b/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap index 77ccf56695..801106e744 100644 --- a/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/FieldDetails.test.tsx.snap @@ -37,7 +37,73 @@ exports[`FieldDetailsComponent renders correctly 1`] = ` - "" + [] + +
+ +
+ + Example: + + + + "example" + +
+
+
+

+ test description +

+ + +
+
+ +`; + +exports[`FieldDetailsComponent renders correctly when default value is object in request body 1`] = ` +
+
+ + + object + + + (test title) + + + + + + + +
+
+ + Default: + + + + {"properties":{}}