Class: Sbuilder::ParamSetLoaderSwagger
- Inherits:
-
ApiLoaderPlugin
- Object
- ApiLoaderPlugin
- Sbuilder::ParamSetLoaderSwagger
- Defined in:
- lib/sbuilder/param_set_loader_swagger.rb
Constant Summary
Constants included from Utils::MyLogger
Class Method Summary collapse
Instance Method Summary collapse
-
#doLoadDefinitions(swagger_hash) ⇒ Object
calls ‘@controller.modelDefinition’ for each parameter set found in swagger configuration.
-
#doLoadInterfaces(swagger_hash) ⇒ Object
calls ‘@facade.modelInterface’ for each parameter set found in swagger configuration.
-
#initialize(options = {}) ⇒ ParamSetLoaderSwagger
constructor
—————————————————————— constrcutore.
- #load(yamlFileUri) ⇒ Object
- #readLines(yamlFileUri) ⇒ Object
-
#validate(json) ⇒ true
Validates this object against the Swagger specification and returns the first detected error.
Methods inherited from ApiLoaderPlugin
Methods included from Utils::MyLogger
Constructor Details
#initialize(options = {}) ⇒ ParamSetLoaderSwagger
constrcutore
17 18 |
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 17 def initialize( = {} ) end |
Class Method Details
.configure(configuration) ⇒ Object
25 26 |
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 25 def self.configure( configuration ) end |
Instance Method Details
#doLoadDefinitions(swagger_hash) ⇒ Object
calls ‘@controller.modelDefinition’ for each parameter set found in swagger configuration
76 77 78 79 80 81 82 |
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 76 def doLoadDefinitions( swagger_hash ) paramsSets = parseDefinitions( swagger_hash ) paramsSets.each do |paramSet| facade.modelDefinition( paramSet ) end end |
#doLoadInterfaces(swagger_hash) ⇒ Object
calls ‘@facade.modelInterface’ for each parameter set found in swagger configuration
89 90 91 92 93 94 95 96 97 |
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 89 def doLoadInterfaces( swagger_hash ) interface_paramsSets = parseInterfaces( swagger_hash ) logger.info( "#{__method__} loaded=#{interface_paramsSets.length} interface_paramsSets" ) interface_paramsSets.each do |interface| facade.modelInterface( interface ) end end |
#load(yamlFileUri) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 42 def load( yamlFileUri ) logger.info( "#{__method__} yamlFileUri=#{yamlFileUri}" ) begin # use facade services to read lines in yaml_lines = readLines( yamlFileUri ) # YAML parse & schema validation swagger_hash = YAML.load( yaml_lines ) rescue Exception => e msg = <<-EOS.gsub( /^\s*/, '' ) Error #{e.} when loading '#{yamlFileUri}' EOS raise Sbuilder::LoaderException.new, msg, e.backtrace end validate( swagger_hash ) # and extract interfaces && definitions doLoadInterfaces( swagger_hash ) doLoadDefinitions( swagger_hash ) end |
#readLines(yamlFileUri) ⇒ Object
32 33 34 35 |
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 32 def readLines( yamlFileUri ) yaml_lines = facade.read_cached( yamlFileUri ) return yaml_lines end |
#validate(json) ⇒ true
Validates this object against the Swagger specification and returns the first detected error. Faster than #fully_validate.
107 108 109 110 111 112 |
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 107 def validate( json ) JSON::Validator.validate!(swagger_schema, json ) # # JSON::Validator.fully_validate(swagger_schema, json ) # rescue JSON::Schema::ValidationError => e raise Sbuilder::LoaderException.new, e. end |