swaggard
swaggard copied to clipboard
Fix undefined methods
- In Operation
def definitions
was building a definitions hash by id, but not actually returning the hash for chaining. Resulting in error:
undefined method `[]=' for #<Swaggard::Swagger::Definition:0x00007feae308c048 @id="Api::V1::CustomersController.create_response", @title="", @properties=[#<Swaggard::Swagger::Response::ResponseModel:0x00007feae308c318 @is_array_response=nil, @response_class="CustomerSerializer", @id="customer">], @description="", @ancestors=[], @ignore_inherited=false>
- In Definition
def to_doc
was selecting required properties, butall_properties
contained aResponseModel
which didn't have arequired?
method.
undefined method `required?' for #<Swaggard::Swagger::Response::ResponseModel:0x00007fc65125fbb0 @is_array_response=nil, @response_class="CustomerSerializer", @id="customer">
Adding the missing required?
method seemed cleaner than checking each for the presence of the method before calling it.
# existing
required_properties = all_properties.select(&:required?).map(&:id)
# meh
required_properties = all_properties.select { |p| p.respond_to?(:required?) && p.required? }.map(&:id)
On Ruby 3.0.6 / Rails 6.1.7.4