Class: Sbuilder::ParamSetLoaderSwagger

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

Constant Summary

Constants included from Utils::MyLogger

Utils::MyLogger::LOGFILE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiLoaderPlugin

#facade, #logger, #setFacade

Methods included from Utils::MyLogger

#getLogger, #logfile

Constructor Details

#initialize(options = {}) ⇒ ParamSetLoaderSwagger


constrcutore



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

def initialize( options = {} )
end

Class Method Details

.configure(configuration) ⇒ Object

Parameters:

  • configuration (Hash)

    properties to configure



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

Parameters:

  • swagger_hash (swagger 2.0)


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

Parameters:

  • swagger_hash (swagger 2.0)


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

Parameters:

  • yamlFileUri (String)

    path or url to YAML file to process



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



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.

Returns:

  • (true)

    if the object fully complies with the Swagger specification.

Raises:

  • (Swagger::InvalidDefinition)

    if an error is found.



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