rspec-openapi 0.3.18 → 0.3.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +8 -0
- data/lib/rspec/openapi/default_schema.rb +1 -0
- data/lib/rspec/openapi/record.rb +1 -0
- data/lib/rspec/openapi/record_builder.rb +7 -0
- data/lib/rspec/openapi/schema_builder.rb +10 -0
- data/lib/rspec/openapi/version.rb +1 -1
- data/lib/rspec/openapi.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc42fc95d88e3523412bf9efbee6066b2789637a5b0213550f9d16711c1c9a94
|
4
|
+
data.tar.gz: fcaa99b78c4cc3404b9ee5b8cb9906fb3872b8c06ceb8ceb5d38f775015ae6ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa9865db15800d17549ee640ed88b2d5f32289e4ac61a30db43cf0adf7021889123cedb96558032c0c8b25c03d5390897fa716352edb98c7a5c091b64210b924
|
7
|
+
data.tar.gz: 5da282aa5811e4a61f24f4c853200c3e8e786704d737eff325651eca75cef49c06fb96d1d7c9547afa821e98e807fa8cf1509c672b934a296e57927f584c3e14
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -114,6 +114,14 @@ RSpec::OpenAPI.enable_example = false
|
|
114
114
|
# Change `info.version`
|
115
115
|
RSpec::OpenAPI.application_version = '1.0.0'
|
116
116
|
|
117
|
+
# Set `headers` - generate parameters with headers for a request
|
118
|
+
RSpec::OpenAPI.request_headers = %w[X-Authorization-Token]
|
119
|
+
|
120
|
+
# Set `server_urls` - generate servers of a schema file
|
121
|
+
RSpec::OpenAPI.server_urls = %w[
|
122
|
+
http://localhost:3000
|
123
|
+
]
|
124
|
+
|
117
125
|
# Generate a comment on top of a schema file
|
118
126
|
RSpec::OpenAPI.comment = <<~EOS
|
119
127
|
This file is auto-generated by rspec-openapi https://github.com/k0kubun/rspec-openapi
|
data/lib/rspec/openapi/record.rb
CHANGED
@@ -5,6 +5,7 @@ RSpec::OpenAPI::Record = Struct.new(
|
|
5
5
|
:query_params, # @param [Hash] - {:query=>"string"}
|
6
6
|
:request_params, # @param [Hash] - {:request=>"body"}
|
7
7
|
:request_content_type, # @param [String] - "application/json"
|
8
|
+
:request_headers, # @param [Array] - [["header_key1", "header_value1"], ["header_key2", "header_value2"]]
|
8
9
|
:summary, # @param [String] - "v1/statuses #show"
|
9
10
|
:tags, # @param [Array] - ["Status"]
|
10
11
|
:description, # @param [String] - "returns a status"
|
@@ -34,6 +34,12 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
34
34
|
nil
|
35
35
|
end
|
36
36
|
|
37
|
+
request_headers = RSpec::OpenAPI.request_headers.each_with_object([]) do |header, headers_arr|
|
38
|
+
header_key = header.gsub(/-/, '_').upcase
|
39
|
+
header_value = request.get_header(['HTTP', header_key].join('_')) || request.get_header(header_key)
|
40
|
+
headers_arr << [header, header_value] if header_value
|
41
|
+
end
|
42
|
+
|
37
43
|
RSpec::OpenAPI::Record.new(
|
38
44
|
method: request.request_method,
|
39
45
|
path: path,
|
@@ -41,6 +47,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
41
47
|
query_params: request.query_parameters,
|
42
48
|
request_params: raw_request_params(request),
|
43
49
|
request_content_type: request.media_type,
|
50
|
+
request_headers: request_headers,
|
44
51
|
summary: summary,
|
45
52
|
tags: tags,
|
46
53
|
description: RSpec::OpenAPI.description_builder.call(example),
|
@@ -67,6 +67,16 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
67
67
|
}.compact
|
68
68
|
end
|
69
69
|
|
70
|
+
record.request_headers.each do |key, value|
|
71
|
+
parameters << {
|
72
|
+
name: build_parameter_name(key, value),
|
73
|
+
in: 'header',
|
74
|
+
required: true,
|
75
|
+
schema: build_property(try_cast(value)),
|
76
|
+
example: (try_cast(value) if example_enabled?),
|
77
|
+
}.compact
|
78
|
+
end
|
79
|
+
|
70
80
|
return nil if parameters.empty?
|
71
81
|
parameters
|
72
82
|
end
|
data/lib/rspec/openapi.rb
CHANGED
@@ -7,8 +7,10 @@ module RSpec::OpenAPI
|
|
7
7
|
@enable_example = true
|
8
8
|
@description_builder = -> (example) { example.description }
|
9
9
|
@application_version = '1.0.0'
|
10
|
+
@request_headers = []
|
11
|
+
@server_urls = []
|
10
12
|
|
11
13
|
class << self
|
12
|
-
attr_accessor :path, :comment, :enable_example, :description_builder, :application_version
|
14
|
+
attr_accessor :path, :comment, :enable_example, :description_builder, :application_version, :request_headers, :server_urls
|
13
15
|
end
|
14
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-openapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|