Skip to content

Commit ad2ddab

Browse files
committed
Prefer examples over example for example data
1 parent d94834c commit ad2ddab

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/Gatherer/Schema.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ public static function gather(
2121
): \ApiClients\Tools\OpenApiClientGenerator\Representation\Schema {
2222
$className = Utils::fixKeyword($className);
2323
$isArray = $schema->type === 'array';
24+
$properties = [];
25+
$example = [];
26+
2427
if ($isArray) {
2528
$schema = $schema->items;
2629
}
2730

28-
$properties = [];
29-
$example = $schema->example ?? [];
3031
foreach ($schema->properties as $propertyName => $property) {
3132
$gatheredProperty = Property::gather(
3233
$className,
@@ -37,24 +38,19 @@ public static function gather(
3738
);
3839
$properties[] = $gatheredProperty;
3940

40-
if (array_key_exists($gatheredProperty->sourceName, $example)) {
41-
continue;
41+
foreach (['examples', 'example'] as $examplePropertyName) {
42+
if (array_key_exists($gatheredProperty->sourceName, $example)) {
43+
break;
44+
}
45+
46+
if (property_exists($schema, $examplePropertyName) && is_array($schema->$examplePropertyName) && array_key_exists($gatheredProperty->sourceName, $schema->$examplePropertyName)) {
47+
$example[$gatheredProperty->sourceName] = $schema->$examplePropertyName[$gatheredProperty->sourceName];
48+
}
4249
}
4350

4451
$example[$gatheredProperty->sourceName] = $gatheredProperty->exampleData;
4552
}
4653

47-
// if ($className === 'WebhookWorkflowRunCompleted\WorkflowRun') {
48-
// var_export([
49-
// $className,
50-
// $schema->title ?? '',
51-
// $schema->description ?? '',
52-
// $example,
53-
//// $properties,
54-
// $isArray,
55-
// ]);
56-
// }
57-
5854
return new \ApiClients\Tools\OpenApiClientGenerator\Representation\Schema(
5955
$className,
6056
$schema->title ?? '',

0 commit comments

Comments
 (0)