Closed dennisameling closed 1 year ago
You can use a new annotation called @OpenApiExampleProperty
to define more complex examples. For instance, this setup:
@OpenApiExample(objects = {
@OpenApiExampleProperty(value = "2022-08-14T21:13:03.546Z"),
@OpenApiExampleProperty(value = "2022-08-14T21:13:03.546Z")
})
public @NotNull String[] getTimestamps() {
return new String[] { timestamp };
}
@OpenApiExample(objects = {
@OpenApiExampleProperty(name = "Barbie", objects = {
@OpenApiExampleProperty(name = "name", value = "Margot Robbie"),
@OpenApiExampleProperty(name = "link", value = "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
}),
})
public @NotNull Object[] getExampleObjects() {
return new String[] { timestamp };
}
should be generated as:
"timestamps" : {
"type" : "array",
"items" : {
"type" : "string"
},
"example" : [ "2022-08-14T21:13:03.546Z", "2022-08-14T21:13:03.546Z" ]
},
"exampleObjects" : {
"type" : "array",
"items" : {
"type" : "object"
},
"example" : {
"Barbie" : {
"name" : "Margot Robbie",
"link" : "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
}
},
Thank you! I can confirm everything works as expected with this new setup 🎉
Describe the feature
Currently, the
@OpenApiExample
annotation in this library only supports strings. Let's consider a scenario where we want to put a list of UUIDs in the example:In the spec, this leads to the following incorrect behavior:
Would it be possible to support lists as well? Thank you!
Additional context
Array examples are supported in the OpenAPI standard: https://swagger.io/docs/specification/adding-examples/