fitting 2.11.0 → 2.14.0

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.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/.rubocop.yml +1 -1
  4. data/.ruby-version +1 -1
  5. data/.tool-versions +1 -0
  6. data/.travis.yml +1 -1
  7. data/CHANGELOG.md +47 -0
  8. data/README.md +136 -76
  9. data/fitting.gemspec +1 -1
  10. data/lib/fitting.rb +5 -0
  11. data/lib/fitting/cover/json_schema.rb +21 -80
  12. data/lib/fitting/cover/json_schema_enum.rb +20 -70
  13. data/lib/fitting/cover/json_schema_one_of.rb +38 -0
  14. data/lib/fitting/records/spherical/requests.rb +3 -1
  15. data/lib/fitting/records/unit/json_schema.rb +26 -0
  16. data/lib/fitting/report/action.rb +53 -0
  17. data/lib/fitting/report/actions.rb +55 -0
  18. data/lib/fitting/report/combination.rb +37 -0
  19. data/lib/fitting/report/combinations.rb +47 -0
  20. data/lib/fitting/report/console.rb +41 -0
  21. data/lib/fitting/report/prefix.rb +53 -0
  22. data/lib/fitting/report/prefixes.rb +44 -0
  23. data/lib/fitting/report/response.rb +71 -0
  24. data/lib/fitting/report/responses.rb +48 -0
  25. data/lib/fitting/report/test.rb +61 -0
  26. data/lib/fitting/report/tests.rb +62 -0
  27. data/lib/fitting/statistics/cover_error_one_of.rb +27 -0
  28. data/lib/fitting/statistics/list.rb +2 -0
  29. data/lib/fitting/statistics/measurement_cover_one_of.rb +92 -0
  30. data/lib/fitting/statistics/template.rb +5 -0
  31. data/lib/fitting/statistics/template_cover_error_one_of.rb +50 -0
  32. data/lib/fitting/tests.rb +0 -1
  33. data/lib/fitting/version.rb +1 -1
  34. data/lib/tasks/fitting.rake +150 -2
  35. data/lib/templates/bomboniere/.gitignore +21 -0
  36. data/lib/templates/bomboniere/.tool-versions +1 -0
  37. data/lib/templates/bomboniere/README.md +19 -0
  38. data/lib/templates/bomboniere/dist/css/app.62e086ac.css +1 -0
  39. data/lib/templates/bomboniere/dist/css/chunk-vendors.ec5f6c3f.css +1 -0
  40. data/lib/templates/bomboniere/dist/favicon.ico +0 -0
  41. data/lib/templates/bomboniere/dist/index.html +1 -0
  42. data/lib/templates/bomboniere/dist/js/app.4356d509.js +2 -0
  43. data/lib/templates/bomboniere/dist/js/app.4356d509.js.map +1 -0
  44. data/lib/templates/bomboniere/dist/js/chunk-vendors.90aeb613.js +13 -0
  45. data/lib/templates/bomboniere/dist/js/chunk-vendors.90aeb613.js.map +1 -0
  46. data/lib/templates/bomboniere/package-lock.json +9263 -0
  47. data/lib/templates/bomboniere/package.json +25 -0
  48. data/lib/templates/bomboniere/public/favicon.ico +0 -0
  49. data/lib/templates/bomboniere/public/index.html +17 -0
  50. data/lib/templates/bomboniere/src/App.vue +102 -0
  51. data/lib/templates/bomboniere/src/assets/logo.png +0 -0
  52. data/lib/templates/bomboniere/src/components/HelloWorld.vue +188 -0
  53. data/lib/templates/bomboniere/src/main.js +10 -0
  54. data/lib/templates/bomboniere/src/router/index.js +31 -0
  55. data/lib/templates/bomboniere/src/views/About.vue +5 -0
  56. data/lib/templates/bomboniere/src/views/Action.vue +154 -0
  57. data/lib/templates/bomboniere/src/views/Home.vue +17 -0
  58. data/lib/templates/bomboniere/vue.config.js +3 -0
  59. metadata +47 -8
@@ -0,0 +1,27 @@
1
+ module Fitting
2
+ class Statistics
3
+ class CoverErrorOneOf
4
+ def initialize(request_unit)
5
+ @request_unit = request_unit
6
+ end
7
+
8
+ def to_s
9
+ res = ''
10
+ @request_unit.map do |request|
11
+ request.responses.map do |response|
12
+ next unless response.tested_bodies != []
13
+ response.json_schemas.map do |json_schema|
14
+ json_schema.combinations_with_one_of.map do |combination|
15
+ next unless combination.valid_bodies == []
16
+ res += "request method: #{request.method}\nrequest path: #{request.path}\n"\
17
+ "response status: #{response.status}\nsource json-schema: #{json_schema.json_schema}\n"\
18
+ "combination: #{combination.description}\nnew json-schema: #{combination.json_schema}\n\n"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ res
24
+ end
25
+ end
26
+ end
27
+ end
@@ -45,6 +45,8 @@ module Fitting
45
45
  res.push("#{json_schema.cover}% #{response.status}")
46
46
  elsif @depth == 'cover_enum'
47
47
  res.push("#{json_schema.cover_enum}% #{response.status}")
48
+ elsif @depth == 'cover_one_of'
49
+ res.push("#{json_schema.cover_one_of}% #{response.status}")
48
50
  end
49
51
  end
50
52
  end
@@ -0,0 +1,92 @@
1
+ module Fitting
2
+ class Statistics
3
+ class MeasurementCoverOneOf
4
+ attr_reader :requests, :all_responses, :cover_responses, :not_cover_responses, :max_response_path,
5
+ :coverage_fully, :coverage_non, :coverage_partially, :not_covered_responses
6
+
7
+ def initialize(requests)
8
+ @requests = requests
9
+ @all_responses = 0
10
+ @cover_responses = 0
11
+ @not_cover_responses = 0
12
+ @max_response_path = 0
13
+ @coverage_fully = []
14
+ @coverage_non = []
15
+ @coverage_partially = []
16
+ @not_covered_responses = []
17
+ check_responses
18
+ end
19
+
20
+ def check_responses
21
+ return if @ready
22
+
23
+ @requests.map do |request|
24
+ chech_request(request)
25
+ end
26
+
27
+ @ready = true
28
+ end
29
+
30
+ private
31
+
32
+ def chech_request(request)
33
+ check_cover(request)
34
+ coverage_push(request)
35
+
36
+ @max_response_path = request.path.to_s.size / 8 if request.path.to_s.size / 8 > @max_response_path
37
+ request.responses.map do |response|
38
+ check_response(response, request)
39
+ end
40
+ end
41
+
42
+ def check_response(response, request)
43
+ json_schema_index = 0
44
+ response.json_schemas.map do |json_schema|
45
+ json_schema_index = check_json_schema(json_schema, request, response, json_schema_index)
46
+ end
47
+ end
48
+
49
+ def check_json_schema(json_schema, request, response, json_schema_index)
50
+ if json_schema.cover_one_of != 100
51
+ @not_cover_responses += 1
52
+ @not_covered_responses.push("#{request.method}\t#{request.path} #{response.status} #{json_schema_index}")
53
+ else
54
+ @cover_responses += 1
55
+ end
56
+ @all_responses += 1
57
+ json_schema_index + 1
58
+ end
59
+
60
+ def coverage_push(request)
61
+ if @all == @cover
62
+ @coverage_fully.push(request)
63
+ elsif @all == @not_cover
64
+ @coverage_non.push(request)
65
+ else
66
+ @coverage_partially.push(request)
67
+ end
68
+ end
69
+
70
+ def check_cover(request)
71
+ @all = 0
72
+ @cover = 0
73
+ @not_cover = 0
74
+
75
+ request.responses.map do |response|
76
+ response.json_schemas.map do |json_schema|
77
+ count_cover(json_schema)
78
+ end
79
+ end
80
+ end
81
+
82
+ def count_cover(json_schema)
83
+ @all += 1
84
+ if json_schema.cover_one_of != 100
85
+ @not_cover += 1
86
+ else
87
+ @cover += 1
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -3,6 +3,7 @@ require 'fitting/statistics/analysis'
3
3
  require 'fitting/statistics/measurement'
4
4
  require 'fitting/statistics/measurement_cover'
5
5
  require 'fitting/statistics/measurement_cover_enum'
6
+ require 'fitting/statistics/measurement_cover_one_of'
6
7
  require 'fitting/records/unit/request'
7
8
  require 'fitting/storage/white_list'
8
9
  require 'fitting/records/documented/request'
@@ -53,6 +54,8 @@ module Fitting
53
54
  Fitting::Statistics::MeasurementCover.new(white_unit)
54
55
  elsif @depth == 'cover_enum'
55
56
  Fitting::Statistics::MeasurementCoverEnum.new(white_unit)
57
+ elsif @depth == 'cover_one_of'
58
+ Fitting::Statistics::MeasurementCoverOneOf.new(white_unit)
56
59
  end
57
60
  end
58
61
 
@@ -64,6 +67,8 @@ module Fitting
64
67
  Fitting::Statistics::MeasurementCover.new(black_unit)
65
68
  elsif @depth == 'cover_enum'
66
69
  Fitting::Statistics::MeasurementCoverEnum.new(black_unit)
70
+ elsif @depth == 'cover_one_of'
71
+ Fitting::Statistics::MeasurementCoverOneOf.new(black_unit)
67
72
  end
68
73
  end
69
74
 
@@ -0,0 +1,50 @@
1
+ require 'fitting/statistics/cover_error_one_of'
2
+ require 'fitting/records/unit/request'
3
+ require 'fitting/storage/white_list'
4
+ require 'fitting/records/documented/request'
5
+
6
+ module Fitting
7
+ class Statistics
8
+ class TemplateCoverErrorOneOf
9
+ def initialize(tested_requests, config)
10
+ @tested_requests = tested_requests
11
+ @config = config
12
+ end
13
+
14
+ def stats
15
+ "#{white_statistics}\n\n"
16
+ end
17
+
18
+ def white_statistics
19
+ @white_statistics ||= Fitting::Statistics::CoverErrorOneOf.new(white_unit)
20
+ end
21
+
22
+ def white_unit
23
+ @white_unit_requests ||= documented_requests_white.inject([]) do |res, documented_request|
24
+ res.push(Fitting::Records::Unit::Request.new(documented_request, @tested_requests))
25
+ end
26
+ end
27
+
28
+ def documented_requests_white
29
+ @documented_requests_white ||= documented.find_all(&:white)
30
+ end
31
+
32
+ def documented
33
+ @documented_requests ||= @config.tomogram.to_a.inject([]) do |res, tomogram_request|
34
+ res.push(Fitting::Records::Documented::Request.new(tomogram_request, white_list.to_a))
35
+ end
36
+ end
37
+
38
+ def white_list
39
+ @white_list ||= Fitting::Storage::WhiteList.new(
40
+ @config.prefix,
41
+ @config.white_list,
42
+ @config.resource_white_list,
43
+ @config.include_resources,
44
+ @config.include_actions,
45
+ @config.tomogram.to_resources
46
+ )
47
+ end
48
+ end
49
+ end
50
+ end
@@ -9,7 +9,6 @@ module Fitting
9
9
  def save
10
10
  make_dir('fitting_tests')
11
11
  array = @tested_requests.inject([]) do |res, request|
12
- next res unless request.path.to_s.start_with?(Fitting.configuration.prefix)
13
12
  res.push(request.to_spherical.to_hash)
14
13
  end
15
14
  json = JSON.dump(array)
@@ -1,3 +1,3 @@
1
1
  module Fitting
2
- VERSION = '2.11.0'.freeze
2
+ VERSION = '2.14.0'.freeze
3
3
  end
@@ -4,8 +4,137 @@ require 'fitting/records/realized_unit'
4
4
  require 'fitting/templates/realized_template'
5
5
  require 'fitting/statistics/template_cover_error'
6
6
  require 'fitting/statistics/template_cover_error_enum'
7
+ require 'fitting/statistics/template_cover_error_one_of'
8
+ require 'fitting/cover/json_schema'
9
+ require 'fitting/report/prefixes'
10
+ require 'fitting/report/tests'
11
+ require 'fitting/report/console'
7
12
 
8
13
  namespace :fitting do
14
+ task :report do
15
+ tests = Fitting::Report::Tests.new_from_config('fitting_tests/*.json')
16
+ prefixes = Fitting::Report::Prefixes.new('.fitting.yml')
17
+
18
+ prefixes.join(tests)
19
+
20
+ prefixes.to_a.map do |prefix|
21
+ prefix.actions.join(prefix.tests) unless prefix.skip?
22
+ end
23
+
24
+ prefixes.to_a.map do |prefix|
25
+ prefix.actions.to_a.map do |action|
26
+ action.responses.join(action.tests)
27
+ end unless prefix.skip?
28
+ end
29
+
30
+ prefixes.to_a.map do |prefix|
31
+ prefix.actions.to_a.map do |action|
32
+ action.responses.to_a.map do |response|
33
+ response.combinations.join(response.tests)
34
+ end
35
+ end unless prefix.skip?
36
+ end
37
+
38
+ report = JSON.pretty_generate(
39
+ {
40
+ tests_without_prefixes: tests.without_prefixes,
41
+ prefixes_details: prefixes.to_a.map { |p| p.details }
42
+ }
43
+ )
44
+
45
+ destination = 'fitting'
46
+ FileUtils.rm_r Dir.glob("#{destination}/*"), :force => true
47
+ File.open('fitting/report.json', 'w') { |file| file.write(report) }
48
+
49
+ gem_path = $LOAD_PATH.find { |i| i.include?('fitting') }
50
+ source_path = "#{gem_path}/templates/bomboniere/dist"
51
+ FileUtils.copy_entry source_path, destination
52
+
53
+ json_schemas = {}
54
+ combinations = {}
55
+ prefixes.to_a.map do |prefix|
56
+ prefix.actions.to_a.map do |action|
57
+ action.responses.to_a.map do |response|
58
+ json_schemas.merge!(response.id => response.body)
59
+ response.combinations.to_a.map do |combination|
60
+ combinations.merge!(combination.id => combination.json_schema)
61
+ end
62
+ end
63
+ end unless prefix.skip?
64
+ end
65
+ File.open('fitting/json_schemas.json', 'w') { |file| file.write(JSON.pretty_generate(json_schemas)) }
66
+ File.open('fitting/combinations.json', 'w') { |file| file.write(JSON.pretty_generate(combinations)) }
67
+
68
+ js_path = Dir["#{destination}/js/*"].find { |f| f[0..14] == 'fitting/js/app.' and f[-3..-1] == '.js' }
69
+ js_file = File.read(js_path)
70
+ new_js_file = js_file.gsub("{stub:\"prefixes report\"}", report)
71
+ new_js_file = new_js_file.gsub("{stub:\"for action page\"}", report)
72
+ new_js_file = new_js_file.gsub("{stub:\"json-schemas\"}", JSON.pretty_generate(json_schemas))
73
+ new_js_file = new_js_file.gsub("{stub:\"combinations\"}", JSON.pretty_generate(combinations))
74
+ File.open(js_path, 'w') { |file| file.write(new_js_file) }
75
+
76
+ console = Fitting::Report::Console.new(
77
+ tests.without_prefixes,
78
+ prefixes.to_a.map { |p| p.details }
79
+ )
80
+
81
+ puts console.output
82
+
83
+ exit 1 unless console.good?
84
+
85
+ exit 0
86
+
87
+ actions.map do |action|
88
+ action.to_hash["responses"].map do |response|
89
+ response['combination'] ||= []
90
+ combinations = Fitting::Cover::JSONSchema.new(response['body']).combi + Fitting::Cover::JSONSchemaEnum.new(response['body']).combi + Fitting::Cover::JSONSchemaOneOf.new(response['body']).combi
91
+ if combinations != []
92
+ combinations.map do |combination|
93
+ response['combination'].push(
94
+ {
95
+ 'json_schema' => combination[0],
96
+ 'type' => combination[1][0],
97
+ 'combination' => combination[1][1],
98
+ 'tests' => [],
99
+ 'error' => []
100
+ }
101
+ )
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ actions.map do |action|
108
+ action.to_hash["responses"].map do |response|
109
+ response['tests'] ||= []
110
+ response['tests'].map do |test|
111
+ if response['combination'][0]
112
+ response['combination'].map do |combination|
113
+ begin
114
+ res = JSON::Validator.fully_validate(combination['json_schema'], test['response']['body'])
115
+ if res == []
116
+ combination['tests'].push(test)
117
+ response['tests'] = response['tests'] - [test]
118
+ next
119
+ else
120
+ combination['error'].push({test: test, error: res})
121
+ end
122
+ rescue JSON::Schema::SchemaError => error
123
+ combination['error'].push({test: test, error: error})
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ actions_test = {actions: actions, tests: tests}
132
+
133
+ makedirs('fitting')
134
+ File.open('fitting/old_report.json', 'w') { |file| file.write(MultiJson.dump(actions_test)) }
135
+ end
136
+
137
+ # deprecated
9
138
  desc 'Fitting documentation'
10
139
  task :documentation do
11
140
  documented_unit = Fitting::Statistics::Template.new(
@@ -53,12 +182,24 @@ namespace :fitting do
53
182
  )
54
183
  puts documented_unit.stats
55
184
 
185
+ unless documented_unit.not_covered == "\n"
186
+ puts 'Not all responses from the whitelist are covered!'
187
+ exit 1
188
+ end
189
+ elsif args.size == 'l'
190
+ documented_unit = Fitting::Statistics::Template.new(
191
+ Fitting::Records::Spherical::Requests.new,
192
+ Fitting.configuration,
193
+ 'cover_one_of'
194
+ )
195
+ puts documented_unit.stats
196
+
56
197
  unless documented_unit.not_covered == "\n"
57
198
  puts 'Not all responses from the whitelist are covered!'
58
199
  exit 1
59
200
  end
60
201
  else
61
- puts 'need key xs, s or m'
202
+ puts 'need key xs, s, m or l'
62
203
  end
63
204
  end
64
205
 
@@ -76,11 +217,18 @@ namespace :fitting do
76
217
  Fitting.configuration
77
218
  )
78
219
  puts documented_unit.stats
220
+ elsif args.size == 'l'
221
+ documented_unit = Fitting::Statistics::TemplateCoverErrorOneOf.new(
222
+ Fitting::Records::Spherical::Requests.new,
223
+ Fitting.configuration
224
+ )
225
+ puts documented_unit.stats
79
226
  else
80
- puts 'need key s or m'
227
+ puts 'need key s, m or l'
81
228
  end
82
229
  end
83
230
 
231
+ # deprecated
84
232
  desc 'Fitting tests'
85
233
  task :tests do
86
234
  realized_unit = Fitting::Records::RealizedUnit.new(
@@ -0,0 +1,21 @@
1
+ .DS_Store
2
+ node_modules
3
+
4
+ # local env files
5
+ .env.local
6
+ .env.*.local
7
+
8
+ # Log files
9
+ npm-debug.log*
10
+ yarn-debug.log*
11
+ yarn-error.log*
12
+ pnpm-debug.log*
13
+
14
+ # Editor directories and files
15
+ .idea
16
+ .vscode
17
+ *.suo
18
+ *.ntvs*
19
+ *.njsproj
20
+ *.sln
21
+ *.sw?
@@ -0,0 +1 @@
1
+ nodejs 13.1.0
@@ -0,0 +1,19 @@
1
+ # bomboniere
2
+
3
+ ## Project setup
4
+ ```
5
+ npm install
6
+ ```
7
+
8
+ ### Compiles and hot-reloads for development
9
+ ```
10
+ npm run serve
11
+ ```
12
+
13
+ ### Compiles and minifies for production
14
+ ```
15
+ npm run build
16
+ ```
17
+
18
+ ### Customize configuration
19
+ See [Configuration Reference](https://cli.vuejs.org/config/).