-
Notifications
You must be signed in to change notification settings - Fork 68
Fix psych disallowedclass error in ruby 3.1 #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ipepe
wants to merge
3
commits into
exoego:master
Choose a base branch
from
ipepe-oss:fix-psych--disallowedclass-error-in-ruby-3.1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Fix Psych disallowed class error by permitting Date in YAML.safe_load.
- Loading branch information
commit ac89c4cfd79a02b06f2991092784eb8abe657cb7
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'date' | ||
|
||
RSpec.describe RSpec::OpenAPI::SchemaFile do | ||
describe '#read' do | ||
let(:schema_content) do | ||
<<~YAML | ||
openapi: 3.0.0 | ||
info: | ||
title: My API | ||
version: 1.0.0 | ||
paths: | ||
/: | ||
get: | ||
summary: A test endpoint | ||
parameters: | ||
- name: date | ||
in: query | ||
schema: | ||
type: string | ||
example: 2020-01-02 # Unquoted date | ||
YAML | ||
end | ||
|
||
it 'deserializes unquoted dates as Date objects when Date is permitted' do | ||
schema_file = RSpec::OpenAPI::SchemaFile.new('nonexistant/schema.yaml') | ||
|
||
expect(File).to receive(:read).and_return(schema_content) | ||
expect(File).to receive(:exist?).and_return(true) | ||
|
||
data = nil | ||
expect do | ||
data = schema_file.send(:read) | ||
end.not_to raise_error(Psych::DisallowedClass) | ||
expect(data.dig(:paths, :/, :get, :parameters, 0, :schema, :example).to_s).to eq('2020-01-02') | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[imho]
How about adding unquoted dates or times to the OpenAPI schema in
spec/apps/
instead of writing tests for the private method?What should be tested is not whether unquoted dates or times are loaded, but whether the resulting OpenAPI schema output is correct—and whether it can be successfully loaded.