openapi: 3.0.0
info:
title: Order API
version: '1'
paths:
/v1/orders:
post:
summary: Place Order
operationId: placeOrder
responses:
'201':
$ref: '#/components/responses/OrderResponse'
components:
responses:
OrderResponse:
description: Order information
content:
application/json:
schema:
type: object
properties:
data:
$ref: '#/components/schemas/Order'
required:
- data
schemas:
Order:
type: object
properties:
id:
type: string
domain:
type: string
nullable: true
group:
type: object
nullable: true
properties:
id:
type: string
required:
- id
generates a wrong Mapper object for the "group" property. The nullable: true attribute on it makes the Mapper::toSchema return a nullable object which is wrong:
// src/Schema/Mapper/OrderMapper.php
if (isset($payload['group'])) {
$schema->setGroup($this->orderGroupMapper->toSchema($payload['group']));
}
...
// src/Schema/Mapper/OrderGroupMapper.php
public function toSchema(array $payload): ?OrderGroup // << here should be OrderGroup instead
{
$missingFields = \implode(', ', \array_diff(['id'], \array_keys($payload)));
if (! empty($missingFields)) {
throw new UnexpectedResponseBodyException('Required attributes for `OrderGroup` missing in the response body: ' . $missingFields);
}
return new OrderGroup($payload['id']);
}
This ::toSchema() always return the OrderGroup so return type hint with ? is wrong.
The following openapi spec:
generates a wrong Mapper object for the "group" property. The
nullable: true
attribute on it makes the Mapper::toSchema return a nullable object which is wrong:This
::toSchema()
always return theOrderGroup
so return type hint with ? is wrong.