I'm trying to use attributes in swagger-php. The intention is to support multiple Content-Type responses with the same API endpoint.
Below a minimal code example:
#[OA\Get(path: '/myEndpoint')]
#[OA\Response(response: 200, description: 'Success', content: new OA\MediaType('text/html'))]`
Let's say I'd like to introduce a new Content-Type 'text/csv'. Duplicating the Response attribute isn't working as I get a complaint that both have the same result code.
#[OA\Response(response: 200, description: 'Success', content: new OA\MediaType('text/html'))]
#[OA\Response(response: 200, description: 'Success', content: new OA\MediaType('text/csv'))]
results in Error: Multiple @OA\Response() with the same response="200":
I've tried all possible options I can think of using oneOf
but I didn't manage to find any working. Documentation is mainly using annotations, so that isn't helping either.
Turns out, oneOf isn't necessary and a simple array is sufficient.
#[OA\Response(response: 200, description: 'Success', content: [
new OA\MediaType(mediaType: "application/json", schema: new OA\Schema('#/components/schemas/MySchema')),
new OA\MediaType(mediaType: "text/csv")
])]