fix: skipReadOnly/skipWritOnly not passing down to nested OneOf

This commit is contained in:
Roman Hotsiy 2018-03-05 13:31:27 +02:00
parent 02c2413da8
commit 2462639f76
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
3 changed files with 46 additions and 2 deletions

View File

@ -47,7 +47,7 @@ export class OneOfSchema extends React.Component<SchemaProps> {
<OneOfButton key={subSchema._$ref} schema={schema} subSchema={subSchema} idx={idx} /> <OneOfButton key={subSchema._$ref} schema={schema} subSchema={subSchema} idx={idx} />
))} ))}
</OneOfList> </OneOfList>
<Schema schema={oneOf[schema.activeOneOf]} /> <Schema {...this.props} schema={oneOf[schema.activeOneOf]} />
</div> </div>
); );
} }

View File

@ -52,7 +52,7 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
} }
if (oneOf !== undefined) { if (oneOf !== undefined) {
return <OneOfSchema schema={schema} />; return <OneOfSchema schema={schema} {...this.props} />;
} }
switch (type) { switch (type) {

View File

@ -0,0 +1,44 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import { filterPropsDeep } from '../../../utils/test-utils';
import { RedocNormalizedOptions } from '../../../services/RedocNormalizedOptions';
import { OpenAPIParser, SchemaModel } from '../../../services';
import { Schema } from '../Schema';
import { OneOfSchema } from '../OneOfSchema';
const options = new RedocNormalizedOptions({});
describe('Components', () => {
describe('SchemaView', () => {
describe('OneOf', () => {
it('should pass down skipReadOnly/skipReadWrite to nested oneOf', () => {
const parser = new OpenAPIParser(
{ openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} },
undefined,
options,
);
const schema = new SchemaModel(
parser,
{ oneOf: [{ type: 'string' }, { type: 'integer' }] },
'',
options,
);
let schemaViewElement = shallow(
<Schema schema={schema} skipWriteOnly={true} />,
).getElement();
expect(schemaViewElement.type).toEqual(OneOfSchema);
expect(schemaViewElement.props.skipWriteOnly).toBeTruthy();
expect(schemaViewElement.props.skipReadOnly).toBeFalsy();
schemaViewElement = shallow(<Schema schema={schema} skipReadOnly={true} />).getElement();
expect(schemaViewElement.type).toEqual(OneOfSchema);
expect(schemaViewElement.props.skipWriteOnly).toBeFalsy();
expect(schemaViewElement.props.skipReadOnly).toBeTruthy();
});
});
});
});