Module: RSpec::OpenAPI

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

Defined Under Namespace

Modules: ExampleKey, ExchangeRecorder, Extractors, Minitest, ParallelRecords 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.33.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.



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

def application_version
  @application_version
end

.commentObject

Returns the value of attribute comment.



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

def comment
  @comment
end

.config_filenameObject (readonly)

Returns the value of attribute config_filename.



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

def config_filename
  @config_filename
end

.description_builderObject

Returns the value of attribute description_builder.



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

def description_builder
  @description_builder
end

.enable_exampleObject

Returns the value of attribute enable_example.



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

def enable_example
  @enable_example
end

.enable_example_summaryObject

Returns the value of attribute enable_example_summary.



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

def enable_example_summary
  @enable_example_summary
end

.example_name_builderObject

Returns the value of attribute example_name_builder.



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

def example_name_builder
  @example_name_builder
end

.example_typesObject

Returns the value of attribute example_types.



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

def example_types
  @example_types
end

.formats_builderObject

Returns the value of attribute formats_builder.



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

def formats_builder
  @formats_builder
end

.ignored_path_paramsObject

Returns the value of attribute ignored_path_params.



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

def ignored_path_params
  @ignored_path_params
end

.ignored_pathsObject

Returns the value of attribute ignored_paths.



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

def ignored_paths
  @ignored_paths
end

.infoObject

Returns the value of attribute info.



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

def info
  @info
end

.openapi_versionObject

Returns the value of attribute openapi_version.



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

def openapi_version
  @openapi_version
end

.pathObject

Returns the value of attribute path.



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

def path
  @path
end

.path_recordsObject

Returns the value of attribute path_records.



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

def path_records
  @path_records
end

.post_process_hookObject

Returns the value of attribute post_process_hook.



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

def post_process_hook
  @post_process_hook
end

.request_headersObject

Returns the value of attribute request_headers.



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

def request_headers
  @request_headers
end

.response_headersObject

Returns the value of attribute response_headers.



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

def response_headers
  @response_headers
end

.root_tagsObject

Returns the value of attribute root_tags.



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

def root_tags
  @root_tags
end

.security_schemesObject

Returns the value of attribute security_schemes.



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

def security_schemes
  @security_schemes
end

.serversObject

Returns the value of attribute servers.



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

def servers
  @servers
end

.summary_builderObject

Returns the value of attribute summary_builder.



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

def summary_builder
  @summary_builder
end

.tags_builderObject

Returns the value of attribute tags_builder.



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

def tags_builder
  @tags_builder
end

.titleObject

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.json_schema_based?Boolean

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

Returns:

  • (Boolean)


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

def json_schema_based?
  openapi_version_at_least?('3.1')
end

.openapi_version_at_least?(version) ⇒ Boolean

Returns:

  • (Boolean)


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

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.



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

def register_http_methods(methods)
  # :nocov:
  # Guards users without Rails. Every job here installs it, so this arm is
  # unreachable from the suite. SimpleCov's token is `nocov`, so the marker
  # this used to carry never actually excluded anything.
  return unless defined?(ActionDispatch::Request::HTTP_METHODS)

  # :nocov:
  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)


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

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)


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

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)


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

def supports_item_schema?
  openapi_version_at_least?('3.2')
end