Skip to content

Make all attributes which are defined in the openapi files attributes of all models #37

@eikes

Description

@eikes

I noticed, that there are many attributes defined in the openapi specification file which are not accessible through the ruby models. As a user of this gem I would like to be able to access all attributes from the API response though.

The match_open_api_definition matcher can be used to show the difference like this:

RSpec::Matchers.define :match_open_api_definition do |scope, model, options = {}|
  # [...]
  match do |actual_model|
    return false if model_node.nil?
    model_attributes = defined_attributes(actual_model)
    (model_attributes - specified_attributes | specified_attributes - model_attributes).empty?
  end

  failure_message do |actual_model|
    if model_node.nil?
      <<~MESSAGE
        Specification not found for #{actual_model}. I was looking for: #{schema_path}. Available specifications:
        #{schemas.keys}
      MESSAGE
    else
      <<~MESSAGE
        expected that the model #{actual_model} would only define attributes defined in the open_api definition, but there are attributes in the model that are not in the specification.
        The attributes which are used in the model but which are not in the specification are:
        #{(defined_attributes(actual_model) - specified_attributes).sort}
        The attributes which are not used in the model but which are in the specification are:
        #{(specified_attributes - defined_attributes(actual_model)).sort}
        The attributes defined in the model are:
        #{defined_attributes(actual_model).sort}
        The attributes defined in the specification are:
        #{specified_attributes.sort}
      MESSAGE
    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions