Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.handlePlusButtonTap = () => {
// 要素を追加します。
let newVal = deepClone(this.opts.val);
// 未定義なら空配列を生成する。
if (isUndefined(newVal)) {
newVal = [];
}
const items = schemaObject.items;
// type値によって作成する要素を分ける。
// @see: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#items-object
// typeは"string", "number", "integer", "boolean", or "array"のいずれかと書いてあるが、"null"と"object"もプラスで想定する。
// 追加分は先頭に。
switch (items.type) {
case 'string':
case 'number':
case 'integer':
case 'boolean':
case 'null':
newVal = append([undefined], newVal);
const checkParameterObject = (parameterObject, val) => {
const name = parameterObject.name;
const _default = parameterObject.default;
const required = parameterObject.required;
const _in = parameterObject.in;
// 値が設定されていればスルー。
if (!isUndefined(val[name])) {
return;
}
// defaultが設定されていればそれを使用する。
if (!isUndefined(_default)) {
val[name] = deepClone(_default);
return;
}
// requiredがfalseならスルー。
if (!required) {
return;
}
// この時点で、入力必須だけどユーザ未入力な状態。可能な限り初期値を設定する。
// inは"query", "header", "path", "formData", "body"のいずれか。
if (contains(['formData', 'header', 'path', 'query'], _in)) {
// 初期値設定不可能。
return;
}
// この時点でinは必ず'body'になる。
const schema = parameterObject.schema;
if (contains(['boolean', 'integer', 'number', 'null', 'string'], schema.type)) {
// 初期値設定不可能。
// ItemsObjectのtype値は"string", "number", "integer", "boolean", "array"のいずれか。
// @see: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields-8
// OAS2.0仕様通りではないが、"object"と"null"も許可する。
this.isFormMode = contains(['boolean', 'integer', 'number', 'null', 'string'], itemsObject.type);
this.isPropertiesMode = (itemsObject.type === 'object');
this.isItemsMode = (itemsObject.type === 'array');
if (this.isFormMode) {
const formObject = deepClone(itemsObject);
this.formObject = formObject;
}
if (this.isPropertiesMode) {
const propertiesObject = deepClone(itemsObject);
this.propertiesObject = propertiesObject;
}
if (this.isItemsMode) {
const _itemsObject = deepClone(itemsObject.items);
this.itemsObject = _itemsObject;
}
// エラー関連。
this.errors = [];
this.hasError = false;
const validate = () => {
this.errors = validator.errors(this.opts.val, ObjectAssign({
required: this.opts.required
}, schemaObject));
this.hasError = !!this.errors.length;
if (!this.opts.onvalidate) {
return;
}
this.opts.onvalidate(this._riot_id, !this.hasError);
};
export default function() {
const schemaObject = this.schemaObject = this.opts.schemaobject;
const itemsObject = this.opts.schemaobject.items;
// ItemsObjectのtype値は"string", "number", "integer", "boolean", "array"のいずれか。
// @see: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields-8
// OAS2.0仕様通りではないが、"object"と"null"も許可する。
this.isFormMode = contains(['boolean', 'integer', 'number', 'null', 'string'], itemsObject.type);
this.isPropertiesMode = (itemsObject.type === 'object');
this.isItemsMode = (itemsObject.type === 'array');
if (this.isFormMode) {
const formObject = deepClone(itemsObject);
this.formObject = formObject;
}
if (this.isPropertiesMode) {
const propertiesObject = deepClone(itemsObject);
this.propertiesObject = propertiesObject;
}
if (this.isItemsMode) {
const _itemsObject = deepClone(itemsObject.items);
this.itemsObject = _itemsObject;
}
// エラー関連。
this.errors = [];
this.hasError = false;
const validate = () => {
this.errors = validator.errors(this.opts.val, ObjectAssign({
required: this.opts.required
}, schemaObject));
this.hasError = !!this.errors.length;
if (!this.opts.onvalidate) {
return;
export default function() {
const schemaObject = this.schemaObject = this.opts.schemaobject;
const itemsObject = this.opts.schemaobject.items;
// ItemsObjectのtype値は"string", "number", "integer", "boolean", "array"のいずれか。
// @see: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields-8
// OAS2.0仕様通りではないが、"object"と"null"も許可する。
this.isFormMode = contains(['boolean', 'integer', 'number', 'null', 'string'], itemsObject.type);
this.isPropertiesMode = (itemsObject.type === 'object');
this.isItemsMode = (itemsObject.type === 'array');
if (this.isFormMode) {
const formObject = deepClone(itemsObject);
this.formObject = formObject;
}
if (this.isPropertiesMode) {
const propertiesObject = deepClone(itemsObject);
this.propertiesObject = propertiesObject;
}
if (this.isItemsMode) {
const _itemsObject = deepClone(itemsObject.items);
this.itemsObject = _itemsObject;
}
// エラー関連。
this.errors = [];
this.hasError = false;
const validate = () => {
this.errors = validator.errors(this.opts.val, ObjectAssign({
required: this.opts.required
this.itemsLabel = parameterObject.description || parameterObject.name;
this.spreadStyle = 'spreadFull';
}
} else {
// inがbodyの場合。
// @see: https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.2
// primitive typesは"array","boolean","integer","number","null","object","string"の7つと定義されている。
const schema = parameterObject.schema;
if (contains(['boolean', 'integer', 'number', 'null', 'string'], schema.type)) {
this.isFormMode = true;
const formObject = deepClone(parameterObject.schema);
this.formObject = formObject;
this.spreadStyle = util.getSpreadStyle(formObject);
} else if (schema.type === 'object') {
this.isPropertiesMode = true;
const propertiesObject = deepClone(schema);
this.propertiesObject = propertiesObject;
this.propertiesLabel = parameterObject.description || parameterObject.name;
this.spreadStyle = 'spreadFull';
} else {
// typeがarrayの場合。
this.isItemsMode = true;
const schemaObject = deepClone(schema);
this.schemaObject = schemaObject;
this.itemsLabel = parameterObject.description || parameterObject.name;
this.spreadStyle = 'spreadFull';
}
}
/**
* Parameter when submit
* @param {String} key
// Items関連。
this.isItemsMode = false;
this.schemaObject = null;
this.itemsLabel = null;
// 横幅調整。
this.spreadStyle = 'spreadSmall';
// 各変数を設定。
// `in`の値は"query", "header", "path", "formData", "body"のいずれか。
// @see: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object
if (contains(['query', 'header', 'path', 'formData'], parameterObject.in)) {
// `in`が`body`以外の場合、typeは必ず"string", "number", "integer", "boolean", "array", "fileのいずれかになる。
if (contains(['string', 'number', 'integer', 'boolean', 'file'], parameterObject.type)) {
this.isFormMode = true;
const formObject = deepClone(parameterObject);
delete formObject.in;
this.formObject = formObject;
this.spreadStyle = util.getSpreadStyle(formObject);
// テーブルのprimaryKeyとnameが一致した場合は、入力フォームを強制的にdisableにします。
if (parameterObject.in === 'path' && parameterObject.name === this.opts.primary) {
this.isFormDisabled = true;
}
} else {
// typeがarrayの場合。
this.isItemsMode = true;
const schemaObject = deepClone(parameterObject);
this.schemaObject = schemaObject;
this.itemsLabel = parameterObject.description || parameterObject.name;
this.spreadStyle = 'spreadFull';
}
} else {
this.getFormObject = (key, property) => {
const ret = deepClone(property);
ret.name = key;
ret.required = contains(propertiesObject.required, key);
return ret;
};
const trimNull = obj => {
const ret = deepClone(obj);
const trim = val => {
let loop;
if (isObject(val)) {
loop = forOwn;
} else if (isArray(val)) {
loop = forEach;
} else {
return;
}
loop(val, (v, k) => {
if (isNull(v)) {
val[k] = undefined;
}
if (isObject(v) || isArray(v)) {
trim(v);
}
this.getSchemaObject = (key, property) => {
const ret = deepClone(property);
return ret;
};