Fix - Clear Yard Registry to use swagger_yard with Sinatra splited routes files #68
Fix - Clear Yard Registry to use swagger_yard with Sinatra splited routes files #68AntoineGirard wants to merge 2 commits intolivingsocial:masterfrom
Conversation
| Hey Antoine, thanks for this contribution! The only issue I'll point out is that back in v0.3.1 the caching functionality of the registry is specifically called out, and is useful in my opinion for larger codebases when using, for example, the swagger controller in swagger_yard-rails. I wonder if we could either make this clearing behavior configurable or find another way to solve your issue. I'll try to think of other ways of solving this too. It might help to have a test case to demonstrate the behavior also. Let me know if you want to try that and need any help with it. |
1a080ab to 47d4bcb Compare 47d4bcb to 722fc7f Compare | Hey @nicksieger |
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_hif yourconfig.controller_pathis set toroutes/**/*because Yard save methods of all files in classMyAppassociated to the first file analyzed path.Example:
Specification#parse_controllersanalyzed my previous file in this order : user -> article.SwaggerYard#yard_objects_from_filesaveMyAppand methodsget userandpost userto the Yard Registry. And::YARD::Registry.all(*types).select {|co| co.file == file_path }return class and methods.SwaggerYard#yard_objects_from_fileadd methodsget articleandpost articleto the Yard Registry. LikeMyAppis associated touser.rbpath,::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::Registryis only use here.I hope that my explanations are clear enough. If you have any comments or questions, please let me know.