Skip to content

Commit 2462639

Browse files
committed
fix: skipReadOnly/skipWritOnly not passing down to nested OneOf
1 parent 02c2413 commit 2462639

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/components/Schema/OneOfSchema.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class OneOfSchema extends React.Component<SchemaProps> {
4747
<OneOfButton key={subSchema._$ref} schema={schema} subSchema={subSchema} idx={idx} />
4848
))}
4949
</OneOfList>
50-
<Schema schema={oneOf[schema.activeOneOf]} />
50+
<Schema {...this.props} schema={oneOf[schema.activeOneOf]} />
5151
</div>
5252
);
5353
}

src/components/Schema/Schema.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class Schema extends React.Component<Partial<SchemaProps>> {
5252
}
5353

5454
if (oneOf !== undefined) {
55-
return <OneOfSchema schema={schema} />;
55+
return <OneOfSchema schema={schema} {...this.props} />;
5656
}
5757

5858
switch (type) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as React from 'react';
2+
import { shallow } from 'enzyme';
3+
import toJson from 'enzyme-to-json';
4+
5+
import { filterPropsDeep } from '../../../utils/test-utils';
6+
7+
import { RedocNormalizedOptions } from '../../../services/RedocNormalizedOptions';
8+
import { OpenAPIParser, SchemaModel } from '../../../services';
9+
import { Schema } from '../Schema';
10+
import { OneOfSchema } from '../OneOfSchema';
11+
12+
const options = new RedocNormalizedOptions({});
13+
describe('Components', () => {
14+
describe('SchemaView', () => {
15+
describe('OneOf', () => {
16+
it('should pass down skipReadOnly/skipReadWrite to nested oneOf', () => {
17+
const parser = new OpenAPIParser(
18+
{ openapi: '3.0', info: { title: 'test', version: '0' }, paths: {} },
19+
undefined,
20+
options,
21+
);
22+
23+
const schema = new SchemaModel(
24+
parser,
25+
{ oneOf: [{ type: 'string' }, { type: 'integer' }] },
26+
'',
27+
options,
28+
);
29+
let schemaViewElement = shallow(
30+
<Schema schema={schema} skipWriteOnly={true} />,
31+
).getElement();
32+
expect(schemaViewElement.type).toEqual(OneOfSchema);
33+
expect(schemaViewElement.props.skipWriteOnly).toBeTruthy();
34+
expect(schemaViewElement.props.skipReadOnly).toBeFalsy();
35+
36+
schemaViewElement = shallow(<Schema schema={schema} skipReadOnly={true} />).getElement();
37+
38+
expect(schemaViewElement.type).toEqual(OneOfSchema);
39+
expect(schemaViewElement.props.skipWriteOnly).toBeFalsy();
40+
expect(schemaViewElement.props.skipReadOnly).toBeTruthy();
41+
});
42+
});
43+
});
44+
});

0 commit comments

Comments
 (0)