Open matrixhcl opened 1 year ago
Hmm, did you try adding a responseField
annotation for those fields you want to customise?
I did check the documentation on https://scribe.knuckles.wtf/laravel/documenting/responses#response-fields , but can't figure out the correct syntax to do so. It seems that all I could do is adding property type, but I cannot mark property as required
or nullable
. The ResponseFromApiResource
Attribute doesn't support this use case too, I suppose?
Not looked at this in detail, but I remembered something: we don't currently support things like required/nullable on response properties. The OpenAPI spec wasn't the primary use case.
My team heavily rely on openapi generator: https://github.com/OpenAPITools/openapi-generator , to generate a type-safe interface from openapi documentation for our frontend typescript project to call API.
For request parameter, this library did a really good job on generate sound request interface. But for response, I struggle on creating a reliable response interface with
#[ResponseFromApiResource]
Attribute.The issue I am facing is that, when converting a open api endpoint response to interface, all openapi generator tools I use will mark object properties as optional, if it's not marked as
required
. For example, for a response with structure like this:would end up generate an interface in typescript like this:
The question-mark indicates that the field is possibly
undefined
, which is not the case for most of our API response. so we need to update the schema like this:It's similar for
nullable
fields.I don't expect this library to automatically add these
required
attributes for me, as I know that's really hard to determine if a field is nullable / required merely by reading the resource file, after all it's not a type-hinted file like a typescript interface. But it seems that there's no way to add it manually too. Did I miss something or it's currently impossible to do so?