2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the 'License');
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import {Factory} from 'rosie';
18 const parsePropertiesForSchema = (obj) => {
19 let schemaProperties = {};
21 Object.keys(obj).forEach(prop => {
22 let type = typeof obj[prop];
23 if (type === undefined){throw new Error('Schema property cannot be undefined');}
24 if (type === 'object'){
25 if (Array.isArray(obj[prop])) {
26 schemaProperties[prop] = {type: 'array'};
27 } else if (Object.is(obj[prop], null)){
28 throw new Error('Schema property cannot be null');
30 schemaProperties[prop] = {properties: parsePropertiesForSchema(obj[prop]), type: 'object'};
33 schemaProperties[prop] = {type};
37 return schemaProperties;
40 export default new Factory()
42 const propertiesForSchema = parsePropertiesForSchema(schema);
43 for (let attribute in schema) {
44 delete schema[attribute];
46 schema.$schema = 'http://json-schema.org/draft-04/schema#';
47 schema.type = 'object';
48 schema.properties = propertiesForSchema;
52 export const SchemaGenericFieldInfoFactory = new Factory()
54 'general/affinityData': {
58 'enum': [{'enum': 'Affinity', 'title': 'Affinity'}, {
59 'enum': 'Anti Affinity',
60 'title': 'Anti Affinity'
61 }, {'enum': 'None', 'title': 'None'}],
65 'general/availability/useAvailabilityZonesForHighAvailability': {
72 'general/regionsData/multiRegion': {
79 'general/regionsData/regions': {
82 'enum': [{'enum': 'Alphareta', 'title': 'Alphareta'}, {
85 }, {'enum': 'Dallas', 'title': 'Dallas'}, {
86 'enum': 'Fairfield CA',
87 'title': 'Fairfield CA'
88 }, {'enum': 'Hayward CA', 'title': 'Hayward CA'}, {'enum': 'Lisle', 'title': 'Lisle'}, {
91 }, {'enum': 'San Diego', 'title': 'San Diego'}, {'enum': 'Secaucus', 'title': 'Secaucus'}],
94 'enum': ['', 'Alphareta', 'Birmingham', 'Dallas', 'Fairfield CA', 'Hayward CA', 'Lisle', 'Mission', 'San Diego', 'Secaucus'],
99 'general/storageDataReplication/storageReplicationAcrossRegion': {
106 'general/storageDataReplication/storageReplicationSize': {
110 'exclusiveMaximum': true,
111 'validations': [{'type': 'maximumExclusive', 'data': 100}]
113 'general/storageDataReplication/storageReplicationFrequency': {
117 'validations': [{'type': 'minimum', 'data': 5}]
119 'general/storageDataReplication/storageReplicationSource': {
123 'validations': [{'type': 'maxLength', 'data': 300}]
125 'general/storageDataReplication/storageReplicationDestination': {
129 'validations': [{'type': 'maxLength', 'data': 300}]