rswag-api 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rswag/api/middleware.rb +29 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f5a77aa4988d76dcd76d251288729514f07fc0e4cb28bb04a184d6be53001f6
|
4
|
+
data.tar.gz: f13c18e015741835531ed97014fffb3d0ba647044ce948ea1d334852f4a64f0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3548dbef713f3e93890d7198c70fe69b9c201081d2797a266add689e0a7a47a8f7a7b85feb38ae01da73abf222138bd387e69beb9cb9c3ef0f24b3a2cc50676
|
7
|
+
data.tar.gz: 02a830a48706320dcdd8ffb3269793376ffb331353ef331a77c54e51a589d70c901f35b20fd3a95ef122e0b8e1d29410b6873be97d0f20f226d38ef58114bf5b
|
data/lib/rswag/api/middleware.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'yaml'
|
3
|
+
require 'rack/mime'
|
2
4
|
|
3
5
|
module Rswag
|
4
6
|
module Api
|
5
|
-
class Middleware
|
7
|
+
class Middleware
|
6
8
|
|
7
9
|
def initialize(app, config)
|
8
10
|
@app = app
|
@@ -14,24 +16,46 @@ module Rswag
|
|
14
16
|
filename = "#{@config.resolve_swagger_root(env)}/#{path}"
|
15
17
|
|
16
18
|
if env['REQUEST_METHOD'] == 'GET' && File.file?(filename)
|
17
|
-
swagger =
|
19
|
+
swagger = parse_file(filename)
|
18
20
|
@config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil?
|
21
|
+
mime = Rack::Mime.mime_type(::File.extname(path), 'text/plain')
|
22
|
+
body = unload_swagger(filename, swagger)
|
19
23
|
|
20
24
|
return [
|
21
25
|
'200',
|
22
|
-
{ 'Content-Type' =>
|
23
|
-
[
|
26
|
+
{ 'Content-Type' => mime },
|
27
|
+
[ body ]
|
24
28
|
]
|
25
29
|
end
|
26
|
-
|
30
|
+
|
27
31
|
return @app.call(env)
|
28
32
|
end
|
29
33
|
|
30
34
|
private
|
31
35
|
|
36
|
+
def parse_file(filename)
|
37
|
+
if /\.ya?ml$/ === filename
|
38
|
+
load_yaml(filename)
|
39
|
+
else
|
40
|
+
load_json(filename)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_yaml(filename)
|
45
|
+
YAML.safe_load(File.read(filename))
|
46
|
+
end
|
47
|
+
|
32
48
|
def load_json(filename)
|
33
49
|
JSON.parse(File.read(filename))
|
34
50
|
end
|
51
|
+
|
52
|
+
def unload_swagger(filename, swagger)
|
53
|
+
if /\.ya?ml$/ === filename
|
54
|
+
YAML.dump(swagger)
|
55
|
+
else
|
56
|
+
JSON.dump(swagger)
|
57
|
+
end
|
58
|
+
end
|
35
59
|
end
|
36
60
|
end
|
37
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rswag-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richie Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.7.
|
70
|
+
rubygems_version: 2.7.8
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: A Rails Engine that exposes Swagger files as JSON endpoints
|