From 83e58c6475e1f05195dc8d942d6aa24df94b4196 Mon Sep 17 00:00:00 2001 From: Simon Zohrabyan Date: Fri, 3 Nov 2023 15:03:25 +0400 Subject: [PATCH 01/33] fix: Error when trying to access tag data on 0 --- src/Support/OperationExtensions/RequestEssentialsExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/OperationExtensions/RequestEssentialsExtension.php b/src/Support/OperationExtensions/RequestEssentialsExtension.php index fd4f9e9b..983306a9 100644 --- a/src/Support/OperationExtensions/RequestEssentialsExtension.php +++ b/src/Support/OperationExtensions/RequestEssentialsExtension.php @@ -130,7 +130,7 @@ private function extractTagsForMethod(RouteInfo $routeInfo) return []; } - return explode(',', $tagNodes[0]->value->value); + return explode(',', array_values($tagNodes)[0]->value->value); } private function getParametersFromString(?string $str) From a8d94ac32c5549ea2a0319e146af77f33db9e262 Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Sun, 24 Dec 2023 14:35:44 +0200 Subject: [PATCH 02/33] fix: proper empty response openapi --- src/Support/Generator/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/Generator/Response.php b/src/Support/Generator/Response.php index e5204ebb..d50638d0 100644 --- a/src/Support/Generator/Response.php +++ b/src/Support/Generator/Response.php @@ -39,7 +39,7 @@ public function toArray() $content = []; foreach ($this->content as $mediaType => $schema) { - $content[$mediaType] = $schema ? ['schema' => $schema->toArray()] : []; + $content[$mediaType] = $schema ? ['schema' => $schema->toArray()] : (object) []; } $result['content'] = $content; From b76c5a005866a40c813eec1446a8dbe86c407804 Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Sun, 24 Dec 2023 12:36:09 +0000 Subject: [PATCH 03/33] Fix styling --- src/Infer/Definition/ClassDefinition.php | 2 +- src/Infer/Scope/Scope.php | 2 +- src/Infer/Services/ReferenceTypeResolver.php | 2 +- src/Support/Generator/ServerVariable.php | 4 ++-- src/Support/Generator/UniqueNamesOptionsCollection.php | 2 +- src/Support/Type/TypeHelper.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Infer/Definition/ClassDefinition.php b/src/Infer/Definition/ClassDefinition.php index db903c02..ae079772 100644 --- a/src/Infer/Definition/ClassDefinition.php +++ b/src/Infer/Definition/ClassDefinition.php @@ -81,7 +81,7 @@ public function getPropertyDefinition($name) return $this->properties[$name] ?? null; } - public function getMethodCallType(string $name, ObjectType $calledOn = null) + public function getMethodCallType(string $name, ?ObjectType $calledOn = null) { $methodDefinition = $this->methods[$name] ?? null; diff --git a/src/Infer/Scope/Scope.php b/src/Infer/Scope/Scope.php index e40a4a28..dc83bbe0 100644 --- a/src/Infer/Scope/Scope.php +++ b/src/Infer/Scope/Scope.php @@ -164,7 +164,7 @@ public function setType(Node $node, Type $type) return $type; } - public function createChildScope(ScopeContext $context = null) + public function createChildScope(?ScopeContext $context = null) { return new Scope( $this->index, diff --git a/src/Infer/Services/ReferenceTypeResolver.php b/src/Infer/Services/ReferenceTypeResolver.php index 75cb04ed..8713b0d9 100644 --- a/src/Infer/Services/ReferenceTypeResolver.php +++ b/src/Infer/Services/ReferenceTypeResolver.php @@ -312,7 +312,7 @@ private function getFunctionCallResult( FunctionLikeDefinition $callee, array $arguments, /* When this is a handling for method call */ - ObjectType|SelfType $calledOnType = null, + ObjectType|SelfType|null $calledOnType = null, ) { $returnType = $callee->type->getReturnType(); $isSelf = false; diff --git a/src/Support/Generator/ServerVariable.php b/src/Support/Generator/ServerVariable.php index a608fbc1..4749a4a3 100644 --- a/src/Support/Generator/ServerVariable.php +++ b/src/Support/Generator/ServerVariable.php @@ -13,7 +13,7 @@ class ServerVariable public function __construct( string $default, array $enum = [], - string $description = null + ?string $description = null ) { $this->default = $default; $this->enum = $enum; @@ -23,7 +23,7 @@ public function __construct( public static function make( string $default, array $enum = [], - string $description = null + ?string $description = null ) { return new self($default, $enum, $description); } diff --git a/src/Support/Generator/UniqueNamesOptionsCollection.php b/src/Support/Generator/UniqueNamesOptionsCollection.php index 77d7fb6f..f5f719d1 100644 --- a/src/Support/Generator/UniqueNamesOptionsCollection.php +++ b/src/Support/Generator/UniqueNamesOptionsCollection.php @@ -42,7 +42,7 @@ public function push(UniqueNameOptions $name) return $this; } - public function getUniqueName(UniqueNameOptions $name, callable $onNotUniqueFallback = null): string + public function getUniqueName(UniqueNameOptions $name, ?callable $onNotUniqueFallback = null): string { if ($name->eloquent && count($this->eloquentNames[$name->eloquent]) === 1) { return $name->eloquent; diff --git a/src/Support/Type/TypeHelper.php b/src/Support/Type/TypeHelper.php index 686481d5..d6381d4f 100644 --- a/src/Support/Type/TypeHelper.php +++ b/src/Support/Type/TypeHelper.php @@ -76,7 +76,7 @@ public static function createTypeFromTypeNode(Node $typeNode) * @param Node\Arg[] $args * @param array{0: string, 1: int} $parameterNameIndex */ - public static function getArgType(Scope $scope, array $args, array $parameterNameIndex, Type $default = null) + public static function getArgType(Scope $scope, array $args, array $parameterNameIndex, ?Type $default = null) { $default = $default ?: new UnknownType("Cannot get a type of the arg #{$parameterNameIndex[1]}($parameterNameIndex[0])"); From c821a15f99d97ce7c4d8ab36acc5811eba84c89b Mon Sep 17 00:00:00 2001 From: Bruno Drzanic Date: Thu, 4 Jan 2024 16:40:31 +0100 Subject: [PATCH 04/33] feat: add ability to deprecate the result --- src/Support/Generator/Operation.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Support/Generator/Operation.php b/src/Support/Generator/Operation.php index f3e8ae24..65dc14ea 100644 --- a/src/Support/Generator/Operation.php +++ b/src/Support/Generator/Operation.php @@ -16,6 +16,8 @@ class Operation public string $summary = ''; + public bool $deprecated = false; + /** @var array */ public array $security = []; @@ -111,6 +113,13 @@ public function description(string $description) return $this; } + public function deprecated(bool $deprecated) + { + $this->deprecated = $deprecated; + + return $this; + } + public function setTags(array $tags) { $this->tags = array_map(fn ($t) => (string) $t, $tags); @@ -141,6 +150,10 @@ public function toArray() $result['summary'] = $this->summary; } + if ($this->deprecated) { + $result['deprecated'] = $this->deprecated; + } + if (count($this->tags)) { $result['tags'] = $this->tags; } From 3c7c4d730dfd6805fc6d8d56a5bbcba9c7c8bbfb Mon Sep 17 00:00:00 2001 From: Bruno Drzanic Date: Mon, 8 Jan 2024 14:43:45 +0100 Subject: [PATCH 05/33] test: added operation deprecated property test --- tests/Generator/Operation/OperationTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/Generator/Operation/OperationTest.php diff --git a/tests/Generator/Operation/OperationTest.php b/tests/Generator/Operation/OperationTest.php new file mode 100644 index 00000000..8c97017a --- /dev/null +++ b/tests/Generator/Operation/OperationTest.php @@ -0,0 +1,12 @@ +deprecated(true); + + $array = $operation->toArray(); + + expect($operation->deprecated)->toBeTrue() + ->and($array)->toHaveKey('deprecated') + ->and($array['deprecated'])->toBeTrue(); +}); From 0f6a798d33863fa695c3a824c98c9de0c3766134 Mon Sep 17 00:00:00 2001 From: Bruno Drzanic Date: Mon, 8 Jan 2024 22:49:29 +0100 Subject: [PATCH 06/33] test: extend operation test --- tests/Generator/Operation/OperationTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Generator/Operation/OperationTest.php b/tests/Generator/Operation/OperationTest.php index 8c97017a..0eb8f2c7 100644 --- a/tests/Generator/Operation/OperationTest.php +++ b/tests/Generator/Operation/OperationTest.php @@ -10,3 +10,12 @@ ->and($array)->toHaveKey('deprecated') ->and($array['deprecated'])->toBeTrue(); }); + +it('default deprecated key is false', function () { + $operation = new \Dedoc\Scramble\Support\Generator\Operation('get'); + + $array = $operation->toArray(); + + expect($operation->deprecated)->toBeFalse() + ->and($array)->not()->toHaveKey('deprecated'); +}); From 13871e4fa99ef50d86c4a0d571c6bb022fcf73dc Mon Sep 17 00:00:00 2001 From: Bruno Drzanic Date: Tue, 9 Jan 2024 13:45:44 +0100 Subject: [PATCH 07/33] feat: add deprecation extension support --- src/ScrambleServiceProvider.php | 2 + .../DeprecationExtension.php | 71 +++++++++++ .../DeprecationExtensionTest.php | 114 ++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 src/Support/OperationExtensions/DeprecationExtension.php create mode 100644 tests/Support/OperationExtensions/DeprecationExtensionTest.php diff --git a/src/ScrambleServiceProvider.php b/src/ScrambleServiceProvider.php index a15f5537..8649b577 100644 --- a/src/ScrambleServiceProvider.php +++ b/src/ScrambleServiceProvider.php @@ -25,6 +25,7 @@ use Dedoc\Scramble\Support\InferExtensions\ResponseFactoryTypeInfer; use Dedoc\Scramble\Support\InferExtensions\ValidatorTypeInfer; use Dedoc\Scramble\Support\OperationBuilder; +use Dedoc\Scramble\Support\OperationExtensions\DeprecationExtension; use Dedoc\Scramble\Support\OperationExtensions\ErrorResponsesExtension; use Dedoc\Scramble\Support\OperationExtensions\RequestBodyExtension; use Dedoc\Scramble\Support\OperationExtensions\RequestEssentialsExtension; @@ -108,6 +109,7 @@ public function configurePackage(Package $package): void RequestBodyExtension::class, ErrorResponsesExtension::class, ResponseExtension::class, + DeprecationExtension::class, ], $operationExtensions); }); diff --git a/src/Support/OperationExtensions/DeprecationExtension.php b/src/Support/OperationExtensions/DeprecationExtension.php new file mode 100644 index 00000000..b9936ff3 --- /dev/null +++ b/src/Support/OperationExtensions/DeprecationExtension.php @@ -0,0 +1,71 @@ +reflectionMethod() || $routeInfo->phpDoc()->getTagsByName('@not-deprecated')) { + return; + } + + $fqdn = $routeInfo->reflectionMethod()->getDeclaringClass()->getName(); + $deprecatedClass = $this->getClassDeprecatedValues($fqdn); + $deprecatedTags = $routeInfo->phpDoc()->getDeprecatedTagValues(); + + // Skip if no deprecations found + if (!$deprecatedClass && !$deprecatedTags) { + return; + } + + $description = Str::of($this->generateDescription($deprecatedClass)); + + if ($description->isNotEmpty()) { + $description = $description->append("\n\n"); + } + + $description = $description->append($this->generateDescription($deprecatedTags)); + + $operation + ->description((string) $description) + ->deprecated(true); + } + + /** + * @return array + */ + protected function getClassDeprecatedValues(string $fqdn) + { + $reflector = ClassReflector::make($fqdn); + $classPhpDocString = $reflector->getReflection()->getDocComment(); + + if ($classPhpDocString === false) { + return []; + } + + return PhpDoc::parse($classPhpDocString)->getDeprecatedTagValues(); + } + + /** + * @return string + */ + private function generateDescription(array $deprecation) + { + return implode("\n", array_map(fn($tag) => $tag->description, $deprecation)); + } +} diff --git a/tests/Support/OperationExtensions/DeprecationExtensionTest.php b/tests/Support/OperationExtensions/DeprecationExtensionTest.php new file mode 100644 index 00000000..b28549e2 --- /dev/null +++ b/tests/Support/OperationExtensions/DeprecationExtensionTest.php @@ -0,0 +1,114 @@ +not()->toHaveKey('description') + ->toHaveKey('deprecated', true); +}); +class Deprecated_ResponseExtensionTest_Controller +{ + /** + * @deprecated + */ + public function deprecated() + { + return false; + } +} + +it('deprecated method sets key and description', function () { + $openApiDocument = generateForRoute(function () { + return RouteFacade::get('api/test', [Deprecated_Description_ResponseExtensionTest_Controller::class, 'deprecated']); + }); + + expect($openApiDocument['paths']['/test']['get']) + ->toHaveKey('description', 'Deprecation description') + ->toHaveKey('deprecated', true); +}); + +class Deprecated_Description_ResponseExtensionTest_Controller +{ + /** + * @deprecated Deprecation description + * + * @response array{ "test": "test"} + */ + public function deprecated() + { + return false; + } +} + +it('deprecated class with description sets keys', function () { + $openApiDocument = generateForRoute(function () { + return RouteFacade::get('api/test', [Deprecated_Class_Description_ResponseExtensionTest_Controller::class, 'deprecated']); + }); + + expect($openApiDocument['paths']['/test']['get']) + ->toHaveKey('description', 'Class description' . "\n\n" . 'Deprecation description') + ->toHaveKey('deprecated', true); +}); + +/** @deprecated Class description */ +class Deprecated_Class_Description_ResponseExtensionTest_Controller +{ + /** + * @deprecated Deprecation description + * + * @response array{ "test": "test"} + */ + public function deprecated() + { + return false; + } +} + +it('deprecated class without description sets keys', function () { + $openApiDocument = generateForRoute(function () { + return RouteFacade::get('api/test', [Deprecated_Class_ResponseExtensionTest_Controller::class, 'deprecated']); + }); + + expect($openApiDocument['paths']['/test']['get']) + ->not()->toHaveKey('description') + ->toHaveKey('deprecated', true); +}); + +/** @deprecated */ +class Deprecated_Class_ResponseExtensionTest_Controller +{ + /** + * @response array{ "test": "test"} + */ + public function deprecated() + { + return false; + } +} + +it('not deprecated ignores the class deprecation', function () { + $openApiDocument = generateForRoute(function () { + return RouteFacade::get('api/test', [Not_Deprecated_Class_ResponseExtensionTest_Controller::class, 'notDeprecated']); + }); + + expect($openApiDocument['paths']['/test']['get']) + ->not()->toHaveKey('description') + ->not()->toHaveKey('deprecated'); +}); + +/** @deprecated */ +class Not_Deprecated_Class_ResponseExtensionTest_Controller +{ + /** + * @not-deprecated + */ + public function notDeprecated() + { + return false; + } +} From fe674d6a7e1c8eea49c565809f30e8ff778931cf Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Tue, 16 Jan 2024 18:05:00 +0000 Subject: [PATCH 08/33] Fix styling --- src/Infer/Definition/FunctionLikeDefinition.php | 2 +- src/Infer/Services/ReferenceTypeResolver.php | 2 +- src/Support/OperationExtensions/DeprecationExtension.php | 6 +++--- .../OperationExtensions/DeprecationExtensionTest.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Infer/Definition/FunctionLikeDefinition.php b/src/Infer/Definition/FunctionLikeDefinition.php index d29814b2..52fdc78d 100644 --- a/src/Infer/Definition/FunctionLikeDefinition.php +++ b/src/Infer/Definition/FunctionLikeDefinition.php @@ -10,7 +10,7 @@ class FunctionLikeDefinition public bool $isFullyAnalyzed = false; /** - * @param array $argumentsDefaults A map where the key is arg name and value is a default type. + * @param array $argumentsDefaults A map where the key is arg name and value is a default type. */ public function __construct( public FunctionType $type, diff --git a/src/Infer/Services/ReferenceTypeResolver.php b/src/Infer/Services/ReferenceTypeResolver.php index 8713b0d9..6d9edc02 100644 --- a/src/Infer/Services/ReferenceTypeResolver.php +++ b/src/Infer/Services/ReferenceTypeResolver.php @@ -401,7 +401,7 @@ private function getFunctionCallResult( * arguments defaults. * * @param ?FunctionLikeDefinition $callee - * @param array $realArguments The list of arguments a function has been called with. + * @param array $realArguments The list of arguments a function has been called with. * @return array The actual list of arguments where not passed arguments replaced with default values. */ private function prepareArguments(?FunctionLikeDefinition $callee, array $realArguments) diff --git a/src/Support/OperationExtensions/DeprecationExtension.php b/src/Support/OperationExtensions/DeprecationExtension.php index b9936ff3..aec644ac 100644 --- a/src/Support/OperationExtensions/DeprecationExtension.php +++ b/src/Support/OperationExtensions/DeprecationExtension.php @@ -20,7 +20,7 @@ class DeprecationExtension extends OperationExtension public function handle(Operation $operation, RouteInfo $routeInfo) { // Skip if method is not deprecated - if (!$routeInfo->reflectionMethod() || $routeInfo->phpDoc()->getTagsByName('@not-deprecated')) { + if (! $routeInfo->reflectionMethod() || $routeInfo->phpDoc()->getTagsByName('@not-deprecated')) { return; } @@ -29,7 +29,7 @@ public function handle(Operation $operation, RouteInfo $routeInfo) $deprecatedTags = $routeInfo->phpDoc()->getDeprecatedTagValues(); // Skip if no deprecations found - if (!$deprecatedClass && !$deprecatedTags) { + if (! $deprecatedClass && ! $deprecatedTags) { return; } @@ -66,6 +66,6 @@ protected function getClassDeprecatedValues(string $fqdn) */ private function generateDescription(array $deprecation) { - return implode("\n", array_map(fn($tag) => $tag->description, $deprecation)); + return implode("\n", array_map(fn ($tag) => $tag->description, $deprecation)); } } diff --git a/tests/Support/OperationExtensions/DeprecationExtensionTest.php b/tests/Support/OperationExtensions/DeprecationExtensionTest.php index b28549e2..c4fa11a5 100644 --- a/tests/Support/OperationExtensions/DeprecationExtensionTest.php +++ b/tests/Support/OperationExtensions/DeprecationExtensionTest.php @@ -51,7 +51,7 @@ public function deprecated() }); expect($openApiDocument['paths']['/test']['get']) - ->toHaveKey('description', 'Class description' . "\n\n" . 'Deprecation description') + ->toHaveKey('description', 'Class description'."\n\n".'Deprecation description') ->toHaveKey('deprecated', true); }); From f2711910c357f24a5c9d10d5f00f9a1dc3042f67 Mon Sep 17 00:00:00 2001 From: Jeffrey van Hees Date: Fri, 19 Jan 2024 11:11:00 +0100 Subject: [PATCH 09/33] Add theme selector (dark/light) Add theme selector (dark/light) --- config/scramble.php | 6 ++++++ resources/views/docs.blade.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/scramble.php b/config/scramble.php index c793302c..dfdae5a1 100644 --- a/config/scramble.php +++ b/config/scramble.php @@ -15,6 +15,12 @@ */ 'api_domain' => null, + /* + * Define the theme of the documentation. + * Available options are `light` and `dark`. + */ + 'theme' => 'dark', + 'info' => [ /* * API version. diff --git a/resources/views/docs.blade.php b/resources/views/docs.blade.php index fba05a39..fbc1ab28 100644 --- a/resources/views/docs.blade.php +++ b/resources/views/docs.blade.php @@ -1,5 +1,5 @@ - + From 46a5f02c793432337d6455fa641e9f6f4ff32d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Gomes?= Date: Thu, 22 Feb 2024 22:58:09 +0000 Subject: [PATCH 10/33] fix(#145): treat numeric strings as strings --- .../OperationExtensions/RulesExtractor/RulesToParameter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Support/OperationExtensions/RulesExtractor/RulesToParameter.php b/src/Support/OperationExtensions/RulesExtractor/RulesToParameter.php index 156e244b..048e01b0 100644 --- a/src/Support/OperationExtensions/RulesExtractor/RulesToParameter.php +++ b/src/Support/OperationExtensions/RulesExtractor/RulesToParameter.php @@ -5,6 +5,7 @@ use Dedoc\Scramble\PhpDoc\PhpDocTypeHelper; use Dedoc\Scramble\Support\Generator\Parameter; use Dedoc\Scramble\Support\Generator\Schema; +use Dedoc\Scramble\Support\Generator\Types\StringType; use Dedoc\Scramble\Support\Generator\Types\Type as OpenApiType; use Dedoc\Scramble\Support\Generator\Types\UnknownType; use Dedoc\Scramble\Support\Generator\TypeTransformer; @@ -90,7 +91,7 @@ private function applyDocsInfo(Parameter $parameter) $exampleValue = null; } elseif (in_array($exampleValue, ['true', 'false'])) { $exampleValue = $exampleValue === 'true'; - } elseif (is_numeric($exampleValue)) { + } elseif (is_numeric($exampleValue) && !($parameter->schema->type instanceof StringType)) { $exampleValue = floatval($exampleValue); } From 53d33b9a35490545915868bb35a2117f8280fb0b Mon Sep 17 00:00:00 2001 From: Jeroen van Vliet Date: Mon, 26 Feb 2024 10:46:18 +0100 Subject: [PATCH 11/33] Always add required property 'scopes' 'scopes' is a required property as per https://spec.openapis.org/oas/v3.1.0#fixed-fields-24 --- .../Generator/SecuritySchemes/OAuthFlow.php | 12 +++++++----- tests/OpenApiBuildersTest.php | 18 ++++++++++++++++++ ...security_scheme_with_empty_scope_map__1.yml | 8 ++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 tests/__snapshots__/OpenApiBuildersTest__it_builds_oauth2_security_scheme_with_empty_scope_map__1.yml diff --git a/src/Support/Generator/SecuritySchemes/OAuthFlow.php b/src/Support/Generator/SecuritySchemes/OAuthFlow.php index 035ca09c..92840f82 100644 --- a/src/Support/Generator/SecuritySchemes/OAuthFlow.php +++ b/src/Support/Generator/SecuritySchemes/OAuthFlow.php @@ -43,11 +43,13 @@ public function addScope(string $name, string $description = '') public function toArray() { - return array_filter([ - 'authorizationUrl' => $this->authorizationUrl, - 'tokenUrl' => $this->tokenUrl, - 'refreshUrl' => $this->refreshUrl, + return [ + ...array_filter([ + 'authorizationUrl' => $this->authorizationUrl, + 'tokenUrl' => $this->tokenUrl, + 'refreshUrl' => $this->refreshUrl, + ]), 'scopes' => $this->scopes, - ]); + ]; } } diff --git a/tests/OpenApiBuildersTest.php b/tests/OpenApiBuildersTest.php index 346a57da..bab8c9f2 100644 --- a/tests/OpenApiBuildersTest.php +++ b/tests/OpenApiBuildersTest.php @@ -40,3 +40,21 @@ assertMatchesSnapshot($openApi->toArray()); }); + +it('builds oauth2 security scheme with empty scope map', function () { + $openApi = (new OpenApi('3.1.0')) + ->setInfo(InfoObject::make('API')->setVersion('0.0.1')); + + $openApi->secure( + SecurityScheme::oauth2() + ->flow('implicit', function (OAuthFlow $flow) { + $flow + ->refreshUrl('https://test.com') + ->tokenUrl('https://test.com/token'); + }) + ); + $document = $openApi->toArray(); + + expect($document['components']['securitySchemes']['oauth2']['flows']['implicit']['scopes']) + ->toBe([]); +}); diff --git a/tests/__snapshots__/OpenApiBuildersTest__it_builds_oauth2_security_scheme_with_empty_scope_map__1.yml b/tests/__snapshots__/OpenApiBuildersTest__it_builds_oauth2_security_scheme_with_empty_scope_map__1.yml new file mode 100644 index 00000000..47c213c7 --- /dev/null +++ b/tests/__snapshots__/OpenApiBuildersTest__it_builds_oauth2_security_scheme_with_empty_scope_map__1.yml @@ -0,0 +1,8 @@ +openapi: 3.1.0 +info: + title: API + version: 0.0.1 +security: + - { oauth2: { } } +components: + securitySchemes: { oauth2: { type: oauth2, flows: { implicit: { tokenUrl: 'https://test.com/token', refreshUrl: 'https://test.com', scopes: { } } } } } From e12aee06ff566375432ac10ed3058b7fcad19097 Mon Sep 17 00:00:00 2001 From: Jeroen van Vliet Date: Fri, 1 Mar 2024 11:07:42 +0100 Subject: [PATCH 12/33] Update scopes type If 'scopes' is empty, it MUST be an object and not an array --- src/Support/Generator/SecuritySchemes/OAuthFlow.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Support/Generator/SecuritySchemes/OAuthFlow.php b/src/Support/Generator/SecuritySchemes/OAuthFlow.php index 92840f82..ca4e72fb 100644 --- a/src/Support/Generator/SecuritySchemes/OAuthFlow.php +++ b/src/Support/Generator/SecuritySchemes/OAuthFlow.php @@ -49,7 +49,8 @@ public function toArray() 'tokenUrl' => $this->tokenUrl, 'refreshUrl' => $this->refreshUrl, ]), - 'scopes' => $this->scopes, + // Never filter 'scopes' as it is allowed to be empty. If empty it must be an object + 'scopes' => empty($this->scopes) ? new \stdClass() : $this->scopes, ]; } } From ffd12e0c4795381cb16b24837e08448a2eaed8ad Mon Sep 17 00:00:00 2001 From: Jeroen van Vliet Date: Fri, 1 Mar 2024 11:13:51 +0100 Subject: [PATCH 13/33] Update OpenApiBuildersTest.php Update test; require result to be object --- tests/OpenApiBuildersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenApiBuildersTest.php b/tests/OpenApiBuildersTest.php index bab8c9f2..67a163cd 100644 --- a/tests/OpenApiBuildersTest.php +++ b/tests/OpenApiBuildersTest.php @@ -56,5 +56,5 @@ $document = $openApi->toArray(); expect($document['components']['securitySchemes']['oauth2']['flows']['implicit']['scopes']) - ->toBe([]); + ->toBeObject(); }); From 407ab086239dd0bb648a34a4eee0eb271425b53a Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Sun, 3 Mar 2024 14:06:21 +0000 Subject: [PATCH 14/33] Fix styling --- .../OperationExtensions/RulesExtractor/RulesToParameter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/OperationExtensions/RulesExtractor/RulesToParameter.php b/src/Support/OperationExtensions/RulesExtractor/RulesToParameter.php index 048e01b0..c73fddb8 100644 --- a/src/Support/OperationExtensions/RulesExtractor/RulesToParameter.php +++ b/src/Support/OperationExtensions/RulesExtractor/RulesToParameter.php @@ -91,7 +91,7 @@ private function applyDocsInfo(Parameter $parameter) $exampleValue = null; } elseif (in_array($exampleValue, ['true', 'false'])) { $exampleValue = $exampleValue === 'true'; - } elseif (is_numeric($exampleValue) && !($parameter->schema->type instanceof StringType)) { + } elseif (is_numeric($exampleValue) && ! ($parameter->schema->type instanceof StringType)) { $exampleValue = floatval($exampleValue); } From 9a15a336e9c76c201ae28bdea86b6c20b89dedb1 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sun, 3 Mar 2024 20:28:25 +0200 Subject: [PATCH 15/33] fixes for the case when non-request class has rules method --- .../FormRequestRulesExtractor.php | 5 ++++ .../RequestEssentialsExtensionTest.php | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Support/OperationExtensions/RulesExtractor/FormRequestRulesExtractor.php b/src/Support/OperationExtensions/RulesExtractor/FormRequestRulesExtractor.php index e4918cd9..de347043 100644 --- a/src/Support/OperationExtensions/RulesExtractor/FormRequestRulesExtractor.php +++ b/src/Support/OperationExtensions/RulesExtractor/FormRequestRulesExtractor.php @@ -52,6 +52,11 @@ public function extract(Route $route) /** @var Request $request */ $request = (new $requestClassName); + + if (! method_exists($request, 'setMethod')) { + return []; + } + $request->setMethod($route->methods()[0]); return $request->rules(); diff --git a/tests/Support/OperationExtensions/RequestEssentialsExtensionTest.php b/tests/Support/OperationExtensions/RequestEssentialsExtensionTest.php index f605a9dd..e3049658 100644 --- a/tests/Support/OperationExtensions/RequestEssentialsExtensionTest.php +++ b/tests/Support/OperationExtensions/RequestEssentialsExtensionTest.php @@ -28,6 +28,31 @@ public function foo(ModelWithCustomRouteKeyName $model) } } +it('correctly handles not request class with rules method', function () { + $openApiDocument = generateForRoute(function () { + return RouteFacade::get('api/test/{model}', [Foo_RequestRulesTest_Controller::class, 'foo']); + }); + + expect($openApiDocument['paths']['/test/{model}']['get']['parameters'][0]) + ->toHaveKey('schema.type', 'integer') + ->toHaveKey('description', 'The model ID'); +}); +class ModelWithRulesMethod extends \Illuminate\Database\Eloquent\Model +{ + protected $table = 'users'; + + public function rules() + { + return []; + } +} +class Foo_RequestRulesTest_Controller +{ + public function foo(ModelWithRulesMethod $model) + { + } +} + it('handles custom key from route to determine model route key type', function () { $openApiDocument = generateForRoute(function () { return RouteFacade::get('api/test/{user:name}', [CustomKey_RequestEssentialsExtensionTest_Controller::class, 'foo']); From 43a12a1c636bed3ae25979a069a6f3624533ced1 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Fri, 8 Mar 2024 15:30:43 +0200 Subject: [PATCH 16/33] wip: prep for l11 - doctrine breaking changes --- src/Support/ResponseExtractor/ModelInfo.php | 118 ++++++------------ .../ModelInfoProviders/DoctrineProvider.php | 98 +++++++++++++++ .../ModelInfoProviders/ModelInfoProvider.php | 10 ++ .../ModelInfoProviders/NativeProvider.php | 8 ++ 4 files changed, 151 insertions(+), 83 deletions(-) create mode 100644 src/Support/ResponseExtractor/ModelInfoProviders/DoctrineProvider.php create mode 100644 src/Support/ResponseExtractor/ModelInfoProviders/ModelInfoProvider.php create mode 100644 src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index a3a785c7..638fbcf8 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -4,6 +4,9 @@ use Dedoc\Scramble\Infer\Definition\ClassDefinition; use Dedoc\Scramble\Infer\Definition\ClassPropertyDefinition; +use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\DoctrineProvider; +use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\ModelAttribute; +use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\ModelInfoProvider; use Dedoc\Scramble\Support\Type\ArrayType; use Dedoc\Scramble\Support\Type\BooleanType; use Dedoc\Scramble\Support\Type\FloatType; @@ -43,11 +46,10 @@ class ModelInfo 'morphedByMany', ]; - private string $class; - - public function __construct(string $class) + public function __construct( + private string $class + ) { - $this->class = $class; } public function handle() @@ -156,48 +158,49 @@ public function type() */ protected function getAttributes($model) { - $schema = $model->getConnection()->getDoctrineSchemaManager(); - $table = $model->getConnection()->getTablePrefix().$model->getTable(); - - $platform = $model->getConnection() - ->getDoctrineConnection() - ->getDatabasePlatform(); + $driver = $this->makeDriver($model); - $platform->registerDoctrineTypeMapping('enum', 'string'); - $platform->registerDoctrineTypeMapping('geometry', 'string'); + $attributes = collect($driver->getAttributes($model)) + ->map(function (array $attribute) use ($model) { + $attribute['hidden'] = $this->attributeIsHidden($attribute['name'], $model); + $attribute['cast'] = $this->getCastType($attribute['name'], $model); - $columns = $schema->listTableColumns($table); - $indexes = $schema->listTableIndexes($table); + return $attribute; + }) + ->toArray(); - return collect($columns) - ->values() - ->map(fn (Column $column) => [ - 'name' => $column->getName(), - 'type' => $this->getColumnType($column), - 'increments' => $column->getAutoincrement(), - 'nullable' => ! $column->getNotnull(), - 'default' => $this->getColumnDefault($column, $model), - 'unique' => $this->columnIsUnique($column->getName(), $indexes), - 'fillable' => $model->isFillable($column->getName()), - 'hidden' => $this->attributeIsHidden($column->getName(), $model), - 'appended' => null, - 'cast' => $this->getCastType($column->getName(), $model), - ]) - ->merge($this->getVirtualAttributes($model, $columns)) + return collect($attributes) + ->merge($this->getVirtualAttributes($model, $attributes)) ->keyBy('name'); } + /** + * @param \Illuminate\Database\Eloquent\Model $model + */ + private function makeDriver($model): ModelInfoProvider + { + $schema = $model->getConnection()->getSchemaBuilder(); + + if (method_exists($schema, 'getColumns')) { + // @todo + } + + return new DoctrineProvider(); + } + /** * Get the virtual (non-column) attributes for the given model. * * @param \Illuminate\Database\Eloquent\Model $model - * @param \Doctrine\DBAL\Schema\Column[] $columns + * @param array[] $attributes * @return \Illuminate\Support\Collection */ - protected function getVirtualAttributes($model, $columns) + protected function getVirtualAttributes($model, $attributes) { $class = new ReflectionClass($model); + $keyedAttributes = collect($attributes)->keyBy('name'); + return collect($class->getMethods()) ->reject( fn (ReflectionMethod $method) => $method->isStatic() @@ -213,7 +216,7 @@ protected function getVirtualAttributes($model, $columns) return []; } }) - ->reject(fn ($cast, $name) => collect($columns)->has($name)) + ->reject(fn ($cast, $name) => $keyedAttributes->has($name)) ->map(fn ($cast, $name) => [ 'name' => $name, 'type' => null, @@ -327,43 +330,6 @@ protected function getCastsWithDates($model) ->merge($model->getCasts()); } - /** - * Get the type of the given column. - * - * @param \Doctrine\DBAL\Schema\Column $column - * @return string - */ - protected function getColumnType($column) - { - $name = $column->getType()->getName(); - - $unsigned = $column->getUnsigned() ? ' unsigned' : ''; - - $details = get_class($column->getType()) === DecimalType::class - ? $column->getPrecision().','.$column->getScale() - : $column->getLength(); - - if ($details) { - return sprintf('%s(%s)%s', $name, $details, $unsigned); - } - - return sprintf('%s%s', $name, $unsigned); - } - - /** - * Get the default value for the given column. - * - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Illuminate\Database\Eloquent\Model $model - * @return mixed|null - */ - protected function getColumnDefault($column, $model) - { - $attributeDefault = $model->getAttributes()[$column->getName()] ?? null; - - return $attributeDefault ?? $column->getDefault(); - } - /** * Determine if the given attribute is hidden. * @@ -384,20 +350,6 @@ protected function attributeIsHidden($attribute, $model) return false; } - /** - * Determine if the given attribute is unique. - * - * @param string $column - * @param \Doctrine\DBAL\Schema\Index[] $indexes - * @return bool - */ - protected function columnIsUnique($column, $indexes) - { - return collect($indexes) - ->filter(fn (Index $index) => count($index->getColumns()) === 1 && $index->getColumns()[0] === $column) - ->contains(fn (Index $index) => $index->isUnique()); - } - /** * Qualify the given model class base name. * diff --git a/src/Support/ResponseExtractor/ModelInfoProviders/DoctrineProvider.php b/src/Support/ResponseExtractor/ModelInfoProviders/DoctrineProvider.php new file mode 100644 index 00000000..e2810195 --- /dev/null +++ b/src/Support/ResponseExtractor/ModelInfoProviders/DoctrineProvider.php @@ -0,0 +1,98 @@ +getConnection()->getDoctrineSchemaManager(); + $table = $model->getConnection()->getTablePrefix().$model->getTable(); + + $platform = $model->getConnection() + ->getDoctrineConnection() + ->getDatabasePlatform(); + + $platform->registerDoctrineTypeMapping('enum', 'string'); + $platform->registerDoctrineTypeMapping('geometry', 'string'); + + $columns = $schema->listTableColumns($table); + $indexes = $schema->listTableIndexes($table); + + return collect($columns) + ->values() + ->map(fn (Column $column) => [ + 'name' => $column->getName(), + 'type' => $this->getColumnType($column), + 'increments' => $column->getAutoincrement(), + 'nullable' => ! $column->getNotnull(), + 'default' => $this->getColumnDefault($column, $model), + 'unique' => $this->columnIsUnique($column->getName(), $indexes), + 'fillable' => $model->isFillable($column->getName()), + 'appended' => null, + ]) + ->toArray(); + } + + /** + * Get the type of the given column. + * + * @param \Doctrine\DBAL\Schema\Column $column + * @return string + */ + protected function getColumnType($column) + { + $name = $column->getType()->getName(); + + $unsigned = $column->getUnsigned() ? ' unsigned' : ''; + + $details = get_class($column->getType()) === DecimalType::class + ? $column->getPrecision().','.$column->getScale() + : $column->getLength(); + + if ($details) { + return sprintf('%s(%s)%s', $name, $details, $unsigned); + } + + return sprintf('%s%s', $name, $unsigned); + } + + /** + * Get the default value for the given column. + * + * @param \Doctrine\DBAL\Schema\Column $column + * @param \Illuminate\Database\Eloquent\Model $model + * @return mixed|null + */ + protected function getColumnDefault($column, $model) + { + $attributeDefault = $model->getAttributes()[$column->getName()] ?? null; + + return $attributeDefault ?? $column->getDefault(); + } + + /** + * Determine if the given attribute is unique. + * + * @param string $column + * @param \Doctrine\DBAL\Schema\Index[] $indexes + * @return bool + */ + protected function columnIsUnique($column, $indexes) + { + return collect($indexes) + ->filter(fn (Index $index) => count($index->getColumns()) === 1 && $index->getColumns()[0] === $column) + ->contains(fn (Index $index) => $index->isUnique()); + } +} diff --git a/src/Support/ResponseExtractor/ModelInfoProviders/ModelInfoProvider.php b/src/Support/ResponseExtractor/ModelInfoProviders/ModelInfoProvider.php new file mode 100644 index 00000000..8245174b --- /dev/null +++ b/src/Support/ResponseExtractor/ModelInfoProviders/ModelInfoProvider.php @@ -0,0 +1,10 @@ + Date: Sat, 9 Mar 2024 13:43:17 +0200 Subject: [PATCH 17/33] upgr php-parser to 5.0 --- composer.json | 2 +- src/Infer/Handler/ThrowHandler.php | 4 ++-- src/Infer/Reflector/MethodReflector.php | 2 +- src/ScrambleServiceProvider.php | 2 +- .../RulesExtractor/ValidateCallExtractor.php | 2 +- tests/Utils/AnalysisResult.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index c771dc5b..4a87823e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^8.1", "illuminate/contracts": "^8.0.0|^9.0.0|^10.0.0", - "nikic/php-parser": "^4.0", + "nikic/php-parser": "^5.0", "phpstan/phpdoc-parser": "^1.0", "spatie/laravel-package-tools": "^1.9.2" }, diff --git a/src/Infer/Handler/ThrowHandler.php b/src/Infer/Handler/ThrowHandler.php index c333bd36..4661eec4 100644 --- a/src/Infer/Handler/ThrowHandler.php +++ b/src/Infer/Handler/ThrowHandler.php @@ -12,10 +12,10 @@ class ThrowHandler { public function shouldHandle($node) { - return $node instanceof Node\Stmt\Throw_; + return $node instanceof Node\Expr\Throw_; } - public function leave(Node\Stmt\Throw_ $node, Scope $scope) + public function leave(Node\Expr\Throw_ $node, Scope $scope) { if (! $scope->isInFunction()) { return; diff --git a/src/Infer/Reflector/MethodReflector.php b/src/Infer/Reflector/MethodReflector.php index 7fe0e102..dcb0fff8 100644 --- a/src/Infer/Reflector/MethodReflector.php +++ b/src/Infer/Reflector/MethodReflector.php @@ -73,7 +73,7 @@ public function __construct($nameContext) $this->nameContext = $nameContext; } - public function beforeTraverse(array $nodes) + public function beforeTraverse(array $nodes): ?array { return null; } diff --git a/src/ScrambleServiceProvider.php b/src/ScrambleServiceProvider.php index 8649b577..1e194230 100644 --- a/src/ScrambleServiceProvider.php +++ b/src/ScrambleServiceProvider.php @@ -54,7 +54,7 @@ public function configurePackage(Package $package): void $this->app->singleton(FileParser::class, function () { return new FileParser( - (new ParserFactory)->create(ParserFactory::PREFER_PHP7) + (new ParserFactory)->createForHostVersion() ); }); diff --git a/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php b/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php index 9198801a..3bec2be8 100644 --- a/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php +++ b/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php @@ -123,7 +123,7 @@ private function getPossibleParamType(Node\Stmt\ClassMethod $methodNode, Node\Ex ->mapWithKeys(function (Node\Param $param) { try { return [ - $param->var->name => implode('\\', $param->type->parts ?? []), + $param->var->name => $param->type->name, ]; } catch (\Throwable $exception) { throw $exception; diff --git a/tests/Utils/AnalysisResult.php b/tests/Utils/AnalysisResult.php index 55a749ee..f76f4c2a 100644 --- a/tests/Utils/AnalysisResult.php +++ b/tests/Utils/AnalysisResult.php @@ -36,7 +36,7 @@ public function getExpressionType(string $code) { $code = 'create(PhpParser\ParserFactory::PREFER_PHP7)->parse($code); + $fileAst = (new PhpParser\ParserFactory)->createForHostVersion()->parse($code); $index = $this->index; $infer = new TypeInferer( From 1f6a34c091ea0dae38340dbdb2d61df87f5c1fa2 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 13:50:41 +0200 Subject: [PATCH 18/33] upgraded dev deps --- .github/workflows/run-tests.yml | 9 +++++++-- composer.json | 14 +++++++------- ...th2_security_scheme_with_empty_scope_map__1.yml | 8 -------- ...___json___call_support_with_phpdoc_help__1.yml} | 0 ...t__response____noContent___call_support__1.yml} | 0 ..._with_data_set_(_var_arrayint,_string_)__1.yml} | 0 ...th_data_set_(_var_arraystring,_string_)__1.yml} | 0 ...rrays_with_data_set_(_var_arraystring_)__1.yml} | 0 ...l_arrays_with_data_set_(_var_string[]_)__1.yml} | 0 ...th_data_set_(_var_array0_string,_1_ng_)__1.yml} | 0 ..._with_data_set_(_var_arrayint,_string_)__1.yml} | 0 ...th_data_set_(_var_arraystring,_string_)__1.yml} | 0 ...rrays_with_data_set_(_var_arraystring_)__1.yml} | 0 ...h_data_set_(_var_arraytest_string,_ng_)__1.yml} | 0 ...s_with_data_set_(_var_arraywow_string_)__1.yml} | 0 ...imple_types_with_data_set_(_var_array_)__1.yml} | 0 ...simple_types_with_data_set_(_var_bool_)__1.yml} | 0 ...ple_types_with_data_set_(_var_boolean_)__1.yml} | 0 ...mple_types_with_data_set_(_var_double_)__1.yml} | 0 ...imple_types_with_data_set_(_var_false_)__1.yml} | 0 ...ple_types_with_data_set_(_var_float_)_1__1.yml} | 0 ...ple_types_with_data_set_(_var_float_)_2__1.yml} | 0 ..._simple_types_with_data_set_(_var_int_)__1.yml} | 0 ...ple_types_with_data_set_(_var_integer_)__1.yml} | 0 ...simple_types_with_data_set_(_var_null_)__1.yml} | 0 ...mple_types_with_data_set_(_var_object_)__1.yml} | 0 ...mple_types_with_data_set_(_var_scalar_)__1.yml} | 0 ...mple_types_with_data_set_(_var_string_)__1.yml} | 0 ...simple_types_with_data_set_(_var_true_)__1.yml} | 0 ...g_literals_with_data_set_(_var_foobar_)__1.yml} | 0 ...rals_with_data_set_(_var_foobarstring_)__1.yml} | 0 ..._rules_from_Validator__make_facade_call__1.yml} | 0 ...racts_rules_from_request__validate_call__1.yml} | 0 33 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 tests/__snapshots__/OpenApiBuildersTest__it_builds_oauth2_security_scheme_with_empty_scope_map__1.yml rename tests/__snapshots__/{ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml => ResponseDocumentingTest__response____json___call_support_with_phpdoc_help__1.yml} (100%) rename tests/__snapshots__/{ResponseDocumentingTest__response()-noContent()_call_support__1.yml => ResponseDocumentingTest__response____noContent___call_support__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml => TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arrayint,_string_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml => TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arraystring,_string_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml => TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arraystring_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml => TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_string[]_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml => TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_array0_string,_1_ng_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml => TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arrayint,_string_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml => TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraystring,_string_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml => TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraystring_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml => TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraytest_string,_ng_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml => TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraywow_string_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_array_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_bool_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_boolean_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_double_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_false_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_float_)_1__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_float_)_2__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_int_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_integer_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_null_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_object_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_scalar_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_string_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml => TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_true_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml => TypesRecognitionTest__it_handles_unions_of_string_literals_with_data_set_(_var_foobar_)__1.yml} (100%) rename tests/__snapshots__/{TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml => TypesRecognitionTest__it_handles_unions_of_string_literals_with_data_set_(_var_foobarstring_)__1.yml} (100%) rename tests/__snapshots__/{ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml => ValidationRulesDocumentingTest__it_extracts_rules_from_Validator__make_facade_call__1.yml} (100%) rename tests/__snapshots__/{ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml => ValidationRulesDocumentingTest__it_extracts_rules_from_request__validate_call__1.yml} (100%) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index c0e4b5da..7d2b4563 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,8 +13,8 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.1] - laravel: [10.*, 9.*, 8.81.*] + php: [8.1, 8.2] + laravel: [11.*, 10.*, 9.*, 8.81.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* @@ -23,6 +23,11 @@ jobs: testbench: 7.* - laravel: 8.81.* testbench: 6.24.* + - laravel: 11.* + testbench: 9.* + exclude: + - laravel: 11.* + php: 8.1 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 4a87823e..6a759cc3 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.1", - "illuminate/contracts": "^8.0.0|^9.0.0|^10.0.0", + "illuminate/contracts": "^8.0.0|^9.0.0|^10.0.0|^11.0", "nikic/php-parser": "^5.0", "phpstan/phpdoc-parser": "^1.0", "spatie/laravel-package-tools": "^1.9.2" @@ -25,12 +25,12 @@ "require-dev": { "doctrine/dbal": "^3.4", "laravel/pint": "^v1.1.0", - "nunomaduro/collision": "^5.0|^v6.0", - "orchestra/testbench": "^6.0|^7.0|^8.0", - "pestphp/pest": "^1.21", - "pestphp/pest-plugin-laravel": "^1.2", - "phpunit/phpunit": "^9.5", - "spatie/pest-plugin-snapshots": "^1.1" + "nunomaduro/collision": "^5.0|^v6.0|^7.0|^8.0", + "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-laravel": "^2.3", + "phpunit/phpunit": "^10.5", + "spatie/pest-plugin-snapshots": "^2.1" }, "autoload": { "psr-4": { diff --git a/tests/__snapshots__/OpenApiBuildersTest__it_builds_oauth2_security_scheme_with_empty_scope_map__1.yml b/tests/__snapshots__/OpenApiBuildersTest__it_builds_oauth2_security_scheme_with_empty_scope_map__1.yml deleted file mode 100644 index 47c213c7..00000000 --- a/tests/__snapshots__/OpenApiBuildersTest__it_builds_oauth2_security_scheme_with_empty_scope_map__1.yml +++ /dev/null @@ -1,8 +0,0 @@ -openapi: 3.1.0 -info: - title: API - version: 0.0.1 -security: - - { oauth2: { } } -components: - securitySchemes: { oauth2: { type: oauth2, flows: { implicit: { tokenUrl: 'https://test.com/token', refreshUrl: 'https://test.com', scopes: { } } } } } diff --git a/tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml b/tests/__snapshots__/ResponseDocumentingTest__response____json___call_support_with_phpdoc_help__1.yml similarity index 100% rename from tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml rename to tests/__snapshots__/ResponseDocumentingTest__response____json___call_support_with_phpdoc_help__1.yml diff --git a/tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml b/tests/__snapshots__/ResponseDocumentingTest__response____noContent___call_support__1.yml similarity index 100% rename from tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml rename to tests/__snapshots__/ResponseDocumentingTest__response____noContent___call_support__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arrayint,_string_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arrayint,_string_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arraystring,_string_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arraystring,_string_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arraystring_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_arraystring_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_string[]_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_data_set_(_var_string[]_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_array0_string,_1_ng_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_array0_string,_1_ng_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arrayint,_string_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arrayint,_string_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraystring,_string_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraystring,_string_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraystring_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraystring_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraytest_string,_ng_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraytest_string,_ng_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraywow_string_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_data_set_(_var_arraywow_string_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_array_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_array_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_bool_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_bool_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_boolean_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_boolean_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_double_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_double_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_false_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_false_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_float_)_1__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_float_)_1__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_float_)_2__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_float_)_2__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_int_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_int_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_integer_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_integer_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_null_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_null_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_object_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_object_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_scalar_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_scalar_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_string_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_string_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_true_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_data_set_(_var_true_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_data_set_(_var_foobar_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_data_set_(_var_foobar_)__1.yml diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_data_set_(_var_foobarstring_)__1.yml similarity index 100% rename from tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml rename to tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_data_set_(_var_foobarstring_)__1.yml diff --git a/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml b/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validator__make_facade_call__1.yml similarity index 100% rename from tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml rename to tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validator__make_facade_call__1.yml diff --git a/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml b/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request__validate_call__1.yml similarity index 100% rename from tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml rename to tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request__validate_call__1.yml From e90dddfc6abb78104a9736ba2d4904c3f4f968f2 Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Sat, 9 Mar 2024 11:51:09 +0000 Subject: [PATCH 19/33] Fix styling --- src/Support/ResponseExtractor/ModelInfo.php | 6 +----- .../ResponseExtractor/ModelInfoProviders/NativeProvider.php | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index 638fbcf8..599b3d41 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -5,7 +5,6 @@ use Dedoc\Scramble\Infer\Definition\ClassDefinition; use Dedoc\Scramble\Infer\Definition\ClassPropertyDefinition; use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\DoctrineProvider; -use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\ModelAttribute; use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\ModelInfoProvider; use Dedoc\Scramble\Support\Type\ArrayType; use Dedoc\Scramble\Support\Type\BooleanType; @@ -18,8 +17,6 @@ use Dedoc\Scramble\Support\Type\Union; use Dedoc\Scramble\Support\Type\UnknownType; use Doctrine\DBAL\Schema\Column; -use Doctrine\DBAL\Schema\Index; -use Doctrine\DBAL\Types\DecimalType; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Collection; @@ -48,8 +45,7 @@ class ModelInfo public function __construct( private string $class - ) - { + ) { } public function handle() diff --git a/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php b/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php index 9add26d4..0371adc7 100644 --- a/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php +++ b/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php @@ -4,5 +4,4 @@ class NativeProvider { - } From c30c1fe0c5c2c787dde5eba76c432c47e9935788 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 13:55:33 +0200 Subject: [PATCH 20/33] ... --- composer.json | 10 +++++----- ...onse()-json()_call_support_with_phpdoc_help__1.yml | 8 ++++++++ ...ngTest__response()-noContent()_call_support__1.yml | 8 ++++++++ ...eneral_arrays_with_(_var_arrayint,_string_)__1.yml | 3 +++ ...ral_arrays_with_(_var_arraystring,_string_)__1.yml | 3 +++ ...les_general_arrays_with_(_var_arraystring_)__1.yml | 3 +++ ...andles_general_arrays_with_(_var_string[]_)__1.yml | 3 +++ ...ape_arrays_with_(_var_array0_string,_1_ng_)__1.yml | 7 +++++++ ..._shape_arrays_with_(_var_arrayint,_string_)__1.yml | 3 +++ ...ape_arrays_with_(_var_arraystring,_string_)__1.yml | 3 +++ ...ndles_shape_arrays_with_(_var_arraystring_)__1.yml | 3 +++ ...pe_arrays_with_(_var_arraytest_string,_ng_)__1.yml | 6 ++++++ ...s_shape_arrays_with_(_var_arraywow_string_)__1.yml | 5 +++++ ..._it_handles_simple_types_with_(_var_array_)__1.yml | 3 +++ ...__it_handles_simple_types_with_(_var_bool_)__1.yml | 1 + ...t_handles_simple_types_with_(_var_boolean_)__1.yml | 1 + ...it_handles_simple_types_with_(_var_double_)__1.yml | 1 + ..._it_handles_simple_types_with_(_var_false_)__1.yml | 1 + ...t_handles_simple_types_with_(_var_float_)_1__1.yml | 1 + ...t_handles_simple_types_with_(_var_float_)_2__1.yml | 1 + ...t__it_handles_simple_types_with_(_var_int_)__1.yml | 1 + ...t_handles_simple_types_with_(_var_integer_)__1.yml | 1 + ...__it_handles_simple_types_with_(_var_null_)__1.yml | 1 + ...it_handles_simple_types_with_(_var_object_)__1.yml | 1 + ...it_handles_simple_types_with_(_var_scalar_)__1.yml | 1 + ...it_handles_simple_types_with_(_var_string_)__1.yml | 1 + ...__it_handles_simple_types_with_(_var_true_)__1.yml | 1 + ...ions_of_string_literals_with_(_var_foobar_)__1.yml | 4 ++++ ...f_string_literals_with_(_var_foobarstring_)__1.yml | 3 +++ ...tracts_rules_from_Validatormake_facade_call__1.yml | 8 ++++++++ ...t_extracts_rules_from_request-validate_call__1.yml | 11 +++++++++++ 31 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml create mode 100644 tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml create mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml create mode 100644 tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml create mode 100644 tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml diff --git a/composer.json b/composer.json index 6a759cc3..7ddc23fc 100644 --- a/composer.json +++ b/composer.json @@ -25,12 +25,12 @@ "require-dev": { "doctrine/dbal": "^3.4", "laravel/pint": "^v1.1.0", - "nunomaduro/collision": "^5.0|^v6.0|^7.0|^8.0", + "nunomaduro/collision": "^5.0|^v6.0|^8.0", "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0", - "pestphp/pest": "^2.34", - "pestphp/pest-plugin-laravel": "^2.3", - "phpunit/phpunit": "^10.5", - "spatie/pest-plugin-snapshots": "^2.1" + "pestphp/pest": "^1.21|^2.34", + "pestphp/pest-plugin-laravel": "^1.2|^2.3", + "phpunit/phpunit": "^9.5|^10.5", + "spatie/pest-plugin-snapshots": "^1.1|^2.1" }, "autoload": { "psr-4": { diff --git a/tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml b/tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml new file mode 100644 index 00000000..66493b6d --- /dev/null +++ b/tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml @@ -0,0 +1,8 @@ +openapi: 3.1.0 +info: + title: Laravel + version: 0.0.1 +servers: + - { url: 'http://localhost/api' } +paths: + /test: { get: { operationId: fooTestTwo.index, tags: [Foo_TestTwo], responses: { 500: { description: '', content: { application/json: { schema: { type: object, properties: { error: { type: object, properties: { msg: { type: string }, code: { type: integer } }, required: [msg, code] } }, required: [error] } } } } } } } diff --git a/tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml b/tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml new file mode 100644 index 00000000..4d2d24fb --- /dev/null +++ b/tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml @@ -0,0 +1,8 @@ +openapi: 3.1.0 +info: + title: Laravel + version: 0.0.1 +servers: + - { url: 'http://localhost/api' } +paths: + /test: { get: { operationId: fooTest.index, tags: [Foo_Test], responses: { 204: { description: 'No content', content: { application/json: { } } } } } } diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml new file mode 100644 index 00000000..6ea0d636 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml @@ -0,0 +1,3 @@ +type: array +items: + type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml new file mode 100644 index 00000000..24d3f790 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml @@ -0,0 +1,3 @@ +type: object +additionalProperties: + type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml new file mode 100644 index 00000000..6ea0d636 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml @@ -0,0 +1,3 @@ +type: array +items: + type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml new file mode 100644 index 00000000..6ea0d636 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml @@ -0,0 +1,3 @@ +type: array +items: + type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml new file mode 100644 index 00000000..991c2d7d --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml @@ -0,0 +1,7 @@ +type: object +properties: + - { type: string } + - { type: string } +required: + - '0' + - '1' diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml new file mode 100644 index 00000000..6ea0d636 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml @@ -0,0 +1,3 @@ +type: array +items: + type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml new file mode 100644 index 00000000..24d3f790 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml @@ -0,0 +1,3 @@ +type: object +additionalProperties: + type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml new file mode 100644 index 00000000..6ea0d636 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml @@ -0,0 +1,3 @@ +type: array +items: + type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml new file mode 100644 index 00000000..0afcbb24 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml @@ -0,0 +1,6 @@ +type: object +properties: + test: { type: string } + wow: { type: string } +required: + - test diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml new file mode 100644 index 00000000..10d36d17 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml @@ -0,0 +1,5 @@ +type: object +properties: + wow: { type: string } +required: + - wow diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml new file mode 100644 index 00000000..6ea0d636 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml @@ -0,0 +1,3 @@ +type: array +items: + type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml new file mode 100644 index 00000000..4d2b30b6 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml @@ -0,0 +1 @@ +type: boolean diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml new file mode 100644 index 00000000..4d2b30b6 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml @@ -0,0 +1 @@ +type: boolean diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml new file mode 100644 index 00000000..71228528 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml @@ -0,0 +1 @@ +type: number diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml new file mode 100644 index 00000000..4d2b30b6 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml @@ -0,0 +1 @@ +type: boolean diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml new file mode 100644 index 00000000..71228528 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml @@ -0,0 +1 @@ +type: number diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml new file mode 100644 index 00000000..71228528 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml @@ -0,0 +1 @@ +type: number diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml new file mode 100644 index 00000000..5797d764 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml @@ -0,0 +1 @@ +type: integer diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml new file mode 100644 index 00000000..5797d764 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml @@ -0,0 +1 @@ +type: integer diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml new file mode 100644 index 00000000..a80caf7b --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml @@ -0,0 +1 @@ +type: 'null' diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml new file mode 100644 index 00000000..91bf3091 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml @@ -0,0 +1 @@ +type: object diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml new file mode 100644 index 00000000..5c21d88b --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml @@ -0,0 +1 @@ +type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml new file mode 100644 index 00000000..5c21d88b --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml @@ -0,0 +1 @@ +type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml new file mode 100644 index 00000000..4d2b30b6 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml @@ -0,0 +1 @@ +type: boolean diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml new file mode 100644 index 00000000..1942b935 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml @@ -0,0 +1,4 @@ +type: string +enum: + - foo + - bar diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml new file mode 100644 index 00000000..90c73310 --- /dev/null +++ b/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml @@ -0,0 +1,3 @@ +anyOf: + - { type: string } + - { type: string, enum: [foo, bar] } diff --git a/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml b/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml new file mode 100644 index 00000000..7047ffeb --- /dev/null +++ b/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml @@ -0,0 +1,8 @@ +openapi: 3.1.0 +info: + title: Laravel + version: 0.0.1 +servers: + - { url: 'http://localhost/api' } +paths: + /test: { get: { operationId: validationFacadeRulesDocumentingTest.index, tags: [ValidationFacadeRulesDocumenting_Test], parameters: [{ name: content, in: query, required: true, schema: { type: string, enum: [wow] } }], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } } } } } diff --git a/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml b/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml new file mode 100644 index 00000000..44199831 --- /dev/null +++ b/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml @@ -0,0 +1,11 @@ +openapi: 3.1.0 +info: + title: Laravel + version: 0.0.1 +servers: + - { url: 'http://localhost/api' } +paths: + /test: { get: { operationId: validationRulesDocumentingTest.index, tags: [ValidationRulesDocumenting_Test], parameters: [{ name: content, in: query, required: true, schema: { type: string, enum: [wow] } }], responses: { 200: { description: '`ValidationRulesDocumenting_TestResource`', content: { application/json: { schema: { type: object, properties: { data: { $ref: '#/components/schemas/ValidationRulesDocumenting_TestResource' } }, required: [data] } } } }, 422: { $ref: '#/components/responses/ValidationException' } } } } +components: + schemas: { ValidationRulesDocumenting_TestResource: { type: object, properties: { id: { type: integer, example: 1 } }, required: [id], title: ValidationRulesDocumenting_TestResource } } + responses: { ValidationException: { description: 'Validation error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Errors overview.' }, errors: { type: object, description: 'A detailed description of each field that failed validation.', additionalProperties: { type: array, items: { type: string } } } }, required: [message, errors] } } } } } From 73368b86f96f364a0e268f8432325fc97bc82e41 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 14:45:03 +0200 Subject: [PATCH 21/33] drop 8 and 9 laravel support --- composer.json | 14 +++++++------- ...e()-json()_call_support_with_phpdoc_help__1.yml | 8 -------- ...est__response()-noContent()_call_support__1.yml | 8 -------- ...ral_arrays_with_(_var_arrayint,_string_)__1.yml | 3 --- ..._arrays_with_(_var_arraystring,_string_)__1.yml | 3 --- ..._general_arrays_with_(_var_arraystring_)__1.yml | 3 --- ...les_general_arrays_with_(_var_string[]_)__1.yml | 3 --- ..._arrays_with_(_var_array0_string,_1_ng_)__1.yml | 7 ------- ...ape_arrays_with_(_var_arrayint,_string_)__1.yml | 3 --- ..._arrays_with_(_var_arraystring,_string_)__1.yml | 3 --- ...es_shape_arrays_with_(_var_arraystring_)__1.yml | 3 --- ...arrays_with_(_var_arraytest_string,_ng_)__1.yml | 6 ------ ...hape_arrays_with_(_var_arraywow_string_)__1.yml | 5 ----- ..._handles_simple_types_with_(_var_array_)__1.yml | 3 --- ...t_handles_simple_types_with_(_var_bool_)__1.yml | 1 - ...andles_simple_types_with_(_var_boolean_)__1.yml | 1 - ...handles_simple_types_with_(_var_double_)__1.yml | 1 - ..._handles_simple_types_with_(_var_false_)__1.yml | 1 - ...andles_simple_types_with_(_var_float_)_1__1.yml | 1 - ...andles_simple_types_with_(_var_float_)_2__1.yml | 1 - ...it_handles_simple_types_with_(_var_int_)__1.yml | 1 - ...andles_simple_types_with_(_var_integer_)__1.yml | 1 - ...t_handles_simple_types_with_(_var_null_)__1.yml | 1 - ...handles_simple_types_with_(_var_object_)__1.yml | 1 - ...handles_simple_types_with_(_var_scalar_)__1.yml | 1 - ...handles_simple_types_with_(_var_string_)__1.yml | 1 - ...t_handles_simple_types_with_(_var_true_)__1.yml | 1 - ...s_of_string_literals_with_(_var_foobar_)__1.yml | 4 ---- ...tring_literals_with_(_var_foobarstring_)__1.yml | 3 --- ...cts_rules_from_Validatormake_facade_call__1.yml | 8 -------- ...xtracts_rules_from_request-validate_call__1.yml | 11 ----------- 31 files changed, 7 insertions(+), 104 deletions(-) delete mode 100644 tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml delete mode 100644 tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml delete mode 100644 tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml delete mode 100644 tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml delete mode 100644 tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml diff --git a/composer.json b/composer.json index 7ddc23fc..daf9f227 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.1", - "illuminate/contracts": "^8.0.0|^9.0.0|^10.0.0|^11.0", + "illuminate/contracts": "^10.0.0|^11.0", "nikic/php-parser": "^5.0", "phpstan/phpdoc-parser": "^1.0", "spatie/laravel-package-tools": "^1.9.2" @@ -25,12 +25,12 @@ "require-dev": { "doctrine/dbal": "^3.4", "laravel/pint": "^v1.1.0", - "nunomaduro/collision": "^5.0|^v6.0|^8.0", - "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0", - "pestphp/pest": "^1.21|^2.34", - "pestphp/pest-plugin-laravel": "^1.2|^2.3", - "phpunit/phpunit": "^9.5|^10.5", - "spatie/pest-plugin-snapshots": "^1.1|^2.1" + "nunomaduro/collision": "^7.0|^8.0", + "orchestra/testbench": "^8.0|^9.0", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-laravel": "^2.3", + "phpunit/phpunit": "^10.5", + "spatie/pest-plugin-snapshots": "^2.1" }, "autoload": { "psr-4": { diff --git a/tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml b/tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml deleted file mode 100644 index 66493b6d..00000000 --- a/tests/__snapshots__/ResponseDocumentingTest__response()-json()_call_support_with_phpdoc_help__1.yml +++ /dev/null @@ -1,8 +0,0 @@ -openapi: 3.1.0 -info: - title: Laravel - version: 0.0.1 -servers: - - { url: 'http://localhost/api' } -paths: - /test: { get: { operationId: fooTestTwo.index, tags: [Foo_TestTwo], responses: { 500: { description: '', content: { application/json: { schema: { type: object, properties: { error: { type: object, properties: { msg: { type: string }, code: { type: integer } }, required: [msg, code] } }, required: [error] } } } } } } } diff --git a/tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml b/tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml deleted file mode 100644 index 4d2d24fb..00000000 --- a/tests/__snapshots__/ResponseDocumentingTest__response()-noContent()_call_support__1.yml +++ /dev/null @@ -1,8 +0,0 @@ -openapi: 3.1.0 -info: - title: Laravel - version: 0.0.1 -servers: - - { url: 'http://localhost/api' } -paths: - /test: { get: { operationId: fooTest.index, tags: [Foo_Test], responses: { 204: { description: 'No content', content: { application/json: { } } } } } } diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml deleted file mode 100644 index 6ea0d636..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arrayint,_string_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -type: array -items: - type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml deleted file mode 100644 index 24d3f790..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring,_string_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -type: object -additionalProperties: - type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml deleted file mode 100644 index 6ea0d636..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_arraystring_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -type: array -items: - type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml deleted file mode 100644 index 6ea0d636..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_general_arrays_with_(_var_string[]_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -type: array -items: - type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml deleted file mode 100644 index 991c2d7d..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_array0_string,_1_ng_)__1.yml +++ /dev/null @@ -1,7 +0,0 @@ -type: object -properties: - - { type: string } - - { type: string } -required: - - '0' - - '1' diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml deleted file mode 100644 index 6ea0d636..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arrayint,_string_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -type: array -items: - type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml deleted file mode 100644 index 24d3f790..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring,_string_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -type: object -additionalProperties: - type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml deleted file mode 100644 index 6ea0d636..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraystring_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -type: array -items: - type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml deleted file mode 100644 index 0afcbb24..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraytest_string,_ng_)__1.yml +++ /dev/null @@ -1,6 +0,0 @@ -type: object -properties: - test: { type: string } - wow: { type: string } -required: - - test diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml deleted file mode 100644 index 10d36d17..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_shape_arrays_with_(_var_arraywow_string_)__1.yml +++ /dev/null @@ -1,5 +0,0 @@ -type: object -properties: - wow: { type: string } -required: - - wow diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml deleted file mode 100644 index 6ea0d636..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_array_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -type: array -items: - type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml deleted file mode 100644 index 4d2b30b6..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_bool_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: boolean diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml deleted file mode 100644 index 4d2b30b6..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_boolean_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: boolean diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml deleted file mode 100644 index 71228528..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_double_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: number diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml deleted file mode 100644 index 4d2b30b6..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_false_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: boolean diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml deleted file mode 100644 index 71228528..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_1__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: number diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml deleted file mode 100644 index 71228528..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_float_)_2__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: number diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml deleted file mode 100644 index 5797d764..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_int_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: integer diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml deleted file mode 100644 index 5797d764..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_integer_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: integer diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml deleted file mode 100644 index a80caf7b..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_null_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: 'null' diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml deleted file mode 100644 index 91bf3091..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_object_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: object diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml deleted file mode 100644 index 5c21d88b..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_scalar_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml deleted file mode 100644 index 5c21d88b..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_string_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: string diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml deleted file mode 100644 index 4d2b30b6..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_simple_types_with_(_var_true_)__1.yml +++ /dev/null @@ -1 +0,0 @@ -type: boolean diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml deleted file mode 100644 index 1942b935..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobar_)__1.yml +++ /dev/null @@ -1,4 +0,0 @@ -type: string -enum: - - foo - - bar diff --git a/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml b/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml deleted file mode 100644 index 90c73310..00000000 --- a/tests/__snapshots__/TypesRecognitionTest__it_handles_unions_of_string_literals_with_(_var_foobarstring_)__1.yml +++ /dev/null @@ -1,3 +0,0 @@ -anyOf: - - { type: string } - - { type: string, enum: [foo, bar] } diff --git a/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml b/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml deleted file mode 100644 index 7047ffeb..00000000 --- a/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_Validatormake_facade_call__1.yml +++ /dev/null @@ -1,8 +0,0 @@ -openapi: 3.1.0 -info: - title: Laravel - version: 0.0.1 -servers: - - { url: 'http://localhost/api' } -paths: - /test: { get: { operationId: validationFacadeRulesDocumentingTest.index, tags: [ValidationFacadeRulesDocumenting_Test], parameters: [{ name: content, in: query, required: true, schema: { type: string, enum: [wow] } }], responses: { 200: { description: '', content: { application/json: { schema: { type: string } } } } } } } diff --git a/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml b/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml deleted file mode 100644 index 44199831..00000000 --- a/tests/__snapshots__/ValidationRulesDocumentingTest__it_extracts_rules_from_request-validate_call__1.yml +++ /dev/null @@ -1,11 +0,0 @@ -openapi: 3.1.0 -info: - title: Laravel - version: 0.0.1 -servers: - - { url: 'http://localhost/api' } -paths: - /test: { get: { operationId: validationRulesDocumentingTest.index, tags: [ValidationRulesDocumenting_Test], parameters: [{ name: content, in: query, required: true, schema: { type: string, enum: [wow] } }], responses: { 200: { description: '`ValidationRulesDocumenting_TestResource`', content: { application/json: { schema: { type: object, properties: { data: { $ref: '#/components/schemas/ValidationRulesDocumenting_TestResource' } }, required: [data] } } } }, 422: { $ref: '#/components/responses/ValidationException' } } } } -components: - schemas: { ValidationRulesDocumenting_TestResource: { type: object, properties: { id: { type: integer, example: 1 } }, required: [id], title: ValidationRulesDocumenting_TestResource } } - responses: { ValidationException: { description: 'Validation error', content: { application/json: { schema: { type: object, properties: { message: { type: string, description: 'Errors overview.' }, errors: { type: object, description: 'A detailed description of each field that failed validation.', additionalProperties: { type: array, items: { type: string } } } }, required: [message, errors] } } } } } From e64dc27086a94a8d5b18e155043bed5a0d1d2dd2 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 14:45:42 +0200 Subject: [PATCH 22/33] drop 8 and 9 support --- .github/workflows/run-tests.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7d2b4563..217c72c2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,15 +14,11 @@ jobs: matrix: os: [ubuntu-latest] php: [8.1, 8.2] - laravel: [11.*, 10.*, 9.*, 8.81.*] + laravel: [11.*, 10.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* testbench: 8.* - - laravel: 9.* - testbench: 7.* - - laravel: 8.81.* - testbench: 6.24.* - laravel: 11.* testbench: 9.* exclude: From 5236f13455757d2ae06fc22911cf6e12e54288a0 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 15:00:31 +0200 Subject: [PATCH 23/33] doctrine fix --- src/Support/ResponseExtractor/ModelInfo.php | 3 +- .../ModelInfoProviders/NativeProvider.php | 49 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index 599b3d41..8b6a7030 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -6,6 +6,7 @@ use Dedoc\Scramble\Infer\Definition\ClassPropertyDefinition; use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\DoctrineProvider; use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\ModelInfoProvider; +use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\NativeProvider; use Dedoc\Scramble\Support\Type\ArrayType; use Dedoc\Scramble\Support\Type\BooleanType; use Dedoc\Scramble\Support\Type\FloatType; @@ -178,7 +179,7 @@ private function makeDriver($model): ModelInfoProvider $schema = $model->getConnection()->getSchemaBuilder(); if (method_exists($schema, 'getColumns')) { - // @todo + return new NativeProvider(); } return new DoctrineProvider(); diff --git a/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php b/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php index 0371adc7..a163791a 100644 --- a/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php +++ b/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php @@ -2,6 +2,53 @@ namespace Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders; -class NativeProvider +use Illuminate\Database\Eloquent\Model; +use UnitEnum; +use BackedEnum; + +/** + * All the code here was written by the great Laravel team and community. Cudos to them. + */ +class NativeProvider implements ModelInfoProvider { + public function getAttributes(Model $model): array + { + $connection = $model->getConnection(); + $schema = $connection->getSchemaBuilder(); + $table = $model->getTable(); + $columns = $schema->getColumns($table); + $indexes = $schema->getIndexes($table); + + return collect($columns) + ->values() + ->map(fn ($column) => [ + 'name' => $column['name'], + 'type' => $column['type'], + 'increments' => $column['auto_increment'], + 'nullable' => $column['nullable'], + 'default' => $this->getColumnDefault($column, $model), + 'unique' => $this->columnIsUnique($column['name'], $indexes), + 'fillable' => $model->isFillable($column['name']), + 'appended' => null, + ]) + ->toArray(); + } + + private function getColumnDefault($column, Model $model) + { + $attributeDefault = $model->getAttributes()[$column['name']] ?? null; + + return match (true) { + $attributeDefault instanceof BackedEnum => $attributeDefault->value, + $attributeDefault instanceof UnitEnum => $attributeDefault->name, + default => $attributeDefault ?? $column['default'], + }; + } + + private function columnIsUnique($column, array $indexes) + { + return collect($indexes)->contains( + fn ($index) => count($index['columns']) === 1 && $index['columns'][0] === $column && $index['unique'] + ); + } } From 4d316a0991047500b33fd1ac53b3bd694aa23ed2 Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Sat, 9 Mar 2024 13:00:59 +0000 Subject: [PATCH 24/33] Fix styling --- .../ResponseExtractor/ModelInfoProviders/NativeProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php b/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php index a163791a..493cd944 100644 --- a/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php +++ b/src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php @@ -2,9 +2,9 @@ namespace Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders; +use BackedEnum; use Illuminate\Database\Eloquent\Model; use UnitEnum; -use BackedEnum; /** * All the code here was written by the great Laravel team and community. Cudos to them. From 3e9164cf64b8f2147e846e59cff9a327fe5b26d3 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 15:12:16 +0200 Subject: [PATCH 25/33] using native column type provider --- composer.json | 2 +- src/Support/InferExtensions/ModelExtension.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index daf9f227..16f18e82 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^8.1", - "illuminate/contracts": "^10.0.0|^11.0", + "illuminate/contracts": "^10.0|^11.0", "nikic/php-parser": "^5.0", "phpstan/phpdoc-parser": "^1.0", "spatie/laravel-package-tools": "^1.9.2" diff --git a/src/Support/InferExtensions/ModelExtension.php b/src/Support/InferExtensions/ModelExtension.php index 1877bf8b..3aa43fa4 100644 --- a/src/Support/InferExtensions/ModelExtension.php +++ b/src/Support/InferExtensions/ModelExtension.php @@ -78,7 +78,7 @@ private function getBaseAttributeType(Model $model, string $key, array $value) $attributeType = match ($typeName) { 'int', 'integer', 'bigint' => new IntegerType(), 'float', 'double', 'decimal' => new FloatType(), - 'string', 'text', 'datetime' => new StringType(), + 'string', 'varchar', 'text', 'datetime' => new StringType(), 'bool', 'boolean' => new BooleanType(), 'json', 'array' => new ArrayType(), default => new UnknownType("unimplemented DB column type [$type[0]]"), From b33c66ab3a8a8dea61ef2233056f1d0ac137a097 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 15:39:13 +0200 Subject: [PATCH 26/33] check no dbal --- composer.json | 1 - src/Support/ResponseExtractor/ModelInfo.php | 18 +--- .../ModelInfoProviders/DoctrineProvider.php | 98 ------------------- 3 files changed, 2 insertions(+), 115 deletions(-) delete mode 100644 src/Support/ResponseExtractor/ModelInfoProviders/DoctrineProvider.php diff --git a/composer.json b/composer.json index 16f18e82..343fad56 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,6 @@ "spatie/laravel-package-tools": "^1.9.2" }, "require-dev": { - "doctrine/dbal": "^3.4", "laravel/pint": "^v1.1.0", "nunomaduro/collision": "^7.0|^8.0", "orchestra/testbench": "^8.0|^9.0", diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index 8b6a7030..ad2eef39 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -155,9 +155,9 @@ public function type() */ protected function getAttributes($model) { - $driver = $this->makeDriver($model); + $provider = new NativeProvider(); - $attributes = collect($driver->getAttributes($model)) + $attributes = collect($provider->getAttributes($model)) ->map(function (array $attribute) use ($model) { $attribute['hidden'] = $this->attributeIsHidden($attribute['name'], $model); $attribute['cast'] = $this->getCastType($attribute['name'], $model); @@ -171,20 +171,6 @@ protected function getAttributes($model) ->keyBy('name'); } - /** - * @param \Illuminate\Database\Eloquent\Model $model - */ - private function makeDriver($model): ModelInfoProvider - { - $schema = $model->getConnection()->getSchemaBuilder(); - - if (method_exists($schema, 'getColumns')) { - return new NativeProvider(); - } - - return new DoctrineProvider(); - } - /** * Get the virtual (non-column) attributes for the given model. * diff --git a/src/Support/ResponseExtractor/ModelInfoProviders/DoctrineProvider.php b/src/Support/ResponseExtractor/ModelInfoProviders/DoctrineProvider.php deleted file mode 100644 index e2810195..00000000 --- a/src/Support/ResponseExtractor/ModelInfoProviders/DoctrineProvider.php +++ /dev/null @@ -1,98 +0,0 @@ -getConnection()->getDoctrineSchemaManager(); - $table = $model->getConnection()->getTablePrefix().$model->getTable(); - - $platform = $model->getConnection() - ->getDoctrineConnection() - ->getDatabasePlatform(); - - $platform->registerDoctrineTypeMapping('enum', 'string'); - $platform->registerDoctrineTypeMapping('geometry', 'string'); - - $columns = $schema->listTableColumns($table); - $indexes = $schema->listTableIndexes($table); - - return collect($columns) - ->values() - ->map(fn (Column $column) => [ - 'name' => $column->getName(), - 'type' => $this->getColumnType($column), - 'increments' => $column->getAutoincrement(), - 'nullable' => ! $column->getNotnull(), - 'default' => $this->getColumnDefault($column, $model), - 'unique' => $this->columnIsUnique($column->getName(), $indexes), - 'fillable' => $model->isFillable($column->getName()), - 'appended' => null, - ]) - ->toArray(); - } - - /** - * Get the type of the given column. - * - * @param \Doctrine\DBAL\Schema\Column $column - * @return string - */ - protected function getColumnType($column) - { - $name = $column->getType()->getName(); - - $unsigned = $column->getUnsigned() ? ' unsigned' : ''; - - $details = get_class($column->getType()) === DecimalType::class - ? $column->getPrecision().','.$column->getScale() - : $column->getLength(); - - if ($details) { - return sprintf('%s(%s)%s', $name, $details, $unsigned); - } - - return sprintf('%s%s', $name, $unsigned); - } - - /** - * Get the default value for the given column. - * - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Illuminate\Database\Eloquent\Model $model - * @return mixed|null - */ - protected function getColumnDefault($column, $model) - { - $attributeDefault = $model->getAttributes()[$column->getName()] ?? null; - - return $attributeDefault ?? $column->getDefault(); - } - - /** - * Determine if the given attribute is unique. - * - * @param string $column - * @param \Doctrine\DBAL\Schema\Index[] $indexes - * @return bool - */ - protected function columnIsUnique($column, $indexes) - { - return collect($indexes) - ->filter(fn (Index $index) => count($index->getColumns()) === 1 && $index->getColumns()[0] === $column) - ->contains(fn (Index $index) => $index->isUnique()); - } -} From d3f780a97ccae45586321faa5ed6acf9a368f9bc Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Sat, 9 Mar 2024 13:39:43 +0000 Subject: [PATCH 27/33] Fix styling --- src/Support/ResponseExtractor/ModelInfo.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index ad2eef39..737de77d 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -4,8 +4,6 @@ use Dedoc\Scramble\Infer\Definition\ClassDefinition; use Dedoc\Scramble\Infer\Definition\ClassPropertyDefinition; -use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\DoctrineProvider; -use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\ModelInfoProvider; use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\NativeProvider; use Dedoc\Scramble\Support\Type\ArrayType; use Dedoc\Scramble\Support\Type\BooleanType; From 9dd3a7479658f5ae02cdc702fe0f1a67b4c336ff Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 15:43:33 +0200 Subject: [PATCH 28/33] fix dbal removal issues --- src/Support/ResponseExtractor/ModelInfo.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index ad2eef39..5d48c3e4 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -4,8 +4,6 @@ use Dedoc\Scramble\Infer\Definition\ClassDefinition; use Dedoc\Scramble\Infer\Definition\ClassPropertyDefinition; -use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\DoctrineProvider; -use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\ModelInfoProvider; use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\NativeProvider; use Dedoc\Scramble\Support\Type\ArrayType; use Dedoc\Scramble\Support\Type\BooleanType; @@ -17,7 +15,6 @@ use Dedoc\Scramble\Support\Type\StringType; use Dedoc\Scramble\Support\Type\Union; use Dedoc\Scramble\Support\Type\UnknownType; -use Doctrine\DBAL\Schema\Column; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Collection; @@ -70,10 +67,6 @@ public function type() return static::$cache[$this->class]; } - if (! class_exists(Column::class)) { - throw new \LogicException('`doctrine/dbal` package is not installed. It is needed to get model attribute types.'); - } - $modelInfo = $this->handle(); /** @var Model $model */ From c5469951ca5be7f2f601ccb69f2e88e54676bd99 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 15:51:45 +0200 Subject: [PATCH 29/33] added comments --- .../InferExtensions/JsonResourceTypeInfer.php | 14 +++++--------- src/Support/InferExtensions/ModelExtension.php | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Support/InferExtensions/JsonResourceTypeInfer.php b/src/Support/InferExtensions/JsonResourceTypeInfer.php index 1ff39fdf..7c2958a9 100644 --- a/src/Support/InferExtensions/JsonResourceTypeInfer.php +++ b/src/Support/InferExtensions/JsonResourceTypeInfer.php @@ -147,17 +147,13 @@ private static function modelType(ClassDefinition $jsonClass, Scope $scope): ?Ty $modelType = new UnknownType("Cannot resolve [$modelClass] model type."); $modelClassDefinition = null; if ($modelClass && is_a($modelClass, Model::class, true)) { - try { - $modelClassDefinition = (new ModelInfo($modelClass))->type(); + // @todo Use ModelExtension implementation of model info to type conversion. + // @todo The problem is that model extension type is dynamic and I'm not sure how to use it here. + $modelClassDefinition = (new ModelInfo($modelClass))->type(); - $scope->index->registerClassDefinition($modelClassDefinition); + $scope->index->registerClassDefinition($modelClassDefinition); - $modelType = new ObjectType($modelClassDefinition->name); - } catch (\LogicException $e) { - // Here doctrine/dbal is not installed. - $modelType = null; - $modelClassDefinition = null; - } + $modelType = new ObjectType($modelClassDefinition->name); } static::$jsonResourcesModelTypesCache[$jsonClass->name] = [$modelType, $modelClassDefinition]; diff --git a/src/Support/InferExtensions/ModelExtension.php b/src/Support/InferExtensions/ModelExtension.php index 3aa43fa4..8353c1d5 100644 --- a/src/Support/InferExtensions/ModelExtension.php +++ b/src/Support/InferExtensions/ModelExtension.php @@ -75,6 +75,7 @@ private function getBaseAttributeType(Model $model, string $key, array $value) return new ObjectType(Carbon::class); } + // @todo Fix to native types $attributeType = match ($typeName) { 'int', 'integer', 'bigint' => new IntegerType(), 'float', 'double', 'decimal' => new FloatType(), From 73f73e73db66eeeda7162ff50393a3c6ca4c7711 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 17:22:59 +0200 Subject: [PATCH 30/33] fixed dates, fixed possibly missing type --- src/Support/InferExtensions/ModelExtension.php | 9 ++++++--- .../RulesExtractor/ValidateCallExtractor.php | 4 ++++ src/Support/ResponseExtractor/ModelInfo.php | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Support/InferExtensions/ModelExtension.php b/src/Support/InferExtensions/ModelExtension.php index 8353c1d5..ff5db67a 100644 --- a/src/Support/InferExtensions/ModelExtension.php +++ b/src/Support/InferExtensions/ModelExtension.php @@ -71,7 +71,10 @@ private function getBaseAttributeType(Model $model, string $key, array $value) $type = explode(' ', $value['type']); $typeName = explode('(', $type[0])[0]; - if (in_array($key, $model->getDates())) { + if ( + ($model->getCasts()[$key] ?? null) === 'datetime' + || in_array($key, $model->getDates()) + ) { return new ObjectType(Carbon::class); } @@ -79,8 +82,8 @@ private function getBaseAttributeType(Model $model, string $key, array $value) $attributeType = match ($typeName) { 'int', 'integer', 'bigint' => new IntegerType(), 'float', 'double', 'decimal' => new FloatType(), - 'string', 'varchar', 'text', 'datetime' => new StringType(), - 'bool', 'boolean' => new BooleanType(), + 'varchar', 'string', 'text', 'datetime' => new StringType(), // string, text - needed? + 'tinyint', 'bool', 'boolean' => new BooleanType(), // bool, boolean - needed? 'json', 'array' => new ArrayType(), default => new UnknownType("unimplemented DB column type [$type[0]]"), }; diff --git a/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php b/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php index 3bec2be8..5d19d86c 100644 --- a/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php +++ b/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php @@ -121,6 +121,10 @@ private function getPossibleParamType(Node\Stmt\ClassMethod $methodNode, Node\Ex { $paramsMap = collect($methodNode->getParams()) ->mapWithKeys(function (Node\Param $param) { + if (!$param->type) { + return []; + } + try { return [ $param->var->name => $param->type->name, diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index 5d48c3e4..86661f1f 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -95,8 +95,10 @@ public function type() 'double' => new FloatType(), 'decimal' => new FloatType(), 'string' => new StringType(), + 'varchar' => new StringType(), 'text' => new StringType(), 'datetime' => new StringType(), + 'tinyint' => new BooleanType(), 'bool' => new BooleanType(), 'boolean' => new BooleanType(), 'json' => new ArrayType(), From 3c7718b597b30befbc37c07771d5e1f1a647df92 Mon Sep 17 00:00:00 2001 From: romalytvynenko Date: Sat, 9 Mar 2024 15:23:32 +0000 Subject: [PATCH 31/33] Fix styling --- .../RulesExtractor/ValidateCallExtractor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php b/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php index 5d19d86c..e9a0e9ac 100644 --- a/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php +++ b/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php @@ -121,7 +121,7 @@ private function getPossibleParamType(Node\Stmt\ClassMethod $methodNode, Node\Ex { $paramsMap = collect($methodNode->getParams()) ->mapWithKeys(function (Node\Param $param) { - if (!$param->type) { + if (! $param->type) { return []; } From d68f2b461e33020d7ea6bcd6d4677645be647a72 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 18:03:53 +0200 Subject: [PATCH 32/33] drop providers for model info and rely on native columns data --- src/Support/ResponseExtractor/ModelInfo.php | 62 ++++++++++++++----- .../ModelInfoProviders/ModelInfoProvider.php | 10 --- .../ModelInfoProviders/NativeProvider.php | 54 ---------------- 3 files changed, 46 insertions(+), 80 deletions(-) delete mode 100644 src/Support/ResponseExtractor/ModelInfoProviders/ModelInfoProvider.php delete mode 100644 src/Support/ResponseExtractor/ModelInfoProviders/NativeProvider.php diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index 86661f1f..2dc2abb2 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -2,9 +2,9 @@ namespace Dedoc\Scramble\Support\ResponseExtractor; +use BackedEnum; use Dedoc\Scramble\Infer\Definition\ClassDefinition; use Dedoc\Scramble\Infer\Definition\ClassPropertyDefinition; -use Dedoc\Scramble\Support\ResponseExtractor\ModelInfoProviders\NativeProvider; use Dedoc\Scramble\Support\Type\ArrayType; use Dedoc\Scramble\Support\Type\BooleanType; use Dedoc\Scramble\Support\Type\FloatType; @@ -22,7 +22,11 @@ use ReflectionClass; use ReflectionMethod; use SplFileObject; +use UnitEnum; +/** + * All the code here was written by the great Laravel team and community. Cudos to them. + */ class ModelInfo { public static array $cache = []; @@ -150,34 +154,60 @@ public function type() */ protected function getAttributes($model) { - $provider = new NativeProvider(); + $connection = $model->getConnection(); + $schema = $connection->getSchemaBuilder(); + $table = $model->getTable(); + $columns = $schema->getColumns($table); + $indexes = $schema->getIndexes($table); - $attributes = collect($provider->getAttributes($model)) - ->map(function (array $attribute) use ($model) { - $attribute['hidden'] = $this->attributeIsHidden($attribute['name'], $model); - $attribute['cast'] = $this->getCastType($attribute['name'], $model); + return collect($columns) + ->values() + ->map(fn ($column) => [ + 'name' => $column['name'], + 'type' => $column['type'], + 'increments' => $column['auto_increment'], + 'nullable' => $column['nullable'], + 'default' => $this->getColumnDefault($column, $model), + 'unique' => $this->columnIsUnique($column['name'], $indexes), + 'fillable' => $model->isFillable($column['name']), + 'appended' => null, + 'hidden' => $this->attributeIsHidden($column['name'], $model), + 'cast' => $this->getCastType($column['name'], $model), + ]) + ->merge($this->getVirtualAttributes($model, $columns)) + ->keyBy('name'); + } - return $attribute; - }) - ->toArray(); + private function getColumnDefault($column, Model $model) + { + $attributeDefault = $model->getAttributes()[$column['name']] ?? null; - return collect($attributes) - ->merge($this->getVirtualAttributes($model, $attributes)) - ->keyBy('name'); + return match (true) { + $attributeDefault instanceof BackedEnum => $attributeDefault->value, + $attributeDefault instanceof UnitEnum => $attributeDefault->name, + default => $attributeDefault ?? $column['default'], + }; + } + + private function columnIsUnique($column, array $indexes) + { + return collect($indexes)->contains( + fn ($index) => count($index['columns']) === 1 && $index['columns'][0] === $column && $index['unique'] + ); } /** * Get the virtual (non-column) attributes for the given model. * * @param \Illuminate\Database\Eloquent\Model $model - * @param array[] $attributes + * @param array[] $columns * @return \Illuminate\Support\Collection */ - protected function getVirtualAttributes($model, $attributes) + protected function getVirtualAttributes($model, $columns) { $class = new ReflectionClass($model); - $keyedAttributes = collect($attributes)->keyBy('name'); + $keyedColumns = collect($columns)->keyBy('name'); return collect($class->getMethods()) ->reject( @@ -194,7 +224,7 @@ protected function getVirtualAttributes($model, $attributes) return []; } }) - ->reject(fn ($cast, $name) => $keyedAttributes->has($name)) + ->reject(fn ($cast, $name) => $keyedColumns->has($name)) ->map(fn ($cast, $name) => [ 'name' => $name, 'type' => null, diff --git a/src/Support/ResponseExtractor/ModelInfoProviders/ModelInfoProvider.php b/src/Support/ResponseExtractor/ModelInfoProviders/ModelInfoProvider.php deleted file mode 100644 index 8245174b..00000000 --- a/src/Support/ResponseExtractor/ModelInfoProviders/ModelInfoProvider.php +++ /dev/null @@ -1,10 +0,0 @@ -getConnection(); - $schema = $connection->getSchemaBuilder(); - $table = $model->getTable(); - $columns = $schema->getColumns($table); - $indexes = $schema->getIndexes($table); - - return collect($columns) - ->values() - ->map(fn ($column) => [ - 'name' => $column['name'], - 'type' => $column['type'], - 'increments' => $column['auto_increment'], - 'nullable' => $column['nullable'], - 'default' => $this->getColumnDefault($column, $model), - 'unique' => $this->columnIsUnique($column['name'], $indexes), - 'fillable' => $model->isFillable($column['name']), - 'appended' => null, - ]) - ->toArray(); - } - - private function getColumnDefault($column, Model $model) - { - $attributeDefault = $model->getAttributes()[$column['name']] ?? null; - - return match (true) { - $attributeDefault instanceof BackedEnum => $attributeDefault->value, - $attributeDefault instanceof UnitEnum => $attributeDefault->name, - default => $attributeDefault ?? $column['default'], - }; - } - - private function columnIsUnique($column, array $indexes) - { - return collect($indexes)->contains( - fn ($index) => count($index['columns']) === 1 && $index['columns'][0] === $column && $index['unique'] - ); - } -} From 40e89595a7afb009622e7e3b8760965e4240b207 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 18:27:32 +0200 Subject: [PATCH 33/33] fix deprecations --- src/Infer/Reflector/ClassReflector.php | 2 ++ src/Support/InferExtensions/ModelExtension.php | 4 ++-- src/Support/ResponseExtractor/ModelInfo.php | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Infer/Reflector/ClassReflector.php b/src/Infer/Reflector/ClassReflector.php index 22b8d864..85f824c5 100644 --- a/src/Infer/Reflector/ClassReflector.php +++ b/src/Infer/Reflector/ClassReflector.php @@ -15,6 +15,8 @@ class ClassReflector private ?NameContext $nameContext = null; + private array $methods = []; + private function __construct( private FileParser $parser, private string $className, diff --git a/src/Support/InferExtensions/ModelExtension.php b/src/Support/InferExtensions/ModelExtension.php index ff5db67a..9eac78c5 100644 --- a/src/Support/InferExtensions/ModelExtension.php +++ b/src/Support/InferExtensions/ModelExtension.php @@ -68,8 +68,8 @@ public function getPropertyType(PropertyFetchEvent $event): ?Type private function getBaseAttributeType(Model $model, string $key, array $value) { - $type = explode(' ', $value['type']); - $typeName = explode('(', $type[0])[0]; + $type = explode(' ', $value['type'] ?? ''); + $typeName = explode('(', $type[0] ?? '')[0]; if ( ($model->getCasts()[$key] ?? null) === 'datetime' diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index 2dc2abb2..4d3ff44a 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -84,8 +84,8 @@ public function type() ? Union::wrap([new NullType(), $t]) : $t; - $type = explode(' ', $value['type']); - $typeName = explode('(', $type[0])[0]; + $type = explode(' ', $value['type'] ?? ''); + $typeName = explode('(', $type[0] ?? '')[0]; if (in_array($key, $model->getDates())) { return $createType(new ObjectType('\\Carbon\\Carbon'));