diff --git a/package/components/LocalProvider/index.js b/package/components/LocalProvider/index.js
index 72e7beb..e00f509 100644
--- a/package/components/LocalProvider/index.js
+++ b/package/components/LocalProvider/index.js
@@ -35,7 +35,9 @@ const langs = {
'enum_desc_msg': 'enum description',
'required': 'required',
'mock': 'mock',
- 'mockLink': 'Help'
+ 'mockLink': 'Help',
+ 'integerFormat': 'integer format',
+ 'className': 'class name'
},
zh_CN: {
'title': '标题',
@@ -70,7 +72,9 @@ const langs = {
'enum_desc_msg': '备注描述信息',
'required': '是否必须',
'mock': 'mock',
- 'mockLink': '查看文档'
+ 'mockLink': '查看文档',
+ 'integerFormat': '整数类型',
+ 'className': '对象类名'
}
}
diff --git a/package/components/SchemaComponents/SchemaJson.js b/package/components/SchemaComponents/SchemaJson.js
index cbfcea1..e48e80f 100644
--- a/package/components/SchemaComponents/SchemaJson.js
+++ b/package/components/SchemaComponents/SchemaJson.js
@@ -179,7 +179,7 @@ class SchemaArray extends PureComponent {
this.handleShowEdit('title')} />}
placeholder={LocaleProvider('title')}
- value={value.title}
+ value={items.title}
onChange={this.handleChangeTitle}
/>
diff --git a/package/components/SchemaComponents/SchemaOther.js b/package/components/SchemaComponents/SchemaOther.js
index 04a61cc..fa3cf0e 100644
--- a/package/components/SchemaComponents/SchemaOther.js
+++ b/package/components/SchemaComponents/SchemaOther.js
@@ -31,6 +31,52 @@ const changeOtherValue = (value, name, data, change) => {
change(data);
};
+class SchemaObject extends PureComponent {
+ constructor(props) {
+ super(props);
+ this.state = {
+ checked: _.isUndefined(props.data.enum) ? false : true
+ };
+ }
+
+ componentWillReceiveProps(nextprops) {
+ if (this.props.data.enum !== nextprops.data.enum) {
+ this.setState({
+ checked: _.isUndefined(nextprops.data.enum) ? false : true
+ });
+ }
+ }
+
+ changeClassNameValue = (value, data) => {
+ data["$$ref"] = "#/definitions/" + value;
+ this.context.changeCustomValue(data);
+ };
+
+ render() {
+ const { data } = this.props;
+ return (
+
+
{LocalProvider('base_setting')}
+
+
+ {LocalProvider('className')}:
+
+
+ this.changeClassNameValue(e.target.value, data)}
+ />
+
+
+
+ );
+ }
+}
+SchemaObject.contextTypes = {
+ changeCustomValue: PropTypes.func
+};
+
class SchemaString extends PureComponent {
constructor(props, context) {
super(props);
@@ -424,6 +470,242 @@ SchemaNumber.contextTypes = {
changeCustomValue: PropTypes.func
};
+class SchemaInteger extends PureComponent {
+
+ constructor(props, context) {
+ super(props);
+ this.state = {
+ checked: _.isUndefined(props.data.enum) ? false : true,
+ enum: _.isUndefined(props.data.enum) ? '' : props.data.enum.join('\n')
+ };
+ this.format = context.Model.__jsonIntegerFormat;
+ }
+
+ componentWillReceiveProps(nextprops) {
+ const enumStr = _.isUndefined(this.props.data.enum) ? '' : this.props.data.enum.join('\n');
+ const nextEnumStr = _.isUndefined(nextprops.data.enum) ? '' : nextprops.data.enum.join('\n');
+ if (enumStr !== nextEnumStr) {
+ this.setState({ enum: nextEnumStr });
+ }
+ }
+
+ changeOtherValue = (value, name, data) => {
+ data[name] = value;
+ this.context.changeCustomValue(data);
+ };
+
+ onChangeCheckBox = (checked, data) => {
+ this.setState({
+ checked
+ });
+
+ if (!checked) {
+ delete data.enum;
+ this.setState({ enum: '' });
+ this.context.changeCustomValue(data);
+ }
+ };
+
+ changeEnumOtherValue = (value, data) => {
+ this.setState({ enum: value });
+ var arr = value.split('\n');
+ if (arr.length === 0 || (arr.length == 1 && !arr[0])) {
+ delete data.enum;
+ this.context.changeCustomValue(data);
+ } else {
+ data.enum = arr.map(item => +item);
+ this.context.changeCustomValue(data);
+ }
+ };
+
+ onEnterEnumOtherValue = (value, data) => {
+ let arr = value.split('\n').map(item => +item);
+ data.enum = arr;
+ this.context.changeCustomValue(data);
+ };
+
+ changeEnumDescOtherValue = (value, data) => {
+ data.enumDesc = value;
+ this.context.changeCustomValue(data);
+ };
+
+ render() {
+ const { data } = this.props;
+ return (
+
+
{LocalProvider('base_setting')}
+
+
+ {LocalProvider('integerFormat')}:
+
+
+
+
+
+ {LocalProvider('default')}:
+
+
+
+ changeOtherValue(e.target.value, 'default', data, this.context.changeCustomValue)
+ }
+ />
+
+
+
+
+
+
+
+ exclusiveMinimum
+
+
+
+ :
+
+
+
+
+ changeOtherValue(e, 'exclusiveMinimum', data, this.context.changeCustomValue)
+ }
+ />
+
+
+
+
+
+
+
+ exclusiveMaximum
+
+
+
+ :
+
+
+
+
+ changeOtherValue(e, 'exclusiveMaximum', data, this.context.changeCustomValue)
+ }
+ />
+
+
+
+
+
+
+
+
+ {LocalProvider('minimum')}:
+
+
+
+ changeOtherValue(e, 'minimum', data, this.context.changeCustomValue)
+ }
+ />
+
+
+
+
+
+
+ {LocalProvider('maximum')}:
+
+
+
+ changeOtherValue(e, 'maximum', data, this.context.changeCustomValue)
+ }
+ />
+
+
+
+
+
+
+
+ {LocalProvider('enum')}
+ this.onChangeCheckBox(e.target.checked, data)}
+ />{' '}
+ :
+
+
+
+
+ {this.state.checked && (
+
+
+ {LocalProvider('enum_desc')} :
+
+
+
+ )}
+
+ );
+ }
+}
+
+SchemaInteger.contextTypes = {
+ changeCustomValue: PropTypes.func,
+ Model: PropTypes.object
+};
+
const SchemaBoolean = (props, context) => {
const { data } = props;
let value = _.isUndefined(data.default) ? '' : data.default ? 'true' : 'false';
@@ -526,7 +808,8 @@ const mapping = data => {
string: ,
number: ,
boolean: ,
- integer: ,
+ integer: ,
+ object: ,
array:
}[data.type];
};
diff --git a/package/index.js b/package/index.js
index db3a00a..3ede1c7 100644
--- a/package/index.js
+++ b/package/index.js
@@ -18,6 +18,11 @@ module.exports = (config = {})=>{
} else {
Model.__jsonSchemaFormat = utils.format
}
+ if(config.integerFormat){
+ Model.__jsonIntegerFormat = config.integerFormat
+ } else {
+ Model.__jsonIntegerFormat = utils.integerFormat
+ }
if(config.mock) {
Model.__jsonSchemaMock = config.mock
diff --git a/package/utils.js b/package/utils.js
index 0129834..b69df87 100644
--- a/package/utils.js
+++ b/package/utils.js
@@ -10,6 +10,11 @@ exports.format = [
{ name: 'ipv6' },
{ name: 'uri' }
];
+exports.integerFormat = [
+ { title: 'Integer', name: 'int32' },
+ { title: 'Long', name: 'int64' },
+ { title: 'Short', name: 'int16' }
+];
const _ = require('underscore');
exports.SCHEMA_TYPE = ['string', 'number', 'array', 'object', 'boolean', 'integer'];
exports.defaultSchema = {