Skip to content

Commit 54fbfda

Browse files
authored
Merge pull request #438 from rennanoliveira/fix-open-api-writer-required
Fix Open Api: issue with multiple required fields
2 parents 1dcc7f8 + e756b32 commit 54fbfda

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

features/open_api.feature

+3-2
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Feature: Generate Open API Specification from test examples
192192
193193
parameter :name, 'The order name', required: true, scope: :data, with_example: true
194194
parameter :amount, required: false, scope: :data, with_example: true
195-
parameter :description, 'The order description', required: false, scope: :data, with_example: true
195+
parameter :description, 'The order description', required: true, scope: :data, with_example: true
196196
197197
header "Content-Type", "application/json"
198198
@@ -700,7 +700,8 @@ Feature: Generate Open API Specification from test examples
700700
}
701701
},
702702
"required": [
703-
"name"
703+
"name",
704+
"description"
704705
]
705706
}
706707
}

lib/rspec_api_documentation/writers/open_api_writer.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ def extract_schema(fields)
149149
opts.each { |k, v| current[:properties][field[:name]][k] = v if v }
150150
end
151151

152-
current[:required] ||= [] << field[:name] if field[:required]
152+
if field[:required]
153+
current[:required] ||= []
154+
current[:required] << field[:name]
155+
end
153156
end
154157

155158
OpenApi::Schema.new(schema)

0 commit comments

Comments
 (0)