Skip to content

Commit

Permalink
fix: skipReadOnly/skipWritOnly not passing down to nested OneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 5, 2018
1 parent 02c2413 commit 2462639
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Schema/OneOfSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class OneOfSchema extends React.Component<SchemaProps> {
<OneOfButton key={subSchema._$ref} schema={schema} subSchema={subSchema} idx={idx} />
))}
</OneOfList>
<Schema schema={oneOf[schema.activeOneOf]} />
<Schema {...this.props} schema={oneOf[schema.activeOneOf]} />
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Schema/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
}

if (oneOf !== undefined) {
return <OneOfSchema schema={schema} />;
return <OneOfSchema schema={schema} {...this.props} />;
}

switch (type) {
Expand Down
44 changes: 44 additions & 0 deletions src/components/Schema/__tests__/OneOfSchema.test.tsx
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
});

0 comments on commit 2462639

Please sign in to comment.