Class: Blufin::YmlSchemaValidator
- Inherits:
-
YmlValidatorBase
- Object
- YmlValidatorBase
- Blufin::YmlSchemaValidator
- Defined in:
- lib/core/yml/schema/yml_schema_validator.rb
Constant Summary collapse
- ID =
'id'
- TYPE =
'type'
- TYPE_BOOLEAN =
'BOOLEAN'
- TYPE_DATE =
'DATE'
- TYPE_DATETIME =
'DATETIME'
- TYPE_DATETIME_INSERT =
'DATETIME_INSERT'
- TYPE_DATETIME_UPDATE =
'DATETIME_UPDATE'
- TYPE_DECIMAL =
'DECIMAL'
- TYPE_ENUM =
'ENUM'
- TYPE_ENUM_CUSTOM =
'ENUM_CUSTOM'
- TYPE_ENUM_SYSTEM =
'ENUM_SYSTEM'
- TYPE_INT =
'INT'
- TYPE_INT_AUTO =
'INT_AUTO'
- TYPE_INT_TINY =
'INT_TINY'
- TYPE_INT_SMALL =
'INT_SMALL'
- TYPE_INT_BIG =
'INT_BIG'
- TYPE_TEXT =
'TEXT'
- TYPE_TEXT_LONG =
'TEXT_LONG'
- TYPE_VARCHAR =
'VARCHAR'
- FLAG =
'flag'
- FLAG_AUTO_INCREMENT =
'AUTO_INCREMENT'
- FLAG_INDEX =
'INDEX'
- FLAG_NULLABLE =
'NULLABLE'
- FLAG_PRIMARY_KEY =
'PRIMARY_KEY'
- FLAG_UNIQUE =
'UNIQUE'
- FKEY =
'fkey'
- LINK =
'link'
- DESCRIPTION =
'description'
- DESCRIPTION_TEXT =
'description_text'
- DESCRIPTION_TYPE =
'description_type'
- DESCRIPTION_HITS =
'description_hits'
- TRANSIENT =
'transient'
- REQUIRED =
'required'
- REQUIRED_IF =
'required_if'
- REQUIRED_IF_ENUM =
'required_if_enum'
- CHILD_OF =
'child_of'
- CHILD_TYPE =
'child_type'
- ENCRYPTED =
'encrypted'
- CURRENCY =
'currency'
- AMOUNT =
'amount'
- ERROR_MULTIPLE_FILES =
'Multiple files'
- VALID_SCHEMAS =
%w(app common config mock)
- VALID_SCHEMAS_REGEX =
'app|common|config|mock'
- VALID_SCHEMAS_GENERATE =
%w(app common config)
- APP =
'app'
- CONFIG =
'config'
- COMMON =
'common'
- MOCK =
'mock'
- REGEX_DECIMAL =
/\ADECIMAL\(\d{1,2},\d{1,2}\)\z/
- REGEX_ENUM =
/\AENUM\('[A-Za-z_',]+'\)\z/
- REGEX_ENUM_CUSTOM =
/\AENUM_CUSTOM\('[A-Za-z]+'\)\z/
- REGEX_ENUM_SYSTEM =
/\AENUM_SYSTEM\('[A-Za-z]+'\)\z/
- REGEX_VARCHAR =
/\AVARCHAR\(\d+\)\z/
- RESOURCE_TYPE_PARENT =
'PARENT'
- RESOURCE_TYPE_OBJECT =
'OBJECT'
- RESOURCE_TYPE_OBJECT_LIST =
'OBJECT_LIST'
- RESOURCE_TYPE_OBJECT_LINK =
'OBJECT_LINK'
- INT_TYPES =
[ TYPE_INT, TYPE_INT_AUTO ]
- TEXT_TYPES =
[ TYPE_TEXT, TYPE_TEXT_LONG ]
- DATETIME_TYPES =
[ TYPE_DATETIME, TYPE_DATETIME_INSERT, TYPE_DATETIME_UPDATE, TYPE_DATE ]
- RESOURCE_SCHEMA =
'schema'
- RESOURCE_TABLE =
'table'
- MAX_TABLE_CHARACTERS =
64
- CONFIG_INTERNAL =
'internal'
- CONFIG_OAUTH =
'oauth'
- PATH_TO_CONFIG_YML =
"#{App::Opt::get_base_path}#{App::Opt::OPT_PATH_YML}/api/schema"
- RESERVED_WORDS =
%w(abstract assert boolean break byte case catch char class const continue data_type default do double else enum extends false final finally float for goto if implements import instanceof int interface list long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while)
- STRUCTURE =
[ { :section_name => 'config', :section_type => Blufin::YmlValidatorBase::SECTION_TYPE_FIXED, :section_data => { CONFIG_INTERNAL => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_NESTED_DATA, :required => false, :section_data => { 'GET' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false }, 'POST' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false }, 'PUT' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false }, 'PATCH' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false }, 'DELETE' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false } } }, CONFIG_OAUTH => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_NESTED_DATA, :required => false, :section_data => { 'GET' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false }, 'POST' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false }, 'PUT' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false }, 'PATCH' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false }, 'DELETE' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, :required => false } } }, 'description' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :required => false } } }, { :section_name => 'schema', :section_type => Blufin::YmlValidatorBase::SECTION_TYPE_DYNAMIC, :section_data => { :section_alphabetical => false, :section_regex => /\A(app\.|common\.|config\.|mock\.|mock\.)*[a-z_]+(\[\]|\[link\])*\z/, :section_fields => { 'type' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :required => false }, 'flag' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :required => false }, 'fkey' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :required => false }, 'encrypted' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :required => false }, 'description' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :required => false }, 'required' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_BOOLEAN, :required => false }, 'required_if' => { :type => Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, :required => false }, } } } ]
Constants inherited from YmlValidatorBase
Blufin::YmlValidatorBase::FIELD_TYPE_ARRAY, Blufin::YmlValidatorBase::FIELD_TYPE_BLANK, Blufin::YmlValidatorBase::FIELD_TYPE_BOOLEAN, Blufin::YmlValidatorBase::FIELD_TYPE_FILE, Blufin::YmlValidatorBase::FIELD_TYPE_FLOAT, Blufin::YmlValidatorBase::FIELD_TYPE_NESTED_DATA, Blufin::YmlValidatorBase::FIELD_TYPE_TEXT, Blufin::YmlValidatorBase::SECTION_MATCHES_FILENAME, Blufin::YmlValidatorBase::SECTION_TYPE_ARRAY, Blufin::YmlValidatorBase::SECTION_TYPE_DYNAMIC, Blufin::YmlValidatorBase::SECTION_TYPE_FIXED
Instance Method Summary collapse
-
#extract_flags(flags) ⇒ Object
Use this to extract flags OUTSIDE the validator.
-
#get_errors_array ⇒ Object
Array.
-
#get_schema_config ⇒ Object
Hash.
-
#get_schema_data ⇒ Object
Hash.
-
#get_schema_descriptions ⇒ Object
Hash.
-
#get_schema_fks ⇒ Object
Hash.
-
#get_schema_fks_dependencies ⇒ Object
Hash.
-
#get_schema_fks_links ⇒ Object
Hash.
-
#get_schema_fks_placeholders ⇒ Object
Hash.
-
#get_schema_resources ⇒ Object
Hash.
-
#get_yml_schema_outputter ⇒ Object
Object.
-
#initialize(site, error_handler) ⇒ Object
constructor
Initialize the class.
Methods inherited from YmlValidatorBase
#validate, #validate_single_file
Constructor Details
#initialize(site, error_handler) ⇒ Object
Initialize the class.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 207 def initialize(site, error_handler) begin @site = Blufin::SiteResolver::validate_site(site) @error_handler = error_handler @schema_data = {} @schema_descriptions = {} @schema_fks = {} # app.person.id (IS REFERENCED BY) => [app.company.primary_person_id:INT, app.invoice.person_id:INT] @schema_fks_dependencies = {} # app.purchase (HAS 'FKEY' FIELDS TO) => [app.person, app.user, app.company] @schema_fks_placeholders = {} # app.product (HAS THE FOLLOWING PLACEHOLDERS) => [app.company[link], app.product_variation[]] @schema_fks_links = {} # app.address (IS LINKED TO FROM) => [app.company, app.person] @schema_resources = {} @primary_key_count = nil @yml_schema_outputter = Blufin::YmlOutputter.new(@site) @yml_enum_scanner = Blufin::ScannerJavaEnums.new(@site) # Contains more descriptive error output. @errors_array = [] # Validate "config:" section. This must be done before looping files because we will need some of the date from it. @schema_config = {} validate_config_section config_files = Blufin::Files.get_files_in_dir(PATH_TO_CONFIG_YML) schema_files = Blufin::Files.get_files_in_dir("#{Blufin::SiteResolver::get_site_location(@site)}/#{Blufin::Site::PATH_TO_YML_API_SCHEMA}") # Loop through the array of files. (config_files + schema_files).each { |file| scan_file(file) } validate_table_duplicates validate_foreign_keys validate_foreign_keys_placeholders validate_required_schema_definitions build_resources build_fks_dependencies validate_resources validate_http_methods @yml_schema_outputter.set_schema_fks_links(@schema_fks_links) rescue Exception => e Blufin::Terminal::print_exception(e) end end |
Instance Method Details
#extract_flags(flags) ⇒ Object
Use this to extract flags OUTSIDE the validator.
317 318 319 320 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 317 def extract_flags(flags) raise RuntimeError, 'Input cannot be nil in YmlSchemaValidator::extract_flags()' if flags.nil? || flags.strip == '' Blufin::YmlCommon::extract_flags(flags)[0] end |
#get_errors_array ⇒ Object
Returns Array.
266 267 268 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 266 def get_errors_array @errors_array end |
#get_schema_config ⇒ Object
Returns Hash.
276 277 278 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 276 def get_schema_config @schema_config end |
#get_schema_data ⇒ Object
Returns Hash.
271 272 273 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 271 def get_schema_data @schema_data end |
#get_schema_descriptions ⇒ Object
Returns Hash.
281 282 283 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 281 def get_schema_descriptions @schema_descriptions end |
#get_schema_fks ⇒ Object
Returns Hash.
286 287 288 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 286 def get_schema_fks @schema_fks end |
#get_schema_fks_dependencies ⇒ Object
Returns Hash.
296 297 298 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 296 def get_schema_fks_dependencies @schema_fks_dependencies end |
#get_schema_fks_links ⇒ Object
Returns Hash.
301 302 303 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 301 def get_schema_fks_links @schema_fks_links end |
#get_schema_fks_placeholders ⇒ Object
Returns Hash.
291 292 293 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 291 def get_schema_fks_placeholders @schema_fks_placeholders end |
#get_schema_resources ⇒ Object
Returns Hash.
306 307 308 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 306 def get_schema_resources @schema_resources end |
#get_yml_schema_outputter ⇒ Object
Returns Object.
311 312 313 |
# File 'lib/core/yml/schema/yml_schema_validator.rb', line 311 def get_yml_schema_outputter @yml_schema_outputter end |