apipie-rails 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +5 -13
  2. data/.travis.yml +4 -1
  3. data/CHANGELOG.md +19 -0
  4. data/Gemfile.rails32 +1 -0
  5. data/Gemfile.rails41 +1 -1
  6. data/Gemfile.rails42 +5 -0
  7. data/README.rst +21 -4
  8. data/apipie-rails.gemspec +3 -3
  9. data/app/controllers/apipie/apipies_controller.rb +22 -1
  10. data/app/public/apipie/javascripts/bundled/jquery.js +5 -0
  11. data/app/views/apipie/apipies/_disqus.html.erb +3 -3
  12. data/app/views/apipie/apipies/_errors.html.erb +23 -0
  13. data/app/views/apipie/apipies/_method_detail.erb +1 -9
  14. data/app/views/apipie/apipies/_params.html.erb +11 -5
  15. data/app/views/apipie/apipies/apipie_404.html.erb +4 -4
  16. data/app/views/apipie/apipies/static.html.erb +1 -6
  17. data/app/views/layouts/apipie/apipie.html.erb +4 -3
  18. data/config/locales/de.yml +28 -0
  19. data/config/locales/en.yml +30 -28
  20. data/config/locales/es.yml +27 -27
  21. data/config/locales/pl.yml +27 -28
  22. data/config/locales/pt-BR.yml +1 -1
  23. data/config/locales/ru.yml +27 -28
  24. data/config/locales/tr.yml +28 -0
  25. data/config/locales/zh-CN.yml +2 -2
  26. data/config/locales/zh-TW.yml +2 -2
  27. data/lib/apipie/configuration.rb +1 -1
  28. data/lib/apipie/dsl_definition.rb +1 -1
  29. data/lib/apipie/errors.rb +9 -1
  30. data/lib/apipie/extractor/collector.rb +2 -2
  31. data/lib/apipie/extractor/writer.rb +6 -0
  32. data/lib/apipie/helpers.rb +22 -1
  33. data/lib/apipie/param_description.rb +5 -2
  34. data/lib/apipie/validator.rb +7 -6
  35. data/lib/apipie/version.rb +1 -1
  36. data/lib/tasks/apipie.rake +3 -2
  37. data/spec/controllers/api/v1/architectures_controller_spec.rb +7 -8
  38. data/spec/controllers/api/v2/architectures_controller_spec.rb +1 -1
  39. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +1 -1
  40. data/spec/controllers/apipies_controller_spec.rb +71 -27
  41. data/spec/controllers/concerns_controller_spec.rb +9 -9
  42. data/spec/controllers/users_controller_spec.rb +122 -123
  43. data/spec/dummy/app/controllers/users_controller.rb +2 -1
  44. data/spec/dummy/config/initializers/secret_token.rb +1 -0
  45. data/spec/lib/application_spec.rb +3 -3
  46. data/spec/lib/extractor/writer_spec.rb +4 -4
  47. data/spec/lib/method_description_spec.rb +7 -7
  48. data/spec/lib/param_description_spec.rb +61 -46
  49. data/spec/lib/param_group_spec.rb +11 -11
  50. data/spec/lib/rake_spec.rb +10 -10
  51. data/spec/lib/resource_description_spec.rb +6 -6
  52. data/spec/lib/validator_spec.rb +7 -7
  53. data/spec/spec_helper.rb +11 -1
  54. metadata +36 -33
  55. data/app/public/apipie/javascripts/bundled/jquery-1.7.2.js +0 -9404
@@ -1,28 +1,28 @@
1
1
  es:
2
- apipie:
3
- resources: Recursos
4
- resource: Recurso
5
- description: Descripción
6
- no_docs_found: No se encontró la documentación
7
- no_docs_found_descr: No hemos encontrado ninguna documentación para tu API.
8
- follow_instructions_html: Siga %{href} sobre cómo describir sus controladores.
9
- follow_instructions_href: más instrucciones
10
- oops: Huy!!
11
- resource_not_found_html: Recurso %{res} no encontrado.
12
- method_not_found_html: Método %{method} no encontrado para el recurso %{resource}.
13
- goto_homepage_html: Trate de ir a %{href}
14
- goto_homepage_href: "%{app_name} página de documentación API "
15
- required: requerido
16
- optional: opcional
17
- nil_allowed: nil permitido
18
- param_name: Nombre del parámetro
19
- params: Parámetros
20
- examples: Ejemplos
21
- metadata: Metadatos
22
- errors: Errores
23
- supported_formats: Formatos soportados
24
- enable_javascript_html: Por favor, active JavaScript para ver el %{comments_href}.
25
- comments_powered_by_disqus: comentarios gracias a %{disqus}
26
- api_documentation: Documentación de la API
27
- headers: Cabeceras
28
- header_name: Nombre de cabecera
2
+ apipie:
3
+ resources: Recursos
4
+ resource: Recurso
5
+ description: Descripción
6
+ no_docs_found: No se encontró la documentación
7
+ no_docs_found_descr: No hemos encontrado ninguna documentación para tu API.
8
+ follow_instructions_html: Siga %{href} sobre cómo describir sus controladores.
9
+ follow_instructions_href: más instrucciones
10
+ oops: Huy!!
11
+ resource_not_found_html: Recurso %{resource} no encontrado.
12
+ method_not_found_html: Método %{method} no encontrado para el recurso %{resource}.
13
+ goto_homepage_html: Trate de ir a %{href}
14
+ goto_homepage_href: "%{app_name} página de documentación API "
15
+ required: requerido
16
+ optional: opcional
17
+ nil_allowed: nil permitido
18
+ param_name: Nombre del parámetro
19
+ params: Parámetros
20
+ examples: Ejemplos
21
+ metadata: Metadatos
22
+ errors: Errores
23
+ supported_formats: Formatos soportados
24
+ enable_javascript_html: Por favor, active JavaScript para ver el %{comments_href}.
25
+ comments_powered_by_disqus: comentarios gracias a %{disqus}
26
+ api_documentation: Documentación de la API
27
+ headers: Cabeceras
28
+ header_name: Nombre de cabecera
@@ -1,29 +1,28 @@
1
1
  pl:
2
- apipie:
3
- resources: Zasoby
4
- resource: Zasób
5
- description: Opis
6
- no_docs_found: Nie znalezionio dokumentacji
7
- no_docs_found_descr: Nie znaleziono dokumentacji dla twojego API.
8
- follow_instructions_html: Przejdź do %{href} aby opisać swoje kontrolery.
9
- follow_instructions_href: dalsze instrukcje
10
- oops: Ups!!
11
- resource_not_found_html: Zasób %{res} nie został znaleziony.
12
- method_not_found_html: Metoda %{method} dla zasobu %{resource} nie została znaleziona.
13
- goto_homepage_html: Spróbuj przejść do %{href}
14
- goto_homepage_href: "%{app_name} Strona główna dokumentacji API"
15
- required: wymagany
16
- optional: opcjonalny
17
- nil_allowed: nil dopuszczalny
18
- param_name: Nazwa parametru
19
- params: Parametry
20
- examples: Przykłady
21
- metadata: Metadane
22
- errors: Błędy
23
- supported_formats: Dostępne formaty
24
- enable_javascript_html: Proszę włączyć obsługę javascript w celu zobaczenia %{comments_href}.
25
- comments_powered_by_disqus: komentarze obsługiwane przez %{disqus}
26
- api_documentation: Dokumentacja API
27
- headers: Nagłówki
28
- header_name: Nazwa nagłówka
29
-
2
+ apipie:
3
+ resources: Zasoby
4
+ resource: Zasób
5
+ description: Opis
6
+ no_docs_found: Nie znalezionio dokumentacji
7
+ no_docs_found_descr: Nie znaleziono dokumentacji dla twojego API.
8
+ follow_instructions_html: Przejdź do %{href} aby opisać swoje kontrolery.
9
+ follow_instructions_href: dalsze instrukcje
10
+ oops: Ups!!
11
+ resource_not_found_html: Zasób %{resource} nie został znaleziony.
12
+ method_not_found_html: Metoda %{method} dla zasobu %{resource} nie została znaleziona.
13
+ goto_homepage_html: Spróbuj przejść do %{href}
14
+ goto_homepage_href: "%{app_name} Strona główna dokumentacji API"
15
+ required: wymagany
16
+ optional: opcjonalny
17
+ nil_allowed: nil dopuszczalny
18
+ param_name: Nazwa parametru
19
+ params: Parametry
20
+ examples: Przykłady
21
+ metadata: Metadane
22
+ errors: Błędy
23
+ supported_formats: Dostępne formaty
24
+ enable_javascript_html: Proszę włączyć obsługę JavaScript w celu zobaczenia %{comments_href}.
25
+ comments_powered_by_disqus: komentarze obsługiwane przez %{disqus}
26
+ api_documentation: Dokumentacja API
27
+ headers: Nagłówki
28
+ header_name: Nazwa nagłówka
@@ -8,7 +8,7 @@
8
8
  follow_instructions_html: Siga %{href} para saber como descrever seus controllers.
9
9
  follow_instructions_href: mais instruções
10
10
  oops: Oops!!
11
- resource_not_found_html: Recurso %{res} não encontrado.
11
+ resource_not_found_html: Recurso %{resource} não encontrado.
12
12
  method_not_found_html: Método %{method} não encontrado para o recurso %{resource}.
13
13
  goto_homepage_html: Tente ir para %{href}
14
14
  goto_homepage_href: "%{app_name} API - Página inicial da documentação"
@@ -1,29 +1,28 @@
1
1
  ru:
2
- apipie:
3
- resources: Ресурсы
4
- resource: Ресурс
5
- description: Описание
6
- no_docs_found: Документация не найдена
7
- no_docs_found_descr: Мы не нашли никакой документации для вашего API.
8
- follow_instructions_html: Перейдите по ссылке %{href}, чтобы узнать как описать ваш API.
9
- follow_instructions_href: дополнительные инструкции
10
- oops: Ой!!
11
- resource_not_found_html: Ресурс %{res} не найден.
12
- method_not_found_html: Метод %{method} для ресурса %{resource} не найден.
13
- goto_homepage_html: Перейдите %{href}
14
- goto_homepage_href: "%{app_name} домашняя страница API документации"
15
- required: обязательно
16
- optional: необязательно
17
- nil_allowed: nil разрешен
18
- param_name: Имя параметра
19
- params: Параметры
20
- examples: Примеры
21
- metadata: Метаданные
22
- errors: Ошибки
23
- supported_formats: Поддерживаемые форматы
24
- enable_javascript_html: Пожалуйста включите JavaScript, чтобы просматривать %{comments_href}.
25
- comments_powered_by_disqus: комментарии представлены %{disqus}
26
- api_documentation: API документация
27
- headers: Заголовки
28
- header_name: Название заголовка
29
-
2
+ apipie:
3
+ resources: Ресурсы
4
+ resource: Ресурс
5
+ description: Описание
6
+ no_docs_found: Документация не найдена
7
+ no_docs_found_descr: Мы не нашли никакой документации для вашего API.
8
+ follow_instructions_html: Перейдите по ссылке %{href}, чтобы узнать как описать ваш API.
9
+ follow_instructions_href: дополнительные инструкции
10
+ oops: Ой!!
11
+ resource_not_found_html: Ресурс %{resource} не найден.
12
+ method_not_found_html: Метод %{method} для ресурса %{resource} не найден.
13
+ goto_homepage_html: Перейдите %{href}
14
+ goto_homepage_href: "%{app_name} домашняя страница API документации"
15
+ required: обязательно
16
+ optional: необязательно
17
+ nil_allowed: nil разрешен
18
+ param_name: Имя параметра
19
+ params: Параметры
20
+ examples: Примеры
21
+ metadata: Метаданные
22
+ errors: Ошибки
23
+ supported_formats: Поддерживаемые форматы
24
+ enable_javascript_html: Пожалуйста включите JavaScript, чтобы просматривать %{comments_href}.
25
+ comments_powered_by_disqus: комментарии представлены %{disqus}
26
+ api_documentation: API документация
27
+ headers: Заголовки
28
+ header_name: Название заголовка
@@ -0,0 +1,28 @@
1
+ tr:
2
+ apipie:
3
+ resources: Kaynaklar
4
+ resource: Kaynak
5
+ description: Açıklama
6
+ no_docs_found: Hiçbir belge bulunamadı
7
+ no_docs_found_descr: API'niz için hiçbir belge bulunamadı.
8
+ follow_instructions_html: Controller açıklaması belgeleri için %{href} yolunu izleyin.
9
+ follow_instructions_href: daha fazla talimatlar
10
+ oops: Üzgünüz!!
11
+ resource_not_found_html: Kaynak %{resource} bulunamadı.
12
+ method_not_found_html: "%{resource} kaynağının %{method} yöntemi bulunamadı."
13
+ goto_homepage_html: "%{href} adresini deneyin"
14
+ goto_homepage_href: "%{app_name} API belgeleri ana sayfası"
15
+ required: gerekli
16
+ optional: isteğe bağlı
17
+ nil_allowed: nil olabilir
18
+ param_name: Parametre adı
19
+ params: Parametreler
20
+ examples: Örnekler
21
+ metadata: Üst veriler
22
+ errors: Hatalar
23
+ supported_formats: Desteklenen Biçimler
24
+ enable_javascript_html: "%{comments_href} adresini görebilmek için lütfen JavaScript'i etkinleştirin."
25
+ comments_powered_by_disqus: yorumlar %{disqus} tarafından desteklenmektedir
26
+ api_documentation: API belgeleri
27
+ headers: Üst bilgiler
28
+ header_name: Üst bilgi adı
@@ -8,8 +8,8 @@
8
8
  follow_instructions_html: 点击 %{href} 查看描述。
9
9
  follow_instructions_href: 高级指导
10
10
  oops: Oops!!
11
- resource_not_found_html: 没有找到资源 %{res} 。
12
- method_not_found_html: 没有找到资源 %{res} 的方法 %{method} 。
11
+ resource_not_found_html: 没有找到资源 %{resource} 。
12
+ method_not_found_html: 没有找到资源 %{resource} 的方法 %{method} 。
13
13
  goto_homepage_html: 试图访问 %{href}
14
14
  goto_homepage_href: "%{app_name} API 文档主页"
15
15
  required: 必填
@@ -8,8 +8,8 @@
8
8
  follow_instructions_html: 點擊 %{href} 查看描述。
9
9
  follow_instructions_href: 高級指導
10
10
  oops: Oops!!
11
- resource_not_found_html: 沒有找到資源 %{res} 。
12
- method_not_found_html: 沒有找到資源 %{res} 的方法 %{method} 。
11
+ resource_not_found_html: 沒有找到資源 %{resource} 。
12
+ method_not_found_html: 沒有找到資源 %{resource} 的方法 %{method} 。
13
13
  goto_homepage_html: 試圖訪問 %{href}
14
14
  goto_homepage_href: "%{app_name} API 文檔主頁"
15
15
  required: 必填
@@ -7,7 +7,7 @@ module Apipie
7
7
  :validate, :validate_value, :validate_presence, :validate_key, :authenticate, :doc_path,
8
8
  :show_all_examples, :process_params, :update_checksum, :checksum_path,
9
9
  :link_extension, :record, :languages, :translate, :locale, :default_locale,
10
- :persist_show_in_doc
10
+ :persist_show_in_doc, :authorize
11
11
 
12
12
  alias_method :validate?, :validate
13
13
  alias_method :required_by_default?, :required_by_default
@@ -223,7 +223,7 @@ module Apipie
223
223
  if Apipie.configuration.validate_presence?
224
224
  method_params.each do |_, param|
225
225
  # check if required parameters are present
226
- raise ParamMissing.new(param.name) if param.required && !params.has_key?(param.name)
226
+ raise ParamMissing.new(param) if param.required && !params.has_key?(param.name)
227
227
  end
228
228
  end
229
229
 
@@ -17,7 +17,15 @@ module Apipie
17
17
 
18
18
  class ParamMissing < DefinedParamError
19
19
  def to_s
20
- "Missing parameter #{@param}"
20
+ unless @param.options[:missing_message].nil?
21
+ if @param.options[:missing_message].kind_of?(Proc)
22
+ @param.options[:missing_message].call
23
+ else
24
+ @param.options[:missing_message].to_s
25
+ end
26
+ else
27
+ "Missing parameter #{@param.name}"
28
+ end
21
29
  end
22
30
  end
23
31
 
@@ -63,12 +63,12 @@ module Apipie
63
63
  # we specify what type it might be. At the end the first type
64
64
  # that left is taken as the more general one
65
65
  unless param_desc[:type]
66
- param_desc[:type] = [:bool, :number]
66
+ param_desc[:type] = [:bool, :boolean, :number]
67
67
  param_desc[:type] << Hash if value.is_a? Hash
68
68
  param_desc[:type] << :undef
69
69
  end
70
70
 
71
- if param_desc[:type].first == :bool && (! [true, false].include?(value))
71
+ if [:boolean, :bool].include?(param_desc[:type].first) && (! [true, false, 1, 0].include?(value))
72
72
  param_desc[:type].shift
73
73
  end
74
74
 
@@ -79,6 +79,12 @@ module Apipie
79
79
  next unless call.has_key?(k)
80
80
  ordered_call[k] = case call[k]
81
81
  when ActiveSupport::HashWithIndifferentAccess
82
+ # UploadedFiles break the to_json call, turn them into a string so they don't break
83
+ call[k].each do |pkey, pval|
84
+ if (pval.is_a?(Rack::Test::UploadedFile) || pval.is_a?(ActionDispatch::Http::UploadedFile))
85
+ call[k][pkey] = "<FILE CONTENT '#{pval.original_filename}'>"
86
+ end
87
+ end
82
88
  JSON.parse(call[k].to_json) # to_hash doesn't work recursively and I'm too lazy to write the recursion:)
83
89
  else
84
90
  call[k]
@@ -33,7 +33,7 @@ module Apipie
33
33
  end
34
34
 
35
35
  def include_javascripts
36
- %w[ bundled/jquery-1.7.2.js
36
+ %w[ bundled/jquery.js
37
37
  bundled/bootstrap-collapse.js
38
38
  bundled/prettify.js
39
39
  apipie.js ].map do |file|
@@ -48,5 +48,26 @@ module Apipie
48
48
  "<link type='text/css' rel='stylesheet' href='#{Apipie.full_url("stylesheets/#{file}")}'/>"
49
49
  end.join("\n").html_safe
50
50
  end
51
+
52
+ def label_class_for_error(err)
53
+ case err[:code]
54
+ when 200
55
+ 'label label-info'
56
+ when 201
57
+ 'label label-success'
58
+ when 204
59
+ 'label label-info2'
60
+ when 401
61
+ 'label label-warning'
62
+ when 403
63
+ 'label label-warning2'
64
+ when 422
65
+ 'label label-important'
66
+ when 404
67
+ 'label label-inverse'
68
+ else
69
+ 'label'
70
+ end
71
+ end
51
72
  end
52
73
  end
@@ -8,7 +8,7 @@ module Apipie
8
8
  # validator - Validator::BaseValidator subclass
9
9
  class ParamDescription
10
10
 
11
- attr_reader :method_description, :name, :desc, :allow_nil, :validator, :options, :metadata, :show, :as
11
+ attr_reader :method_description, :name, :desc, :allow_nil, :validator, :options, :metadata, :show, :as, :validations
12
12
  attr_accessor :parent, :required
13
13
 
14
14
  def self.from_dsl_data(method_description, args)
@@ -63,6 +63,8 @@ module Apipie
63
63
  @validator = Validator::BaseValidator.find(self, validator, @options, block)
64
64
  raise "Validator for #{validator} not found." unless @validator
65
65
  end
66
+
67
+ @validations = Array(options[:validations]).map {|v| concern_subst(Apipie.markup_to_html(v)) }
66
68
  end
67
69
 
68
70
  def from_concern?
@@ -112,7 +114,8 @@ module Apipie
112
114
  :validator => validator.to_s,
113
115
  :expected_type => validator.expected_type,
114
116
  :metadata => metadata,
115
- :show => show }
117
+ :show => show,
118
+ :validations => validations }
116
119
  if sub_params = validator.params_ordered
117
120
  hash[:params] = sub_params.map { |p| p.to_json(lang)}
118
121
  end
@@ -129,7 +129,7 @@ module Apipie
129
129
  end
130
130
 
131
131
  def description
132
- "Must match regular expression /#{@regexp.source}/."
132
+ "Must match regular expression <code>/#{@regexp.source}/</code>."
133
133
  end
134
134
  end
135
135
 
@@ -149,7 +149,8 @@ module Apipie
149
149
  end
150
150
 
151
151
  def description
152
- "Must be one of: #{@array.join(', ')}."
152
+ string = @array.map { |value| "<code>#{value}</code>" }.join(', ')
153
+ "Must be one of: #{string}."
153
154
  end
154
155
  end
155
156
 
@@ -305,7 +306,7 @@ module Apipie
305
306
  if @hash_params
306
307
  @hash_params.each do |k, p|
307
308
  if Apipie.configuration.validate_presence?
308
- raise ParamMissing.new(k) if p.required && !value.has_key?(k)
309
+ raise ParamMissing.new(p) if p.required && !value.has_key?(k)
309
310
  end
310
311
  if Apipie.configuration.validate_value?
311
312
  p.validate(value[k]) if value.has_key?(k)
@@ -398,11 +399,11 @@ module Apipie
398
399
  class BooleanValidator < BaseValidator
399
400
 
400
401
  def validate(value)
401
- %w[true false].include?(value.to_s)
402
+ %w[true false 1 0].include?(value.to_s)
402
403
  end
403
404
 
404
405
  def self.build(param_description, argument, options, block)
405
- if argument == :bool
406
+ if argument == :bool || argument == :boolean
406
407
  self.new(param_description)
407
408
  end
408
409
  end
@@ -412,7 +413,7 @@ module Apipie
412
413
  end
413
414
 
414
415
  def description
415
- "Must be 'true' or 'false'"
416
+ "Must be 'true' or 'false' or '1' or '0'"
416
417
  end
417
418
  end
418
419
 
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.6'
3
3
  end
@@ -105,7 +105,8 @@ namespace :apipie do
105
105
  else
106
106
  File.expand_path("../../../app/views/apipie/apipies", __FILE__)
107
107
  end
108
- @apipie_renderer = ActionView::Base.new(base_path)
108
+ layouts_path = File.expand_path("../../../app/views/layouts", __FILE__)
109
+ @apipie_renderer = ActionView::Base.new([base_path, layouts_path])
109
110
  @apipie_renderer.singleton_class.send(:include, ApipieHelper)
110
111
  return @apipie_renderer
111
112
  end
@@ -118,7 +119,7 @@ namespace :apipie do
118
119
  end
119
120
  f.write av.render(
120
121
  :template => "#{template}",
121
- :layout => (layout && "../../layouts/apipie/#{layout}"))
122
+ :layout => (layout && "apipie/#{layout}"))
122
123
  end
123
124
  end
124
125
 
@@ -5,24 +5,23 @@ describe Api::V1::ArchitecturesController do
5
5
  subject { Apipie.get_resource_description(Api::V1::ArchitecturesController, "1.0") }
6
6
 
7
7
  it "should be version 1.0" do
8
- subject._version.should eq('1.0')
8
+ expect(subject._version).to eq('1.0')
9
9
 
10
- Apipie.resource_descriptions['1.0'].size.should == 2
11
- Apipie.resource_descriptions['1.0'].keys.should
12
- include('architectures', 'base')
10
+ expect(Apipie.resource_descriptions['1.0'].size).to eq(2)
11
+ expect(Apipie.resource_descriptions['1.0'].keys).to include('architectures', 'base')
13
12
  end
14
13
 
15
14
  context "there is another version" do
16
15
  let(:v2) { archv2 = Apipie.get_resource_description(Api::V2::ArchitecturesController, "2.0") }
17
16
 
18
17
  it "should have unique doc url" do
19
- subject.doc_url.should_not eq(v2.doc_url)
18
+ expect(subject.doc_url).not_to eq(v2.doc_url)
20
19
  end
21
20
 
22
21
  it "should have unique methods" do
23
- subject._methods.keys.should include(:index)
24
- v2._methods.keys.should include(:index)
25
- subject._methods[:index].should_not eq(v2._methods[:index])
22
+ expect(subject._methods.keys).to include(:index)
23
+ expect(v2._methods.keys).to include(:index)
24
+ expect(subject._methods[:index]).not_to eq(v2._methods[:index])
26
25
  end
27
26
 
28
27
  end