Skip to content

Commit 78dcd58

Browse files
author
David Brewer
committed
Support Swagger-UI validatorUrl option.
When you are running Swagger-UI on a server which is not open to external access, the default validation behavior causes an error message to be displayed. This change allows you to set a validator_url option to nil, which suppresses this error message. You could also point to a validator service under your own control.
1 parent 11671d3 commit 78dcd58

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### 0.2.1 (Next)
22

3-
* Your contribution here.
3+
* Support Swagger-UI validatorUrl option - [@davidbrewer](https://github.com/davidbrewer).
44

55
### 0.2.0 (February 23, 2016)
66

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ See the official Swagger-UI documentation about [SwaggerUi Parameters](https://g
7474
GrapeSwaggerRails.options.doc_expansion = 'list'
7575
```
7676

77+
You can set validatorUrl to your own locally deployed Swagger validator, or disable validation by setting this option to nil.
78+
This is useful to avoid error messages when running Swagger-UI on a server which is not accessible from outside your network.
79+
80+
```ruby
81+
GrapeSwaggerRails.options.validator_url = nil
82+
```
83+
7784
Using the `headers` option above, you could hard-code Basic Authentication credentials.
7885
Alternatively, you can configure Basic Authentication through the UI, as described below.
7986

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

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
}
3737
},
3838
docExpansion: options.doc_expansion,
39+
validatorUrl: options.validator_url,
3940
apisSorter: "alpha"
4041
});
4142

spec/features/swagger_spec.rb

+30
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,36 @@
153153
end
154154
end
155155
end
156+
context '#validator_url' do
157+
context 'set null' do
158+
before do
159+
GrapeSwaggerRails.options.validator_url = nil
160+
visit '/swagger'
161+
end
162+
it 'sets SwaggerUI validatorUrl to null' do
163+
expect(page.evaluate_script('window.swaggerUi.options.validatorUrl === null && '\
164+
'typeof window.swaggerUi.options.validatorUrl === "object"')).to be true
165+
end
166+
end
167+
context 'set a url' do
168+
before do
169+
GrapeSwaggerRails.options.validator_url = 'http://www.example.com/'
170+
visit '/swagger'
171+
end
172+
it 'sets SwaggerUI validatorUrl to expected url' do
173+
expect(page.evaluate_script('window.swaggerUi.options.validatorUrl === "http://www.example.com/"')).to be true
174+
end
175+
end
176+
context 'not set' do
177+
before do
178+
visit '/swagger'
179+
end
180+
it 'defaults SwaggerUI validatorUrl' do
181+
expect(page.evaluate_script('window.swaggerUi.options.validatorUrl === undefined && '\
182+
'typeof window.swaggerUi.options.validatorUrl === "undefined"')).to be true
183+
end
184+
end
185+
end
156186
after do
157187
GrapeSwaggerRails.options = @options
158188
end

0 commit comments

Comments
 (0)