Commit 4207eec2 authored by Guillaume Perréal's avatar Guillaume Perréal

Assouplit les regexps de vérification des IRIs.

Ne vérifie pas le contenu exact de l'IRI, mais seulement le nombre
de segments séparés par des / et les paramètres.
parent 42d5c436
<?php declare(strict_types=1);
/*
* This file is part of "irstea/ng-model-generator-bundle".
*
* "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata.
* Copyright (C) 2018-2020 IRSTEA
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace Irstea\NgModelGeneratorBundle\Models\Types\Operations;
/**
* Class AnyPathPart.
*/
final class AnyPathPart extends FixedPathPart
{
/**
* @var string
*/
private $pattern;
public function __construct(string $part)
{
parent::__construct($part);
$this->pattern = $this->createPattern($part);
}
private function createPattern(string $input): string
{
$parts = explode('/', $input);
$outputParts = [];
foreach ($parts as $part) {
$outputParts[] = ($part === '') ? '' : '[^\/]+';
}
return implode('\/', $outputParts);
}
/**
* {@inheritdoc}
*/
public function asTestPattern(): string
{
return $this->pattern;
}
}
......@@ -24,7 +24,7 @@ namespace Irstea\NgModelGeneratorBundle\Models\Types\Operations;
/**
* Class FixedPathPart.
*/
final class FixedPathPart implements PathPart
class FixedPathPart implements PathPart
{
/**
* @var string
......
......@@ -24,7 +24,7 @@ namespace Irstea\NgModelGeneratorBundle;
use Assert\Assertion;
use Irstea\NgModelGeneratorBundle\Models\Types\BuiltinType;
use Irstea\NgModelGeneratorBundle\Models\Types\Objects\Property;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\FixedPathPart;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\AnyPathPart;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Parameter;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\ParameterPathPart;
use Irstea\NgModelGeneratorBundle\Models\Types\Operations\Path;
......@@ -60,7 +60,7 @@ final class PathParser implements PathParserInterface
$num = \count($stringParts);
for ($i = 0; $i < $num; ++$i) {
if ($stringParts[$i]) {
$parts[] = new FixedPathPart($stringParts[$i]);
$parts[] = new AnyPathPart($stringParts[$i]);
}
++$i;
......
......@@ -55,8 +55,8 @@ TYPESCRIPT
new ResourceMetadata<EntityWithIntegerIdentifier, 'EntityWithIntegerIdentifier', number>(
'EntityWithIntegerIdentifier',
new IRIMetadata(
/^\/api\/entity_with_integer_identifiers\/[^\/]*$/u,
/^\/api\/entity_with_integer_identifiers\/([^\/]*)$/u,
/^\/[^\/]+\/[^\/]+\/[^\/]*$/u,
/^\/[^\/]+\/[^\/]+\/([^\/]*)$/u,
(id: number) => `/api/entity_with_integer_identifiers/${id}`
),
[ '@id', 'id', '@type', ],
......
......@@ -125,8 +125,8 @@ TYPESCRIPT
Project: () => new ResourceMetadata<Project, 'Project', string>(
'Project',
new IRIMetadata(
/^\/api\/projects\/[^\/]*$/u,
/^\/api\/projects\/([^\/]*)$/u,
/^\/[^\/]+\/[^\/]+\/[^\/]*$/u,
/^\/[^\/]+\/[^\/]+\/([^\/]*)$/u,
(id: string) => `/api/projects/${id}`
),
[ '@id', 'id', '@type', 'acronym', 'name', 'participants', 'startDate', ],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment