a-chacon / oas_rails

Generate Automatic Interactive Documentation for Your Rails API
GNU General Public License v3.0
69 stars 4 forks source link

NameError (@get|post) #27

Closed Metalzoid closed 3 months ago

Metalzoid commented 3 months ago

Hi,

I tryed to install rails_aos in my project.

After gemfile, bundle, oas_rails:config, and routing, i can't access /docs.

My app is not api_only, i tried with ans without devise auth.

My configs :

routes.rb : authenticate :admin do mount OasRails::Engine, at: '/docs' end I've a admin model devise.

Logs : `Started GET "/docs" for ::1 at 2024-08-20 12:37:51 +0200 Admin Load (0.3ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]] Processing by OasRails::OasRailsController#index as HTML Rendering /usr/share/rvm/gems/ruby-3.3.0/gems/oas_rails-0.4.3/app/views/oas_rails/oas_rails/index.html.erb Rendered /usr/share/rvm/gems/ruby-3.3.0/gems/oas_rails-0.4.3/app/views/oas_rails/oas_rails/index.html.erb (Duration: 0.8ms | Allocations: 284) Completed 200 OK in 3ms (Views: 1.6ms | ActiveRecord: 0.0ms | Allocations: 1248)

Started GET "/docs.json" for ::1 at 2024-08-20 12:37:51 +0200 Admin Load (0.2ms) SELECT "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]] Processing by OasRails::OasRailsController#index as JSON Completed 500 Internal Server Error in 48ms (ActiveRecord: 0.0ms | Allocations: 48836)

NameError (`@get|post' is not allowed as an instance variable name):

oas_rails (0.4.3) lib/oas_rails/spec/path_item.rb:25:in instance_variable_set' oas_rails (0.4.3) lib/oas_rails/spec/path_item.rb:25:inadd_operation' oas_rails (0.4.3) lib/oas_rails/builders/path_item_builder.rb:11:in block in from_path' oas_rails (0.4.3) lib/oas_rails/builders/path_item_builder.rb:10:ineach' oas_rails (0.4.3) lib/oas_rails/builders/path_item_builder.rb:10:in from_path' oas_rails (0.4.3) lib/oas_rails/spec/paths.rb:14:inadd_path' oas_rails (0.4.3) lib/oas_rails/spec/specification.rb:25:in block in build' oas_rails (0.4.3) lib/oas_rails/spec/specification.rb:24:ineach' oas_rails (0.4.3) lib/oas_rails/spec/specification.rb:24:in build' oas_rails (0.4.3) lib/oas_rails.rb:60:inbuild' oas_rails (0.4.3) app/controllers/oas_rails/oas_rails_controller.rb:9:in block (2 levels) in index' actionpack (7.1.3.4) lib/action_controller/metal/mime_responds.rb:214:inrespond_to' oas_rails (0.4.3) app/controllers/oas_rails/oas_rails_controller.rb:6:in index' actionpack (7.1.3.4) lib/action_controller/metal/basic_implicit_render.rb:6:insend_action' actionpack (7.1.3.4) lib/abstract_controller/base.rb:224:in process_action' actionpack (7.1.3.4) lib/action_controller/metal/rendering.rb:165:inprocess_action' actionpack (7.1.3.4) lib/abstract_controller/callbacks.rb:259:in block in process_action' activesupport (7.1.3.4) lib/active_support/callbacks.rb:121:inblock in run_callbacks' turbo-rails (2.0.6) lib/turbo-rails.rb:24:in with_request_id' turbo-rails (2.0.6) app/controllers/concerns/turbo/request_id_tracking.rb:10:inturbo_tracking_request_id' activesupport (7.1.3.4) lib/active_support/callbacks.rb:130:in block in run_callbacks' actiontext (7.1.3.4) lib/action_text/rendering.rb:23:inwith_renderer' actiontext (7.1.3.4) lib/action_text/engine.rb:69:in block (4 levels) in <class:Engine>' activesupport (7.1.3.4) lib/active_support/callbacks.rb:130:ininstance_exec' activesupport (7.1.3.4) lib/active_support/callbacks.rb:130:in block in run_callbacks' activesupport (7.1.3.4) lib/active_support/callbacks.rb:141:inrun_callbacks' actionpack (7.1.3.4) lib/abstract_controller/callbacks.rb:258:in process_action' actionpack (7.1.3.4) lib/action_controller/metal/rescue.rb:25:inprocess_action' actionpack (7.1.3.4) lib/action_controller/metal/instrumentation.rb:74:in block in process_action' activesupport (7.1.3.4) lib/active_support/notifications.rb:206:inblock in instrument' activesupport (7.1.3.4) lib/active_support/notifications/instrumenter.rb:58:in instrument' activesupport (7.1.3.4) lib/active_support/notifications.rb:206:ininstrument' actionpack (7.1.3.4) lib/action_controller/metal/instrumentation.rb:73:in process_action' actionpack (7.1.3.4) lib/action_controller/metal/params_wrapper.rb:261:inprocess_action' activerecord (7.1.3.4) lib/active_record/railties/controller_runtime.rb:32:in process_action' actionpack (7.1.3.4) lib/abstract_controller/base.rb:160:inprocess' actionview (7.1.3.4) lib/action_view/rendering.rb:40:in process' actionpack (7.1.3.4) lib/action_controller/metal.rb:227:indispatch' actionpack (7.1.3.4) lib/action_controller/metal.rb:309:in dispatch' actionpack (7.1.3.4) lib/action_dispatch/routing/route_set.rb:49:indispatch' actionpack (7.1.3.4) lib/action_dispatch/routing/route_set.rb:32:in serve' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:51:inblock in serve' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:131:in block in find_routes' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:124:ineach' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:124:in find_routes' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:32:inserve' actionpack (7.1.3.4) lib/action_dispatch/routing/route_set.rb:882:in call' railties (7.1.3.4) lib/rails/engine.rb:536:incall' railties (7.1.3.4) lib/rails/railtie.rb:226:in public_send' railties (7.1.3.4) lib/rails/railtie.rb:226:inmethod_missing' actionpack (7.1.3.4) lib/action_dispatch/routing/mapper.rb:22:in block in <class:Constraints>' actionpack (7.1.3.4) lib/action_dispatch/routing/mapper.rb:51:inserve' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:51:in block in serve' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:131:inblock in find_routes' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:124:in each' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:124:infind_routes' actionpack (7.1.3.4) lib/action_dispatch/journey/router.rb:32:in serve' actionpack (7.1.3.4) lib/action_dispatch/routing/route_set.rb:882:incall' omniauth (2.1.2) lib/omniauth/strategy.rb:202:in call!' omniauth (2.1.2) lib/omniauth/strategy.rb:169:incall' omniauth (2.1.2) lib/omniauth/strategy.rb:202:in call!' omniauth (2.1.2) lib/omniauth/strategy.rb:169:incall' warden-jwt_auth (0.10.0) lib/warden/jwt_auth/middleware/token_dispatcher.rb:20:in call' warden-jwt_auth (0.10.0) lib/warden/jwt_auth/middleware/revocation_manager.rb:21:incall' rack (3.1.7) lib/rack/builder.rb:277:in call' warden-jwt_auth (0.10.0) lib/warden/jwt_auth/middleware.rb:22:incall' rack-attack (6.7.0) lib/rack/attack.rb:127:in call' rack (3.1.7) lib/rack/method_override.rb:28:incall' rack-session (2.0.0) lib/rack/session/abstract/id.rb:272:in context' rack-session (2.0.0) lib/rack/session/abstract/id.rb:266:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/cookies.rb:689:in call' warden (1.2.9) lib/warden/manager.rb:36:inblock in call' warden (1.2.9) lib/warden/manager.rb:34:in catch' warden (1.2.9) lib/warden/manager.rb:34:incall' rack (3.1.7) lib/rack/tempfile_reaper.rb:20:in call' rack (3.1.7) lib/rack/etag.rb:29:incall' rack (3.1.7) lib/rack/conditional_get.rb:31:in call' rack (3.1.7) lib/rack/head.rb:15:incall' actionpack (7.1.3.4) lib/action_dispatch/http/permissions_policy.rb:36:in call' actionpack (7.1.3.4) lib/action_dispatch/http/content_security_policy.rb:33:incall' rack-session (2.0.0) lib/rack/session/abstract/id.rb:272:in context' rack-session (2.0.0) lib/rack/session/abstract/id.rb:266:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/cookies.rb:689:in call' activerecord (7.1.3.4) lib/active_record/migration.rb:655:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/callbacks.rb:29:in block in call' activesupport (7.1.3.4) lib/active_support/callbacks.rb:101:inrun_callbacks' actionpack (7.1.3.4) lib/action_dispatch/middleware/callbacks.rb:28:in call' actionpack (7.1.3.4) lib/action_dispatch/middleware/executor.rb:14:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in call' actionpack (7.1.3.4) lib/action_dispatch/middleware/debug_exceptions.rb:29:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/show_exceptions.rb:31:in call' railties (7.1.3.4) lib/rails/rack/logger.rb:37:incall_app' railties (7.1.3.4) lib/rails/rack/logger.rb:24:in block in call' activesupport (7.1.3.4) lib/active_support/tagged_logging.rb:135:inblock in tagged' activesupport (7.1.3.4) lib/active_support/tagged_logging.rb:39:in tagged' activesupport (7.1.3.4) lib/active_support/tagged_logging.rb:135:intagged' activesupport (7.1.3.4) lib/active_support/broadcast_logger.rb:240:in method_missing' railties (7.1.3.4) lib/rails/rack/logger.rb:24:incall' sprockets-rails (3.5.2) lib/sprockets/rails/quiet_assets.rb:17:in call' actionpack (7.1.3.4) lib/action_dispatch/middleware/remote_ip.rb:92:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/request_id.rb:28:in call' rack (3.1.7) lib/rack/method_override.rb:28:incall' rack (3.1.7) lib/rack/runtime.rb:24:in call' activesupport (7.1.3.4) lib/active_support/cache/strategy/local_cache_middleware.rb:29:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/server_timing.rb:59:in block in call' actionpack (7.1.3.4) lib/action_dispatch/middleware/server_timing.rb:24:incollect_events' actionpack (7.1.3.4) lib/action_dispatch/middleware/server_timing.rb:58:in call' actionpack (7.1.3.4) lib/action_dispatch/middleware/executor.rb:14:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/static.rb:25:in call' rack (3.1.7) lib/rack/sendfile.rb:114:incall' actionpack (7.1.3.4) lib/action_dispatch/middleware/host_authorization.rb:141:in call' rack-cors (2.0.2) lib/rack/cors.rb:102:incall' railties (7.1.3.4) lib/rails/engine.rb:536:in call' puma (6.4.2) lib/puma/configuration.rb:272:incall' puma (6.4.2) lib/puma/request.rb:100:in block in handle_request' puma (6.4.2) lib/puma/thread_pool.rb:378:inwith_force_shutdown' puma (6.4.2) lib/puma/request.rb:99:in handle_request' puma (6.4.2) lib/puma/server.rb:464:inprocess_client' puma (6.4.2) lib/puma/server.rb:245:in block in run' puma (6.4.2) lib/puma/thread_pool.rb:155:inblock in spawn_thread'`

I'm junior in rails, can you help me ? Ps: I don't have a file docs.json on my root app folder.

Thanks

a-chacon commented 3 months ago

Hello @Metalzoid ! Yes, I can help you. It is really good that you report to me the error so I can do it better. I can see in the logs that the error is on my gem so don't worry about devise, the authetication is working fine. And the docs.json file is generated on the request so it is not required to add nothing more to the project.

Is your project on a public repo? I will try to find the error during the day, if you have your code public then it will be easier for me find the error.

Metalzoid commented 3 months ago

Yes, my repo is public. The name is DatesCalendar. I push my latest modification after Eat 😁.

Thanks

Metalzoid commented 3 months ago

Pushed. You can clone it.

You need .env file, with GitHub et Google oauth for devise (You can turn off if You want in devise initialiser and Admin model.

You need master key generated, and add in .env a key DEVISE_JWT_SECRET_KEY (rails secret that) before rails db:migrate

a-chacon commented 3 months ago

Don't worry, I don't want to run the project. I know where is the problem:

admin_github_omniauth_authorize GET|POST /api/v1/admin/auth/github(.:format)                                                               admins/omniauth_callbacks#passthru
          admin_github_omniauth_callback GET|POST /api/v1/admin/auth/github/callback(.:format)                                                      admins/omniauth_callbacks#github
  admin_google_oauth2_omniauth_authorize GET|POST /api/v1/admin/auth/google_oauth2(.:format)                                                        admins/omniauth_callbacks#passthru
   admin_google_oauth2_omniauth_callback GET|POST /api/v1/admin/auth/google_oauth2/callback(.:format)                                               admins/omniauth_callbacks#google_oauth2

OasRails is not managing the case when the route has two or more verbs like GET|POST. I will try to resolve this during the day, I will notify you!

a-chacon commented 3 months ago

@Metalzoid I fixed it. Please update to last version and test it. If you have another issue, please just tell me :)

I was looking your API, and it goes deeper than a simple CRUD API so OasRails try to give the best, but you will need to add documentation through the yard tags for it works as you expect hehe