-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Scholz
committed
Mar 16, 2016
1 parent
db3ef51
commit 3a97ec1
Showing
21 changed files
with
275 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module GrapeSwagger | ||
module DocMethods | ||
class OperationId | ||
class << self | ||
def build(method, path = nil) | ||
verb = method.to_s.downcase | ||
|
||
unless path.nil? | ||
operation = path.split('/').map(&:capitalize).join | ||
operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation.include?('-') | ||
operation.gsub!(/\_(\w)/, &:upcase).delete!('_') if operation.include?('_') | ||
if path.include?('{') | ||
operation.gsub!(/\{(\w)/, &:upcase) | ||
operation.delete!('{').delete!('}') | ||
end | ||
end | ||
|
||
"#{verb}#{operation}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module GrapeSwagger | ||
module DocMethods | ||
class OptionalObject | ||
class << self | ||
def build(key, options, request = nil) | ||
if options[key] | ||
options[key].is_a?(Proc) ? options[key].call : options[key] | ||
else | ||
request | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module GrapeSwagger | ||
module DocMethods | ||
class PathString | ||
class << self | ||
def build(path, options = {}) | ||
# always removing format | ||
path.sub!(/\(\.\w+?\)$/, '') | ||
path.sub!('(.:format)', '') | ||
|
||
# ... format path params | ||
path.gsub!(/:(\w+)/, '{\1}') | ||
|
||
# set item from path, this could be used for the definitions object | ||
item = path.gsub(%r{/{(.+?)}}, '').split('/').last.singularize.underscore.camelize || 'Item' | ||
|
||
if options[:version] && options[:add_version] | ||
path.sub!('{version}', options[:version]) | ||
else | ||
path.sub!('/{version}', '') | ||
end | ||
|
||
path = "#{GrapeSwagger::DocMethods::OptionalObject.build(:base_path, options)}#{path}" if options[:add_base_path] | ||
|
||
[item, path.start_with?('/') ? path : "/#{path}"] | ||
end | ||
end | ||
end | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
lib/grape-swagger/doc_methods/produces.rb → ...-swagger/doc_methods/produces_consumes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module GrapeSwagger | ||
module DocMethods | ||
class TagNameDescription | ||
class << self | ||
def build(options = {}) | ||
target_class = options[:target_class] | ||
namespaces = target_class.combined_namespaces | ||
namespace_routes = target_class.combined_namespace_routes | ||
|
||
namespace_routes.keys.map do |local_route| | ||
next if namespace_routes[local_route].map(&:route_hidden).all? { |value| value.respond_to?(:call) ? value.call : value } | ||
|
||
original_namespace_name = target_class.combined_namespace_identifiers.key?(local_route) ? target_class.combined_namespace_identifiers[local_route] : local_route | ||
description = namespaces[original_namespace_name] && namespaces[original_namespace_name].options[:desc] | ||
description ||= "Operations about #{original_namespace_name.pluralize}" | ||
|
||
{ | ||
name: local_route, | ||
description: description | ||
} | ||
end.compact | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper' | ||
|
||
describe GrapeSwagger::DocMethods::OperationId do | ||
subject { described_class } | ||
|
||
specify { expect(subject).to eql GrapeSwagger::DocMethods::OperationId } | ||
specify { expect(subject).to respond_to :build } | ||
|
||
describe 'build' do | ||
specify do | ||
expect(subject.build('GET')).to eql 'get' | ||
expect(subject.build('get')).to eql 'get' | ||
expect(subject.build(:get)).to eql 'get' | ||
expect(subject.build('GET', 'foo')).to eql 'getFoo' | ||
expect(subject.build('GET', '/foo')).to eql 'getFoo' | ||
expect(subject.build('GET', 'bar/foo')).to eql 'getBarFoo' | ||
expect(subject.build('GET', 'bar/foo{id}')).to eql 'getBarFooId' | ||
expect(subject.build('GET', '/bar_foo{id}')).to eql 'getBarFooId' | ||
expect(subject.build('GET', '/bar-foo{id}')).to eql 'getBarFooId' | ||
expect(subject.build('GET', '/simple_test/bar-foo{id}')).to eql 'getSimpleTestBarFooId' | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.