-
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe RSpec::OpenAPI::SchemaFile do | ||
describe '#read' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [imho] 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. |
||
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 | ||
date: 2020-01-02 # Unquoted date | ||
time: 2025-06-10 01:47:28Z | ||
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, :date).to_s).to eq('2020-01-02') | ||
expect(data.dig(:paths, :/, :get, :parameters, 0, :schema, :time).to_s).to eq('2025-06-10 01:47:28 UTC') | ||
end | ||
end | ||
end |
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.
[nits]
require 'yaml'
also loadsDate
.Time
is available without requiring anything explicitly.