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 +4 -4
- data/lib/webspicy/configuration/scope.rb +3 -1
- data/lib/webspicy/specification/service.rb +4 -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/generator.rb +53 -13
- 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 +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a55b29fa6f9f5f48358b4a050582679f7e32816b82ea818c3f8d07ee1f6e166
|
4
|
+
data.tar.gz: 045b1c9ea0127645ddfd8bb14a7b464daa1c9a309d0796d31898800f7629637e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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|
|
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|
|
@@ -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
@@ -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,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 [
|
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
|
-
|
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:
|
127
|
+
schema: { type: 'string' },
|
88
128
|
required: true
|
89
129
|
}
|
90
130
|
}
|
@@ -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
|
|