Skip to content

Commit

Permalink
Update api_swagger_v2_format-content_type_spec.rb
Browse files Browse the repository at this point in the history
removes pry

runs under 2.3

updates gems, corrects parameter, which is in array, make rubocop happy

fixes jruby build

changes for TravisCI
  • Loading branch information
peter scholz committed Feb 5, 2016
1 parent eb981fd commit b3ce344
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Metrics/AbcSize:
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 142
Max: 333

# Offense count: 6
Metrics/CyclomaticComplexity:
Expand Down
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ language: ruby
sudo: false

rvm:
- 2.2.2
- 2.1.1
- 2.0.0
- rbx-2.2.10
- 2.3.0
- 2.2.3
- 2.1.7
- rbx-2
- jruby-19mode

matrix:
allow_failures:
- rvm: rbx-2
env:
- GRAPE_VERSION=0.8.0
- GRAPE_VERSION=0.9.0
- GRAPE_VERSION=0.10.0
- GRAPE_VERSION=0.10.1
- GRAPE_VERSION=0.11.0
- GRAPE_VERSION=0.12.0
- GRAPE_VERSION=0.13.0
- GRAPE_VERSION=0.14.0
- GRAPE_VERSION=HEAD
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

n.n.n / 2016-02-05
==================

### 0.10.3 (Next)

* Your contribution here.
[#336](https://github.com/ruby-grape/grape-swagger/pull/336) changes of swagger-2.0 fork, to support it

* updates gems, corrects parameter, which is in array, make rubocop happy
* runs under 2.3
* documents produces of an end-point
* Update api_swagger_v2_format-content_type_spec.rb
* upgrades to grape 0.14.x; grape-entity 0.5.x

### 0.10.2 (August 19, 2015)

Expand Down
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ source 'http://rubygems.org'

gemspec

# case version = ENV['GRAPE_VERSION'] || '~> 0.14.1'
# when 'HEAD'
gem 'grape', github: 'ruby-grape/grape'
# else
# gem 'grape', version
# end
case version = ENV['GRAPE_VERSION'] || '~> 0.14.0'
when 'HEAD'
gem 'grape', github: 'ruby-grape/grape'
else
gem 'grape', version
end
12 changes: 6 additions & 6 deletions grape-swagger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Gem::Specification.new do |s|
s.add_development_dependency 'bundler'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'rack-cors'
s.add_development_dependency 'rubocop', '0.33.0'
s.add_development_dependency 'kramdown', '~> 1.4.1'
s.add_development_dependency 'redcarpet', '~> 3.1.2' unless RUBY_PLATFORM.eql? 'java'
s.add_development_dependency 'rouge', '~> 1.6.1'
s.add_development_dependency 'pry'
s.add_development_dependency 'pry-byebug'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'kramdown'
s.add_development_dependency 'redcarpet' unless RUBY_PLATFORM.eql? 'java'
s.add_development_dependency 'rouge' unless RUBY_PLATFORM.eql? 'java'
s.add_development_dependency 'pry' unless RUBY_PLATFORM.eql? 'java'
s.add_development_dependency 'pry-byebug' unless RUBY_PLATFORM.eql? 'java'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
Expand Down
17 changes: 8 additions & 9 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def combine_namespace_routes(namespaces)

if namespace.options.key?(:swagger) && namespace.options[:swagger][:nested] == false
# Namespace shall appear as standalone resource, use specified name or use normalized path as name
if namespace.options[:swagger].key?(:name)
identifier = namespace.options[:swagger][:name].tr(' ', '-')
else
identifier = name.tr('_', '-').gsub(/\//, '_')
end
identifier = if namespace.options[:swagger].key?(:name)
name.tr(' ', '-')
else
name.tr('_', '-').gsub(/\//, '_')
end
@target_class.combined_namespace_identifiers[identifier] = name
@target_class.combined_namespace_routes[identifier] = namespace_routes

Expand All @@ -105,8 +105,8 @@ def combine_namespace_routes(namespaces)
# default case when not explicitly specified or nested == true
standalone_namespaces = namespaces.reject do |_, ns|
!ns.options.key?(:swagger) ||
!ns.options[:swagger].key?(:nested) ||
ns.options[:swagger][:nested] != false
!ns.options[:swagger].key?(:nested) ||
ns.options[:swagger][:nested] != false
end

parent_standalone_namespaces = standalone_namespaces.reject { |ns_name, _| !name.start_with?(ns_name) }
Expand Down Expand Up @@ -143,8 +143,7 @@ def route_path_start_with?(route, name)
route_prefix = route.route_prefix ? "/#{route.route_prefix}/#{name}" : "/#{name}"
route_versioned_prefix = route.route_prefix ? "/#{route.route_prefix}/:version/#{name}" : "/:version/#{name}"

route.route_path.start_with?(route_prefix) ||
route.route_path.start_with?(route_versioned_prefix)
route.route_path.start_with?(route_prefix, route_versioned_prefix)
end

def standalone_sub_namespaces(name, namespaces)
Expand Down
31 changes: 16 additions & 15 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Endpoint
'byte' => %w(string byte),
'date' => %w(string date),
'dateTime' => %w(string date-time)
}
}.freeze

def content_types_for(target_class)
content_types = (target_class.content_types || {}).values
Expand Down Expand Up @@ -103,7 +103,7 @@ def path_item(routes, options)
path.gsub!(/:(\w+)/, '{\1}')

# set item from path, this could be used for the definitions object
@item = path.gsub(/\/\{(.+?)\}/, '').split('/').last.singularize.underscore.camelize || 'Item'
@item = path.gsub(%r{/{(.+?)}}, '').split('/').last.singularize.underscore.camelize || 'Item'
@entity = route.route_entity || route.route_success

# ... replacing version params through submitted version
Expand Down Expand Up @@ -175,14 +175,15 @@ def response_object(route)
response_model = @item
response_model = expose_params_from_model(value[:model]) if value[:model]

next unless !response_model.start_with?('Swagger_doc') && ((@definitions[response_model] && value[:code].to_s.start_with?('2')) || value[:model])
next unless !response_model.start_with?('Swagger_doc') &&
((@definitions[response_model] && value[:code].to_s.start_with?('2')) || value[:model])

# TODO: proof that the definition exist, if model isn't specified
if route.route_is_array
memo[value[:code]][:schema] = { 'type' => 'array', 'items' => { '$ref' => "#/definitions/#{response_model}" } }
else
memo[value[:code]][:schema] = { '$ref' => "#/definitions/#{response_model}" }
end
memo[value[:code]][:schema] = if route.route_is_array
{ 'type' => 'array', 'items' => { '$ref' => "#/definitions/#{response_model}" } }
else
{ '$ref' => "#/definitions/#{response_model}" }
end
end
end

Expand Down Expand Up @@ -287,7 +288,7 @@ def hidden?(route)
end

def parse_params(param, value, path, method)
items = {}
@array_items = {}

additional_documentation = value.is_a?(Hash) ? value[:documentation] : nil
data_type = data_type(value)
Expand All @@ -306,6 +307,7 @@ def parse_params(param, value, path, method)
enum_or_range_values = parse_enum_or_range_values(values)

value_type = { value: value, data_type: data_type, path: path }

parsed_params = {
in: param_type(value_type, param, method, is_array),
name: name,
Expand All @@ -319,12 +321,10 @@ def parse_params(param, value, path, method)
parsed_params[:type], parsed_params[:format] = PRIMITIVE_MAPPINGS[data_type]
end

parsed_params[:items] = items if items.present?
parsed_params[:items] = @array_items if @array_items.present?

parsed_params[:defaultValue] = example if example
if default_value && example.blank?
parsed_params[:defaultValue] = default_value
end
parsed_params[:defaultValue] = default_value if default_value && example.blank?

parsed_params.merge!(enum_or_range_values) if enum_or_range_values
parsed_params
Expand Down Expand Up @@ -368,8 +368,9 @@ def param_type(value_type, param, method, is_array)
value_type[:value][:documentation].key?(:param_type)

if is_array
items = { '$ref' => value_type[:data_type] }
data_type = 'array'
@array_items = { 'type' => value_type[:data_type] }

'array'
end
else
case
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GrapeSwagger
VERSION = '0.10.3'
VERSION = '0.11.0'.freeze
end
6 changes: 0 additions & 6 deletions spec/markdown/kramdown_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@

expect(adapter.options).to eq(options)
end

it 'raises an GrapeSwagger::Errors::MarkdownDependencyMissingError if module can not be required' do
expect_any_instance_of(Kernel).to receive(:require).with('kramdown').and_raise(LoadError)

expect { GrapeSwagger::Markdown::KramdownAdapter.new }.to raise_error(GrapeSwagger::Errors::MarkdownDependencyMissingError, 'Missing required dependency: kramdown')
end
end

context 'markdown' do
Expand Down
14 changes: 0 additions & 14 deletions spec/markdown/redcarpet_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
expect(adapter.extension_options).to eq(extensions)
expect(adapter.render_options).to eq(no_links: true)
end

it 'raises an GrapeSwagger::Errors::MarkdownDependencyMissingError if module can not be required.' do
expect_any_instance_of(Kernel).to receive(:require).with('redcarpet').and_raise(LoadError)

expect { GrapeSwagger::Markdown::RedcarpetAdapter.new }.to raise_error(GrapeSwagger::Errors::MarkdownDependencyMissingError, 'Missing required dependency: redcarpet')
end
end

context 'markdown' do
Expand All @@ -60,14 +54,6 @@
expect(renderer.superclass).to be(Redcarpet::Render::HTML)
end

it 'throws an error when rouge syntax highlighter cant be included' do
adapter = GrapeSwagger::Markdown::RedcarpetAdapter.new

expect_any_instance_of(Kernel).to receive(:require).with('rouge').and_raise(LoadError)

expect { adapter.send(:new_redcarpet_renderer, :rouge) }.to raise_error(GrapeSwagger::Errors::MarkdownDependencyMissingError, 'Missing required dependency: rouge')
end

it 'returns a default syntax highlighter' do
adapter = GrapeSwagger::Markdown::RedcarpetAdapter.new
renderer = adapter.send(:new_redcarpet_renderer, :none)
Expand Down
9 changes: 5 additions & 4 deletions spec/support/api_swagger_v2_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ class ApiError < Grape::Entity
"/v3/other_thing/{elements}"=>{
"get"=>{
"produces"=>["application/json"],
"parameters"=>[{"in"=>"array", "name"=>"elements", "description"=>"Set of configuration", "type"=>"string", "required"=>true, "allowMultiple"=>true}],
"responses"=>{"200"=>{"description"=>"nested route inside namespace", "schema"=>{"$ref"=>"#/definitions/QueryInput"}}},
"x-amazon-apigateway-auth"=>{"type"=>"none"},
"x-amazon-apigateway-integration"=>{"type"=>"aws", "uri"=>"foo_bar_uri", "httpMethod"=>"get"}}},
"parameters"=>[
{"in"=>"array", "name"=>"elements", "description"=>"Set of configuration", "type"=>"string", "required"=>true, "allowMultiple"=>true, "items"=>{"type"=>"string"}}],
"responses"=>{"200"=>{"description"=>"nested route inside namespace", "schema"=>{"$ref"=>"#/definitions/QueryInput"}}},
"x-amazon-apigateway-auth"=>{"type"=>"none"},
"x-amazon-apigateway-integration"=>{"type"=>"aws", "uri"=>"foo_bar_uri", "httpMethod"=>"get"}}},
"/thing"=>{
"get"=>{
"produces"=>["application/json"],
Expand Down
6 changes: 4 additions & 2 deletions spec/swagger_v2/api_swagger_v2_detail_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: UTF-8

require 'spec_helper'

def details
Expand Down Expand Up @@ -109,7 +111,7 @@ def app
end
end

describe 'details, convert markdown with redcarpet' do
describe 'details, convert markdown with redcarpet', unless: RUBY_PLATFORM.eql?('java') do
include_context "the api entities"

before :all do
Expand Down Expand Up @@ -142,7 +144,7 @@ def app
specify do
expect(subject['paths']['/use_gfm_rc_detail']['get']).to include('description')
expect(subject['paths']['/use_gfm_rc_detail']['get']['description']).to eql(
"<h1>Burgers in Heaven</h1>\n\n<blockquote>\n<p>A burger doesn&#39;t come for free</p>\n</blockquote>\n\n<p>If you want to reserve a burger in heaven, you have to do\nsome crazy stuff on earth.</p>\n<pre><code class=\"highlight plaintext\">def do_good\nputs 'help people'\nend\n</code></pre>\n\n<ul>\n<li><em>Will go to Heaven:</em> Probably</li>\n<li><em>Will go to Hell:</em> Probably not</li>\n</ul>"
"<h1>Burgers in Heaven</h1>\n\n<blockquote>\n<p>A burger doesn&#39;t come for free</p>\n</blockquote>\n\n<p>If you want to reserve a burger in heaven, you have to do\nsome crazy stuff on earth.</p>\n<pre class=\"highlight plaintext\"><code>def do_good\nputs 'help people'\nend\n</code></pre>\n\n<ul>\n<li><em>Will go to Heaven:</em> Probably</li>\n<li><em>Will go to Hell:</em> Probably not</li>\n</ul>"
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ def app
specify do
expect(subject['paths']['/use_produces']['get']).to include('produces')
expect(subject['paths']['/use_produces']['get']['produces']).to eql(produced)
end
end
end
end

0 comments on commit b3ce344

Please sign in to comment.