File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ defmodule OpenApiSpex.Schema do
183
183
:xml ,
184
184
:externalDocs ,
185
185
:example ,
186
+ :examples ,
186
187
:deprecated ,
187
188
:"x-struct" ,
188
189
:"x-validate" ,
@@ -250,6 +251,7 @@ defmodule OpenApiSpex.Schema do
250
251
xml: Xml . t ( ) | nil ,
251
252
externalDocs: ExternalDocumentation . t ( ) | nil ,
252
253
example: any ,
254
+ examples: [ any ] | nil ,
253
255
deprecated: boolean | nil ,
254
256
"x-struct": module | nil ,
255
257
"x-validate": module | nil ,
@@ -369,6 +371,10 @@ defmodule OpenApiSpex.Schema do
369
371
schema . example
370
372
end
371
373
374
+ def example ( % Schema { examples: [ example | _ ] } ) when not is_nil ( example ) do
375
+ example
376
+ end
377
+
372
378
def example ( % Schema { enum: [ example | _ ] } ) do
373
379
example
374
380
end
Original file line number Diff line number Diff line change @@ -103,6 +103,10 @@ defmodule OpenApiSpex.SchemaTest do
103
103
assert Schema . example ( % Schema { type: :string , example: "foo" } ) == "foo"
104
104
end
105
105
106
+ test "uses the first value in `examples` property when not nil" do
107
+ assert Schema . example ( % Schema { type: :string , examples: [ "foo" , "bar" ] } ) == "foo"
108
+ end
109
+
106
110
test "defaults to type-appropriate value for :string" do
107
111
assert Schema . example ( % Schema { type: :string } ) == ""
108
112
end
You can’t perform that action at this time.
0 commit comments