openapi_first 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/openapi_first/file_loader.rb +9 -1
- data/lib/openapi_first/ref_resolver.rb +12 -1
- data/lib/openapi_first/utils.rb +10 -0
- data/lib/openapi_first/version.rb +1 -1
- data/lib/openapi_first.rb +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dc1e6456e7c11e5079255b24e6407f61d9e94677fe07bef54000c26fe1174e05
|
|
4
|
+
data.tar.gz: 313d87080b433ca45defd7a47a811f6f2a91b93804a6655b9121b86d95c2e2f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a04433e95586c8cc5ad34f791e1a2fc598584be5e23c7e7518c5eb9bd04d77c96fb3b1fe9330a16e4a9060b119b835e42863a11a1abb77c8f5b2cbba246fdcc
|
|
7
|
+
data.tar.gz: bb8a46ea7aaf083819cac30ede78fe6f560f339f2d8282d727e111b3e504dab42aa0a7b82d1372bd060a5217818f694cadad11f71085e15baed7a10c48f5578e
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 4.0.1
|
|
6
|
+
|
|
7
|
+
- Fix: Reduced memory usage with large API descriptions. Schemas no longer each deep-copy (stringify keys) the whole OAD to build a root schema. This is a json_schemer specific optimization.
|
|
8
|
+
|
|
5
9
|
## 4.0.0
|
|
6
10
|
|
|
7
11
|
This release has no stricter or less strict request validation. It changes mostly internal stuff and adds a Sinatra integration. It's a major version, but it should be safe to upgrade.
|
|
@@ -26,12 +26,20 @@ module OpenapiFirst
|
|
|
26
26
|
if extname == '.json'
|
|
27
27
|
::JSON.parse(body)
|
|
28
28
|
elsif ['.yaml', '.yml'].include?(extname)
|
|
29
|
-
|
|
29
|
+
load_yaml(body, file_path)
|
|
30
30
|
else
|
|
31
31
|
body
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def load_yaml(body, file_path)
|
|
40
|
+
Utils.deep_stringify_keys(YAML.unsafe_load(body))
|
|
41
|
+
rescue ::JSON::GeneratorError => e
|
|
42
|
+
raise Error, "Could not load #{file_path.inspect}: #{e.message}"
|
|
43
|
+
end
|
|
36
44
|
end
|
|
37
45
|
end
|
|
@@ -184,6 +184,17 @@ module OpenapiFirst
|
|
|
184
184
|
vocabulary: { 'https://json-schema.org/draft/2020-12/vocab/core' => true }
|
|
185
185
|
)
|
|
186
186
|
|
|
187
|
+
# This class is here to monkey-patch JSONSchemer::Schema when we are passing
|
|
188
|
+
# an instance to sub-schemas. It skips stringifying all keys of the passed object to
|
|
189
|
+
# allocate fewer objects. We don't have to stringify the keys, because they are already stringified upstream.
|
|
190
|
+
# @visibility private
|
|
191
|
+
class DocumentRootSchema < JSONSchemer::Schema
|
|
192
|
+
private
|
|
193
|
+
|
|
194
|
+
def deep_stringify_keys(value) = value
|
|
195
|
+
end
|
|
196
|
+
private_constant :DocumentRootSchema
|
|
197
|
+
|
|
187
198
|
def initialize(value:, context:, base_uri:, options:)
|
|
188
199
|
@value = value
|
|
189
200
|
@context = context
|
|
@@ -197,7 +208,7 @@ module OpenapiFirst
|
|
|
197
208
|
|
|
198
209
|
def schema
|
|
199
210
|
@schema ||= begin
|
|
200
|
-
root_schema =
|
|
211
|
+
root_schema = DocumentRootSchema.new(context, base_uri:, **options, meta_schema: DOCUMENT_META_SCHEMA)
|
|
201
212
|
apply_dialect(root_schema)
|
|
202
213
|
JSONSchemer::Schema.new(value, nil, root_schema, base_uri:, **options)
|
|
203
214
|
end
|
data/lib/openapi_first.rb
CHANGED
|
@@ -4,6 +4,7 @@ require_relative 'openapi_first/json'
|
|
|
4
4
|
require_relative 'openapi_first/file_loader'
|
|
5
5
|
require_relative 'openapi_first/errors'
|
|
6
6
|
require_relative 'openapi_first/registry'
|
|
7
|
+
require_relative 'openapi_first/utils'
|
|
7
8
|
require_relative 'openapi_first/configuration'
|
|
8
9
|
require_relative 'openapi_first/child_configuration'
|
|
9
10
|
require_relative 'openapi_first/definition'
|
|
@@ -82,7 +83,7 @@ module OpenapiFirst
|
|
|
82
83
|
# @return [Definition]
|
|
83
84
|
# TODO: This needs to work with unresolved contents as well
|
|
84
85
|
def self.parse(contents, only: nil, filepath: nil, path_prefix: nil, &)
|
|
85
|
-
contents =
|
|
86
|
+
contents = Utils.deep_stringify_keys(contents) # Deeply stringify keys, because of YAML. See https://github.com/ahx/openapi_first/issues/367
|
|
86
87
|
contents['paths'].filter!(&->(key, _) { only.call(key) }) if only
|
|
87
88
|
Definition.new(contents, filepath, path_prefix, &)
|
|
88
89
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openapi_first
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.0.
|
|
4
|
+
version: 4.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andreas Haller
|
|
@@ -154,6 +154,7 @@ files:
|
|
|
154
154
|
- lib/openapi_first/test/observe.rb
|
|
155
155
|
- lib/openapi_first/test/observer_middleware.rb
|
|
156
156
|
- lib/openapi_first/test/plain_helpers.rb
|
|
157
|
+
- lib/openapi_first/utils.rb
|
|
157
158
|
- lib/openapi_first/validated_request.rb
|
|
158
159
|
- lib/openapi_first/validated_response.rb
|
|
159
160
|
- lib/openapi_first/validators/multipart_request_body.rb
|