Skip to content

Commit c338724

Browse files
authored
Update example (#46)
1 parent f022974 commit c338724

File tree

4 files changed

+184
-177
lines changed

4 files changed

+184
-177
lines changed

example.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,9 @@ function (\Swaggest\PhpCodeBuilder\PhpClass $class, $path, $schema) use ($app, $
104104
$user->name = 123;
105105

106106
// Exception: String expected, 123 received at #->$ref[#]->properties:name
107-
$jsonData = \Swaggest\PhpCodeBuilder\Tests\Tmp\Example\User::export($user);
107+
try {
108+
$jsonData = \Swaggest\PhpCodeBuilder\Tests\Tmp\Example\User::export($user);
109+
} catch (Exception $e) {
110+
echo 'Failed to export user: ' . $e->getMessage(). "\n";
111+
}
108112

tests/src/Tmp/Example/Info.php

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,64 @@
1414
/**
1515
* Built from #/definitions/info
1616
*/
17-
class Info extends ClassStructure {
18-
/** @var string */
19-
public $lastName;
17+
class Info extends ClassStructure
18+
{
19+
/** @var string */
20+
public $lastName;
2021

21-
/** @var string */
22-
public $birthDate;
22+
/** @var string */
23+
public $birthDate;
2324

24-
/** @var Options */
25-
public $options;
25+
/** @var Options */
26+
public $options;
2627

27-
/**
28-
* @param Properties|static $properties
29-
* @param Schema $ownerSchema
30-
*/
31-
public static function setUpProperties($properties, Schema $ownerSchema)
32-
{
33-
$properties->lastName = Schema::string();
34-
$properties->birthDate = Schema::string();
35-
$properties->birthDate->format = "date";
36-
$properties->options = Options::schema();
37-
$ownerSchema->type = 'object';
38-
$ownerSchema->setFromRef('#/definitions/info');
39-
}
28+
/**
29+
* @param Properties|static $properties
30+
* @param Schema $ownerSchema
31+
*/
32+
public static function setUpProperties($properties, Schema $ownerSchema)
33+
{
34+
$properties->lastName = Schema::string();
35+
$properties->birthDate = Schema::string();
36+
$properties->birthDate->format = "date";
37+
$properties->options = Options::schema();
38+
$ownerSchema->type = Schema::OBJECT;
39+
$ownerSchema->setFromRef('#/definitions/info');
40+
}
4041

41-
/**
42-
* @param string $lastName
43-
* @return $this
44-
* @codeCoverageIgnoreStart
45-
*/
46-
public function setLastName($lastName)
47-
{
48-
$this->lastName = $lastName;
49-
return $this;
50-
}
51-
/** @codeCoverageIgnoreEnd */
42+
/**
43+
* @param string $lastName
44+
* @return $this
45+
* @codeCoverageIgnoreStart
46+
*/
47+
public function setLastName($lastName)
48+
{
49+
$this->lastName = $lastName;
50+
return $this;
51+
}
52+
/** @codeCoverageIgnoreEnd */
5253

53-
/**
54-
* @param string $birthDate
55-
* @return $this
56-
* @codeCoverageIgnoreStart
57-
*/
58-
public function setBirthDate($birthDate)
59-
{
60-
$this->birthDate = $birthDate;
61-
return $this;
62-
}
63-
/** @codeCoverageIgnoreEnd */
54+
/**
55+
* @param string $birthDate
56+
* @return $this
57+
* @codeCoverageIgnoreStart
58+
*/
59+
public function setBirthDate($birthDate)
60+
{
61+
$this->birthDate = $birthDate;
62+
return $this;
63+
}
64+
/** @codeCoverageIgnoreEnd */
6465

65-
/**
66-
* @param Options $options
67-
* @return $this
68-
* @codeCoverageIgnoreStart
69-
*/
70-
public function setOptions(Options $options)
71-
{
72-
$this->options = $options;
73-
return $this;
74-
}
75-
/** @codeCoverageIgnoreEnd */
66+
/**
67+
* @param Options $options
68+
* @return $this
69+
* @codeCoverageIgnoreStart
70+
*/
71+
public function setOptions(Options $options)
72+
{
73+
$this->options = $options;
74+
return $this;
75+
}
76+
/** @codeCoverageIgnoreEnd */
7677
}

tests/src/Tmp/Example/Options.php

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,47 @@
1414
/**
1515
* Built from #/definitions/options
1616
*/
17-
class Options extends ClassStructure {
18-
/** @var bool */
19-
public $rememberSession;
20-
21-
/** @var bool */
22-
public $allowNotifications;
23-
24-
/**
25-
* @param Properties|static $properties
26-
* @param Schema $ownerSchema
27-
*/
28-
public static function setUpProperties($properties, Schema $ownerSchema)
29-
{
30-
$properties->rememberSession = Schema::boolean();
31-
$properties->allowNotifications = Schema::boolean();
32-
$ownerSchema->type = 'object';
33-
$ownerSchema->setFromRef('#/definitions/options');
34-
}
35-
36-
/**
37-
* @param bool $rememberSession
38-
* @return $this
39-
* @codeCoverageIgnoreStart
40-
*/
41-
public function setRememberSession($rememberSession)
42-
{
43-
$this->rememberSession = $rememberSession;
44-
return $this;
45-
}
46-
/** @codeCoverageIgnoreEnd */
47-
48-
/**
49-
* @param bool $allowNotifications
50-
* @return $this
51-
* @codeCoverageIgnoreStart
52-
*/
53-
public function setAllowNotifications($allowNotifications)
54-
{
55-
$this->allowNotifications = $allowNotifications;
56-
return $this;
57-
}
58-
/** @codeCoverageIgnoreEnd */
17+
class Options extends ClassStructure
18+
{
19+
/** @var bool */
20+
public $rememberSession;
21+
22+
/** @var bool */
23+
public $allowNotifications;
24+
25+
/**
26+
* @param Properties|static $properties
27+
* @param Schema $ownerSchema
28+
*/
29+
public static function setUpProperties($properties, Schema $ownerSchema)
30+
{
31+
$properties->rememberSession = Schema::boolean();
32+
$properties->allowNotifications = Schema::boolean();
33+
$ownerSchema->type = Schema::OBJECT;
34+
$ownerSchema->setFromRef('#/definitions/options');
35+
}
36+
37+
/**
38+
* @param bool $rememberSession
39+
* @return $this
40+
* @codeCoverageIgnoreStart
41+
*/
42+
public function setRememberSession($rememberSession)
43+
{
44+
$this->rememberSession = $rememberSession;
45+
return $this;
46+
}
47+
/** @codeCoverageIgnoreEnd */
48+
49+
/**
50+
* @param bool $allowNotifications
51+
* @return $this
52+
* @codeCoverageIgnoreStart
53+
*/
54+
public function setAllowNotifications($allowNotifications)
55+
{
56+
$this->allowNotifications = $allowNotifications;
57+
return $this;
58+
}
59+
/** @codeCoverageIgnoreEnd */
5960
}

tests/src/Tmp/Example/User.php

Lines changed: 82 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -14,95 +14,96 @@
1414
/**
1515
* Built from #
1616
*/
17-
class User extends ClassStructure {
18-
/** @var int */
19-
public $id;
17+
class User extends ClassStructure
18+
{
19+
/** @var int */
20+
public $id;
2021

21-
/** @var string */
22-
public $name;
22+
/** @var string */
23+
public $name;
2324

24-
/** @var User */
25-
public $parent;
25+
/** @var User */
26+
public $parent;
2627

27-
/** @var User[]|array */
28-
public $children;
28+
/** @var User[]|array */
29+
public $children;
2930

30-
/** @var Info */
31-
public $info;
31+
/** @var Info */
32+
public $info;
3233

33-
/**
34-
* @param Properties|static $properties
35-
* @param Schema $ownerSchema
36-
*/
37-
public static function setUpProperties($properties, Schema $ownerSchema)
38-
{
39-
$properties->id = Schema::integer();
40-
$properties->name = Schema::string();
41-
$properties->parent = User::schema();
42-
$properties->children = Schema::arr();
43-
$properties->children->items = User::schema();
44-
$properties->info = Info::schema();
45-
$ownerSchema->type = 'object';
46-
$ownerSchema->setFromRef('#');
47-
}
34+
/**
35+
* @param Properties|static $properties
36+
* @param Schema $ownerSchema
37+
*/
38+
public static function setUpProperties($properties, Schema $ownerSchema)
39+
{
40+
$properties->id = Schema::integer();
41+
$properties->name = Schema::string();
42+
$properties->parent = User::schema();
43+
$properties->children = Schema::arr();
44+
$properties->children->items = User::schema();
45+
$properties->info = Info::schema();
46+
$ownerSchema->type = Schema::OBJECT;
47+
$ownerSchema->setFromRef('#');
48+
}
4849

49-
/**
50-
* @param int $id
51-
* @return $this
52-
* @codeCoverageIgnoreStart
53-
*/
54-
public function setId($id)
55-
{
56-
$this->id = $id;
57-
return $this;
58-
}
59-
/** @codeCoverageIgnoreEnd */
50+
/**
51+
* @param int $id
52+
* @return $this
53+
* @codeCoverageIgnoreStart
54+
*/
55+
public function setId($id)
56+
{
57+
$this->id = $id;
58+
return $this;
59+
}
60+
/** @codeCoverageIgnoreEnd */
6061

61-
/**
62-
* @param string $name
63-
* @return $this
64-
* @codeCoverageIgnoreStart
65-
*/
66-
public function setName($name)
67-
{
68-
$this->name = $name;
69-
return $this;
70-
}
71-
/** @codeCoverageIgnoreEnd */
62+
/**
63+
* @param string $name
64+
* @return $this
65+
* @codeCoverageIgnoreStart
66+
*/
67+
public function setName($name)
68+
{
69+
$this->name = $name;
70+
return $this;
71+
}
72+
/** @codeCoverageIgnoreEnd */
7273

73-
/**
74-
* @param User $parent
75-
* @return $this
76-
* @codeCoverageIgnoreStart
77-
*/
78-
public function setParent(User $parent)
79-
{
80-
$this->parent = $parent;
81-
return $this;
82-
}
83-
/** @codeCoverageIgnoreEnd */
74+
/**
75+
* @param User $parent
76+
* @return $this
77+
* @codeCoverageIgnoreStart
78+
*/
79+
public function setParent(User $parent)
80+
{
81+
$this->parent = $parent;
82+
return $this;
83+
}
84+
/** @codeCoverageIgnoreEnd */
8485

85-
/**
86-
* @param User[]|array $children
87-
* @return $this
88-
* @codeCoverageIgnoreStart
89-
*/
90-
public function setChildren($children)
91-
{
92-
$this->children = $children;
93-
return $this;
94-
}
95-
/** @codeCoverageIgnoreEnd */
86+
/**
87+
* @param User[]|array $children
88+
* @return $this
89+
* @codeCoverageIgnoreStart
90+
*/
91+
public function setChildren($children)
92+
{
93+
$this->children = $children;
94+
return $this;
95+
}
96+
/** @codeCoverageIgnoreEnd */
9697

97-
/**
98-
* @param Info $info
99-
* @return $this
100-
* @codeCoverageIgnoreStart
101-
*/
102-
public function setInfo(Info $info)
103-
{
104-
$this->info = $info;
105-
return $this;
106-
}
107-
/** @codeCoverageIgnoreEnd */
98+
/**
99+
* @param Info $info
100+
* @return $this
101+
* @codeCoverageIgnoreStart
102+
*/
103+
public function setInfo(Info $info)
104+
{
105+
$this->info = $info;
106+
return $this;
107+
}
108+
/** @codeCoverageIgnoreEnd */
108109
}

0 commit comments

Comments
 (0)