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

Support for model and resource classes in module #14

Open
codeguru42 opened this issue Apr 14, 2022 · 1 comment
Open

Support for model and resource classes in module #14

codeguru42 opened this issue Apr 14, 2022 · 1 comment

Comments

@codeguru42
Copy link

I have a model in a module:

module MyProject
    class MyModel
        # associations, etc
    end
end

And a resource with the same structure:

module MyProject
    class MyModelResource
        # associations, filters, etc.
    end
end

When I try rails generate jsonapi:swagger MyProject::MyModel, I get the following error:

Traceback (most recent call last):
	57: from -e:1:in `<main>'
	56: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	55: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	54: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/fork_tracker.rb:27:in `fork'
	53: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/fork_tracker.rb:8:in `fork'
	52: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/fork_tracker.rb:8:in `fork'
	51: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/activesupport-6.1.4.1/lib/active_support/fork_tracker.rb:10:in `block in fork'
	50: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
	49: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:60:in `load'
	48: from /Users/username/src/mason/api/bin/rails:6:in `<main>'
	47: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
	46: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	45: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	44: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	43: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	42: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	41: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-6.1.4.1/lib/rails/commands.rb:18:in `<main>'
	40: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-6.1.4.1/lib/rails/command.rb:48:in `invoke'
	39: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-6.1.4.1/lib/rails/command/base.rb:69:in `perform'
	38: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
	37: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
	36: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
	35: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-6.1.4.1/lib/rails/commands/generate/generate_command.rb:26:in `perform'
	34: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-6.1.4.1/lib/rails/generators.rb:275:in `invoke'
	33: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
	32: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/group.rb:232:in `dispatch'
	31: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `invoke_all'
	30: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `map'
	29: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `each'
	28: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `block in invoke_all'
	27: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
	26: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
	25: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/swagger_generator.rb:10:in `create_swagger_file'
	24: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-6.1.4.1/lib/rails/generators/named_base.rb:24:in `template'
	23: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-6.1.4.1/lib/rails/generators/named_base.rb:45:in `inside_template'
	22: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/railties-6.1.4.1/lib/rails/generators/named_base.rb:25:in `block in template'
	21: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/file_manipulation.rb:122:in `template'
	20: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:25:in `create_file'
	19: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions.rb:93:in `action'
	18: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:60:in `invoke!'
	17: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/empty_directory.rb:115:in `invoke_with_conflict_check'
	16: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:73:in `on_conflict_behavior'
	15: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:46:in `identical?'
	14: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/create_file.rb:53:in `render'
	13: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/actions/file_manipulation.rb:131:in `block in template'
	12: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/2.7.0/erb.rb:905:in `result'
	11: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/2.7.0/erb.rb:905:in `eval'
	10: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:266:in `template'
	 9: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:167:in `list_resource_responses'
	 8: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:77:in `properties'
	 7: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:77:in `tap'
	 6: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:78:in `block in properties'
	 5: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:78:in `each'
	 4: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:78:in `each_key'
	 3: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:79:in `block (2 levels) in properties'
	 2: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/swagger_generator.rb:129:in `columns_with_comment'
	 1: from /Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/swagger_generator.rb:129:in `tap'
/Users/username/.rbenv/versions/2.7.3/lib/ruby/gems/2.7.0/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/swagger_generator.rb:133:in `block in columns_with_comment': undefined method `columns' for nil:NilClass (NoMethodError)

I think that modules just are not supported. It would be nice to have support for this.

@codeguru42
Copy link
Author

codeguru42 commented Jul 12, 2022

I'm revisiting this and now I get the following error which is more on the nose for the request I'm making here:

% bin/rails g jsonapi:swagger 'Dental::Patient'
Traceback (most recent call last):
        43: from bin/rails:6:in `<main>'
        42: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        41: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        40: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        39: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        38: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        37: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/railties-6.1.4.1/lib/rails/commands.rb:18:in `<main>'
        36: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/railties-6.1.4.1/lib/rails/command.rb:48:in `invoke'
        35: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/railties-6.1.4.1/lib/rails/command/base.rb:69:in `perform'
        34: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        33: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        32: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        31: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/railties-6.1.4.1/lib/rails/commands/generate/generate_command.rb:26:in `perform'
        30: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/railties-6.1.4.1/lib/rails/generators.rb:275:in `invoke'
        29: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/base.rb:485:in `start'
        28: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/group.rb:232:in `dispatch'
        27: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `invoke_all'
        26: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `map'
        25: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `each'
        24: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/invocation.rb:134:in `block in invoke_all'
        23: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        22: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        21: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/swagger_generator.rb:10:in `create_swagger_file'
        20: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/railties-6.1.4.1/lib/rails/generators/named_base.rb:24:in `template'
        19: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/railties-6.1.4.1/lib/rails/generators/named_base.rb:45:in `inside_template'
        18: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/railties-6.1.4.1/lib/rails/generators/named_base.rb:25:in `block in template'
        17: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions/file_manipulation.rb:122:in `template'
        16: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions/create_file.rb:25:in `create_file'
        15: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions.rb:93:in `action'
        14: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions/create_file.rb:60:in `invoke!'
        13: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions/empty_directory.rb:115:in `invoke_with_conflict_check'
        12: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions/create_file.rb:73:in `on_conflict_behavior'
        11: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions/create_file.rb:46:in `identical?'
        10: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions/create_file.rb:53:in `render'
         9: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/thor-1.2.1/lib/thor/actions/file_manipulation.rb:131:in `block in template'
         8: from /Users/username/.rbenv/versions/2.7.6/lib/ruby/2.7.0/erb.rb:905:in `result'
         7: from /Users/username/.rbenv/versions/2.7.6/lib/ruby/2.7.0/erb.rb:905:in `eval'
         6: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:265:in `template'
         5: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:7:in `list_resource_parameters'
         4: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:7:in `tap'
         3: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/templates/swagger.json.erb:10:in `block in list_resource_parameters'
         2: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/swagger_generator.rb:101:in `sortable_fields'
         1: from /Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/jsonapi-swagger-0.8.1/lib/generators/jsonapi/swagger/swagger_generator.rb:89:in `resource_klass'
/Users/username/.rbenv/versions/2.7.6/gemsets/masonapi/gems/jsonapi-swagger-0.8.1/lib/jsonapi/swagger/resource.rb:28:in `with': Dental::Patient not support! (Jsonapi::Swagger::Error)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant