Skip to content

Commit d2d25ea

Browse files
committed
Add initial support for openapi v3
1 parent c449900 commit d2d25ea

File tree

10 files changed

+2588
-11
lines changed

10 files changed

+2588
-11
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
bundle exec rspec spec/
2626
- name: Lint with rubocop
2727
run: |
28-
bundle exec rubocop --verbose && bundle exec rubocop
28+
bundle exec rubocop

lib/open_api_parser/document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module OpenApiParser
44
class Document
55
def self.resolve(path, file_cache = OpenApiParser::FileCache.new)
66
file_cache.get(path) do
7-
content = YAML.load_file(path)
7+
content = YAML.safe_load(ERB.new(File.read(path)).result)
88
Document.new(path, content, file_cache).resolve
99
end
1010
end

lib/open_api_parser/specification.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22

33
module OpenApiParser
44
module Specification
5-
META_SCHEMA_PATH = File.expand_path('../../resources/swagger_meta_schema.json', __dir__)
5+
META_SCHEMA_PATH_2 = File.expand_path('../../resources/swagger_meta_schema_2.0.json', __dir__)
6+
META_SCHEMA_PATH_3 = File.expand_path('../../resources/swagger_meta_schema_3.0.json', __dir__)
67

78
def self.resolve(path, validate_meta_schema: true)
89
raw_specification = Document.resolve(path)
910

1011
if validate_meta_schema
11-
meta_schema = JSON.parse(File.read(META_SCHEMA_PATH))
12+
meta_schema = JSON.parse(File.read(meta_schema_path(raw_specification)))
1213
JSON::Validator.validate!(meta_schema, raw_specification)
1314
end
1415

1516
OpenApiParser::Specification::Root.new(raw_specification)
1617
end
18+
19+
def self.meta_schema_path(raw_specification)
20+
if raw_specification.key?('openapi')
21+
META_SCHEMA_PATH_3
22+
else
23+
META_SCHEMA_PATH_2
24+
end
25+
end
1726
end
1827
end

0 commit comments

Comments
 (0)