Skip to content

Commit 4bcd27c

Browse files
author
Jakub Jankowski
authored
fix: array subtype (#46)
* fix: setting array subtype * test: add Prorerty tests * chore: update inferType
1 parent dcc8eea commit 4bcd27c

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { shallow } from 'enzyme';
2+
import 'jest-enzyme';
3+
import * as React from 'react';
4+
import { SchemaNodeWithMeta } from '../../types';
5+
import { Property, Types } from '../shared';
6+
7+
describe('Property component', () => {
8+
it('should render Types with propper type and subtype', () => {
9+
const node: SchemaNodeWithMeta = {
10+
id: '1',
11+
type: 'array',
12+
items: {
13+
type: 'string',
14+
},
15+
annotations: {
16+
examples: {},
17+
},
18+
validations: {},
19+
path: [],
20+
};
21+
22+
const wrapper = shallow(<Property node={node} />);
23+
expect(wrapper.find(Types)).toExist();
24+
expect(wrapper.find(Types)).toHaveProp('type', 'array');
25+
expect(wrapper.find(Types)).toHaveProp('subtype', 'string');
26+
});
27+
});

src/utils/inferType.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { JSONSchema4, JSONSchema4TypeName } from 'json-schema';
22
import { SchemaKind } from '../types';
33

4-
export function inferType(node: JSONSchema4): JSONSchema4TypeName | undefined {
4+
export function inferType(node: JSONSchema4): JSONSchema4TypeName | JSONSchema4TypeName[] | undefined {
5+
if ('type' in node) {
6+
return node.type;
7+
}
8+
59
if ('properties' in node) {
610
return SchemaKind.Object;
711
}

0 commit comments

Comments
 (0)