-
Notifications
You must be signed in to change notification settings - Fork 6k
Organize the generated Ruby code into a module structure #662
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
Conversation
Hi @xhh thank you for this. I'd like to avoid the |
@fehguy that is for the # Models
require 'swagger_client/models/user'
require 'swagger_client/models/category'
require 'swagger_client/models/pet'
require 'swagger_client/models/tag'
require 'swagger_client/models/order'
# APIs
require 'swagger_client/api/user_api'
require 'swagger_client/api/pet_api'
require 'swagger_client/api/store_api' The template generating the above is:
The Any other ways to generate the require/import paths for all models? If there are I'm happy to make the changes. |
There is another way to require ruby files dynamically, similar to the PHP approach, which does not need to iterate the list of models/apis (so the If that approach looks OK I can make the change. However, I'd like to know the concerns of avoiding |
@fehguy let me know what else needs to be done for this if you have time |
just rebased this |
Could build and install the Petstore Ruby gem locally without any issue/warning. |
Here's a note about something I noticed while playing with swagger codegen: A bit of a concern with the current Ruby API consumer is that the generated libraries aren't thread-safe. An easy way would be to move the The result is perhaps a client that requires a bit more setup but it gets rid of the class methods that rely on shared global state. I just did a cursory look through the patch and the resulting code seems more ruby-esque which is super awesome. |
Hi @xhh I'd like to merge this but looking to see if we can avoid modifying the |
Conflicts: modules/swagger-codegen/src/main/resources/ruby/swagger/version.mustache samples/client/petstore/ruby/lib/swagger/version.rb
according to guides from rubygems: http://guides.rubygems.org/name-your-gem/
Organize the generated Ruby code into a module structure
This PR is to make the folder/file structure of the generated Ruby code comply with the conventions of Ruby gems.
Taking Petstore as an example:
1. Place all files in the
lib
folderAs suggested by RubyGems Basics:
2. Move source files in an enclosing namespace module to avoid potential conflicts
This is a practice used by most gems (e.g. stripe-ruby).
As in the Petstore sample, use
SwaggerClient::PetApi
andSwaggerClient::Pet
to access API and model classes.3. Rename gem name of Petstore sample from
swagger-client
toswagger_client
according to the naming conventions from RubyGems guides.