You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+20-5Lines changed: 20 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,31 @@
1
1
# rswag
2
2
All notable changes to this project will be documented in this file.
3
3
4
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Copy file name to clipboardExpand all lines: README.md
+29-26Lines changed: 29 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ rswag
5
5
6
6
OpenApi 3.0 and Swagger 2.0 compatible!
7
7
8
+
Seeking maintainers! Got a pet-bug that needs fixing? Just let us know in your issue/pr that you'd like to step up to help.
9
+
8
10
Rswag extends rspec-rails "request specs" with a Swagger-based DSL for describing and testing API operations. You describe your API operations with a succinct, intuitive syntax, and it automaticaly runs the tests. Once you have green tests, run a rake task to auto-generate corresponding Swagger files and expose them as YAML or JSON endpoints. Rswag also provides an embedded version of the awesome [swagger-ui](https://github.com/swagger-api/swagger-ui) that's powered by the exposed file. This toolchain makes it seamless to go from integration specs, which youre probably doing in some form already, to living documentation for your API consumers.
9
11
10
12
Api Rswag creates [Swagger](http://swagger.io) tooling for Rails API's. Generate beautiful API documentation, including a UI to explore and test operations, directly from your rspec integration tests.
@@ -18,7 +20,7 @@ Once you have an API that can describe itself in Swagger, you've opened the trea
@@ -136,7 +138,7 @@ There is also a generator which can help get you started `rails generate rspec:s
136
138
path '/blogs/{id}' do
137
139
138
140
get 'Retrieves a blog' do
139
-
tags 'Blogs'
141
+
tags 'Blogs', 'Another Tag'
140
142
produces 'application/json', 'application/xml'
141
143
parameter name: :id, in: :path, type: :string
142
144
@@ -363,8 +365,8 @@ you should use the folowing syntax, making sure there are no whitespaces at the
363
365
364
366
### Specifying/Testing API Security ###
365
367
366
-
Swagger allows for the specification of different security schemes and their applicability to operations in an API.
367
-
To leverage this in rswag, you define the schemes globally in _swagger_helper.rb_ and then use the "security" attribute at the operation level to specify which schemes, if any, are applicable to that operation.
368
+
Swagger allows for the specification of different security schemes and their applicability to operations in an API.
369
+
To leverage this in rswag, you define the schemes globally in _swagger_helper.rb_ and then use the "security" attribute at the operation level to specify which schemes, if any, are applicable to that operation.
368
370
Swagger supports :basic, :bearer, :apiKey and :oauth2 and :openIdConnect scheme types. See [the spec](https://swagger.io/docs/specification/authentication/) for more info, as this underwent major changes between Swagger 2.0 and Open API 3.0
369
371
370
372
```ruby
@@ -416,7 +418,7 @@ describe 'Blogs API' do
416
418
end
417
419
418
420
# example of documenting an endpoint that handles basic auth and api key based security
419
-
describe 'Auth examples API'do
421
+
describe 'Auth examples API'do
420
422
path '/auth-tests/basic-and-api-key'do
421
423
post 'Authenticates with basic auth and api key'do
422
424
tags 'Auth Tests'
@@ -437,11 +439,11 @@ describe 'Auth examples API' do
437
439
end
438
440
end
439
441
end
440
-
442
+
441
443
442
444
```
443
445
444
-
__NOTE:__ Depending on the scheme types, you'll be required to assign a corresponding parameter value with each example.
446
+
__NOTE:__ Depending on the scheme types, you'll be required to assign a corresponding parameter value with each example.
445
447
For example, :basic auth is required above and so the :Authorization (header) parameter must be set accordingly
You need to disable --dry-run option for Rspec > 3
621
+
#### Dry Run Option ####
616
622
617
-
<!-- This is now enabled by default in rswag.
618
-
You need to set the ``` config.swagger_dry_run = false``` value in the spec/spec_helper.rb file.
619
-
This is one of the more powerful features of rswag. When rswag runs your integration test suite via ```bundle exec rspec```, it will capture the request and response bodies and output those values in the examples section.
620
-
These integration tests are usually written with ```let``` variables for post body parameters, and since its an integration test the service is returning actual values.
621
-
We might as well re-use these values and embed them into the generated swagger to provide a more real world example for request/response examples. -->
623
+
The `--dry-run` option is enabled by default for Rspec 3, but if you need to
624
+
disable it you can use the environment varible `SWAGGER_DRY_RUN=0` during the
625
+
generation command or add the following to your `config/environments/test.rb`:
622
626
623
-
Add to config/environments/test.rb:
624
627
```ruby
625
628
RSpec.configure do |config|
626
629
config.swagger_dry_run =false
@@ -656,8 +659,8 @@ describe 'Blogs API', document: false do
656
659
```
657
660
658
661
##### rswag helper methods #####
659
-
<!--
660
-
There are some helper methods to help with documenting request bodies.
662
+
<!--
663
+
There are some helper methods to help with documenting request bodies.
661
664
```ruby
662
665
describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
s.summary='A Rails Engine that exposes Swagger files as JSON endpoints'
13
-
s.description='Open up your API to the phenomenal Swagger ecosystem by exposing Swagger files, that describe your service, as JSON endpoints'
12
+
s.summary='A Rails Engine that exposes OpenAPI (formerly called Swagger) files as JSON endpoints'
13
+
s.description='Open up your API to the phenomenal OpenAPI ecosystem by exposing OpenAPI files, that describe your service, as JSON endpoints. More about the OpenAPI initiative here: http://spec.openapis.org/'
0 commit comments