lurker 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -1
- data/Gemfile +1 -0
- data/features/dereferencing_through_inlining.feature +102 -0
- data/features/partials.feature +3 -1
- data/features/step_definitions/additional_cli_steps.rb +19 -0
- data/features/support/files_helper.rb +7 -0
- data/lib/lurker/endpoint.rb +85 -50
- data/lib/lurker/json/concerns/validatable.rb +47 -0
- data/lib/lurker/json/orderer.rb +19 -0
- data/lib/lurker/json/parser/expertise.rb +30 -0
- data/lib/lurker/json/parser/plain_strategy.rb +39 -0
- data/lib/lurker/json/parser/typed_strategy.rb +71 -0
- data/lib/lurker/json/parser.rb +73 -0
- data/lib/lurker/json/reader.rb +28 -0
- data/lib/lurker/json/schema/attribute.rb +115 -0
- data/lib/lurker/json/schema/extensions.rb +19 -0
- data/lib/lurker/json/schema/list.rb +51 -0
- data/lib/lurker/json/schema/object.rb +67 -0
- data/lib/lurker/json/schema/reference.rb +34 -0
- data/lib/lurker/{endpoint → json/schema}/response_codes.rb +13 -16
- data/lib/lurker/json/schema/tuple/all_of.rb +17 -0
- data/lib/lurker/json/schema/tuple/any_of.rb +17 -0
- data/lib/lurker/json/schema/tuple/one_of.rb +17 -0
- data/lib/lurker/json/schema/tuple.rb +38 -0
- data/lib/lurker/json/schema.rb +122 -0
- data/lib/lurker/json/writter.rb +58 -0
- data/lib/lurker/presenters/endpoint_presenter.rb +2 -2
- data/lib/lurker/presenters/schema_presenter.rb +4 -1
- data/lib/lurker/presenters/service_presenter.rb +8 -2
- data/lib/lurker/service.rb +4 -4
- data/lib/lurker/version.rb +1 -1
- data/lib/lurker.rb +19 -8
- data/spec/lurker/json/list_spec.rb +101 -0
- data/spec/lurker/json/schema_spec.rb +126 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/matchers/json_attribute.rb +27 -0
- data/spec/support/matchers/json_object.rb +33 -0
- data/templates/generate_stuff.rb +19 -10
- data.tar.gz.sig +2 -4
- metadata +33 -9
- metadata.gz.sig +0 -0
- data/lib/lurker/endpoint/http_parameters.rb +0 -77
- data/lib/lurker/schema.rb +0 -89
- data/lib/lurker/schema_modifier/array.rb +0 -28
- data/lib/lurker/schema_modifier/atom.rb +0 -97
- data/lib/lurker/schema_modifier/hash.rb +0 -30
- data/lib/lurker/schema_modifier.rb +0 -48
data/lib/lurker/schema.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Lurker
|
4
|
-
class Schema
|
5
|
-
EXTENSIONS = "extensions".freeze
|
6
|
-
DESCRPTIONS = {
|
7
|
-
'index' => 'listing',
|
8
|
-
'show' => '',
|
9
|
-
'edit' => 'editing',
|
10
|
-
'create' => 'creation',
|
11
|
-
'update' => 'updating',
|
12
|
-
'destroy' => 'descruction'
|
13
|
-
}
|
14
|
-
attr_reader :extensions
|
15
|
-
|
16
|
-
def initialize(json_schema_hash, extensions = {})
|
17
|
-
@hash = json_schema_hash
|
18
|
-
|
19
|
-
existing_extensions = @hash.delete(EXTENSIONS) || {}
|
20
|
-
@extensions = select_extensions(existing_extensions, extensions)
|
21
|
-
end
|
22
|
-
|
23
|
-
def respond_to_missing?(method, include_private = false)
|
24
|
-
@hash.send(:respond_to_missing?, method, include_private)
|
25
|
-
end
|
26
|
-
|
27
|
-
def method_missing(method, *args, &block)
|
28
|
-
@hash.send method, *args, &block
|
29
|
-
end
|
30
|
-
|
31
|
-
def write_to(path)
|
32
|
-
if @hash['prefix'].blank?
|
33
|
-
@hash['prefix'] = "#{default_subject} management"
|
34
|
-
end
|
35
|
-
if @hash['description'].blank?
|
36
|
-
@hash['description'] = default_descrption.strip
|
37
|
-
end
|
38
|
-
|
39
|
-
dirname = File.dirname(path)
|
40
|
-
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
|
41
|
-
|
42
|
-
File.open(path, "w") do |file|
|
43
|
-
file.write(to_yaml)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def to_yaml
|
48
|
-
YAML.dump(@hash.merge(
|
49
|
-
EXTENSIONS => @extensions
|
50
|
-
))
|
51
|
-
end
|
52
|
-
|
53
|
-
def ordered!
|
54
|
-
@hash = Hash[@hash.sort]
|
55
|
-
@extensions = Hash[@extensions.sort]
|
56
|
-
self
|
57
|
-
end
|
58
|
-
|
59
|
-
protected
|
60
|
-
|
61
|
-
def serialized_for_diff
|
62
|
-
@serialized_for_diff ||= YAML.dump(@hash).each_line.map do |l|
|
63
|
-
l unless l.match(/description|example/)
|
64
|
-
end.compact.join
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def select_extensions(existing, given)
|
70
|
-
if Lurker.upgrade? || (existing.blank? && given.present?)
|
71
|
-
given
|
72
|
-
else
|
73
|
-
existing
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def default_descrption
|
78
|
-
"#{default_subject.singularize} #{DESCRPTIONS[path_params['action']]}"
|
79
|
-
end
|
80
|
-
|
81
|
-
def default_subject
|
82
|
-
"#{path_params['controller'].to_s.split(/\//).last}"
|
83
|
-
end
|
84
|
-
|
85
|
-
def path_params
|
86
|
-
@extensions['path_params'] || {}
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module Lurker
|
2
|
-
class SchemaModifier
|
3
|
-
class Array
|
4
|
-
def initialize(json_schema_hash)
|
5
|
-
@array = json_schema_hash
|
6
|
-
end
|
7
|
-
|
8
|
-
def merge!(data)
|
9
|
-
build_array
|
10
|
-
|
11
|
-
data.each do |value|
|
12
|
-
Lurker::SchemaModifier.merge!(@array["items"], value)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def append!(data)
|
17
|
-
@array << data
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def build_array
|
23
|
-
@array["type"] ||= "array"
|
24
|
-
@array["items"] ||= {}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
module Lurker
|
2
|
-
class SchemaModifier
|
3
|
-
class Atom
|
4
|
-
TYPE_MAP = {
|
5
|
-
"ActionDispatch::Http::UploadedFile" => "string",
|
6
|
-
"Fixnum" => "integer",
|
7
|
-
"Float" => "number",
|
8
|
-
"Hash" => "object",
|
9
|
-
"Time" => "string",
|
10
|
-
"TrueClass" => "boolean",
|
11
|
-
"FalseClass" => "boolean",
|
12
|
-
"NilClass" => "null"
|
13
|
-
}.freeze
|
14
|
-
|
15
|
-
DATE_TIME_FORMAT = "date-time".freeze
|
16
|
-
COLOR_FORMAT = "color".freeze
|
17
|
-
URI_FORMAT = "uri".freeze
|
18
|
-
|
19
|
-
def initialize(json_schema_hash)
|
20
|
-
@atom = json_schema_hash
|
21
|
-
end
|
22
|
-
|
23
|
-
def merge!(data)
|
24
|
-
atom = build_atom(data)
|
25
|
-
combined? ? append_new(atom) : combine_with(atom)
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def combine_with(atom)
|
31
|
-
return @atom.clear.merge!(atom) unless @atom.key?("type")
|
32
|
-
|
33
|
-
if @atom["type"] != atom["type"]
|
34
|
-
existing_atom = JsonSchemaHash === @atom ? @atom.to_h : @atom.dup
|
35
|
-
@atom.clear
|
36
|
-
@atom["anyOf"] = [existing_atom, atom]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def append_new(atom)
|
41
|
-
# TODO : If example empty - fill from duplicate
|
42
|
-
return if @atom["anyOf"].detect { |atm| atm["type"] == atom["type"] }
|
43
|
-
|
44
|
-
@atom["anyOf"] << atom
|
45
|
-
end
|
46
|
-
|
47
|
-
def combined?
|
48
|
-
!!@atom["anyOf"]
|
49
|
-
end
|
50
|
-
|
51
|
-
def build_atom(data)
|
52
|
-
atom = {
|
53
|
-
"description" => "",
|
54
|
-
"type" => guess_type(data),
|
55
|
-
"example" => serialize_example(data)
|
56
|
-
}
|
57
|
-
|
58
|
-
if format = guess_format(data)
|
59
|
-
atom["format"] = format
|
60
|
-
end
|
61
|
-
|
62
|
-
atom
|
63
|
-
end
|
64
|
-
|
65
|
-
def serialize_example(data)
|
66
|
-
if data.is_a?(ActionDispatch::Http::UploadedFile)
|
67
|
-
data.headers
|
68
|
-
else
|
69
|
-
data
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def guess_type(data)
|
74
|
-
in_type = data.class.to_s
|
75
|
-
TYPE_MAP[in_type] || in_type.downcase
|
76
|
-
end
|
77
|
-
|
78
|
-
def guess_format(data)
|
79
|
-
if data.is_a?(Time)
|
80
|
-
DATE_TIME_FORMAT
|
81
|
-
elsif data.is_a?(String)
|
82
|
-
if data.start_with? "http://"
|
83
|
-
URI_FORMAT
|
84
|
-
elsif data.match(/\#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3})?\b/)
|
85
|
-
COLOR_FORMAT
|
86
|
-
else
|
87
|
-
begin
|
88
|
-
DATE_TIME_FORMAT if Time.iso8601(data)
|
89
|
-
rescue
|
90
|
-
nil
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end # class Atom
|
96
|
-
end
|
97
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Lurker
|
2
|
-
class SchemaModifier
|
3
|
-
class Hash
|
4
|
-
def initialize(json_schema_hash)
|
5
|
-
@hash = json_schema_hash
|
6
|
-
end
|
7
|
-
|
8
|
-
def merge!(data)
|
9
|
-
build_hash
|
10
|
-
|
11
|
-
data.each do |name, value|
|
12
|
-
unless @hash[name]
|
13
|
-
@hash["properties"][name] ||= {}
|
14
|
-
Lurker::SchemaModifier.merge!(@hash["properties"][name], value)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def build_hash
|
22
|
-
@hash["description"] ||= ""
|
23
|
-
@hash["type"] ||= "object"
|
24
|
-
@hash["additionalProperties"] = false if @hash["additionalProperties"].nil?
|
25
|
-
@hash["required"] ||= []
|
26
|
-
@hash["properties"] ||= {}
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Lurker
|
2
|
-
class SchemaModifier
|
3
|
-
class << self
|
4
|
-
def merge!(schema, data)
|
5
|
-
new(schema, data).merge!
|
6
|
-
end
|
7
|
-
|
8
|
-
def append!(schema, data)
|
9
|
-
new(schema, data).append!
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(schema, data)
|
14
|
-
@schema = schema
|
15
|
-
@data = data
|
16
|
-
end
|
17
|
-
|
18
|
-
def merge!
|
19
|
-
modifier_klass.new(@schema).merge!(@data)
|
20
|
-
@schema
|
21
|
-
end
|
22
|
-
|
23
|
-
def append!
|
24
|
-
schema_klass.new(@schema).append!(@data)
|
25
|
-
@schema
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def schema_klass
|
31
|
-
klass_from_type(@schema)
|
32
|
-
end
|
33
|
-
|
34
|
-
def modifier_klass
|
35
|
-
klass_from_type(@data)
|
36
|
-
end
|
37
|
-
|
38
|
-
def klass_from_type(anything)
|
39
|
-
if anything.is_a?(::Hash)
|
40
|
-
Lurker::SchemaModifier::Hash
|
41
|
-
elsif anything.is_a?(::Array)
|
42
|
-
Lurker::SchemaModifier::Array
|
43
|
-
else
|
44
|
-
Lurker::SchemaModifier::Atom
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|