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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd7d2eb0e69e2e60405a7d71d10acd3b2edf2d4db0358297a900200a0a69012e
4
- data.tar.gz: 577545384d404ba11382ab4425e0bd40abeeb3e58db922e82d923f0d6d6ae8e9
3
+ metadata.gz: bc42fc95d88e3523412bf9efbee6066b2789637a5b0213550f9d16711c1c9a94
4
+ data.tar.gz: fcaa99b78c4cc3404b9ee5b8cb9906fb3872b8c06ceb8ceb5d38f775015ae6ed
5
5
  SHA512:
6
- metadata.gz: 5f60ee2cf93946405e3e151786965b3a0f68e53ad147a6d7613f59f46f834efd9a641d0f878943af934879d2f5e27e8c8d4cd55dac5288d62a85dc2b77009ddb
7
- data.tar.gz: 7dc56150dfb4a8a5b526d7ec626b4ebc9c0680878cd1f976213490a489a598dfe2a285f01029e5a17cdbbe0d8b492fe79a2e51148ac24df94d532c404b0231fd
6
+ metadata.gz: aa9865db15800d17549ee640ed88b2d5f32289e4ac61a30db43cf0adf7021889123cedb96558032c0c8b25c03d5390897fa716352edb98c7a5c091b64210b924
7
+ data.tar.gz: 5da282aa5811e4a61f24f4c853200c3e8e786704d737eff325651eca75cef49c06fb96d1d7c9547afa821e98e807fa8cf1509c672b934a296e57927f584c3e14
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.3.19
2
+
3
+ * Add `server_urls` and `request_headers` configs
4
+ [#30](https://github.com/k0kubun/rspec-openapi/pull/30)
5
+
1
6
  ## v0.3.18
2
7
 
3
8
  * Support nested query parameters
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
@@ -6,6 +6,7 @@ class << RSpec::OpenAPI::DefaultSchema = Object.new
6
6
  title: title,
7
7
  version: RSpec::OpenAPI.application_version,
8
8
  },
9
+ servers: RSpec::OpenAPI.server_urls.map { |url| { url: url } } || [],
9
10
  paths: {},
10
11
  }.freeze
11
12
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.3.18'
3
+ VERSION = '0.3.19'
4
4
  end
5
5
  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.18
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-06-17 00:00:00.000000000 Z
11
+ date: 2021-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack