Skip to content

Commit bc28cf8

Browse files
committed
Add "application/vnd.api+json" support: add post request example
1 parent 122e08a commit bc28cf8

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@
1313
use Test\Request\Mapper\GuzzleRequestMapper;
1414
use Test\Request\Mapper\RequestMapperInterface;
1515
use Test\Response\ResponseHandler;
16+
use Test\Schema\Mapper\AddHumanResponseBodyMapper;
1617
use Test\Schema\Mapper\FindHumanByIdResponseBodyMapper;
1718
use Test\Schema\Mapper\FoodMapper;
1819
use Test\Schema\Mapper\HumanMapper;
1920
use Test\Schema\Mapper\PetCollectionMapper;
2021
use Test\Schema\Mapper\PetMapper;
2122
use Test\Serializer\BodySerializer;
2223
use Test\Serializer\ContentType\JsonContentTypeSerializer;
24+
use Test\Serializer\ContentType\VdnApiJsonContentTypeSerializer;
2325
use Test\Serializer\QuerySerializer;
2426

2527
class ServiceProvider
2628
{
2729
public function register(Container $container): void
2830
{
2931
$container[BodySerializer::class] = static function (): BodySerializer {
30-
return (new BodySerializer())->add(new JsonContentTypeSerializer());
32+
return (new BodySerializer())->add(new JsonContentTypeSerializer())->add(new VdnApiJsonContentTypeSerializer());
3133
};
3234
$container[QuerySerializer::class] = static function (): QuerySerializer {
3335
return new QuerySerializer();
@@ -47,11 +49,14 @@ public function register(Container $container): void
4749
$container[FoodMapper::class] = static function () use ($container): FoodMapper {
4850
return new FoodMapper();
4951
};
50-
$container[FindHumanByIdResponseBodyMapper::class] = static function () use ($container): FindHumanByIdResponseBodyMapper {
51-
return new FindHumanByIdResponseBodyMapper($container[HumanMapper::class]);
52+
$container[AddHumanResponseBodyMapper::class] = static function () use ($container): AddHumanResponseBodyMapper {
53+
return new AddHumanResponseBodyMapper($container[HumanMapper::class]);
5254
};
5355
$container[HumanMapper::class] = static function () use ($container): HumanMapper {
5456
return new HumanMapper();
5557
};
58+
$container[FindHumanByIdResponseBodyMapper::class] = static function () use ($container): FindHumanByIdResponseBodyMapper {
59+
return new FindHumanByIdResponseBodyMapper($container[HumanMapper::class]);
60+
};
5661
}
5762
}

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@
1313
use Test\Request\Mapper\GuzzleRequestMapper;
1414
use Test\Request\Mapper\RequestMapperInterface;
1515
use Test\Response\ResponseHandler;
16+
use Test\Schema\Mapper\AddHumanResponseBodyMapper;
1617
use Test\Schema\Mapper\FindHumanByIdResponseBodyMapper;
1718
use Test\Schema\Mapper\FoodMapper;
1819
use Test\Schema\Mapper\HumanMapper;
1920
use Test\Schema\Mapper\PetCollectionMapper;
2021
use Test\Schema\Mapper\PetMapper;
2122
use Test\Serializer\BodySerializer;
2223
use Test\Serializer\ContentType\JsonContentTypeSerializer;
24+
use Test\Serializer\ContentType\VdnApiJsonContentTypeSerializer;
2325
use Test\Serializer\QuerySerializer;
2426

2527
class ServiceProvider
2628
{
2729
public function register(Container $container): void
2830
{
2931
$container[BodySerializer::class] = static function (): BodySerializer {
30-
return (new BodySerializer())->add(new JsonContentTypeSerializer());
32+
return (new BodySerializer())->add(new JsonContentTypeSerializer())->add(new VdnApiJsonContentTypeSerializer());
3133
};
3234
$container[QuerySerializer::class] = static function (): QuerySerializer {
3335
return new QuerySerializer();
@@ -47,11 +49,14 @@ public function register(Container $container): void
4749
$container[FoodMapper::class] = static function () use ($container): FoodMapper {
4850
return new FoodMapper();
4951
};
50-
$container[FindHumanByIdResponseBodyMapper::class] = static function () use ($container): FindHumanByIdResponseBodyMapper {
51-
return new FindHumanByIdResponseBodyMapper($container[HumanMapper::class]);
52+
$container[AddHumanResponseBodyMapper::class] = static function () use ($container): AddHumanResponseBodyMapper {
53+
return new AddHumanResponseBodyMapper($container[HumanMapper::class]);
5254
};
5355
$container[HumanMapper::class] = static function () use ($container): HumanMapper {
5456
return new HumanMapper();
5557
};
58+
$container[FindHumanByIdResponseBodyMapper::class] = static function () use ($container): FindHumanByIdResponseBodyMapper {
59+
return new FindHumanByIdResponseBodyMapper($container[HumanMapper::class]);
60+
};
5661
}
5762
}

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

+20
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ paths:
107107
application/json:
108108
schema:
109109
$ref: '#/components/schemas/Error'
110+
/humans:
111+
post:
112+
operationId: addHuman
113+
requestBody:
114+
description: Add Human
115+
required: true
116+
content:
117+
application/vnd.api+json:
118+
schema:
119+
$ref: '#/components/schemas/Human'
120+
responses:
121+
'200':
122+
description: Human response
123+
content:
124+
application/vnd.api+json:
125+
schema:
126+
type: object
127+
properties:
128+
data:
129+
$ref: '#/components/schemas/Human'
110130
/humans/{id}:
111131
get:
112132
operationId: findHumanById

test/suite/functional/Output/Copy/Serializer/BodySerializerTest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use DoclerLabs\ApiClientException\UnexpectedResponseException;
88
use DoclerLabs\ApiClientGenerator\Output\Copy\Serializer\BodySerializer;
99
use DoclerLabs\ApiClientGenerator\Output\Copy\Serializer\ContentType\FormUrlencodedContentTypeSerializer;
10-
use DoclerLabs\ApiClientGenerator\Output\Copy\Serializer\ContentType\Json\Json;
1110
use DoclerLabs\ApiClientGenerator\Output\Copy\Serializer\ContentType\JsonContentTypeSerializer;
11+
use DoclerLabs\ApiClientGenerator\Output\Copy\Serializer\ContentType\VdnApiJsonContentTypeSerializer;
1212
use GuzzleHttp\Psr7\Response;
1313
use GuzzleHttp\Psr7\Stream;
1414
use PHPUnit\Framework\TestCase;
@@ -22,6 +22,7 @@ protected function setUp(): void
2222
$this->sut = new BodySerializer();
2323
$this->sut
2424
->add(new JsonContentTypeSerializer())
25+
->add(new VdnApiJsonContentTypeSerializer())
2526
->add(new FormUrlencodedContentTypeSerializer());
2627
}
2728

@@ -32,6 +33,13 @@ public function testUnserializeJsonResponseForEmptyBody(): void
3233
self::assertEquals([], $this->sut->unserializeResponse($response));
3334
}
3435

36+
public function testUnserializeVdnApiJsonResponseForEmptyBody(): void
37+
{
38+
$response = $this->getResponse('application/vnd.api+json', '');
39+
40+
self::assertEquals([], $this->sut->unserializeResponse($response));
41+
}
42+
3543
public function testExceptionIsThrownForUnsupportedContentType(): void
3644
{
3745
$this->expectException(UnexpectedResponseException::class);

0 commit comments

Comments
 (0)