openapi-ruby 2.0.0 → 2.1.0
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2fa2e6a3989eed9e11e17ff251bccf6044dd6ecb280bb32fb390f11179955afb
|
|
4
|
+
data.tar.gz: 15bcdc40a54580d95d5e71ec88665d9c1911b7d7630e38d4ebe56bcdf031aba2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d1ba7835ecebbfe335a86fddc39b772c730517729bc0f0a03902e31b5d35e6b53929cd6e693f4841c054a32ecf8eeaf821fe9913b7b6fd9d2faacead2834bd1
|
|
7
|
+
data.tar.gz: b18fdcc9aa4d8706b934bf775bfcd4c4a1505b4387277ef7f9c5efc4b80f678cad0a038b178e35a70b8343b5d55e4b8df137cfc93081b61170dd7a0573960f0c
|
|
@@ -8,14 +8,19 @@ module OpenapiRuby
|
|
|
8
8
|
return head :not_found unless OpenapiRuby.configuration.ui_enabled
|
|
9
9
|
|
|
10
10
|
config = OpenapiRuby.configuration
|
|
11
|
-
@schemas = config.schemas
|
|
12
|
-
@default_schema = @schemas.first
|
|
11
|
+
@schemas = config.schemas
|
|
13
12
|
@ui_config = config.ui_config
|
|
14
|
-
@schema_url = openapi_ruby.schema_path(@default_schema, format: schema_format)
|
|
15
13
|
|
|
16
14
|
render html: swagger_ui_html.html_safe
|
|
17
15
|
end
|
|
18
16
|
|
|
17
|
+
def oauth2_redirect
|
|
18
|
+
return head :not_found unless OpenapiRuby.configuration.ui_enabled
|
|
19
|
+
|
|
20
|
+
file = File.join(OpenapiRuby::Engine.root, "app", "views", "openapi_ruby", "oauth2_redirect.html")
|
|
21
|
+
render file: file, layout: false, content_type: "text/html"
|
|
22
|
+
end
|
|
23
|
+
|
|
19
24
|
private
|
|
20
25
|
|
|
21
26
|
def schema_format
|
|
@@ -41,14 +46,14 @@ module OpenapiRuby
|
|
|
41
46
|
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
|
|
42
47
|
<script>
|
|
43
48
|
SwaggerUIBundle({
|
|
44
|
-
|
|
49
|
+
#{schema_urls_js},
|
|
45
50
|
dom_id: '#swagger-ui',
|
|
46
51
|
deepLinking: true,
|
|
47
52
|
presets: [
|
|
48
53
|
SwaggerUIBundle.presets.apis,
|
|
49
54
|
SwaggerUIBundle.SwaggerUIStandalonePreset
|
|
50
55
|
],
|
|
51
|
-
layout: "BaseLayout",
|
|
56
|
+
layout: "#{(@schemas.size > 1) ? "StandaloneLayout" : "BaseLayout"}",
|
|
52
57
|
#{ui_config_js}
|
|
53
58
|
});
|
|
54
59
|
</script>
|
|
@@ -57,6 +62,22 @@ module OpenapiRuby
|
|
|
57
62
|
HTML
|
|
58
63
|
end
|
|
59
64
|
|
|
65
|
+
def schema_urls_js
|
|
66
|
+
fmt = schema_format
|
|
67
|
+
if @schemas.size > 1
|
|
68
|
+
urls = @schemas.map { |name, schema_config|
|
|
69
|
+
title = schema_config.dig(:info, :title) || name.to_s
|
|
70
|
+
url = openapi_ruby.schema_path(name.to_s, format: fmt)
|
|
71
|
+
{url: url, name: title}
|
|
72
|
+
}
|
|
73
|
+
"urls: #{urls.to_json}"
|
|
74
|
+
else
|
|
75
|
+
name = @schemas.keys.first.to_s
|
|
76
|
+
url = openapi_ruby.schema_path(name, format: fmt)
|
|
77
|
+
"url: \"#{url}\""
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
60
81
|
def ui_config_js
|
|
61
82
|
@ui_config.except(:title).map { |k, v|
|
|
62
83
|
"#{k}: #{v.to_json}"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en-US">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Swagger UI: OAuth2 Redirect</title>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<script>
|
|
8
|
+
'use strict';
|
|
9
|
+
function run () {
|
|
10
|
+
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
|
11
|
+
var sentState = oauth2.state;
|
|
12
|
+
var redirectUrl = oauth2.redirectUrl;
|
|
13
|
+
var isValid, qp, arr;
|
|
14
|
+
|
|
15
|
+
if (/code|token|error/.test(window.location.href)) {
|
|
16
|
+
if (window.location.search) {
|
|
17
|
+
qp = parseSearch(window.location.search);
|
|
18
|
+
} else {
|
|
19
|
+
qp = parseHash(window.location.hash);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isValid = qp.state === sentState;
|
|
23
|
+
|
|
24
|
+
if ((
|
|
25
|
+
oauth2.auth.schema.get("flow") === "accessCode"||
|
|
26
|
+
oauth2.auth.schema.get("flow") === "authorizationCode"||
|
|
27
|
+
oauth2.auth.schema.get("flow") === "authorization_code"
|
|
28
|
+
) && !oauth2.auth.code) {
|
|
29
|
+
if (!isValid) {
|
|
30
|
+
oauth2.errCb({
|
|
31
|
+
authId: oauth2.auth.name,
|
|
32
|
+
source: "auth",
|
|
33
|
+
level: "warning",
|
|
34
|
+
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (qp.code) {
|
|
39
|
+
delete qp.state;
|
|
40
|
+
oauth2.auth.code = qp.code;
|
|
41
|
+
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
|
42
|
+
} else {
|
|
43
|
+
var oauthErrorMsg;
|
|
44
|
+
if (qp.error) {
|
|
45
|
+
oauthErrorMsg = "["+qp.error+"]: " + (qp.error_description ? qp.error_description + ". " : "no accessCode received from the server. ") + (qp.error_uri ? "More info: "+qp.error_uri : "");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
oauth2.errCb({
|
|
49
|
+
authId: oauth2.auth.name,
|
|
50
|
+
source: "auth",
|
|
51
|
+
level: "error",
|
|
52
|
+
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
window.close();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function parseSearch(str) {
|
|
63
|
+
return parseParams(str.substr(1));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function parseHash(str) {
|
|
67
|
+
return parseParams(str.substr(1));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseParams(str) {
|
|
71
|
+
return str.split("&").reduce(function (params, param) {
|
|
72
|
+
var keyValue = param.split("=");
|
|
73
|
+
params[keyValue[0]] = decodeURIComponent(keyValue[1]);
|
|
74
|
+
return params;
|
|
75
|
+
}, {});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
window.addEventListener('DOMContentLoaded', function () {
|
|
79
|
+
run();
|
|
80
|
+
});
|
|
81
|
+
</script>
|
|
82
|
+
</body>
|
|
83
|
+
</html>
|
data/config/routes.rb
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
OpenapiRuby::Engine.routes.draw do
|
|
4
4
|
get "schemas", to: "schemas#index", as: :schemas
|
|
5
|
-
get "schemas
|
|
5
|
+
get "schemas/*id", to: "schemas#show", as: :schema
|
|
6
6
|
|
|
7
7
|
get "ui", to: "ui#index", as: :ui
|
|
8
|
+
get "oauth2-redirect.html", to: "ui#oauth2_redirect", as: :oauth2_redirect
|
|
8
9
|
end
|
data/lib/openapi_ruby/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openapi-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Morten Hartvig
|
|
@@ -79,6 +79,7 @@ files:
|
|
|
79
79
|
- Rakefile
|
|
80
80
|
- app/controllers/openapi_ruby/schemas_controller.rb
|
|
81
81
|
- app/controllers/openapi_ruby/ui_controller.rb
|
|
82
|
+
- app/views/openapi_ruby/oauth2_redirect.html
|
|
82
83
|
- config/routes.rb
|
|
83
84
|
- lib/generators/openapi_ruby/component/component_generator.rb
|
|
84
85
|
- lib/generators/openapi_ruby/component/templates/component.rb.tt
|
|
@@ -118,13 +119,13 @@ files:
|
|
|
118
119
|
- lib/openapi_ruby/testing/response_validator.rb
|
|
119
120
|
- lib/openapi_ruby/version.rb
|
|
120
121
|
- lib/tasks/openapi_ruby.rake
|
|
121
|
-
homepage: https://github.com/
|
|
122
|
+
homepage: https://github.com/openapi-ruby/openapi-ruby
|
|
122
123
|
licenses:
|
|
123
124
|
- MIT
|
|
124
125
|
metadata:
|
|
125
|
-
homepage_uri: https://github.com/
|
|
126
|
-
source_code_uri: https://github.com/
|
|
127
|
-
changelog_uri: https://github.com/
|
|
126
|
+
homepage_uri: https://github.com/openapi-ruby/openapi-ruby
|
|
127
|
+
source_code_uri: https://github.com/openapi-ruby/openapi-ruby
|
|
128
|
+
changelog_uri: https://github.com/openapi-ruby/openapi-ruby/blob/main/CHANGELOG.md
|
|
128
129
|
rubygems_mfa_required: 'true'
|
|
129
130
|
rdoc_options: []
|
|
130
131
|
require_paths:
|