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 +4 -4
- data/lib/webspicy/configuration/scope.rb +3 -1
- data/lib/webspicy/specification/service.rb +8 -0
- data/lib/webspicy/support/deep_merge.rb +13 -0
- data/lib/webspicy/version.rb +1 -1
- data/lib/webspicy/web/formaldoc.fio +1 -0
- data/lib/webspicy/web/openapi/ext.rb +18 -0
- data/lib/webspicy/web/openapi/generator.rb +60 -13
- data/lib/webspicy/web/openapi.rb +1 -0
- data/lib/webspicy/web/specification/service.rb +0 -2
- data/spec/unit/configuration/scope/test_each_specification.rb +4 -2
- data/spec/unit/web/openapi/test_generator.rb +5 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd39249e2d93a03a088b344c149394e112e57e8b34f5fb20ae2d48018a7c48c5
|
4
|
+
data.tar.gz: 73cbf44b32c9f8609106ddac8495e94d590d3d827325ca40ce7d7d483b35767d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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|
|
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
|
data/lib/webspicy/version.rb
CHANGED
@@ -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
|
2
|
-
require
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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 [
|
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
|
-
|
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:
|
134
|
+
schema: { type: 'string' },
|
88
135
|
required: true
|
89
136
|
}
|
90
137
|
}
|
data/lib/webspicy/web/openapi.rb
CHANGED
@@ -18,7 +18,8 @@ module Webspicy
|
|
18
18
|
}
|
19
19
|
|
20
20
|
it 'returns all files' do
|
21
|
-
|
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
|
-
|
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('
|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
+
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
|