Class: Sbuilder::ParamSetLoaderSwagger

Inherits:
ApiLoaderPlugin show all
Defined in:
lib/sbuilder/param_set_loader_swagger.rb

Constant Summary

Constants inherited from LoaderPluginRoot

LoaderPluginRoot::PROGNAME

Constants included from Utils::MyLogger

Utils::MyLogger::LOGFILE

Construct && configure collapse

Instance Method Summary collapse

Methods included from ApiLoaderPluginMixer

#facade, #setFacade

Methods inherited from LoaderPluginRoot

#configure, #logger, #oneOf, #validateProperties, validateProperties

Methods included from Utils::MyLogger

#getLogger, #logfile

Constructor Details

#initialize(options = {}) ⇒ ParamSetLoaderSwagger




18
19
20
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 18

def initialize( options = {} )
  super( options )
end

Class Method Details

.configure(configuration) ⇒ Object

class method configure

Parameters:

  • configuration (Hash)

    properties to configure



27
28
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 27

def self.configure( configuration )
end

Instance Method Details

#doConfigure(configuration) ⇒ Object

Instance configuration

sbuilder.yaml

Parameters:

  • configuration (Hash)

    for object instance, defined in



36
37
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 36

def doConfigure( configuration )
end

#doLoadDefinitions(swagger_hash) ⇒ Object

calls ‘@controller.modelDefinition’ for each parameter set found in swagger configuration

Parameters:

  • swagger_hash (swagger 2.0)


90
91
92
93
94
95
96
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 90

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

Parameters:

  • swagger_hash (swagger 2.0)


103
104
105
106
107
108
109
110
111
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 103

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

Parameters:

  • yamlFileUri (String)

    path or url to YAML file to process



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 56

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.message}  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

Parameters:

  • yamlFileUri (String)

    path or url to YAML file to process



46
47
48
49
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 46

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.

Returns:

  • (true)

    if the object fully complies with the Swagger specification.

Raises:

  • (Swagger::InvalidDefinition)

    if an error is found.



121
122
123
124
125
126
# File 'lib/sbuilder/param_set_loader_swagger.rb', line 121

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.message
end