Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - Clear Yard Registry to use swagger_yard with Sinatra splited routes files #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,41 @@ Install the gem with Bunder:

Place configuration in a Rails initializer or suitable configuration file:

# config/initializers/swagger_yard.rb
SwaggerYard.configure do |config|
config.api_version = "1.0"
```ruby
# config/initializers/swagger_yard.rb
SwaggerYard.configure do |config|
config.api_version = "1.0"

config.title = 'Your API'
config.description = 'Your API does this'
config.title = 'Your API'
config.description = 'Your API does this'

# where your actual api is hosted from
config.api_base_path = "http://localhost:3000/api"
# Where your actual api is hosted from
config.api_base_path = "http://localhost:3000/api"

# Where to find controllers (can be an array of paths/globs)
config.controller_path = ::Rails.root + 'app/controllers/**/*'
# Where to find controllers (can be an array of paths/globs)
config.controller_path = ::Rails.root + 'app/controllers/**/*'

# Where to find models (can be an array)
config.model_path = ::Rails.root + 'app/decorators/**/*'
# Where to find models (can be an array)
config.model_path = ::Rails.root + 'app/decorators/**/*'

# Whether to include controller methods marked as private
# (either with ruby `private` or YARD `# @visibility private`
# Default: true
config.include_private = true
end
# Whether to include controller methods marked as private
# (either with ruby `private` or YARD `# @visibility private`
# Default: true
config.include_private = true

# When you are using multiple files with same class name
# (for ex: Sinatra with routes splited in multiples files)
config.use_yard_cache = false
end
```

Then start to annotate controllers and models as described below.

### Generate Specification ###

To generate a Swagger or OpenAPI specification, use one of the `SwaggerYard::Swagger` or `SwaggerYard::OpenAPI` classes as follows in a script or Rake task (or use [swagger_yard-rails](/livingsocial/swagger_yard-rails)):

```
```ruby
# Register the yard tags
SwaggerYard.register_custom_yard_tags!

Expand Down Expand Up @@ -380,7 +386,7 @@ SwaggerYard.configure do |config|
authorizationUrl: "http://swagger.io/api/oauth/dialog",
scopes: {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
"read:pets": "read your pets"
}
}
}
Expand Down Expand Up @@ -431,4 +437,3 @@ Rails routing tables to reverse look up and compute paths.


[swagger_yard-rails]: https://github.com/livingsocial/swagger_yard-rails

1 change: 1 addition & 0 deletions lib/swagger_yard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def requires_type(tag)
# @return [YARD] objects representing class/methods and tags from the file
#
def yard_objects_from_file(file_path, *types)
::YARD::Registry.clear unless config.use_yard_cache
::YARD.parse(file_path)
::YARD::Registry.all(*types).select {|co| co.file == file_path }
end
Expand Down
2 changes: 2 additions & 0 deletions lib/swagger_yard/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Configuration
attr_accessor :path_discovery_function
attr_accessor :security_definitions
attr_accessor :include_private
attr_accessor :use_yard_cache

# openapi-compatible names
alias openapi_version swagger_version
Expand All @@ -22,6 +23,7 @@ def initialize
@security_definitions = {}
@external_schema = {}
@include_private = true
@use_yard_cache = true
end

def external_schema(mappings = nil)
Expand Down