Skip to content

Commit 9863b7c

Browse files
committed
rad for swagger
1 parent c7f8736 commit 9863b7c

File tree

137 files changed

+51
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+51
-13
lines changed

.bundle/config

100644100755
File mode changed.

.gitignore

100644100755
File mode changed.

.rspec

100644100755
File mode changed.

.travis.yml

100644100755
File mode changed.

Gemfile

100644100755
File mode changed.

Gemfile.lock

100644100755
File mode changed.

LICENSE.md

100644100755
File mode changed.

README.md

100644100755
File mode changed.

Rakefile

100644100755
File mode changed.

example/.gitignore

100644100755
File mode changed.

example/.rspec

100644100755
File mode changed.

example/Gemfile

100644100755
File mode changed.

example/Gemfile.lock

100644100755
File mode changed.

example/README

100644100755
File mode changed.

example/Rakefile

100644100755
File mode changed.

example/app/assets/images/rails.png

100644100755
File mode changed.

example/app/assets/javascripts/application.js

100644100755
File mode changed.

example/app/assets/stylesheets/application.css

100644100755
File mode changed.

example/app/controllers/application_controller.rb

100644100755
File mode changed.

example/app/controllers/orders_controller.rb

100644100755
File mode changed.

example/app/helpers/application_helper.rb

100644100755
File mode changed.

example/app/mailers/.gitkeep

100644100755
File mode changed.

example/app/models/.gitkeep

100644100755
File mode changed.

example/app/models/order.rb

100644100755
File mode changed.

example/app/views/layouts/application.html.erb

100644100755
File mode changed.

example/config.ru

100644100755
File mode changed.

example/config/application.rb

100644100755
File mode changed.

example/config/boot.rb

100644100755
File mode changed.

example/config/database.yml

100644100755
File mode changed.

example/config/environment.rb

100644100755
File mode changed.

example/config/environments/development.rb

100644100755
File mode changed.

example/config/environments/production.rb

100644100755
File mode changed.

example/config/environments/test.rb

100644100755
File mode changed.

example/config/initializers/backtrace_silencers.rb

100644100755
File mode changed.

example/config/initializers/inflections.rb

100644100755
File mode changed.

example/config/initializers/mime_types.rb

100644100755
File mode changed.

example/config/initializers/raddocs.rb

100644100755
File mode changed.

example/config/initializers/secret_token.rb

100644100755
File mode changed.

example/config/initializers/session_store.rb

100644100755
File mode changed.

example/config/initializers/wrap_parameters.rb

100644100755
File mode changed.

example/config/locales/en.yml

100644100755
File mode changed.

example/config/routes.rb

100644100755
File mode changed.

example/db/migrate/20111215005439_create_orders.rb

100644100755
File mode changed.

example/db/schema.rb

100644100755
File mode changed.

example/db/seeds.rb

100644100755
File mode changed.

example/lib/assets/.gitkeep

100644100755
File mode changed.

example/lib/tasks/.gitkeep

100644100755
File mode changed.

example/log/.gitkeep

100644100755
File mode changed.

example/public/404.html

100644100755
File mode changed.

example/public/422.html

100644100755
File mode changed.

example/public/500.html

100644100755
File mode changed.

example/public/favicon.ico

100644100755
File mode changed.

example/public/index.html

100644100755
File mode changed.

example/public/robots.txt

100644100755
File mode changed.

example/spec/acceptance/orders_spec.rb

100644100755
File mode changed.

example/spec/spec_helper.rb

100644100755
File mode changed.

features/callbacks.feature

100644100755
File mode changed.

features/combined_json.feature

100644100755
File mode changed.

features/combined_text.feature

100644100755
File mode changed.

features/curl.feature

100644100755
File mode changed.

features/example_request.feature

100644100755
File mode changed.

features/fixtures/file.png

100644100755
File mode changed.

features/folder_structure.feature

100644100755
File mode changed.

features/headers.feature

100644100755
File mode changed.

features/html_documentation.feature

100644100755
File mode changed.

features/json_iodocs.feature

100644100755
File mode changed.

features/oauth2_mac_client.feature

100644100755
File mode changed.

features/patch.feature

100644100755
File mode changed.

features/readme.md

100644100755
File mode changed.

features/redefining_client.feature

100644100755
File mode changed.

features/step_definitions/curl_steps.rb

100644100755
File mode changed.

features/step_definitions/html_steps.rb

100644100755
File mode changed.

features/step_definitions/image_steps.rb

100644100755
File mode changed.

features/step_definitions/json_steps.rb

100644100755
File mode changed.

features/support/capybara.rb

100644100755
File mode changed.

features/support/env.rb

100644100755
File mode changed.

features/textile_documentation.feature

100644100755
File mode changed.

features/upload_file.feature

100644100755
File mode changed.

lib/rspec_api_documentation.rb

100644100755
File mode changed.

lib/rspec_api_documentation/api_documentation.rb

100644100755
File mode changed.

lib/rspec_api_documentation/api_formatter.rb

100644100755
File mode changed.

lib/rspec_api_documentation/client_base.rb

100644100755
File mode changed.

lib/rspec_api_documentation/configuration.rb

100644100755
File mode changed.

lib/rspec_api_documentation/curl.rb

100644100755
File mode changed.

lib/rspec_api_documentation/dsl.rb

100644100755
File mode changed.

lib/rspec_api_documentation/dsl/callback.rb

100644100755
File mode changed.

lib/rspec_api_documentation/dsl/endpoint.rb

100644100755
File mode changed.

lib/rspec_api_documentation/dsl/resource.rb

100644100755
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def parameter(name, description, options = {})
4242
parameters.push(options.merge(:name => name.to_s, :description => description))
4343
end
4444

45+
def modified_root_path(path)
46+
metadata[:modified_root_path] = path
47+
if superclass_metadata && metadata[:modified_root_path].equal?(superclass_metadata[:modified_root_path])
48+
metadata[:modified_root_path] = Marshal.load(Marshal.dump(superclass_metadata[:modified_root_path]))
49+
end
50+
metadata[:modified_root_path]
51+
end
52+
4553
def header(name, value)
4654
headers[name] = value
4755
end
@@ -50,6 +58,15 @@ def descriptionf(text)
5058
example.metadata[:descriptionf] = text
5159
end
5260

61+
def example(title, params={}, &block)
62+
metadata[:mute] = !!params[:mute]
63+
if superclass_metadata && metadata[:mute].equal?(superclass_metadata[:mute])
64+
metadata[:mute] = Marshal.load(Marshal.dump(superclass_metadata[:mute]))
65+
end
66+
67+
super title, &block
68+
end
69+
5370
def root_path(path)
5471
metadata[:root_path] = path
5572
if superclass_metadata && metadata[:root_path].equal?(superclass_metadata[:root_path])

lib/rspec_api_documentation/example.rb

100644100755
File mode changed.

lib/rspec_api_documentation/headers.rb

100644100755
File mode changed.

lib/rspec_api_documentation/index.rb

100644100755
File mode changed.

lib/rspec_api_documentation/oauth2_mac_client.rb

100644100755
File mode changed.

lib/rspec_api_documentation/rack_test_client.rb

100644100755
File mode changed.

lib/rspec_api_documentation/railtie.rb

100644100755
File mode changed.

lib/rspec_api_documentation/test_server.rb

100644100755
File mode changed.

lib/rspec_api_documentation/views/html_example.rb

100644100755
File mode changed.

lib/rspec_api_documentation/views/html_index.rb

100644100755
File mode changed.

lib/rspec_api_documentation/views/markup_example.rb

100644100755
File mode changed.

lib/rspec_api_documentation/views/markup_index.rb

100644100755
File mode changed.

lib/rspec_api_documentation/views/textile_example.rb

100644100755
File mode changed.

lib/rspec_api_documentation/views/textile_index.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/append_json_writer.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/combined_json_writer.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/combined_text_writer.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/formatter.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/general_markup_writer.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/html_writer.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/index_helper.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/json_iodocs_writer.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/json_swagger_writer.rb

100644100755
Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,50 @@ class JsonSwaggerWriter < Writer
66
delegate :docs_dir, :to => :configuration
77

88
def write
9-
File.open(docs_dir.join("index.json"), "w+") do |f|
9+
FileUtils.rm_rf docs_dir.join('v1')
10+
FileUtils.mkdir_p(docs_dir.join('v1'))
11+
12+
File.open(docs_dir.join('v1', "index.json"), "w+") do |f|
1013
f.write Formatter.to_json(JsonSwaggerIndex.new(index, configuration))
1114
end
1215
write_examples
1316
end
1417

1518
def write_examples
1619
json_examples = {}
20+
a = []
1721
index.examples.each do |example|
18-
json_example = JsonSwaggerExample.new(example, configuration)
19-
(json_examples[json_example.dirname] ||= []) << JsonSwaggerExample.new(example, configuration)
22+
unless example.mute
23+
a << example.route
24+
json_example = JsonSwaggerExample.new(example, configuration)
25+
dirname = example.route.split('/').reject(&:blank?)
26+
FileUtils.mkdir_p(docs_dir.join(dirname[0..-2].join('/')))
27+
#(json_examples[docs_dir.join(dirname.join('/') << '.json')] ||= []) << JsonSwaggerExample.new(example, configuration)
28+
(json_examples[docs_dir.join('v1', (example.root_path.gsub(/^\//, "") << '.json'))] ||= []) << JsonSwaggerExample.new(example, configuration)
29+
end
2030
end
2131

2232
json_examples.each do |dirname, examples|
23-
File.open(docs_dir.join(dirname + ".json"), "a+") do |f|
33+
#directory = File.dirname(dirname)
34+
35+
File.open(docs_dir.join(dirname), "a+") do |f|
2436
f.write Formatter.to_json(format_examples(examples))
2537
end
2638
end
2739
end
2840

2941
def format_examples(json_examples)
42+
json_examples_sorted = {}
43+
json_examples.each do |example|
44+
root_path = example.root_path
45+
root_path = example.modified_root_path if example.try(:modified_root_path)
46+
(json_examples_sorted[root_path] ||= []) << example
47+
end
48+
3049
{
3150
basePath: @configuration.base_api_path,
3251
apiVersion: @configuration.api_version,
33-
apis: []
52+
apis: json_examples_sorted.map { |path, examples| { path: path, operations: examples } }
3453
}
3554
end
3655
end
@@ -51,7 +70,6 @@ def examples
5170

5271
def as_json(opts = nil)
5372
{
54-
basePath: @configuration.base_api_path,
5573
apiVersion: @configuration.api_version,
5674
apis: section_hash
5775
}
@@ -93,13 +111,12 @@ def filename
93111

94112
def as_json(opts = nil)
95113
{
96-
method: method,
97-
operations: [],
98-
resource: resource_name,
99-
:http_method => http_method,
100-
:description => description,
101-
:explanation => explanation,
102-
:parameters => respond_to?(:parameters) ? parameters : [],
114+
method: http_method,
115+
type: resource_name,
116+
summary: description,
117+
nickname: "#{http_method}#{resource_name}",
118+
parameters: respond_to?(:parameters) ? formatted_parameters : [],
119+
responseMessages: []
103120
}
104121
end
105122

@@ -115,6 +132,10 @@ def requests
115132
hash
116133
end
117134
end
135+
136+
def formatted_parameters
137+
parameters
138+
end
118139
end
119140
end
120141
end

lib/rspec_api_documentation/writers/json_writer.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/textile_writer.rb

100644100755
File mode changed.

lib/rspec_api_documentation/writers/writer.rb

100644100755
File mode changed.

lib/tasks/docs.rake

100644100755
File mode changed.

rspec_api_documentation.gemspec

100644100755
File mode changed.

spec/api_documentation_spec.rb

100644100755
File mode changed.

spec/api_formatter_spec.rb

100644100755
File mode changed.

spec/configuration_spec.rb

100644100755
File mode changed.

spec/curl_spec.rb

100644100755
File mode changed.

spec/dsl_spec.rb

100644100755
File mode changed.

spec/example_spec.rb

100644100755
File mode changed.

spec/index_spec.rb

100644100755
File mode changed.

spec/rack_test_client_spec.rb

100644100755
File mode changed.

spec/rspec_api_documentation_spec.rb

100644100755
File mode changed.

spec/spec_helper.rb

100644100755
File mode changed.

spec/views/html_example_spec.rb

100644100755
File mode changed.

spec/writers/combined_text_example_spec.rb

100644100755
File mode changed.

spec/writers/html_writer_spec.rb

100644100755
File mode changed.

spec/writers/index_helper_spec.rb

100644100755
File mode changed.

spec/writers/json_iodocs_writer_spec.rb

100644100755
File mode changed.

spec/writers/json_swagger_writer.rb

100644100755
File mode changed.

spec/writers/json_writer_spec.rb

100644100755
File mode changed.

spec/writers/textile_writer_spec.rb

100644100755
File mode changed.

templates/rspec_api_documentation/html_example.mustache

100644100755
File mode changed.

templates/rspec_api_documentation/html_index.mustache

100644100755
File mode changed.

templates/rspec_api_documentation/textile_example.mustache

100644100755
File mode changed.

templates/rspec_api_documentation/textile_index.mustache

100644100755
File mode changed.

0 commit comments

Comments
 (0)