Skip to content

Commit 122e08a

Browse files
committed
Add "application/vnd.api+json" support
1 parent 39b40c9 commit 122e08a

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

example/gen/src/Serializer/ContentType/AbstractJsonContentTypeSerializer.php

-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ public function decode(StreamInterface $body): array
5252
throw new SerializeException('JSON decode error: ' . $this->getErrorMessage($lastErrorCode));
5353
}
5454

55-
public function getMimeType(): string
56-
{
57-
return static::MIME_TYPE;
58-
}
59-
6055
private function getErrorMessage(int $errorCode): string
6156
{
6257
$errorMessages = [JSON_ERROR_NONE => 'No errors', JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', JSON_ERROR_RECURSION => 'Recursive reference was found', JSON_ERROR_INF_OR_NAN => 'NaN or Inf was found', JSON_ERROR_UNSUPPORTED_TYPE => 'Unsupported type was found'];

example/gen/src/Serializer/ContentType/JsonContentTypeSerializer.php

+5
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@
1313
class JsonContentTypeSerializer extends AbstractJsonContentTypeSerializer
1414
{
1515
public const MIME_TYPE = 'application/json';
16+
17+
public function getMimeType(): string
18+
{
19+
return self::MIME_TYPE;
20+
}
1621
}

test/suite/functional/Generator/ServiceProvider/ServiceProviderPhp70.php

+8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use Test\Request\Mapper\GuzzleRequestMapper;
1414
use Test\Request\Mapper\RequestMapperInterface;
1515
use Test\Response\ResponseHandler;
16+
use Test\Schema\Mapper\FindHumanByIdResponseBodyMapper;
1617
use Test\Schema\Mapper\FoodMapper;
18+
use Test\Schema\Mapper\HumanMapper;
1719
use Test\Schema\Mapper\PetCollectionMapper;
1820
use Test\Schema\Mapper\PetMapper;
1921
use Test\Serializer\BodySerializer;
@@ -45,5 +47,11 @@ public function register(Container $container): void
4547
$container[FoodMapper::class] = static function () use ($container): FoodMapper {
4648
return new FoodMapper();
4749
};
50+
$container[FindHumanByIdResponseBodyMapper::class] = static function () use ($container): FindHumanByIdResponseBodyMapper {
51+
return new FindHumanByIdResponseBodyMapper($container[HumanMapper::class]);
52+
};
53+
$container[HumanMapper::class] = static function () use ($container): HumanMapper {
54+
return new HumanMapper();
55+
};
4856
}
4957
}

test/suite/functional/Generator/ServiceProvider/ServiceProviderPhp72.php

+8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use Test\Request\Mapper\GuzzleRequestMapper;
1414
use Test\Request\Mapper\RequestMapperInterface;
1515
use Test\Response\ResponseHandler;
16+
use Test\Schema\Mapper\FindHumanByIdResponseBodyMapper;
1617
use Test\Schema\Mapper\FoodMapper;
18+
use Test\Schema\Mapper\HumanMapper;
1719
use Test\Schema\Mapper\PetCollectionMapper;
1820
use Test\Schema\Mapper\PetMapper;
1921
use Test\Serializer\BodySerializer;
@@ -45,5 +47,11 @@ public function register(Container $container): void
4547
$container[FoodMapper::class] = static function () use ($container): FoodMapper {
4648
return new FoodMapper();
4749
};
50+
$container[FindHumanByIdResponseBodyMapper::class] = static function () use ($container): FindHumanByIdResponseBodyMapper {
51+
return new FindHumanByIdResponseBodyMapper($container[HumanMapper::class]);
52+
};
53+
$container[HumanMapper::class] = static function () use ($container): HumanMapper {
54+
return new HumanMapper();
55+
};
4856
}
4957
}

test/suite/functional/Generator/ServiceProvider/petstore.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ paths:
107107
application/json:
108108
schema:
109109
$ref: '#/components/schemas/Error'
110+
/humans/{id}:
111+
get:
112+
operationId: findHumanById
113+
parameters:
114+
- name: id
115+
in: path
116+
description: ID of human to fetch
117+
required: true
118+
schema:
119+
type: integer
120+
format: int64
121+
responses:
122+
'200':
123+
description: Human response
124+
content:
125+
application/vnd.api+json:
126+
schema:
127+
type: object
128+
properties:
129+
data:
130+
$ref: '#/components/schemas/Human'
110131
components:
111132
schemas:
112133
Pet:
@@ -152,3 +173,19 @@ components:
152173
format: int32
153174
message:
154175
type: string
176+
Human:
177+
type: object
178+
properties:
179+
id:
180+
type: integer
181+
format: int32
182+
example: 2
183+
firstName:
184+
type: string
185+
example: John
186+
lastName:
187+
type: string
188+
example: Doe
189+
birthDate:
190+
type: string
191+
format: date-time

0 commit comments

Comments
 (0)