Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
bundle exec rspec spec/
- name: Lint with rubocop
run: |
bundle exec rubocop --verbose && bundle exec rubocop
bundle exec rubocop
2 changes: 1 addition & 1 deletion lib/open_api_parser/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module OpenApiParser
class Document
def self.resolve(path, file_cache = OpenApiParser::FileCache.new)
file_cache.get(path) do
content = YAML.load_file(path)
content = YAML.safe_load(ERB.new(File.read(path)).result)
Document.new(path, content, file_cache).resolve
end
end
Expand Down
13 changes: 11 additions & 2 deletions lib/open_api_parser/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@

module OpenApiParser
module Specification
META_SCHEMA_PATH = File.expand_path('../../resources/swagger_meta_schema.json', __dir__)
META_SCHEMA_PATH_2 = File.expand_path('../../resources/swagger_meta_schema_2.0.json', __dir__)
META_SCHEMA_PATH_3 = File.expand_path('../../resources/swagger_meta_schema_3.0.json', __dir__)

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

if validate_meta_schema
meta_schema = JSON.parse(File.read(META_SCHEMA_PATH))
meta_schema = JSON.parse(File.read(meta_schema_path(raw_specification)))
JSON::Validator.validate!(meta_schema, raw_specification)
end

OpenApiParser::Specification::Root.new(raw_specification)
end

def self.meta_schema_path(raw_specification)
if raw_specification.key?('openapi')
META_SCHEMA_PATH_3
else
META_SCHEMA_PATH_2
end
end
end
end
Loading