Closed Reizar closed 3 months ago
Hi @Reizar! You are welcome, and thanks to you for reporting the issue so we can build a better solution.
I think you are not using your Rails app with config.api_only = true
. Am I correct? So, when you add resources :outgoing_bond_transfer
(Example) into your routes.rb file, your app generates routes for the entire crud thinking in a full stack app including a outgoing_bond_transfer/new
path. Then the OasRails engine is looking for the def new
instance method implementation, but it could find it.
When you call OutgoingBondTransfersController.new
you are just initializing the object and this will work in almost all ruby classes.
So the solution here is to check if the route has a method implementation first, then proceed. If not, then the route will be discarded. I will be working on it asap.
There is a configuration you can use. Maybe you can follow the next approach to mount the engine just for your version 2:
config/initialzers/oas_rails.rb
set the next config:
config.api_path = "/api/v2/" # whatever your rails api path is
# routes.rb
namespace :api do
namespace :v2 do
mount OasRails::Engine, at: '/docs'
end
end
...
So after fix the first point you can try to do it. I hope will be helping you.
Hi, I'm trying a similar approach where I set the mount engine in a subdomain docs and I specify my ressource but I'm getting this error message : NameError - uninitialized constant Api::V2::Search
Seems there is missmatch between Search & Searches (see below)
# routes.rb
constraints subdomain: "docs" do
mount OasRails::Engine => "/"
resources :searches, only: [:create]
end
I did set my config path correctly :
config.api_path = "/api/v2/"
And I have my controller in the correct location
#app/controllers/api/v2/searches_controller.rb
class Api::V2::SearchesController < ApplicationController
respond_to :json
def create
# my method
end
end
Is there something that I'm doing wrong ?
Hi,
First off thank you for releasing and working on this gem. I'm eager to give it a try, however I'm getting an error when I try running and accessing the docs.
Steps I followed:
However I get this error ( see screenshot )
Full stack trace here:
If I run the rails console and do
OutgoingBondTransfersController.new
it returns an object correctly.I am running: Rails 7.1.3.4 Ruby 3.3.0 oas_rails 0.2.0
Also if it helps with the roadmap at all, being able to filter to only include certain controllers / routes would be good. Our current API is powered by graphiti and we're not looking to add docs for those. But are working on a v2 that won't be graphiti based and we'd like to have docs for just those endpoints.
Thanks!