praxis 2.0.pre.3 → 2.0.pre.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +0 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +1 -1
- data/Guardfile +2 -1
- data/Rakefile +1 -7
- data/TODO.md +28 -0
- data/lib/api_browser/package-lock.json +7110 -0
- data/lib/praxis.rb +7 -4
- data/lib/praxis/action_definition.rb +9 -16
- data/lib/praxis/api_general_info.rb +21 -0
- data/lib/praxis/application.rb +1 -2
- data/lib/praxis/bootloader_stages/routing.rb +2 -4
- data/lib/praxis/docs/generator.rb +11 -6
- data/lib/praxis/docs/open_api_generator.rb +255 -0
- data/lib/praxis/docs/openapi/info_object.rb +31 -0
- data/lib/praxis/docs/openapi/media_type_object.rb +59 -0
- data/lib/praxis/docs/openapi/operation_object.rb +40 -0
- data/lib/praxis/docs/openapi/parameter_object.rb +69 -0
- data/lib/praxis/docs/openapi/paths_object.rb +55 -0
- data/lib/praxis/docs/openapi/request_body_object.rb +51 -0
- data/lib/praxis/docs/openapi/response_object.rb +63 -0
- data/lib/praxis/docs/openapi/responses_object.rb +44 -0
- data/lib/praxis/docs/openapi/schema_object.rb +87 -0
- data/lib/praxis/docs/openapi/server_object.rb +24 -0
- data/lib/praxis/docs/openapi/tag_object.rb +21 -0
- data/lib/praxis/extensions/attribute_filtering.rb +2 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb +148 -157
- data/lib/praxis/extensions/attribute_filtering/active_record_patches.rb +15 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/5x.rb +90 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_0.rb +68 -0
- data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_1_plus.rb +58 -0
- data/lib/praxis/extensions/attribute_filtering/filter_tree_node.rb +35 -0
- data/lib/praxis/extensions/attribute_filtering/filtering_params.rb +13 -12
- data/lib/praxis/extensions/attribute_filtering/sequel_filter_query_builder.rb +3 -2
- data/lib/praxis/extensions/field_selection/active_record_query_selector.rb +7 -9
- data/lib/praxis/extensions/field_selection/field_selector.rb +4 -0
- data/lib/praxis/extensions/field_selection/sequel_query_selector.rb +6 -9
- data/lib/praxis/extensions/pagination.rb +130 -0
- data/lib/praxis/extensions/pagination/active_record_pagination_handler.rb +42 -0
- data/lib/praxis/extensions/pagination/header_generator.rb +70 -0
- data/lib/praxis/extensions/pagination/ordering_params.rb +238 -0
- data/lib/praxis/extensions/pagination/pagination_handler.rb +68 -0
- data/lib/praxis/extensions/pagination/pagination_params.rb +378 -0
- data/lib/praxis/extensions/pagination/sequel_pagination_handler.rb +45 -0
- data/lib/praxis/handlers/json.rb +2 -0
- data/lib/praxis/handlers/www_form.rb +5 -0
- data/lib/praxis/handlers/{xml.rb → xml-sample.rb} +6 -0
- data/lib/praxis/links.rb +4 -0
- data/lib/praxis/mapper/active_model_compat.rb +23 -5
- data/lib/praxis/mapper/resource.rb +16 -9
- data/lib/praxis/mapper/selector_generator.rb +11 -10
- data/lib/praxis/mapper/sequel_compat.rb +1 -0
- data/lib/praxis/media_type.rb +1 -56
- data/lib/praxis/multipart/part.rb +5 -2
- data/lib/praxis/plugins/mapper_plugin.rb +1 -1
- data/lib/praxis/plugins/pagination_plugin.rb +71 -0
- data/lib/praxis/resource_definition.rb +4 -12
- data/lib/praxis/response_definition.rb +1 -1
- data/lib/praxis/route.rb +2 -4
- data/lib/praxis/routing_config.rb +4 -8
- data/lib/praxis/tasks/api_docs.rb +23 -0
- data/lib/praxis/tasks/routes.rb +10 -15
- data/lib/praxis/types/media_type_common.rb +10 -0
- data/lib/praxis/types/multipart_array.rb +62 -0
- data/lib/praxis/validation_handler.rb +1 -2
- data/lib/praxis/version.rb +1 -1
- data/praxis.gemspec +4 -5
- data/spec/functional_spec.rb +9 -6
- data/spec/praxis/action_definition_spec.rb +4 -16
- data/spec/praxis/api_general_info_spec.rb +6 -6
- data/spec/praxis/extensions/attribute_filtering/active_record_filter_query_builder_spec.rb +304 -0
- data/spec/praxis/extensions/attribute_filtering/filter_tree_node_spec.rb +39 -0
- data/spec/praxis/extensions/attribute_filtering/filtering_params_spec.rb +34 -0
- data/spec/praxis/extensions/field_expansion_spec.rb +6 -24
- data/spec/praxis/extensions/field_selection/active_record_query_selector_spec.rb +15 -11
- data/spec/praxis/extensions/field_selection/sequel_query_selector_spec.rb +4 -3
- data/spec/praxis/extensions/pagination/active_record_pagination_handler_spec.rb +130 -0
- data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_active_model.rb +45 -2
- data/spec/praxis/extensions/{field_selection/support → support}/spec_resources_sequel.rb +0 -0
- data/spec/praxis/mapper/selector_generator_spec.rb +32 -0
- data/spec/praxis/media_type_spec.rb +5 -129
- data/spec/praxis/request_spec.rb +3 -22
- data/spec/praxis/resource_definition_spec.rb +1 -1
- data/spec/praxis/response_definition_spec.rb +8 -9
- data/spec/praxis/route_spec.rb +2 -9
- data/spec/praxis/routing_config_spec.rb +4 -13
- data/spec/praxis/types/multipart_array_spec.rb +4 -21
- data/spec/spec_app/config/environment.rb +0 -2
- data/spec/spec_app/design/api.rb +7 -1
- data/spec/spec_app/design/media_types/instance.rb +0 -8
- data/spec/spec_app/design/media_types/volume.rb +0 -12
- data/spec/spec_app/design/resources/instances.rb +1 -2
- data/spec/spec_helper.rb +6 -0
- data/spec/support/spec_media_types.rb +0 -73
- metadata +51 -49
- data/spec/praxis/handlers/xml_spec.rb +0 -177
- data/spec/praxis/links_spec.rb +0 -68
@@ -95,14 +95,6 @@ module Praxis
|
|
95
95
|
@on_finalize
|
96
96
|
end
|
97
97
|
|
98
|
-
# FIXME: this is inconsistent with the rest of the magic DSL convention.
|
99
|
-
def routing(&block)
|
100
|
-
warn "DEPRECATED: ResourceDefinition.routing is deprecated use prefix directly instead."
|
101
|
-
|
102
|
-
# eval this assuming it will only call #prefix
|
103
|
-
self.instance_eval(&block)
|
104
|
-
end
|
105
|
-
|
106
98
|
def prefix(prefix=nil)
|
107
99
|
return @prefix if prefix.nil?
|
108
100
|
@routing_prefix = nil # reset routing_prefix
|
@@ -125,7 +117,7 @@ module Praxis
|
|
125
117
|
@routing_prefix = nil # reset routing_prefix
|
126
118
|
|
127
119
|
parent_action = parent.canonical_path
|
128
|
-
parent_route = parent_action.
|
120
|
+
parent_route = parent_action.route.path
|
129
121
|
|
130
122
|
# if a mapping is passed, it *must* resolve any param name conflicts
|
131
123
|
unless mapping.any?
|
@@ -146,7 +138,7 @@ module Praxis
|
|
146
138
|
if mapping.key?(name)
|
147
139
|
param = mapping[name]
|
148
140
|
# FIXME: this won't handle URI Template type paths, ie '/{parent_id}'
|
149
|
-
prefixed_path = parent_action.
|
141
|
+
prefixed_path = parent_action.route.prefixed_path
|
150
142
|
@parent_prefix = prefixed_path.gsub(/(:)(#{name})(\W+|$)/, "\\1#{param.to_s}\\3")
|
151
143
|
else
|
152
144
|
mapping[name] = name
|
@@ -221,14 +213,14 @@ module Praxis
|
|
221
213
|
end
|
222
214
|
|
223
215
|
def to_href( params )
|
224
|
-
canonical_path.
|
216
|
+
canonical_path.route.path.expand(params)
|
225
217
|
end
|
226
218
|
|
227
219
|
def parse_href(path)
|
228
220
|
if path.kind_of?(::URI::Generic)
|
229
221
|
path = path.path
|
230
222
|
end
|
231
|
-
param_values = canonical_path.
|
223
|
+
param_values = canonical_path.route.path.params(path)
|
232
224
|
attrs = canonical_path.params.attributes
|
233
225
|
param_values.each_with_object({}) do |(key,value),hash|
|
234
226
|
hash[key.to_sym] = attrs[key.to_sym].load(value,[key])
|
data/lib/praxis/route.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module Praxis
|
2
2
|
|
3
3
|
class Route
|
4
|
-
attr_accessor :verb, :path, :version, :
|
4
|
+
attr_accessor :verb, :path, :version, :prefixed_path, :options
|
5
5
|
|
6
|
-
def initialize(verb, path, version='n/a',
|
6
|
+
def initialize(verb, path, version='n/a', prefixed_path:nil, **options)
|
7
7
|
@verb = verb
|
8
8
|
@path = path
|
9
9
|
@version = version
|
10
|
-
@name = name
|
11
10
|
@options = options
|
12
11
|
@prefixed_path = prefixed_path
|
13
12
|
end
|
@@ -34,7 +33,6 @@ module Praxis
|
|
34
33
|
path: path.to_s,
|
35
34
|
version: version
|
36
35
|
}
|
37
|
-
result[:name] = name unless name.nil?
|
38
36
|
result[:options] = options if options.any?
|
39
37
|
result
|
40
38
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Praxis
|
2
2
|
class RoutingConfig
|
3
3
|
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :route
|
5
5
|
attr_reader :version
|
6
6
|
attr_reader :base
|
7
7
|
|
@@ -10,7 +10,7 @@ module Praxis
|
|
10
10
|
@base = base
|
11
11
|
@prefix_segments = Array(prefix)
|
12
12
|
|
13
|
-
@
|
13
|
+
@route = nil
|
14
14
|
|
15
15
|
if block_given?
|
16
16
|
instance_eval(&block)
|
@@ -53,12 +53,8 @@ module Praxis
|
|
53
53
|
end
|
54
54
|
prefixed_path = path.gsub('//','/')
|
55
55
|
path = (base + path).gsub('//','/')
|
56
|
-
|
57
|
-
|
58
|
-
pattern = Mustermann.new(path, **{ignore_unknown_options: true}.merge( options ))
|
59
|
-
route = Route.new(verb, pattern, version, name: route_name, prefixed_path: prefixed_path, **options)
|
60
|
-
@routes << route
|
61
|
-
route
|
56
|
+
pattern = Mustermann.new(path, {ignore_unknown_options: true}.merge( options ))
|
57
|
+
@route = Route.new(verb, pattern, version, prefixed_path: prefixed_path, **options)
|
62
58
|
end
|
63
59
|
|
64
60
|
end
|
@@ -62,5 +62,28 @@ namespace :praxis do
|
|
62
62
|
generator.save!
|
63
63
|
end
|
64
64
|
|
65
|
+
desc "Generate OpenAPI 3 docs for a Praxis App"
|
66
|
+
task :openapi => [:environment] do |t, args|
|
67
|
+
require 'fileutils'
|
68
|
+
|
69
|
+
Praxis::Blueprint.caching_enabled = false
|
70
|
+
generator = Praxis::Docs::OpenApiGenerator.new(Dir.pwd)
|
71
|
+
generator.save!
|
72
|
+
end
|
73
|
+
|
74
|
+
desc "Preview (and Generate) OpenAPI 3 docs for a Praxis App"
|
75
|
+
task :openapipreview => [:openapi] do |t, args|
|
76
|
+
require 'webrick'
|
77
|
+
docs_port = 9090
|
78
|
+
root = Dir.pwd + '/docs/openapi/'
|
79
|
+
wb = Thread.new do
|
80
|
+
s = WEBrick::HTTPServer.new(:Port => docs_port, :DocumentRoot => root)
|
81
|
+
trap('INT') { s.shutdown }
|
82
|
+
s.start
|
83
|
+
end
|
84
|
+
`open http://localhost:#{docs_port}/`
|
85
|
+
wb.join
|
86
|
+
end
|
87
|
+
|
65
88
|
end
|
66
89
|
end
|
data/lib/praxis/tasks/routes.rb
CHANGED
@@ -7,7 +7,7 @@ namespace :praxis do
|
|
7
7
|
table = Terminal::Table.new title: "Routes",
|
8
8
|
headings: [
|
9
9
|
"Version", "Path", "Verb",
|
10
|
-
"Resource", "Action", "Implementation", "
|
10
|
+
"Resource", "Action", "Implementation", "Options"
|
11
11
|
]
|
12
12
|
|
13
13
|
rows = []
|
@@ -27,24 +27,20 @@ namespace :praxis do
|
|
27
27
|
implementation: method_name,
|
28
28
|
}
|
29
29
|
|
30
|
-
|
30
|
+
unless action.route
|
31
31
|
warn "Warning: No routes defined for #{resource_definition.name}##{name}."
|
32
32
|
rows << row
|
33
33
|
else
|
34
|
-
action.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
options: route.options
|
42
|
-
})
|
34
|
+
route = action.route
|
35
|
+
rows << row.merge({
|
36
|
+
version: route.version,
|
37
|
+
verb: route.verb,
|
38
|
+
path: route.path,
|
39
|
+
options: route.options
|
40
|
+
})
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
46
|
-
end
|
47
|
-
|
48
44
|
case args[:format] || "table"
|
49
45
|
when "json"
|
50
46
|
puts JSON.pretty_generate(rows)
|
@@ -52,7 +48,7 @@ namespace :praxis do
|
|
52
48
|
rows.each do |row|
|
53
49
|
formatted_options = row[:options].map{|(k,v)| "#{k}:#{v.to_s}"}.join("\n")
|
54
50
|
row_data = row.values_at(:version, :path, :verb, :resource,
|
55
|
-
:action, :implementation
|
51
|
+
:action, :implementation)
|
56
52
|
row_data << formatted_options
|
57
53
|
table.add_row(row_data)
|
58
54
|
end
|
@@ -60,6 +56,5 @@ namespace :praxis do
|
|
60
56
|
else
|
61
57
|
raise "unknown output format: #{args[:format]}"
|
62
58
|
end
|
63
|
-
|
64
59
|
end
|
65
60
|
end
|
@@ -14,6 +14,16 @@ module Praxis
|
|
14
14
|
hash
|
15
15
|
end
|
16
16
|
|
17
|
+
def as_json_schema(**args)
|
18
|
+
the_type = @attribute && @attribute.type || member_type
|
19
|
+
the_type.as_json_schema(args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def json_schema_type
|
23
|
+
the_type = @attribute && @attribute.type || member_type
|
24
|
+
the_type.json_schema_type
|
25
|
+
end
|
26
|
+
|
17
27
|
def description(text=nil)
|
18
28
|
@description = text if text
|
19
29
|
@description
|
@@ -153,6 +153,68 @@ module Praxis
|
|
153
153
|
example
|
154
154
|
end
|
155
155
|
|
156
|
+
def self.json_schema_type
|
157
|
+
:object
|
158
|
+
end
|
159
|
+
|
160
|
+
# Multipart request bodies are special in OPEN API
|
161
|
+
# schema: # Request payload
|
162
|
+
# type: object
|
163
|
+
# properties: # Request parts
|
164
|
+
# id: # Part 1 (string value)
|
165
|
+
# type: string
|
166
|
+
# format: uuid
|
167
|
+
# address: # Part2 (object)
|
168
|
+
# type: object
|
169
|
+
# properties:
|
170
|
+
# street:
|
171
|
+
# type: string
|
172
|
+
# city:
|
173
|
+
# type: string
|
174
|
+
# profileImage: # Part 3 (an image)
|
175
|
+
# type: string
|
176
|
+
# format: binary
|
177
|
+
#
|
178
|
+
# NOTE: not sure if this
|
179
|
+
def self.as_openapi_request_body( attribute_options: {} )
|
180
|
+
hash = { type: json_schema_type }
|
181
|
+
opts = self.options.merge( attribute_options )
|
182
|
+
hash[:description] = opts[:description] if opts[:description]
|
183
|
+
hash[:default] = opts[:default] if opts[:default]
|
184
|
+
|
185
|
+
unless self.attributes.empty?
|
186
|
+
props = {}
|
187
|
+
encoding = {}
|
188
|
+
self.attributes.each do |part_name, part_attribute|
|
189
|
+
part_example = part_attribute.example
|
190
|
+
key_to_use = part_name.is_a?(Regexp) ? part_name.source : part_name
|
191
|
+
|
192
|
+
part_info = {}
|
193
|
+
if (payload_attribute = part_attribute.options[:payload_attribute])
|
194
|
+
props[key_to_use] = payload_attribute.as_json_schema(example: part_example.payload)
|
195
|
+
end
|
196
|
+
#{
|
197
|
+
# contentType: 'fff',
|
198
|
+
# headers: {
|
199
|
+
# custom1: 'safd'
|
200
|
+
# }
|
201
|
+
if (headers_attribute = part_attribute.options[:headers_attribute])
|
202
|
+
# Does this 'Content-Type' string check work?...can it be a symbol? what does it mean anyway?
|
203
|
+
encoding[key_to_use][:contentType] = headers_attribute['Content-Type'] if headers_attribute['Content-Type']
|
204
|
+
# TODO?rethink? ...is this correct?: att a 'headers' key with some header schemas if this part have some
|
205
|
+
encoding[key_to_use]['headers'] = headers_attribute.as_json_schema(example: part_example.headers)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
hash[:properties] = props
|
210
|
+
hash[:encoding] = encoding unless encoding.empty?
|
211
|
+
end
|
212
|
+
hash
|
213
|
+
end
|
214
|
+
|
215
|
+
def self.as_json_schema( shallow: false, example: nil, attribute_options: {} )
|
216
|
+
as_openapi_request_body(attribute_options: attribute_options)
|
217
|
+
end
|
156
218
|
|
157
219
|
def self.describe(shallow=true, example: nil)
|
158
220
|
type_name = Attributor.type_name(self)
|
@@ -3,8 +3,7 @@ module Praxis
|
|
3
3
|
|
4
4
|
# Should return the Response to send back
|
5
5
|
def handle!(summary:, request:, stage:, errors: nil, exception: nil, **opts)
|
6
|
-
|
7
|
-
Responses::ValidationError.new(summary: summary, errors: errors, exception: exception, documentation: documentation, **opts)
|
6
|
+
Responses::ValidationError.new(summary: summary, errors: errors, exception: exception, **opts)
|
8
7
|
end
|
9
8
|
|
10
9
|
end
|
data/lib/praxis/version.rb
CHANGED
data/praxis.gemspec
CHANGED
@@ -24,14 +24,14 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency 'mustermann', '>=1.1', '<=2'
|
25
25
|
spec.add_dependency 'activesupport', '>= 3'
|
26
26
|
spec.add_dependency 'mime', '~> 0'
|
27
|
-
spec.add_dependency 'praxis-blueprints', '>= 3.
|
28
|
-
spec.add_dependency 'attributor', '>= 5.
|
27
|
+
spec.add_dependency 'praxis-blueprints', '>= 3.5'
|
28
|
+
spec.add_dependency 'attributor', '>= 5.5'
|
29
29
|
spec.add_dependency 'thor'
|
30
30
|
spec.add_dependency 'terminal-table', '~> 1.4'
|
31
31
|
|
32
32
|
spec.add_development_dependency 'bundler'
|
33
|
-
spec.add_development_dependency 'rake', '
|
34
|
-
|
33
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
34
|
+
|
35
35
|
if RUBY_PLATFORM !~ /java/
|
36
36
|
spec.add_development_dependency 'pry'
|
37
37
|
spec.add_development_dependency 'pry-byebug'
|
@@ -49,7 +49,6 @@ Gem::Specification.new do |spec|
|
|
49
49
|
spec.add_development_dependency 'rack-test', '~> 0'
|
50
50
|
spec.add_development_dependency 'simplecov', '~> 0'
|
51
51
|
spec.add_development_dependency 'fuubar', '~> 2'
|
52
|
-
spec.add_development_dependency 'yard', ">= 0.9.20"
|
53
52
|
spec.add_development_dependency 'coveralls'
|
54
53
|
# Just for the query selector extensions etc...
|
55
54
|
spec.add_development_dependency 'sequel', '~> 5'
|
data/spec/functional_spec.rb
CHANGED
@@ -331,12 +331,15 @@ describe 'Functional specs' do
|
|
331
331
|
end
|
332
332
|
|
333
333
|
context 'wildcard verb routing' do
|
334
|
+
let(:content_type){ 'application/json' }
|
334
335
|
it 'can terminate instances with POST' do
|
335
|
-
post '/api/clouds/23/instances/1/terminate?api_version=1.0', '', 'global_session' => session
|
336
|
+
post '/api/clouds/23/instances/1/terminate?api_version=1.0', nil, 'CONTENT_TYPE' => content_type, 'global_session' => session
|
337
|
+
puts last_response.body
|
338
|
+
#binding.pry
|
336
339
|
expect(last_response.status).to eq(200)
|
337
340
|
end
|
338
341
|
it 'can terminate instances with DELETE' do
|
339
|
-
post '/api/clouds/23/instances/1/terminate?api_version=1.0', '', 'global_session' => session
|
342
|
+
post '/api/clouds/23/instances/1/terminate?api_version=1.0', nil, 'CONTENT_TYPE' => content_type, 'global_session' => session
|
340
343
|
expect(last_response.status).to eq(200)
|
341
344
|
end
|
342
345
|
|
@@ -355,7 +358,7 @@ describe 'Functional specs' do
|
|
355
358
|
|
356
359
|
context 'auth_plugin' do
|
357
360
|
it 'can terminate' do
|
358
|
-
post '/api/clouds/23/instances/1/terminate?api_version=1.0',
|
361
|
+
post '/api/clouds/23/instances/1/terminate?api_version=1.0', nil, 'global_session' => session
|
359
362
|
expect(last_response.status).to eq(200)
|
360
363
|
end
|
361
364
|
|
@@ -366,8 +369,8 @@ describe 'Functional specs' do
|
|
366
369
|
end
|
367
370
|
|
368
371
|
context 'with mismatch between Content-Type and payload' do
|
369
|
-
let(:body) { '
|
370
|
-
let(:content_type) { 'application/
|
372
|
+
let(:body) { 'some-text' }
|
373
|
+
let(:content_type) { 'application/json' }
|
371
374
|
|
372
375
|
before do
|
373
376
|
post '/api/clouds/1/instances/2/terminate?api_version=1.0', body, 'CONTENT_TYPE' => content_type, 'global_session' => session
|
@@ -376,7 +379,7 @@ describe 'Functional specs' do
|
|
376
379
|
it 'returns a useful error message' do
|
377
380
|
body = JSON.parse(last_response.body)
|
378
381
|
expect(body['name']).to eq('ValidationError')
|
379
|
-
expect(body['summary']).to match("Error loading payload. Used Content-Type: 'application/
|
382
|
+
expect(body['summary']).to match("Error loading payload. Used Content-Type: 'application/json'")
|
380
383
|
expect(body['errors']).to_not be_empty
|
381
384
|
end
|
382
385
|
end
|
@@ -115,7 +115,7 @@ describe Praxis::ActionDefinition do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
its('params.attributes.keys') { should eq [:inherited, :app_name, :name, :one]}
|
118
|
-
its('
|
118
|
+
its('route.path.to_s') { should eq '/api/foobars/hello_world/test_trait/:app_name/:one' }
|
119
119
|
its(:traits) { should eq [:test] }
|
120
120
|
|
121
121
|
it 'is reflected in the describe output' do
|
@@ -231,7 +231,7 @@ describe Praxis::ActionDefinition do
|
|
231
231
|
let(:parent_param) { ApiResources::Volumes.actions[:show].params.attributes[:id] }
|
232
232
|
|
233
233
|
it 'has the right path' do
|
234
|
-
expect(action.
|
234
|
+
expect(action.route.path.to_s).to eq '/api/clouds/:cloud_id/volumes/:volume_id/snapshots/:id'
|
235
235
|
end
|
236
236
|
|
237
237
|
its('params.attributes'){ should have_key(:cloud_id) }
|
@@ -281,22 +281,10 @@ describe Praxis::ActionDefinition do
|
|
281
281
|
subject(:action) { resource_definition.actions[:show] }
|
282
282
|
|
283
283
|
it 'works' do
|
284
|
-
expansion = action.
|
284
|
+
expansion = action.route.path.expand(cloud_id:232, id: 2)
|
285
285
|
expect(expansion).to eq "/api/clouds/232/instances/2"
|
286
286
|
end
|
287
287
|
|
288
|
-
context '#primary_route' do
|
289
|
-
it 'is the first-defined route' do
|
290
|
-
expect(action.primary_route).to be(action.routes.first)
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
context '#named_routes' do
|
295
|
-
subject(:named_routes) { action.named_routes }
|
296
|
-
|
297
|
-
its([:alternate]) { should be(action.routes[1]) }
|
298
|
-
end
|
299
|
-
|
300
288
|
end
|
301
289
|
|
302
290
|
context 'with nodoc!' do
|
@@ -339,7 +327,7 @@ describe Praxis::ActionDefinition do
|
|
339
327
|
allow(Praxis::ApiDefinition).to receive(:instance).and_return(non_singleton_api)
|
340
328
|
end
|
341
329
|
|
342
|
-
its('
|
330
|
+
its('route.path.to_s') { should eq '/apps/:app_name/foobars/hello_world/:one' }
|
343
331
|
its('params.attributes.keys') { should match_array [:inherited, :app_name, :one]}
|
344
332
|
|
345
333
|
context 'where the action overrides a base_param' do
|
@@ -17,8 +17,8 @@ describe Praxis::ApiGeneralInfo do
|
|
17
17
|
endpoint 'api.example.com'
|
18
18
|
base_path "/base"
|
19
19
|
|
20
|
-
consumes '
|
21
|
-
produces 'json'
|
20
|
+
consumes 'json'
|
21
|
+
produces 'json'
|
22
22
|
|
23
23
|
base_params do
|
24
24
|
attribute :name, String
|
@@ -40,8 +40,8 @@ describe Praxis::ApiGeneralInfo do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
its(:name) { should eq 'Name' }
|
43
|
-
its(:consumes) { should eq ['
|
44
|
-
its(:produces) { should eq ['json'
|
43
|
+
its(:consumes) { should eq ['json']}
|
44
|
+
its(:produces) { should eq ['json']}
|
45
45
|
end
|
46
46
|
|
47
47
|
context '.describe' do
|
@@ -59,8 +59,8 @@ describe Praxis::ApiGeneralInfo do
|
|
59
59
|
its([:base_params, :name, :type, :name]) { should eq 'String' }
|
60
60
|
its([:version_with]) { should eq([:header, :params]) }
|
61
61
|
its([:endpoint]) { should eq 'api.example.com' }
|
62
|
-
its([:consumes]) { should eq ['
|
63
|
-
its([:produces]) { should eq ['json'
|
62
|
+
its([:consumes]) { should eq ['json'] }
|
63
|
+
its([:produces]) { should eq ['json'] }
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'base_path with versioning' do
|