Skip to content

Commit

Permalink
fix(metadata): make the schema attribute to fallback to null for para…
Browse files Browse the repository at this point in the history
…meters in YamlResourceExtractor
  • Loading branch information
wuchen90 committed Jan 8, 2025
1 parent f8dae8e commit a9bb865
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Metadata/Extractor/YamlResourceExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ private function buildParameters(array $resource): ?array
$parameters[$key] = new $cl(
key: $key,
required: $this->phpize($parameter, 'required', 'bool'),
schema: $parameter['schema'],
schema: $parameter['schema'] ?? null,
openApi: ($parameter['openapi'] ?? null) ? new Parameter(
name: $parameter['openapi']['name'],
in: $parameter['in'] ?? 'query',
Expand Down
10 changes: 8 additions & 2 deletions src/Metadata/Tests/Extractor/Adapter/XmlResourceAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,14 @@ private function buildParameters(\SimpleXMLElement $resource, ?array $values = n
$childNode = $node->addChild('parameter');
$childNode->addAttribute('in', 'query');
$childNode->addAttribute('key', $key);
$childNode->addAttribute('required', $this->parse($value['required']));
$this->buildValues($childNode->addChild('schema'), $value['schema']);

if (\array_key_exists('required', $value)) {
$childNode->addAttribute('required', $this->parse($value['required']));
}

if (\array_key_exists('schema', $value)) {
$this->buildValues($childNode->addChild('schema'), $value['schema']);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Tests/Extractor/Adapter/resources.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Metadata/Tests/Extractor/Adapter/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ resources:
-
rel: 'http://www.w3.org/ns/json-ld#error'
href: 'http://www.w3.org/ns/hydra/error'
parameters:
date:
key: date
formats:
json: null
jsonld: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ final class ResourceMetadataCompatibilityTest extends TestCase
'links' => [
['rel' => 'http://www.w3.org/ns/json-ld#error', 'href' => 'http://www.w3.org/ns/hydra/error'],
],
'parameters' => [
'date' => ['key' => 'date'],
],
],
],
],
Expand Down Expand Up @@ -761,7 +764,7 @@ private function withParameters(array $values): ?array

$parameters = [];
foreach ($values as $k => $value) {
$parameters[$k] = new QueryParameter(key: $value['key'], required: $value['required'], schema: $value['schema']);
$parameters[$k] = new QueryParameter(key: $value['key'] ?? null, required: $value['required'] ?? null, schema: $value['schema'] ?? null);
}

return $parameters;
Expand Down

0 comments on commit a9bb865

Please sign in to comment.