Skip to content

Commit

Permalink
fix: Avoid properties with a larger http method mask then the parent …
Browse files Browse the repository at this point in the history
…endpoint (#207)

* fix: Avoid properties with a larger http method mask then the parent endpoint

* fix: Bump checkout action to v4
  • Loading branch information
DannyvdSluijs authored May 4, 2024
1 parent a34cbdf commit ad286e9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: composer validate
Expand Down
16 changes: 7 additions & 9 deletions MetaDataTool/Crawlers/EndpointCrawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private function crawlWebPage(string $url): ?Endpoint
);

$properties = $this->domCrawler->filterXpath(self::ATTRIBUTE_ROWS_XPATH)
->each($this->getPropertyRowParser($propertyRowParserConfig));
->each($this->getPropertyRowParser($propertyRowParserConfig, $httpMethods));

$goodToKnows = $this->domCrawler->filterXPath('//*[@id="goodToKnow"]');
$deprecationMessage = 'This endpoint is redundant and is going to be removed.';
Expand Down Expand Up @@ -147,9 +147,9 @@ private function fetchHtmlFromUrl(string $url): string
return $html;
}

private function getPropertyRowParser(PropertyRowParserConfig $config): \Closure
private function getPropertyRowParser(PropertyRowParserConfig $config, HttpMethodMask $endpointSupportedMethods): \Closure
{
return function (Crawler $node) use ($config): Property {
return function (Crawler $node) use ($config, $endpointSupportedMethods): Property {
if ($node->filterXpath('//td[2]/a')->count() === 1) {
$this->processDiscoveredUrl(self::BASE_URL . $node->filterXpath('//td[2]/a')->attr('href'));
}
Expand All @@ -163,18 +163,16 @@ private function getPropertyRowParser(PropertyRowParserConfig $config): \Closure

$httpMethods = HttpMethodMask::none()->addGet();
$class = (string) $node->attr('class');
if ($name === 'ID') {
if ($name === 'ID' && $endpointSupportedMethods->supportsDelete()) {
$httpMethods = $httpMethods->addDelete();
}
if (!str_contains($class, 'hideput') && !str_contains($class, 'showget')) {
if (!str_contains($class, 'hideput') && !str_contains($class, 'showget') && $endpointSupportedMethods->supportsPut()) {
$httpMethods = $httpMethods->addPut();
}
if (!str_contains($class, 'hidepost') && !str_contains($class, 'showget')) {
if (!str_contains($class, 'hidepost') && !str_contains($class, 'showget') && $endpointSupportedMethods->supportsPost()) {
$httpMethods = $httpMethods->addPost();
}
if ($name === 'ID') {
$httpMethods = HttpMethodMask::all();
}

$hidden = str_contains($node->attr('class') ?? '', 'hiderow');
$mandatory = strtolower(trim($node->filterXpath("//td[{$config->getMandatoryColumnIndex()}]")->text())) === 'true';

Expand Down

0 comments on commit ad286e9

Please sign in to comment.