Skip to content
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

fix Multipart/form-data example object to filename #17

Merged
Merged
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
15 changes: 14 additions & 1 deletion lib/rspec/openapi/schema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def build_request_body(record)
content: {
normalize_content_type(record.request_content_type) => {
schema: build_property(record.request_params),
example: (record.request_params if example_enabled?),
example: (build_example(record.request_params) if example_enabled?),
}.compact
}
}
Expand Down Expand Up @@ -126,6 +126,19 @@ def try_cast(value)
end
end

def build_example(value)
return nil if value.nil?
examples = {}
value.each do |key, v|
if v.is_a? ActionDispatch::Http::UploadedFile
examples[key] = v.original_filename
else
examples[key] = v
end
end
examples
end

def normalize_path(path)
path.gsub(%r|/:([^:/]+)|, '/{\1}')
end
Expand Down
13 changes: 1 addition & 12 deletions spec/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,7 @@ paths:
type: string
format: binary
example:
image: !ruby/object:ActionDispatch::Http::UploadedFile
tempfile: !ruby/object:Tempfile
unlinked: true
mode: 194
tmpfile: &1 !ruby/object:File {}
opts:
:perm: 384
delegate_dc_obj: *1
original_filename: test.png
content_type: image/png
headers: "Content-Disposition: form-data; name=\"image\"; filename=\"test.png\"\r\nContent-Type:
image/png\r\nContent-Length: 71\r\n"
image: test.png
responses:
'200':
description: returns a table
Expand Down