api_schema 0.2.2.1 → 0.2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3358bdecaec39f6472c13ae3e3fd1ea154ec2a0d
4
- data.tar.gz: a79b3e5828f4ab3fc5149b755967668339ee4329
3
+ metadata.gz: d16c885ecc2244dedb62a305988a3119768c17dc
4
+ data.tar.gz: a3c607eb9ec54baea72f10b704ab02ceb4d5e595
5
5
  SHA512:
6
- metadata.gz: ae92521c717add88eba74d5287f00d6ba493e53b1237e06ddfd0a678e10024a0e86ad4b9f5c86d685f0d3766dc3b743df115c546c41bba5313d34d2d73d27c07
7
- data.tar.gz: 7bf634c99b23adfcb1ebf2c7809b26dcb8b8e760c5f050f669e932d196a4aa4fa8877d0c01fe82d423b05b40247125a90455b89b23c5a814046ca0c56b82e494
6
+ metadata.gz: 559137990458f47c04250aa5a8f125727fa075763ee84814c250b0b045c5f29ab358daeb88033c112050e781df59eba13377656b0d84fa54d80206d68a2195e7
7
+ data.tar.gz: 1fb654b77552faa11e16e85f8fc3b4cb0c728b59d4329b0e2f571cf99d669d087d3b4cfc32481b11125a5f11e51974d9f5d1def2638a718581d186f149f83349
@@ -14,6 +14,7 @@ module ApiSchema
14
14
  def check_consistency
15
15
  check_serializers_consistency
16
16
  check_resources_consistency
17
+ check_desc_files_consistency
17
18
 
18
19
  raise UndefinedSerializersError, error_message unless errors.empty?
19
20
  end
@@ -35,6 +36,18 @@ module ApiSchema
35
36
  end
36
37
  end
37
38
 
39
+ def check_desc_files_consistency
40
+ resources.each do |resource|
41
+ add_errors(:undefined_desc_file, resource) unless find_or_import_desc_file(resource)
42
+ end
43
+ end
44
+
45
+ def find_or_import_desc_file(resource)
46
+ return true unless resource.desc_file_name
47
+ return true if find_in_version_desc_file(self, resource)
48
+ return true if find_in_another_version_desc_file(resource)
49
+ end
50
+
38
51
  def find_or_import(serializer_id)
39
52
  return true unless serializer_id
40
53
  return true if find_in_version(self, serializer_id)
@@ -55,8 +68,23 @@ module ApiSchema
55
68
  version.serializers.detect { |s| s.id == serializer_id }
56
69
  end
57
70
 
71
+ def find_in_another_version_desc_file(resource)
72
+ imported_versions.each do |import|
73
+ version = imported_version(import)
74
+ return true if find_in_version_desc_file(version, resource)
75
+ end
76
+
77
+ false
78
+ end
79
+
80
+ def find_in_version_desc_file(version, resource)
81
+ file_path = "#{version.configuration.descriptions_path}/#{resource.desc_file_name}.md"
82
+ return resource.desc_file_path = file_path if File.file?(file_path)
83
+ end
84
+
58
85
  def imported_version(import)
59
- "#{import.name.capitalize}::#{import.api_version.capitalize}::BaseDocs".constantize.api_version
86
+ "#{import.name.capitalize}::#{import.api_version.capitalize}::BaseDocs"
87
+ .constantize.api_version
60
88
  end
61
89
 
62
90
  def add_errors(key, object)
@@ -73,6 +101,8 @@ module ApiSchema
73
101
  memo += errors.map(&self.method(:response_error))
74
102
  when :undefined_reference
75
103
  memo += errors.map(&self.method(:reference_error))
104
+ when :undefined_desc_file
105
+ memo += errors.map(&self.method(:desc_file_error))
76
106
  end
77
107
  end
78
108
 
@@ -80,15 +110,21 @@ module ApiSchema
80
110
  end
81
111
 
82
112
  def body_error(object)
83
- "There is no '#{object.body_param}' body parameter defined for #{object.base_path} resource. Please define it with 'request_body' method"
113
+ "There is no '#{object.body_param}' body parameter defined for #{object.base_path}
114
+ resource. Please define it with 'request_body' method"
84
115
  end
85
116
 
86
117
  def response_error(object)
87
- "There is no '#{object.resp.model}' response defined for '#{object.summary}' resource. Please define it with 'serializer' method"
118
+ "There is no '#{object.resp.model}' response defined for '#{object.summary}'
119
+ resource. Please define it with 'serializer' method"
88
120
  end
89
121
 
90
122
  def reference_error(object)
91
123
  "Reference #{object.id} is not defined"
92
124
  end
125
+
126
+ def desc_file_error(object)
127
+ "The file '#{object.desc_file_name}' cannot be found"
128
+ end
93
129
  end
94
130
  end
@@ -17,9 +17,11 @@ module ApiSchema
17
17
  PathParam = ::Struct.new(:name, :type, :required)
18
18
  QueryParam = ::Struct.new(:name, :type, :required)
19
19
 
20
- attr_reader :method, :api_version, :summary, :description, :header_params, :body_param,
21
- :path_params, :query_params, :resp,
22
- :errors, :base_path, :extra_path, :full_path
20
+ attr_accessor :desc_file_path
21
+
22
+ attr_reader :method, :api_version, :summary, :description, :header_params,
23
+ :body_param, :path_params, :query_params, :resp, :errors,
24
+ :base_path, :extra_path, :full_path, :desc_file_name
23
25
 
24
26
  def name(name)
25
27
  @summary = name
@@ -29,8 +31,8 @@ module ApiSchema
29
31
  @description = desc
30
32
  end
31
33
 
32
- def desc_file(desc_file)
33
- @description = IO.read("#{api_version.configuration.descriptions_path}/#{desc_file}.md", encoding: 'utf-8')
34
+ def desc_file(desc_file_name)
35
+ @desc_file_name = desc_file_name
34
36
  end
35
37
 
36
38
  def header(name, type, required: true)
@@ -77,6 +79,10 @@ module ApiSchema
77
79
  @full_path << "/#{extra_path}" if extra_path
78
80
  end
79
81
 
82
+ def build_description
83
+ @description = IO.read(desc_file_path, encoding: 'utf-8')
84
+ end
85
+
80
86
  def build_neighbors(neighbors)
81
87
  generate_full_path
82
88
  neighbors[full_path] ||= []
@@ -91,6 +97,8 @@ module ApiSchema
91
97
  '404' => "Not found",
92
98
  '422' => "Unprocessable Entity"
93
99
  }
100
+
101
+ build_description if desc_file_name
94
102
  resource = self
95
103
  swagger_path resource.full_path do
96
104
  neighbors[resource.full_path].each do |r|
@@ -1,3 +1,3 @@
1
1
  module ApiSchema
2
- VERSION = "0.2.2.1"
2
+ VERSION = "0.2.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2.1
4
+ version: 0.2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Chopey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-09 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport