Open AryaSvitkona opened 3 weeks ago
Ah, so a preferred resolution would be: for an array of items, rather than generate an empty array as example
, omit the example
if not sure?
If you're looking for a pointer, I think the cause is in generateFieldData
. https://github.com/knuckleswtf/scribe/blob/a6aee1d56177e2f541c07f1a02a7a9e795d1facd/src/Writing/OpenAPISpecWriter.php#L517
It may be as easy as adding a check to remove the example:
if(Utils::isArrayType($baseType) && is_empty($field->example)) {
unset($fieldData['example']);
}
But I haven't verified. I don't know when I'll get to this, so I encourage you to give it a try.
Thanks! I already thought about to contribute this small improvement, since I now have the confirmation, that we didn't do anything wrong.
Scribe version
4.36.0
Your question
One of our endpoints receives an array of objects which is wrapped in a data wrapper (see example). We validate the input with a Laravel Form Request and provide more meaningful description and examples via
bodyParameter()
method (see below). This leads to an almost perfect OpenAPI Yaml, which we use with the Scalar theme.Problem: The
data
property which holds all child objects has an empty array as example value in the OpenAPI spec. If we would remove theexample: []
property from the specification, the provided body parameters appear in the example request.Steps I tried:
P.S. Kudos to you for providing this awesome dependency! Thank you!
Docs