Fix - Clear Yard Registry to use swagger_yard with Sinatra splited routes files #68
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Allow to use it, with Sinatra routes splited in multiple files.
Sinatra doesn't have the concept of controller like Rails. If you want to split your routes in multiple files you need to do something like this.
Before split
After split
user.rb
article.rb
In this case, only the first file documentation is returned by
Swagger#to_h
if yourconfig.controller_path
is set toroutes/**/*
because Yard save methods of all files in classMyApp
associated to the first file analyzed path.Example:
Specification#parse_controllers
analyzed my previous file in this order : user -> article.SwaggerYard#yard_objects_from_file
saveMyApp
and methodsget user
andpost user
to the Yard Registry. And::YARD::Registry.all(*types).select {|co| co.file == file_path }
return class and methods.SwaggerYard#yard_objects_from_file
add methodsget article
andpost article
to the Yard Registry. LikeMyApp
is associated touser.rb
path,::YARD::Registry.all(*types).select {|co| co.file == file_path }
returns empty array.By clearing Yard Registry each time, this permit to return methods for each file and tags associated to these methods.
It shouldn't have side effects cause
Yard::Registry
is only use here.I hope that my explanations are clear enough. If you have any comments or questions, please let me know.