-
Notifications
You must be signed in to change notification settings - Fork 20
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
Multiple components blocks #18
Comments
Sorry, it seems that I can't completely reproduce your problem, could you provide more detailed information? |
For example, if you have something like this: module Version1::OpenApi::ModelAResponses
def self.included(base)
base.components do
response :SingleModelA => ['success', :json, data: {
field: { type: String, desc: 'Test' }
}]
response :ListModelA => ['success', :json, data: {
data: [{ field: { type: String, desc: 'Test' } }]
}]
end
end
end and another module module Version1::OpenApi::ModelBResponses
def self.included(base)
base.components do
response :SingleModelB => ['success', :json, data: {
field: { type: String, desc: 'Test' }
}]
response :ListModelB => ['success', :json, data: {
data: [{ field: { type: String, desc: 'Test' } }]
}]
end
end
end and in your BaseController, you do something like: class Version1::BaseController < ApplicationController
Version1::OpenApi::ModelAResponses
Version1::OpenApi::ModelBResponses
end This will not work, :ListModelA will not be defined because Version1::OpenApi::ModelAResponses was not the last included module, and Version1::OpenApi::ModelBResponses redefines components class Version1::ModelAController < Version1::BaseController
api :index, 'List model A' do
response_ref 200 => :ListModelA # This does not exist now
end
def index
# ....
end
end But this will work: class Version1::ModelBController < Version1::BaseController
api :index, 'List model B' do
response_ref 200 => :ListModelB # This exists
end
def index
# ....
end
end The .json schema generated will only contain components defined in The only way I can get it to work is to put all responses and all parameter components in the same component block, if you have more than 1 component block, only the last component block will be used |
Please update this gem and try again. 😄 |
Is there any problem? |
Thank you @zhandao! I will try it out tonight and tell you how it went :-) Appreciate the quick response! |
Hi, should I finish this issue? @Amnesthesia |
I want to separate components into multiple files without duplicating them, so I have some modules that define response_refs and param_refs, and then I include these helpers.
It seems like only the last
components do ... end
will be evaluated, and all the ones before will be overwritten.Is there a way I can define components in multiple files?
The text was updated successfully, but these errors were encountered: