Module: RSpec::OpenAPI

Defined in:
lib/rspec/openapi/version.rb,
lib/rspec/openapi.rb

Defined Under Namespace

Modules: ExampleKey, ExchangeRecorder, Extractors, Minitest Classes: ComponentsUpdater=Object.new, Config, DefaultSchema=Object.new, HashHelper=Object.new, KeyTransformer=Object.new, NullableConverter=Object.new, OperationConverter=Object.new, Record, RecordBuilder=Object.new, ResultRecorder, SchemaCleaner=Object.new, SchemaFile, SchemaMerger=Object.new, SchemaSorter=Object.new, StreamParser=Object.new

Constant Summary collapse

VERSION =
'0.30.0'
SchemaBuilder =
Object.new
SEQUENTIAL_MEDIA_TYPES =

Streaming media types whose body is a sequence of items, not one document. Their raw body is kept unparsed and split per item (see StreamParser).

[
  'application/jsonl',
  'application/x-ndjson',
  'application/json-seq',
  'text/event-stream',
].freeze
SUPPORTED_OPENAPI_MAJOR_MINORS =
['3.0', '3.1', '3.2'].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.application_versionObject

Returns the value of attribute application_version.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def application_version
  @application_version
end

.commentObject

Returns the value of attribute comment.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def comment
  @comment
end

.config_filenameObject (readonly)

Returns the value of attribute config_filename.



95
96
97
# File 'lib/rspec/openapi.rb', line 95

def config_filename
  @config_filename
end

.description_builderObject

Returns the value of attribute description_builder.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def description_builder
  @description_builder
end

.enable_exampleObject

Returns the value of attribute enable_example.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def enable_example
  @enable_example
end

.enable_example_summaryObject

Returns the value of attribute enable_example_summary.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def enable_example_summary
  @enable_example_summary
end

.example_name_builderObject

Returns the value of attribute example_name_builder.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def example_name_builder
  @example_name_builder
end

.example_typesObject

Returns the value of attribute example_types.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def example_types
  @example_types
end

.formats_builderObject

Returns the value of attribute formats_builder.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def formats_builder
  @formats_builder
end

.ignored_path_paramsObject

Returns the value of attribute ignored_path_params.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def ignored_path_params
  @ignored_path_params
end

.ignored_pathsObject

Returns the value of attribute ignored_paths.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def ignored_paths
  @ignored_paths
end

.infoObject

Returns the value of attribute info.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def info
  @info
end

.openapi_versionObject

Returns the value of attribute openapi_version.



95
96
97
# File 'lib/rspec/openapi.rb', line 95

def openapi_version
  @openapi_version
end

.pathObject

Returns the value of attribute path.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def path
  @path
end

.path_recordsObject

Returns the value of attribute path_records.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def path_records
  @path_records
end

.post_process_hookObject

Returns the value of attribute post_process_hook.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def post_process_hook
  @post_process_hook
end

.request_headersObject

Returns the value of attribute request_headers.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def request_headers
  @request_headers
end

.response_headersObject

Returns the value of attribute response_headers.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def response_headers
  @response_headers
end

.root_tagsObject

Returns the value of attribute root_tags.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def root_tags
  @root_tags
end

.security_schemesObject

Returns the value of attribute security_schemes.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def security_schemes
  @security_schemes
end

.serversObject

Returns the value of attribute servers.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def servers
  @servers
end

.summary_builderObject

Returns the value of attribute summary_builder.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def summary_builder
  @summary_builder
end

.tags_builderObject

Returns the value of attribute tags_builder.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def tags_builder
  @tags_builder
end

.titleObject

Returns the value of attribute title.



72
73
74
# File 'lib/rspec/openapi.rb', line 72

def title
  @title
end

Class Method Details

.json_schema_based?Boolean

3.1+ drops nullable in favour of JSON Schema null types.

Returns:

  • (Boolean)


113
114
115
# File 'lib/rspec/openapi.rb', line 113

def json_schema_based?
  openapi_version_at_least?('3.1')
end

.openapi_version_at_least?(version) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/rspec/openapi.rb', line 108

def openapi_version_at_least?(version)
  Gem::Version.new(openapi_version) >= Gem::Version.new(version)
end

.register_http_methods(methods) ⇒ Object

Allow Rails request specs to issue extra verbs (e.g. QUERY); ActionDispatch otherwise rejects unknown verbs. No-op outside Rails.



133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/rspec/openapi.rb', line 133

def register_http_methods(methods)
  # simplecov:disable branch non-Rails guard for roda/hanami; the suite always loads Rails
  return unless defined?(ActionDispatch::Request::HTTP_METHODS)

  # simplecov:enable
  Array(methods).each do |method|
    verb = method.to_s.upcase
    next if ActionDispatch::Request::HTTP_METHODS.include?(verb)

    ActionDispatch::Request::HTTP_METHODS << verb
    ActionDispatch::Request::HTTP_METHOD_LOOKUP[verb] = verb.downcase.to_sym
  end
end

.sequential_media_type?(media_type) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/rspec/openapi.rb', line 127

def sequential_media_type?(media_type)
  SEQUENTIAL_MEDIA_TYPES.include?(media_type)
end

.supports_additional_operations?Boolean

3.2 adds the query field and the additionalOperations map.

Returns:

  • (Boolean)


118
119
120
# File 'lib/rspec/openapi.rb', line 118

def supports_additional_operations?
  openapi_version_at_least?('3.2')
end

.supports_item_schema?Boolean

3.2 adds itemSchema for sequential (streaming) media types.

Returns:

  • (Boolean)


123
124
125
# File 'lib/rspec/openapi.rb', line 123

def supports_item_schema?
  openapi_version_at_least?('3.2')
end