Class: Swagger::Docs::Generator
- Inherits:
-
Object
- Object
- Swagger::Docs::Generator
- Defined in:
- lib/swagger/docs/generator.rb
Constant Summary collapse
- DEFAULT_VER =
"1.0"- DEFAULT_CONFIG =
{ :api_file_path => "public/", :base_path => "/", :clean_directory => false, :formatting => :pretty }
Class Method Summary collapse
- .set_real_methods ⇒ Object
- .write_doc(api_version, config) ⇒ Object
- .write_docs(apis = nil) ⇒ Object
Class Method Details
.set_real_methods ⇒ Object
15 16 17 |
# File 'lib/swagger/docs/generator.rb', line 15 def set_real_methods Config.base_api_controller.send(:include, Methods) # replace impotent methods with live ones end |
.write_doc(api_version, config) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/swagger/docs/generator.rb', line 34 def write_doc(api_version, config) settings = get_settings(api_version, config) create_output_paths(settings[:api_file_path]) clean_output_paths(settings[:api_file_path]) if config[:clean_directory] || false root = { :api_version => api_version, :swagger_version => "1.2", :base_path => settings[:base_path] + "/", :apis => []} results = {:processed => [], :skipped => []} get_route_paths(settings[:controller_base_path]).each do |path| ret = process_path(path, root, config, settings) results[ret[:action]] << ret if ret[:action] == :processed create_resource_file(ret[:path], ret[:apis], ret[:models], settings, root, config) debased_path = get_debased_path(ret[:path], settings[:controller_base_path]) resource_api = { path: "#{Config.transform_path(trim_leading_slash(debased_path))}.{format}", description: ret[:klass].swagger_config[:description] } root[:apis] << resource_api end end camelize_keys_deep!(root) write_to_file("#{settings[:api_file_path]}/api-docs.json", root, config) results end |
.write_docs(apis = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/swagger/docs/generator.rb', line 19 def write_docs(apis = nil) apis ||= Config.registered_apis results = {} set_real_methods unless apis.empty? apis.each do |api_version,config| config.reverse_merge!(DEFAULT_CONFIG) results[api_version] = write_doc(api_version, config) end else results[DEFAULT_VER] = write_doc(DEFAULT_VER, DEFAULT_CONFIG) end results end |