webspicy 0.21.4 → 0.21.5

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
  SHA256:
3
- metadata.gz: ba04baed1cda2292312644692901a18bc5a24f04a27be985a27097417ed731a9
4
- data.tar.gz: 67edeff75f3cc4064c197efbd65b2bc4533b7214033226e31092b19f21bdc355
3
+ metadata.gz: 1a55b29fa6f9f5f48358b4a050582679f7e32816b82ea818c3f8d07ee1f6e166
4
+ data.tar.gz: 045b1c9ea0127645ddfd8bb14a7b464daa1c9a309d0796d31898800f7629637e
5
5
  SHA512:
6
- metadata.gz: 560122db62b3024ad5ab6c76f171438e2c45ed4bc1b23fcc9af895e444a7c86ba655826f59d1719ed3020e6bc75d224a072717391ab0862a09f37cb96f89c61a
7
- data.tar.gz: 1ffb6d303cfcec6cc4d19c3f03c94f54acd16e50246f73171d00ab878229bf6fe16b18e4c16f9f8c139ca0557134d1b2c66af53c0c4c5cc3ef68782bd32c4710
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
@@ -2,7 +2,7 @@ module Webspicy
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 21
5
- TINY = 4
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(
@@ -14,18 +22,48 @@ module Webspicy
14
22
  attr_reader :config, :generator
15
23
 
16
24
  def call(info = {})
17
- {
18
- openapi: "3.0.2",
19
- info: {
20
- version: "1.0.0",
21
- title: "Webspicy Specification"
22
- }.merge(info),
23
- paths: paths
24
- }
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
 
@@ -20,6 +20,7 @@ module Webspicy
20
20
  end
21
21
 
22
22
  def openapi_document
23
+ #puts JSON.pretty_generate(subject)
23
24
  document = Openapi3Parser.load(subject)
24
25
  document.errors.each do |err|
25
26
  puts err.inspect
@@ -29,7 +30,7 @@ module Webspicy
29
30
 
30
31
  it 'works fine' do
31
32
  expect(openapi_document.errors).to be_empty
32
- expect(openapi_document.info.title).to eql('Webspicy Specification')
33
+ expect(openapi_document.info.title).to eql('Todo API')
33
34
  end
34
35
 
35
36
  describe 'when passing specific info' do
@@ -41,9 +42,9 @@ module Webspicy
41
42
  }
42
43
 
43
44
  it 'takes it into account' do
44
- expect(openapi_document.errors).to be_empty
45
- expect(openapi_document.info.title).to eql('Webspicy API')
46
- expect(openapi_document.info.version).to eql('1.1.1')
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')
47
48
  end
48
49
  end
49
50
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webspicy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.4
4
+ version: 0.21.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau