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

Empty request body is not generated, but it should #196

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 lib/rspec/openapi/schema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def build(record)
private

def enrich_with_required_keys(obj)
obj[:required] = obj[:properties]&.keys
obj[:required] = obj[:properties]&.keys || []
obj
end

Expand Down
2 changes: 1 addition & 1 deletion spec/rails/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class UsersController < ApplicationController
def create
res = {
name: params[:name],
name: params[:name] || 'alice',
relations: {
avatar: {
url: params[:avatar_url] || 'https://example.com/avatar.png',
Expand Down
4 changes: 0 additions & 4 deletions spec/rails/doc/smart/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,5 @@ components:
properties:
baz:
type: integer
required:
- baz
required:
- bar
required:
- name
16 changes: 16 additions & 0 deletions spec/requests/rails_smart_merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@
expect(response.status).to eq(201)
end

it 'accepts nested object where some fields are missing' do
post '/users', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {
name: 'alice',
foo: {
bar: {
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
},
},
}.to_json
expect(response.status).to eq(201)
end

it 'can accept empty body' do
post '/users', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {}.to_json
expect(response.status).to eq(201)
end

it 'returns an user' do
post '/users', headers: { authorization: 'k0kubun', 'Content-Type': 'application/json' }, params: {
Fixed Show fixed Hide fixed
name: 'alice',
Expand Down
Loading