Skip to content

Commit 8c39a51

Browse files
committed
Возможность настроить discoveryUrl из рельс
1 parent f8df34a commit 8c39a51

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ Or install it yourself as:
1818

1919
## Usage: add this line to your routes.rb
2020

21-
mount GrapeSwaggerRails::Engine => '/apidoc'
21+
mount GrapeSwaggerRails::Engine => '/swagger'
22+
23+
Create `./config/initializer/swagger.rg` with lines:
24+
25+
GrapeSwaggerRails.discoveryUrl = "/swagger_doc.json"
2226

2327
## Нюансы
2428

app/views/grape_swagger_rails/application/index.html.erb

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@
77
<%= javascript_include_tag 'grape_swagger_rails/application.js' %>
88
<script type="text/javascript">
99
$(function () {
10-
window.swaggerUi = new SwaggerUi({
11-
discoveryUrl:"/swagger_doc.json",
12-
apiKey:"special-key",
13-
dom_id:"swagger-ui-container",
14-
supportHeaderParams: true,
15-
supportedSubmitMethods: ['get', 'post', 'put'],
16-
onComplete: function(swaggerApi, swaggerUi){
17-
if(console) {
18-
console.log("Loaded SwaggerUI")
19-
console.log(swaggerApi);
20-
console.log(swaggerUi);
21-
}
22-
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
23-
},
24-
onFailure: function(data) {
25-
if(console) {
26-
console.log("Unable to Load SwaggerUI");
27-
console.log(data);
28-
}
29-
},
30-
docExpansion: "none"
31-
});
10+
window.swaggerUi = new SwaggerUi({
11+
discoveryUrl: "<%= GrapeSwaggerRails.discoveryUrl %>",
12+
apiKey: "<%= GrapeSwaggerRails.apiKey %>",
13+
dom_id:"swagger-ui-container",
14+
supportHeaderParams: true,
15+
supportedSubmitMethods: ['get', 'post', 'put'],
16+
onComplete: function(swaggerApi, swaggerUi){
17+
if(console) {
18+
console.log("Loaded SwaggerUI")
19+
console.log(swaggerApi);
20+
console.log(swaggerUi);
21+
}
22+
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
23+
},
24+
onFailure: function(data) {
25+
if(console) {
26+
console.log("Unable to Load SwaggerUI");
27+
console.log(data);
28+
}
29+
},
30+
docExpansion: "none"
31+
});
3232

33-
window.swaggerUi.load();
34-
});
33+
window.swaggerUi.load();
34+
});
3535

3636
</script>
3737
</head>

lib/grape-swagger-rails.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
require "grape-swagger-rails/engine"
22

33
module GrapeSwaggerRails
4+
mattr_accessor :discoveryUrl, :apiKey
5+
6+
self.discoveryUrl = '/swagger_doc.json'
7+
self.apiKey = 'special-key'
8+
49
end
10+

0 commit comments

Comments
 (0)