webspicy 0.21.4 → 0.21.6

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: ba04baed1cda2292312644692901a18bc5a24f04a27be985a27097417ed731a9
4
- data.tar.gz: 67edeff75f3cc4064c197efbd65b2bc4533b7214033226e31092b19f21bdc355
3
+ metadata.gz: dd39249e2d93a03a088b344c149394e112e57e8b34f5fb20ae2d48018a7c48c5
4
+ data.tar.gz: 73cbf44b32c9f8609106ddac8495e94d590d3d827325ca40ce7d7d483b35767d
5
5
  SHA512:
6
- metadata.gz: 560122db62b3024ad5ab6c76f171438e2c45ed4bc1b23fcc9af895e444a7c86ba655826f59d1719ed3020e6bc75d224a072717391ab0862a09f37cb96f89c61a
7
- data.tar.gz: 1ffb6d303cfcec6cc4d19c3f03c94f54acd16e50246f73171d00ab878229bf6fe16b18e4c16f9f8c139ca0557134d1b2c66af53c0c4c5cc3ef68782bd32c4710
6
+ metadata.gz: bddeb1dc84bcbe261f037df5051e575d2540eb781538bc240b736b33b15b7d6876362ffcce456510a9fa90e8b2574952c73006bec8e670a5cc737f625402b843
7
+ data.tar.gz: 8e0c0275a2b14909491ca835e002fb33869f0d44617605339869a1275ccaf5457b1e1cda356106cd23ef4bd4d73c595bac151d551cf9144bfb363062eb49ca5d
@@ -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,10 +21,18 @@ 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
27
31
 
32
+ def conditions
33
+ preconditions + postconditions
34
+ end
35
+
28
36
  def preconditions
29
37
  @preconditions ||= compile_preconditions
30
38
  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 = 6
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
@@ -0,0 +1,18 @@
1
+ module Webspicy
2
+ class Specification
3
+ module Pre
4
+
5
+ def contribute_to_openapi_verb(verb_defn)
6
+ verb_defn
7
+ end
8
+
9
+ end # module Pre
10
+ module Post
11
+
12
+ def contribute_to_openapi_verb(verb_defn)
13
+ verb_defn
14
+ end
15
+
16
+ end # module Post
17
+ end # class Specification
18
+ end # module Webspicy
@@ -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,13 +91,22 @@ 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
103
+ verb_defn = service.conditions.inject(verb_defn) do |memo, p|
104
+ if p.respond_to?(:contribute_to_openapi_verb)
105
+ p.contribute_to_openapi_verb(memo)
106
+ else
107
+ memo
108
+ end
109
+ end
63
110
  verbs.merge({ verb => verb_defn })
64
111
  end
65
112
  end
@@ -70,7 +117,7 @@ module Webspicy
70
117
  {
71
118
  required: true,
72
119
  content: {
73
- "application/json" => {
120
+ 'application/json' => {
74
121
  schema: schema.to_json_schema,
75
122
  example: example
76
123
  }.compact
@@ -84,7 +131,7 @@ module Webspicy
84
131
  {
85
132
  in: 'path',
86
133
  name: p,
87
- schema: { type: "string" },
134
+ schema: { type: 'string' },
88
135
  required: true
89
136
  }
90
137
  }
@@ -1 +1,2 @@
1
1
  require_relative 'openapi/generator'
2
+ require_relative 'openapi/ext'
@@ -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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
@@ -351,6 +351,7 @@ files:
351
351
  - lib/webspicy/web/mocker.rb
352
352
  - lib/webspicy/web/mocker/config.ru
353
353
  - lib/webspicy/web/openapi.rb
354
+ - lib/webspicy/web/openapi/ext.rb
354
355
  - lib/webspicy/web/openapi/generator.rb
355
356
  - lib/webspicy/web/specification.rb
356
357
  - lib/webspicy/web/specification/file_upload.rb