Skip to content

Commit f940a89

Browse files
committed
v3.1
1 parent c45662e commit f940a89

File tree

8 files changed

+111
-6
lines changed

8 files changed

+111
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"psr/log": "^1.0 || ^2.0 || ^3.0",
3333
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
3434
"sunrise/coder": "^1.1",
35-
"sunrise/hydrator": "^3.16",
35+
"sunrise/hydrator": "^3.18",
3636
"sunrise/translator": "^1.0"
3737
},
3838
"require-dev": {

src/OpenApi/PhpTypeSchemaResolver/StringPhpTypeSchemaResolver.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Sunrise\Http\Router\OpenApi\PhpTypeSchemaResolver;
1515

1616
use ReflectionParameter;
17+
use ReflectionProperty;
1718
use Reflector;
1819
use SensitiveParameter;
1920
use Sunrise\Http\Router\OpenApi\Exception\UnsupportedPhpTypeException;
@@ -47,6 +48,18 @@ public function resolvePhpTypeSchema(Type $phpType, Reflector $phpTypeHolder): a
4748
}
4849
}
4950

51+
if ($phpTypeHolder instanceof ReflectionProperty) {
52+
foreach ($phpTypeHolder->getDeclaringClass()->getConstructor()?->getParameters() ?? [] as $parameter) {
53+
if ($parameter->name === $phpTypeHolder->name) {
54+
if ($parameter->isPromoted() && $parameter->getAttributes(SensitiveParameter::class) !== []) {
55+
$phpTypeSchema['format'] = 'password';
56+
}
57+
58+
break;
59+
}
60+
}
61+
}
62+
5063
return $phpTypeSchema;
5164
}
5265

src/OpenApi/PhpTypeSchemaResolver/SymfonyUidPhpTypeSchemaResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Uid\AbstractUid;
2121
use Symfony\Component\Uid\Uuid;
2222

23+
use function is_a;
2324
use function is_subclass_of;
2425

2526
/**
@@ -43,7 +44,7 @@ public function resolvePhpTypeSchema(Type $phpType, Reflector $phpTypeHolder): a
4344
'type' => Type::OAS_TYPE_NAME_STRING,
4445
];
4546

46-
if (is_subclass_of($phpType->name, Uuid::class)) {
47+
if (is_a($phpType->name, Uuid::class, true)) {
4748
$phpTypeSchema['format'] = 'uuid';
4849
}
4950

src/Validation/ConstraintViolation/HydratorConstraintViolationAdapter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Sunrise\Http\Router\Validation\ConstraintViolation;
1515

1616
use Sunrise\Http\Router\Validation\ConstraintViolationInterface;
17-
use Sunrise\Hydrator\Dictionary\TranslationDomain;
1817
use Sunrise\Hydrator\Exception\InvalidValueException;
1918

2019
/**
@@ -67,6 +66,6 @@ public function getInvalidValue(): mixed
6766

6867
public function getTranslationDomain(): string
6968
{
70-
return TranslationDomain::HYDRATOR;
69+
return $this->hydratorConstraintViolation->getTranslationDomain();
7170
}
7271
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sunrise\Http\Router\Tests\Fixture\App\Controller\Api;
6+
7+
use Sunrise\Http\Router\Annotation\Consumes;
8+
use Sunrise\Http\Router\Annotation\PostApiRoute;
9+
use Sunrise\Http\Router\Annotation\RequestBody;
10+
use Sunrise\Http\Router\Dictionary\MediaType;
11+
use Sunrise\Http\Router\Tests\Fixture\App\Dto\Auth\SignInRequest;
12+
13+
final class AuthController extends AbstractController
14+
{
15+
#[PostApiRoute('signIn', '/sign-in')]
16+
#[Consumes(MediaType::JSON)]
17+
public function signIn(#[RequestBody] SignInRequest $signInRequest): void
18+
{
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sunrise\Http\Router\Tests\Fixture\App\Dto\Auth;
6+
7+
use SensitiveParameter;
8+
9+
final class SignInRequest
10+
{
11+
public function __construct(
12+
#[SensitiveParameter]
13+
public readonly string $email,
14+
#[SensitiveParameter]
15+
public readonly string $password,
16+
) {
17+
}
18+
}

tests/Fixture/App/Dto/Product/ProductTagDto.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Sunrise\Http\Router\Tests\Fixture\App\Dto\Product;
66

7-
use Symfony\Component\Uid\UuidV4;
7+
use Symfony\Component\Uid\Uuid;
88

99
final class ProductTagDto
1010
{
1111
public function __construct(
12-
public readonly UuidV4 $id,
12+
public readonly Uuid $id,
1313
) {
1414
}
1515
}

tests/Fixture/App/openapi.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,42 @@
2626
"description": ""
2727
}
2828
},
29+
"/api/sign-in": {
30+
"post": {
31+
"externalDocs": {
32+
"description": "Find more info here",
33+
"url": "https://example.com"
34+
},
35+
"parameters": [
36+
{
37+
"in": "header",
38+
"name": "X-Request-ID",
39+
"schema": {
40+
"type": "string"
41+
}
42+
}
43+
],
44+
"responses": {
45+
"204": {
46+
"description": "The operation was successful."
47+
}
48+
},
49+
"requestBody": {
50+
"content": {
51+
"application/json": {
52+
"schema": {
53+
"$ref": "#/components/schemas/Sunrise.Http.Router.Tests.Fixture.App.Dto.Auth.SignInRequest"
54+
}
55+
}
56+
},
57+
"required": true
58+
},
59+
"operationId": "api.signIn",
60+
"tags": [],
61+
"summary": "",
62+
"description": ""
63+
}
64+
},
2965
"/api/products": {
3066
"post": {
3167
"externalDocs": {
@@ -308,6 +344,24 @@
308344
},
309345
"components": {
310346
"schemas": {
347+
"Sunrise.Http.Router.Tests.Fixture.App.Dto.Auth.SignInRequest": {
348+
"type": "object",
349+
"additionalProperties": false,
350+
"properties": {
351+
"email": {
352+
"type": "string",
353+
"format": "password"
354+
},
355+
"password": {
356+
"type": "string",
357+
"format": "password"
358+
}
359+
},
360+
"required": [
361+
"email",
362+
"password"
363+
]
364+
},
311365
"Sunrise.Http.Router.Tests.Fixture.App.Dto.Product.ProductTagDto": {
312366
"type": "object",
313367
"additionalProperties": false,

0 commit comments

Comments
 (0)