Skip to content

Commit 55ec4a9

Browse files
author
oleg.strelenko
committed
new tests
1 parent c3b5d2d commit 55ec4a9

11 files changed

+327
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file was generated by docler-labs/api-client-generator.
7+
*
8+
* Do not edit it manually.
9+
*/
10+
11+
namespace Test\Schema\Mapper;
12+
13+
use Test\Schema\GetExampleResponseBody;
14+
15+
class GetExampleResponseBodyMapper implements SchemaMapperInterface
16+
{
17+
private AnimalMapper $animalMapper;
18+
19+
private MachineMapper $machineMapper;
20+
21+
public function __construct(AnimalMapper $animalMapper, MachineMapper $machineMapper)
22+
{
23+
$this->animalMapper = $animalMapper;
24+
$this->machineMapper = $machineMapper;
25+
}
26+
27+
public function toSchema(array $payload): GetExampleResponseBody
28+
{
29+
$schema = new GetExampleResponseBody();
30+
if (array_key_exists('objectType', $payload)) {
31+
$methodName = 'set' . ucfirst($payload['objectType']);
32+
$mapperName = $payload['objectType'] . 'Mapper';
33+
$schema->$methodName($this->$mapperName->toSchema($payload));
34+
}
35+
36+
return $schema;
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file was generated by docler-labs/api-client-generator.
7+
*
8+
* Do not edit it manually.
9+
*/
10+
11+
namespace Test\Schema\Mapper;
12+
13+
use DoclerLabs\ApiClientException\UnexpectedResponseBodyException;
14+
use Test\Schema\GetExampleResponseBody;
15+
16+
class GetExampleResponseBodyMapper implements SchemaMapperInterface
17+
{
18+
private AnimalMapper $animalMapper;
19+
20+
private MachineMapper $machineMapper;
21+
22+
public function __construct(AnimalMapper $animalMapper, MachineMapper $machineMapper)
23+
{
24+
$this->animalMapper = $animalMapper;
25+
$this->machineMapper = $machineMapper;
26+
}
27+
28+
/**
29+
* @throws UnexpectedResponseBodyException
30+
*/
31+
public function toSchema(array $payload): GetExampleResponseBody
32+
{
33+
$schema = new GetExampleResponseBody();
34+
$matches = 0;
35+
36+
try {
37+
$schema->setAnimal($this->animalMapper->toSchema($payload));
38+
$matches = $matches + 1;
39+
} catch (UnexpectedResponseBodyException $exception) {
40+
}
41+
42+
try {
43+
$schema->setMachine($this->machineMapper->toSchema($payload));
44+
$matches = $matches + 1;
45+
} catch (UnexpectedResponseBodyException $exception) {
46+
}
47+
if ($matches === 0) {
48+
throw new UnexpectedResponseBodyException();
49+
}
50+
51+
return $schema;
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file was generated by docler-labs/api-client-generator.
7+
*
8+
* Do not edit it manually.
9+
*/
10+
11+
namespace Test\Schema\Mapper;
12+
13+
use Test\Schema\GetExampleResponseBody;
14+
15+
class GetExampleResponseBodyMapper implements SchemaMapperInterface
16+
{
17+
private AnimalMapper $animalMapper;
18+
19+
private MachineMapper $machineMapper;
20+
21+
public function __construct(AnimalMapper $animalMapper, MachineMapper $machineMapper)
22+
{
23+
$this->animalMapper = $animalMapper;
24+
$this->machineMapper = $machineMapper;
25+
}
26+
27+
public function toSchema(array $payload): GetExampleResponseBody
28+
{
29+
$schema = new GetExampleResponseBody();
30+
if (array_key_exists('objectType', $payload)) {
31+
$methodName = 'set' . ucfirst($payload['objectType']);
32+
$mapperName = $payload['objectType'] . 'Mapper';
33+
$schema->$methodName($this->$mapperName->toSchema($payload));
34+
}
35+
36+
return $schema;
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file was generated by docler-labs/api-client-generator.
7+
*
8+
* Do not edit it manually.
9+
*/
10+
11+
namespace Test\Schema\Mapper;
12+
13+
use Test\Schema\GetExampleResponseBody;
14+
15+
class GetExampleResponseBodyMapper implements SchemaMapperInterface
16+
{
17+
public function __construct(private AnimalMapper $animalMapper, private MachineMapper $machineMapper)
18+
{
19+
}
20+
21+
public function toSchema(array $payload): GetExampleResponseBody
22+
{
23+
$schema = new GetExampleResponseBody();
24+
if (array_key_exists('objectType', $payload)) {
25+
$methodName = 'set' . ucfirst($payload['objectType']);
26+
$mapperName = $payload['objectType'] . 'Mapper';
27+
$schema->$methodName($this->$mapperName->toSchema($payload));
28+
}
29+
30+
return $schema;
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file was generated by docler-labs/api-client-generator.
7+
*
8+
* Do not edit it manually.
9+
*/
10+
11+
namespace Test\Schema\Mapper;
12+
13+
use DoclerLabs\ApiClientException\UnexpectedResponseBodyException;
14+
use Test\Schema\GetExampleResponseBody;
15+
16+
class GetExampleResponseBodyMapper implements SchemaMapperInterface
17+
{
18+
private AnimalMapper $animalMapper;
19+
20+
private MachineMapper $machineMapper;
21+
22+
public function __construct(AnimalMapper $animalMapper, MachineMapper $machineMapper)
23+
{
24+
$this->animalMapper = $animalMapper;
25+
$this->machineMapper = $machineMapper;
26+
}
27+
28+
/**
29+
* @throws UnexpectedResponseBodyException
30+
*/
31+
public function toSchema(array $payload): GetExampleResponseBody
32+
{
33+
$schema = new GetExampleResponseBody();
34+
$matches = 0;
35+
36+
try {
37+
$schema->setAnimal($this->animalMapper->toSchema($payload));
38+
$matches = $matches + 1;
39+
} catch (UnexpectedResponseBodyException $exception) {
40+
}
41+
42+
try {
43+
$schema->setMachine($this->machineMapper->toSchema($payload));
44+
$matches = $matches + 1;
45+
} catch (UnexpectedResponseBodyException $exception) {
46+
}
47+
if ($matches !== 1) {
48+
throw new UnexpectedResponseBodyException();
49+
}
50+
51+
return $schema;
52+
}
53+
}

test/suite/functional/Generator/SchemaMapper/anyOf.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ paths:
1515
anyOf:
1616
- $ref: '#/components/schemas/Animal'
1717
- $ref: '#/components/schemas/Machine'
18+
discriminator:
19+
propertyName: objectType
20+
mapping:
21+
animal: '#/components/schemas/Animal'
22+
machine: '#/components/schemas/Machine'
1823

1924
components:
2025
schemas:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
openapi: 3.0.0
2+
info:
3+
title: OneOf with Nested Structures
4+
version: 1.0.0
5+
6+
paths:
7+
/example:
8+
get:
9+
responses:
10+
'200':
11+
description: An example of an oneOf structure
12+
content:
13+
application/json:
14+
schema:
15+
anyOf:
16+
- $ref: '#/components/schemas/Animal'
17+
- $ref: '#/components/schemas/Machine'
18+
19+
components:
20+
schemas:
21+
Animal:
22+
type: object
23+
required:
24+
- objectType
25+
- name
26+
properties:
27+
objectType:
28+
type: string
29+
name:
30+
type: string
31+
characteristics:
32+
anyOf:
33+
- $ref: '#/components/schemas/Mammal'
34+
- $ref: '#/components/schemas/Bird'
35+
Mammal:
36+
type: object
37+
required:
38+
- type
39+
- furColor
40+
properties:
41+
type:
42+
type: string
43+
furColor:
44+
type: string
45+
Bird:
46+
type: object
47+
required:
48+
- type
49+
- wingSpan
50+
properties:
51+
type:
52+
type: string
53+
enum: [bird]
54+
wingSpan:
55+
type: integer
56+
Machine:
57+
type: object
58+
required:
59+
- objectType
60+
- model
61+
properties:
62+
objectType:
63+
type: string
64+
model:
65+
type: string
66+
specifications:
67+
type: object
68+
properties:
69+
power:
70+
type: integer
71+
year:
72+
type: integer

test/suite/functional/Generator/SchemaMapperGeneratorTest.php

+36-6
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,51 @@ public function exampleProvider(): array
6464
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\FreeFormItemMapper',
6565
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(),
6666
],
67-
'OneOf response' => [
67+
'OneOf response with php 7.4' => [
6868
'/SchemaMapper/oneOf.yaml',
69-
'/SchemaMapper/OneOfResponseBodyMapper.php',
69+
'/SchemaMapper/OneOfResponseBodyMapper74.php',
70+
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\GetExampleResponseBodyMapper',
71+
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP74)->build(),
72+
],
73+
'OneOf response with php 8.0' => [
74+
'/SchemaMapper/oneOf.yaml',
75+
'/SchemaMapper/OneOfResponseBodyMapper80.php',
7076
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\GetExampleResponseBodyMapper',
7177
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(),
7278
],
73-
'OneOf response without discriminator' => [
79+
'OneOf response without discriminator with php 7.4' => [
7480
'/SchemaMapper/oneOfWithoutDiscriminator.yaml',
75-
'/SchemaMapper/OneOfResponseBodyMapperWithoutDiscriminator.php',
81+
'/SchemaMapper/OneOfResponseBodyMapperWithoutDiscriminator74.php',
82+
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\GetExampleResponseBodyMapper',
83+
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP74)->build(),
84+
],
85+
'OneOf response without discriminator with php 8.0' => [
86+
'/SchemaMapper/oneOfWithoutDiscriminator.yaml',
87+
'/SchemaMapper/OneOfResponseBodyMapperWithoutDiscriminator80.php',
7688
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\GetExampleResponseBodyMapper',
7789
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(),
7890
],
79-
'AnyOf response' => [
91+
'AnyOf response with php 7.4' => [
92+
'/SchemaMapper/anyOf.yaml',
93+
'/SchemaMapper/AnyOfResponseBodyMapper74.php',
94+
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\GetExampleResponseBodyMapper',
95+
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP74)->build(),
96+
],
97+
'AnyOf response with php 8.0' => [
8098
'/SchemaMapper/anyOf.yaml',
81-
'/SchemaMapper/AnyOfResponseBodyMapper.php',
99+
'/SchemaMapper/AnyOfResponseBodyMapper80.php',
100+
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\GetExampleResponseBodyMapper',
101+
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(),
102+
],
103+
'AnyOf response with php 7.4' => [
104+
'/SchemaMapper/anyOfWithoutDiscriminator.yaml',
105+
'/SchemaMapper/AnyOfResponseBodyMapperWithoutDiscriminator74.php',
106+
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\GetExampleResponseBodyMapper',
107+
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP74)->build(),
108+
],
109+
'AnyOf response with php 8.0' => [
110+
'/SchemaMapper/anyOfWithoutDiscriminator.yaml',
111+
'/SchemaMapper/AnyOfResponseBodyMapperWithoutDiscriminator80.php',
82112
self::BASE_NAMESPACE . SchemaMapperGenerator::NAMESPACE_SUBPATH . '\\GetExampleResponseBodyMapper',
83113
ConfigurationBuilder::fake()->withPhpVersion(PhpVersion::VERSION_PHP80)->build(),
84114
],

0 commit comments

Comments
 (0)