rspec-openapi 0.3.6 → 0.3.11

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: 3c2228341b1c207993fd9f98f74069e06a14fde9107d2fce34d4d6ae6d2c2184
4
- data.tar.gz: 23b931010297c4618edac4ce3b51e0d78a9f052891c1c9384844742846988424
3
+ metadata.gz: 07e405e19fc7324fbfb0c67f18643ef3a924441f75971920e29dcb074c5fee41
4
+ data.tar.gz: 55ed7e046ef1dccb8e51d5d9d04012f32007a22da8d20217a582e14112eadc64
5
5
  SHA512:
6
- metadata.gz: fc620c878f8bc514b6f802c324984d16029632f819d2b92815f3a5c9122e93b982658c28ba1a6bf20b4c0021c0570d634a807f9d1e90cd6782f1dc0805aa3762
7
- data.tar.gz: 2cbc49093a983dcd0c1efdf2a41785ec202b6cc582ba72a7fe2f2a4339dbfbcffcab56bf13d2899fa7e7ef067fd794362ae0ffecd1aa52980e8ecc56fa667142
6
+ metadata.gz: d8784246f9827274f9a16ad7e70201f0470a63c9568109ae8e5f02a6a154a02829d6ae8e34d6e4b767ec92afa470a3b72be2bf32dcb2c51b6a628b0fdfa3c8fe
7
+ data.tar.gz: b690fb8885f58626825f072cd75e740649faa05e1b398bf26480a2b8b6013f51f0596c177c92ed57c23fa7c5e49d92d3110c6af406c17bf0f570a8fdcc50f272
@@ -19,6 +19,7 @@ jobs:
19
19
  - ruby:2.5
20
20
  - ruby:2.6
21
21
  - ruby:2.7
22
+ - ruby:3.0
22
23
  steps:
23
24
  - uses: actions/checkout@v2
24
25
  - name: bundle install
@@ -1,3 +1,27 @@
1
+ ## v0.3.11
2
+
3
+ * Show a filename as an `example` for `ActionDispatch::Http::UploadedFile`
4
+ [#17](https://github.com/k0kubun/rspec-openapi/pull/17)
5
+
6
+ ## v0.3.10
7
+
8
+ * Add `info.version`
9
+ [#16](https://github.com/k0kubun/rspec-openapi/pull/16)
10
+
11
+ ## v0.3.9
12
+
13
+ * Initial support for multipart/form-data
14
+ [#12](https://github.com/k0kubun/rspec-openapi/pull/12)
15
+
16
+ ## v0.3.8
17
+
18
+ * Generate `type: 'number', format: 'float'` instead of `type: 'float'` for Float
19
+ [#11](https://github.com/k0kubun/rspec-openapi/issues/11)
20
+
21
+ ## v0.3.7
22
+
23
+ * Classify tag names and remove controller names from summary in Rails
24
+
1
25
  ## v0.3.6
2
26
 
3
27
  * Fix documents generated by Rails engines
data/README.md CHANGED
@@ -64,9 +64,9 @@ info:
64
64
  paths:
65
65
  "/tables":
66
66
  get:
67
- summary: 'tables #index'
67
+ summary: index
68
68
  tags:
69
- - tables
69
+ - Table
70
70
  parameters:
71
71
  - name: page
72
72
  in: query
@@ -111,6 +111,9 @@ RSpec::OpenAPI.path = 'doc/schema.yaml'
111
111
  # Disable generating `example`
112
112
  RSpec::OpenAPI.enable_example = false
113
113
 
114
+ # Change `info.version`
115
+ RSpec::OpenAPI.application_version = '1.0.0'
116
+
114
117
  # Generate a comment on top of a schema file
115
118
  RSpec::OpenAPI.comment = <<~EOS
116
119
  This file is auto-generated by rspec-openapi https://github.com/k0kubun/rspec-openapi
@@ -6,8 +6,9 @@ module RSpec::OpenAPI
6
6
  @comment = nil
7
7
  @enable_example = true
8
8
  @description_builder = -> (example) { example.description }
9
+ @application_version = '1.0.0'
9
10
 
10
11
  class << self
11
- attr_accessor :path, :comment, :enable_example, :description_builder
12
+ attr_accessor :path, :comment, :enable_example, :description_builder, :application_version
12
13
  end
13
14
  end
@@ -4,6 +4,7 @@ class << RSpec::OpenAPI::DefaultSchema = Object.new
4
4
  openapi: '3.0.3',
5
5
  info: {
6
6
  title: title,
7
+ version: RSpec::OpenAPI.application_version,
7
8
  },
8
9
  paths: {},
9
10
  }.freeze
@@ -18,8 +18,8 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
18
18
  if rails?
19
19
  route = find_rails_route(request)
20
20
  path = route.path.spec.to_s.delete_suffix('(.:format)')
21
- summary = "#{route.requirements[:controller]} ##{route.requirements[:action]}"
22
- tags = [route.requirements[:controller]]
21
+ summary = "#{route.requirements[:action]}"
22
+ tags = [route.requirements[:controller].classify]
23
23
  else
24
24
  path = request.path
25
25
  summary = "#{request.method} #{request.path}"
@@ -72,14 +72,15 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
72
72
  content: {
73
73
  normalize_content_type(record.request_content_type) => {
74
74
  schema: build_property(record.request_params),
75
- example: (record.request_params if example_enabled?),
75
+ example: (build_example(record.request_params) if example_enabled?),
76
76
  }.compact
77
77
  }
78
78
  }
79
79
  end
80
80
 
81
81
  def build_property(value)
82
- property = { type: build_type(value) }
82
+ property = build_type(value)
83
+
83
84
  case value
84
85
  when Array
85
86
  property[:items] = build_property(value.first)
@@ -96,19 +97,21 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
96
97
  def build_type(value)
97
98
  case value
98
99
  when String
99
- 'string'
100
- when Float
101
- 'float'
100
+ { type: 'string' }
102
101
  when Integer
103
- 'integer'
102
+ { type: 'integer' }
103
+ when Float
104
+ { type: 'number', format: 'float' }
104
105
  when TrueClass, FalseClass
105
- 'boolean'
106
+ { type: 'boolean' }
106
107
  when Array
107
- 'array'
108
+ { type: 'array' }
108
109
  when Hash
109
- 'object'
110
+ { type: 'object' }
111
+ when ActionDispatch::Http::UploadedFile
112
+ { type: 'string', format: 'binary' }
110
113
  when NilClass
111
- 'null'
114
+ { type: 'null' }
112
115
  else
113
116
  raise NotImplementedError, "type detection is not implemented for: #{value.inspect}"
114
117
  end
@@ -123,6 +126,16 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
123
126
  end
124
127
  end
125
128
 
129
+ def build_example(value)
130
+ return nil if value.nil?
131
+ value = value.dup
132
+ value.each do |key, v|
133
+ if v.is_a?(ActionDispatch::Http::UploadedFile)
134
+ value[key] = v.original_filename
135
+ end
136
+ end
137
+ end
138
+
126
139
  def normalize_path(path)
127
140
  path.gsub(%r|/:([^:/]+)|, '/{\1}')
128
141
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.3.6'
3
+ VERSION = '0.3.11'
4
4
  end
5
5
  end
Binary file
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.6
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-23 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -66,6 +66,7 @@ files:
66
66
  - lib/rspec/openapi/schema_merger.rb
67
67
  - lib/rspec/openapi/version.rb
68
68
  - rspec-openapi.gemspec
69
+ - test.png
69
70
  homepage: https://github.com/k0kubun/rspec-openapi
70
71
  licenses:
71
72
  - MIT
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  - !ruby/object:Gem::Version
89
90
  version: '0'
90
91
  requirements: []
91
- rubygems_version: 3.1.2
92
+ rubygems_version: 3.2.6
92
93
  signing_key:
93
94
  specification_version: 4
94
95
  summary: Generate OpenAPI schema from RSpec request specs