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
Lines changed: 38 additions & 0 deletions
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+
}
Lines changed: 53 additions & 0 deletions
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+
}
Lines changed: 38 additions & 0 deletions
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+
}
Lines changed: 32 additions & 0 deletions
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+
}
Lines changed: 53 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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:
Lines changed: 72 additions & 0 deletions
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

0 commit comments

Comments
 (0)