Skip to content

Commit

Permalink
Make yard clear usage configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineGirard committed Nov 4, 2021
1 parent 2bc70a6 commit 47d4bcb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.5.0
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

2 changes: 1 addition & 1 deletion lib/swagger_yard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +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
::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

0 comments on commit 47d4bcb

Please sign in to comment.