Skip to content

Commit

Permalink
Handle nullable string and add deprecated to docblock scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Feb 4, 2024
1 parent ab71392 commit 6f996ef
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/Processors/AugmentProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __invoke(Analysis $analysis)
$property->example = $example;
}

if (Generator::isDefault($property->deprecated) && ($deprecated = $this->isDeprecated((string) $context->comment))) {
if (Generator::isDefault($property->deprecated) && ($deprecated = $this->isDeprecated($context->comment))) {
$property->deprecated = $deprecated;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Processors/Concerns/DocblockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ public function extractExampleDescription(?string $docblock): ?string
}

/**
* Returns true if the `@deprecated` tag is present, false otherwise.
* Returns true if the `\@deprecated` tag is present, false otherwise.
*/
public function isDeprecated(?string $docblock): bool
{
return 1 === preg_match('/@deprecated\s+([ \t])?(?<deprecated>.+)?$/im', $docblock);
return 1 === preg_match('/@deprecated\s+([ \t])?(?<deprecated>.+)?$/im', (string) $docblock);
}
}
8 changes: 8 additions & 0 deletions tests/Fixtures/Scratch/Docblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class DocblockSchema
* @var string The name
*/
public $name;

/**
* @OA\Property
* @var string The name (old)
*
* @deprecated
*/
public $oldName;
}

#[OAT\Schema]
Expand Down
4 changes: 4 additions & 0 deletions tests/Fixtures/Scratch/Docblocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ components:
name:
description: 'The name'
type: string
oldName:
description: 'The name (old)'
type: string
deprecated: true
type: object
DocblockSchemaChild:
type: object
Expand Down
62 changes: 31 additions & 31 deletions tests/Fixtures/Scratch/ExclusiveMinMax31.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ info:
title: 'Exclusive minimum and maximum'
version: '1.0'
paths:
/api/endpoint:
get:
description: 'An endpoint'
operationId: da2bbb06428a6f5ae9199a22a80436d7
responses:
'200':
description: OK
/api/endpoint:
get:
description: 'An endpoint'
operationId: da2bbb06428a6f5ae9199a22a80436d7
responses:
'200':
description: OK
components:
schemas:
minMaxClass31:
properties:
min:
type: integer
minimum: 10
exclusiveMin:
type: integer
exclusiveMinimum: 20
max:
type: integer
maximum: 30
exclusiveMax:
type: integer
exclusiveMaximum: 40
exclusiveMinMax:
type: integer
exclusiveMinimum: 50
exclusiveMaximum: 60
exclusiveMinMaxNumber:
type: integer
exclusiveMinimum: 60
exclusiveMaximum: 70
type: object
schemas:
minMaxClass31:
properties:
min:
type: integer
minimum: 10
exclusiveMin:
type: integer
exclusiveMinimum: 20
max:
type: integer
maximum: 30
exclusiveMax:
type: integer
exclusiveMaximum: 40
exclusiveMinMax:
type: integer
exclusiveMaximum: 60
exclusiveMinimum: 50
exclusiveMinMaxNumber:
type: integer
exclusiveMaximum: 70
exclusiveMinimum: 60
type: object
4 changes: 2 additions & 2 deletions tests/Fixtures/Scratch/Nullable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ components:
type: 'null'
description:
type:
- string
- 'null'
- string
- 'null'
type: object

0 comments on commit 6f996ef

Please sign in to comment.