From 2606ac882e0e02ebd850967025ca21ea795b24c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 31 Aug 2026 17:23:02 +0200 Subject: [PATCH] feat(inco): mask internal allergen ids in api presentation responses --- documentation/OpenApi/openapi.yaml | 17 ++-------- .../Api/V1/Dto/IncoSheets/IncoSheetDto.php | 4 +-- .../V1/Dto/IncoSheets/Parts/AllergenDto.php | 32 ------------------- .../IncoSheets/IncoSheetsIndexResponse.php | 3 +- .../IncoSheets/IncoSheetsSearchResponse.php | 3 +- .../IncoSheets/IncoSheetsShowResponse.php | 3 +- .../Api/V1/IncoSheets/IncoSheetShowTest.php | 1 + 7 files changed, 7 insertions(+), 56 deletions(-) delete mode 100644 src/Presentation/Api/V1/Dto/IncoSheets/Parts/AllergenDto.php diff --git a/documentation/OpenApi/openapi.yaml b/documentation/OpenApi/openapi.yaml index a66adfb..c593fea 100644 --- a/documentation/OpenApi/openapi.yaml +++ b/documentation/OpenApi/openapi.yaml @@ -1000,7 +1000,8 @@ components: allergens: type: array items: - $ref: "#/components/schemas/IncoAllergen" + type: string + example: ["Gluten", "Lait"] brand: $ref: "#/components/schemas/IncoBrand" isSeasonal: @@ -1120,20 +1121,6 @@ components: description: Indique si la portion est approximative. example: false - IncoAllergen: - type: object - description: Allergène présent ou en trace dans la recette. - required: - - code - - label - properties: - code: - type: integer - example: 21 - label: - type: string - example: Aucun allergène - IncoNutriscore: type: object description: Note Nutri-Score affichée sur l'emballage. diff --git a/src/Presentation/Api/V1/Dto/IncoSheets/IncoSheetDto.php b/src/Presentation/Api/V1/Dto/IncoSheets/IncoSheetDto.php index 90b4512..e1c65ef 100644 --- a/src/Presentation/Api/V1/Dto/IncoSheets/IncoSheetDto.php +++ b/src/Presentation/Api/V1/Dto/IncoSheets/IncoSheetDto.php @@ -7,7 +7,6 @@ namespace Presentation\Api\V1\Dto\IncoSheets; use Presentation\Api\V1\Contracts\ApiResponseDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\AdditiveDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\AllegationsDto; -use Presentation\Api\V1\Dto\IncoSheets\Parts\AllergenDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\BrandDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\NutriscoreDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\PortionsDto; @@ -17,7 +16,7 @@ use Presentation\Api\V1\Dto\IncoSheets\Parts\WeightDto; final readonly class IncoSheetDto implements ApiResponseDto { /** - * @param array $allergens + * @param array $allergens * @param array $additives */ public function __construct( @@ -52,7 +51,6 @@ final readonly class IncoSheetDto implements ApiResponseDto /** @var array $vars */ $vars = get_object_vars($this); - $vars['allergens'] = array_map(static fn (AllergenDto $dto): array => $dto->toArray(), $this->allergens); $vars['additives'] = array_map(static fn (AdditiveDto $dto): array => $dto->toArray(), $this->additives); $vars['allegations'] = $this->allegations->toArray(); diff --git a/src/Presentation/Api/V1/Dto/IncoSheets/Parts/AllergenDto.php b/src/Presentation/Api/V1/Dto/IncoSheets/Parts/AllergenDto.php deleted file mode 100644 index e7c42fa..0000000 --- a/src/Presentation/Api/V1/Dto/IncoSheets/Parts/AllergenDto.php +++ /dev/null @@ -1,32 +0,0 @@ -code, - label: $allergen->label, - ); - } - - #[\Override] - public function toArray(): array - { - /** @var array */ - return get_object_vars($this); - } -} diff --git a/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsIndexResponse.php b/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsIndexResponse.php index 4bff93c..b13b59a 100644 --- a/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsIndexResponse.php +++ b/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsIndexResponse.php @@ -14,7 +14,6 @@ use Presentation\Api\V1\Dto\IncoSheets\IncoSheetDto; use Presentation\Api\V1\Dto\IncoSheets\IncoShortSheetDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\AdditiveDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\AllegationsDto; -use Presentation\Api\V1\Dto\IncoSheets\Parts\AllergenDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\BrandDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\NutriscoreDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\PortionsDto; @@ -92,7 +91,7 @@ final readonly class IncoSheetsIndexResponse implements ApiResponse ingredients: $ingObject, portions: $sheet->portions !== null ? PortionsDto::fromDomain($sheet->portions) : null, allergens: array_values(array_map( - static fn (Allergen $a): AllergenDto => AllergenDto::fromDomain($a), + static fn (Allergen $a): string => $a->label, $sheet->allergens )), brand: BrandDto::fromDomain($sheet->brand), diff --git a/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsSearchResponse.php b/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsSearchResponse.php index e0e3cc2..6a01618 100644 --- a/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsSearchResponse.php +++ b/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsSearchResponse.php @@ -14,7 +14,6 @@ use Presentation\Api\V1\Dto\IncoSheets\IncoSheetDto; use Presentation\Api\V1\Dto\IncoSheets\IncoShortSheetDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\AdditiveDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\AllegationsDto; -use Presentation\Api\V1\Dto\IncoSheets\Parts\AllergenDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\BrandDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\NutriscoreDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\PortionsDto; @@ -92,7 +91,7 @@ final readonly class IncoSheetsSearchResponse implements ApiResponse ingredients: $ingObject, portions: $sheet->portions !== null ? PortionsDto::fromDomain($sheet->portions) : null, allergens: array_values(array_map( - static fn (Allergen $a): AllergenDto => AllergenDto::fromDomain($a), + static fn (Allergen $a): string => $a->label, $sheet->allergens )), brand: BrandDto::fromDomain($sheet->brand), diff --git a/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsShowResponse.php b/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsShowResponse.php index 4db066a..69f5420 100644 --- a/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsShowResponse.php +++ b/src/Presentation/Api/V1/Http/Responses/IncoSheets/IncoSheetsShowResponse.php @@ -12,7 +12,6 @@ use Presentation\Api\V1\Contracts\ApiResponse; use Presentation\Api\V1\Dto\IncoSheets\IncoSheetDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\AdditiveDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\AllegationsDto; -use Presentation\Api\V1\Dto\IncoSheets\Parts\AllergenDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\BrandDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\NutriscoreDto; use Presentation\Api\V1\Dto\IncoSheets\Parts\PortionsDto; @@ -60,7 +59,7 @@ final readonly class IncoSheetsShowResponse implements ApiResponse ingredients: $ingObject, portions: $output->portions !== null ? PortionsDto::fromDomain($output->portions) : null, allergens: array_values(array_map( - static fn (Allergen $a): AllergenDto => AllergenDto::fromDomain($a), + static fn (Allergen $a): string => $a->label, $output->allergens )), brand: BrandDto::fromDomain($output->brand), diff --git a/tests/Feature/Api/V1/IncoSheets/IncoSheetShowTest.php b/tests/Feature/Api/V1/IncoSheets/IncoSheetShowTest.php index 0786495..6ab9c80 100644 --- a/tests/Feature/Api/V1/IncoSheets/IncoSheetShowTest.php +++ b/tests/Feature/Api/V1/IncoSheets/IncoSheetShowTest.php @@ -50,5 +50,6 @@ describe('IncoSheet Show Feature API', function (): void { $response->assertStatus(200); $response->assertJsonPath('incoSheet.incoId', '47789'); $response->assertJsonPath('incoSheet.sellFamilly', 'Panes du volailler <=400g'); + $response->assertJsonPath('incoSheet.allergens', ['Gluten', 'Lait']); }); });