webspicy 0.21.3 → 0.21.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adc3c1464cb9c8972496a11fedda7a0dfda39e34ba82c5ad60a71ccc574d712c
4
- data.tar.gz: 892220efe2eadc8e1b62ea7e97039814de451f8949b5a89030cca027b3b4c383
3
+ metadata.gz: 1a55b29fa6f9f5f48358b4a050582679f7e32816b82ea818c3f8d07ee1f6e166
4
+ data.tar.gz: 045b1c9ea0127645ddfd8bb14a7b464daa1c9a309d0796d31898800f7629637e
5
5
  SHA512:
6
- metadata.gz: 74243ff6d5c32357fa04da777ec9eede39a703405c8297abc7246b9f023dd1a34ed38c6ca6564326265fc9b59c46ae227ea0698de19c3256ffca2dc50d3a0ff0
7
- data.tar.gz: 79ed95fa65038bfff561c1956f728de2cfa57f705bc6d7b73bf8ba541d53f30056fc99eb231c28a1a91a5c61e8ca9b2b0ad8eaf1c5d5b482f9178068c97472ad
6
+ metadata.gz: d8d6e028b67558796b58b9a24ec27e0594b33160613838e211557a75e924447acafe9c75ead65a2d91cc4c62b55b714b8c45a9af1af3ad3d30f1ad80a379fce6
7
+ data.tar.gz: 251d467be2ec28bf4dd9f6026b71dae998290911bb613a53a540c888e2287ae7b9d81c57e947f35c451c7c975b096709692c44dddc1534204895dcc24613dca5
@@ -22,7 +22,9 @@ module Webspicy
22
22
  def _each_specification_file(config, apply_filter = true)
23
23
  folder = config.folder
24
24
  world = config.folder/"world"
25
- fs = folder.glob("**/*.{yml, yaml}").reject{|f| f.to_s.start_with?(world.to_s) }
25
+ fs = folder.glob("**/*.{yml, yaml}").reject{|f|
26
+ f.to_s.start_with?(world.to_s) || f.to_s =~ /openapi.base.yml/
27
+ }
26
28
  fs = fs.sort
27
29
  fs = fs.select(&to_filter_proc(config.file_filter)) if apply_filter
28
30
  fs.each do |file|
@@ -21,6 +21,10 @@ module Webspicy
21
21
  specification.config
22
22
  end
23
23
 
24
+ def name
25
+ @raw[:name]
26
+ end
27
+
24
28
  def description
25
29
  @raw[:description]
26
30
  end
@@ -3,6 +3,19 @@ module Webspicy
3
3
  class DeepMerge
4
4
  class << self
5
5
 
6
+ def symbolize_keys(arg)
7
+ case arg
8
+ when Hash
9
+ arg.each_pair.each_with_object({}){|(k,v),memo|
10
+ memo[k.to_sym] = symbolize_keys(v)
11
+ }
12
+ when Array
13
+ arg.map{|item| symbolize_keys(item) }
14
+ else
15
+ arg
16
+ end
17
+ end
18
+
6
19
  def deep_merge(h1, h2)
7
20
  merge_maps(deep_dup(h1), deep_dup(h2))
8
21
  end
@@ -13,6 +13,7 @@ module Webspicy
13
13
  @invocation = tester.invocation
14
14
  @assertions = []
15
15
  @failures = []
16
+ @warnings = []
16
17
  @errors = []
17
18
  if @invocation
18
19
  check!
@@ -2,7 +2,7 @@ module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 21
5
- TINY = 3
5
+ TINY = 5
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
@@ -36,6 +36,7 @@ Specification = .Webspicy::Web::Specification
36
36
 
37
37
  Service =
38
38
  .Webspicy::Web::Specification::Service <info> {
39
+ name :? String
39
40
  method : Method
40
41
  description : String
41
42
  preconditions :? [String]|String
@@ -1,10 +1,18 @@
1
- require "finitio/generation"
2
- require "finitio/json_schema"
1
+ require 'finitio/generation'
2
+ require 'finitio/json_schema'
3
3
  module Webspicy
4
4
  module Web
5
5
  module Openapi
6
6
  class Generator
7
7
 
8
+ DEFAULT_OPENAPI = {
9
+ openapi: '3.0.2',
10
+ info: {
11
+ version: '1.0.0',
12
+ title: 'Webspicy Specification'
13
+ }
14
+ }
15
+
8
16
  def initialize(config)
9
17
  @config = Configuration.dress(config)
10
18
  @generator = config.generator || Finitio::Generation.new(
@@ -13,19 +21,49 @@ module Webspicy
13
21
  end
14
22
  attr_reader :config, :generator
15
23
 
16
- def call
17
- {
18
- openapi: "3.0.2",
19
- info: {
20
- version: "1.0.0",
21
- title: "Hello API"
22
- },
23
- paths: paths
24
- }
24
+ def call(info = {})
25
+ base = Support::DeepMerge.deep_merge(
26
+ DEFAULT_OPENAPI,
27
+ base_openapi
28
+ )
29
+ Support::DeepMerge.deep_merge(
30
+ base,
31
+ {
32
+ info: info,
33
+ tags: tags,
34
+ paths: paths
35
+ }
36
+ )
25
37
  end
26
38
 
27
39
  private
28
40
 
41
+ def base_openapi
42
+ file = config.folder/'openapi.base.yml'
43
+ if file.exists?
44
+ Support::DeepMerge.symbolize_keys(file.load)
45
+ else
46
+ {}
47
+ end
48
+ end
49
+
50
+ def tags
51
+ config.each_scope.inject([]) do |tags,scope|
52
+ scope.each_specification.inject(tags) do |tags,specification|
53
+ tags + tags_for(specification)
54
+ end
55
+ end.uniq.sort_by{|t| t[:name] }
56
+ end
57
+
58
+ def tags_for(specification)
59
+ return [] unless specification.name.is_a?(String)
60
+ return [] if specification.name.empty?
61
+
62
+ [{
63
+ name: specification.name.gsub(/\n/, ' ').strip
64
+ }]
65
+ end
66
+
29
67
  def paths
30
68
  config.each_scope.inject({}) do |paths,scope|
31
69
  scope.each_specification.inject(paths) do |paths,specification|
@@ -53,11 +91,13 @@ module Webspicy
53
91
  specification.services.inject({}) do |verbs,service|
54
92
  verb = service.method.downcase.gsub(/_form$/, '')
55
93
  verb_defn = {
94
+ summary: service.name,
56
95
  description: service.description,
96
+ tags: tags_for(specification).map{|s| s[:name] },
57
97
  parameters: parameters_for(service),
58
98
  responses: responses_for(service)
59
99
  }.compact
60
- unless ["get", "options", "delete", "head"].include?(verb)
100
+ unless ['get', 'options', 'delete', 'head'].include?(verb)
61
101
  verb_defn[:requestBody] = request_body_for(service)
62
102
  end
63
103
  verbs.merge({ verb => verb_defn })
@@ -70,7 +110,7 @@ module Webspicy
70
110
  {
71
111
  required: true,
72
112
  content: {
73
- "application/json" => {
113
+ 'application/json' => {
74
114
  schema: schema.to_json_schema,
75
115
  example: example
76
116
  }.compact
@@ -84,7 +124,7 @@ module Webspicy
84
124
  {
85
125
  in: 'path',
86
126
  name: p,
87
- schema: { type: "string" },
127
+ schema: { type: 'string' },
88
128
  required: true
89
129
  }
90
130
  }
@@ -2,11 +2,9 @@ module Webspicy
2
2
  module Web
3
3
  class Specification
4
4
  class Service < Webspicy::Specification::Service
5
-
6
5
  def method
7
6
  @raw[:method]
8
7
  end
9
-
10
8
  end # class Service
11
9
  end # class Specification
12
10
  end # module Web
@@ -18,7 +18,8 @@ module Webspicy
18
18
  }
19
19
 
20
20
  it 'returns all files' do
21
- expect(subject.size).to eql(restful_folder.glob('**/*.{yml, yaml}').size)
21
+ # -1 because of openapi.base.yml
22
+ expect(subject.size).to eql(restful_folder.glob('**/*.{yml, yaml}').size - 1)
22
23
  end
23
24
  end
24
25
 
@@ -59,7 +60,8 @@ module Webspicy
59
60
  }
60
61
 
61
62
  it 'returns all files' do
62
- expect(subject.size).to eql(restful_folder.glob('**/*.{yml, yaml}').size)
63
+ # -1 because of openapi.base.yml
64
+ expect(subject.size).to eql(restful_folder.glob('**/*.{yml, yaml}').size - 1)
63
65
  end
64
66
  end
65
67
 
@@ -6,23 +6,46 @@ module Webspicy
6
6
  module Web
7
7
  module Openapi
8
8
  describe Generator do
9
-
10
- let(:config) {
9
+ let(:config) do
11
10
  Configuration.new(restful_folder)
12
- }
11
+ end
13
12
 
14
- subject {
15
- ruby_objs = Generator.new(config).call
13
+ subject do
14
+ ruby_objs = Generator.new(config).call(info)
16
15
  JSON.parse(ruby_objs.to_json)
17
- }
16
+ end
18
17
 
19
- it 'works fine' do
20
- document = Openapi3Parser.load(subject)
18
+ let(:info) do
19
+ {}
20
+ end
21
+
22
+ def openapi_document
21
23
  #puts JSON.pretty_generate(subject)
24
+ document = Openapi3Parser.load(subject)
22
25
  document.errors.each do |err|
23
26
  puts err.inspect
24
27
  end unless document.errors.empty?
25
- expect(document.errors).to be_empty
28
+ document
29
+ end
30
+
31
+ it 'works fine' do
32
+ expect(openapi_document.errors).to be_empty
33
+ expect(openapi_document.info.title).to eql('Todo API')
34
+ end
35
+
36
+ describe 'when passing specific info' do
37
+ let(:info) {
38
+ {
39
+ version: '1.1.1',
40
+ title: 'Webspicy API'
41
+ }
42
+ }
43
+
44
+ it 'takes it into account' do
45
+ expect(openapi_document.errors).to be_empty
46
+ expect(openapi_document.info.title).to eql('Webspicy API')
47
+ expect(openapi_document.info.version).to eql('1.1.1')
48
+ end
26
49
  end
27
50
 
28
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.3
4
+ version: 0.21.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-03 00:00:00.000000000 Z
11
+ date: 2023-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -408,7 +408,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
408
408
  - !ruby/object:Gem::Version
409
409
  version: '0'
410
410
  requirements: []
411
- rubygems_version: 3.3.7
411
+ rubygems_version: 3.3.26
412
412
  signing_key:
413
413
  specification_version: 4
414
414
  summary: Webspicy helps testing web services as software operation black boxes!