Skip to content

Commit 585d282

Browse files
chore: improve model annotations
1 parent 586c954 commit 585d282

File tree

21 files changed

+60
-67
lines changed

21 files changed

+60
-67
lines changed

src/Core/Attributes/Api.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Scrapegraphai\Core\Conversion\Contracts\Converter;
88
use Scrapegraphai\Core\Conversion\Contracts\ConverterSource;
9+
use Scrapegraphai\Core\Conversion\ListOf;
10+
use Scrapegraphai\Core\Conversion\MapOf;
911

1012
/**
1113
* @internal
@@ -22,15 +24,18 @@ final class Api
2224
* @param class-string<ConverterSource>|Converter|string|null $type
2325
* @param class-string<ConverterSource>|Converter|null $enum
2426
* @param class-string<ConverterSource>|Converter|string|null $union
27+
* @param class-string<ConverterSource>|Converter|string|null $list
2528
*/
2629
public function __construct(
2730
public readonly ?string $apiName = null,
2831
Converter|string|null $type = null,
2932
Converter|string|null $enum = null,
3033
Converter|string|null $union = null,
34+
Converter|string|null $list = null,
35+
Converter|string|null $map = null,
3136
public readonly bool $nullable = false,
3237
public readonly bool $optional = false,
3338
) {
34-
$this->type = $type ?? $enum ?? $union;
39+
$this->type = $type ?? $enum ?? $union ?? ($list ? new ListOf($list) : ($map ? new MapOf($map) : null));
3540
}
3641
}

src/Core/BaseClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ protected function followRedirect(
146146
}
147147

148148
/**
149-
* @param bool|int|float|string|array<string, mixed>|resource|\Traversable<
150-
* mixed
151-
* >|null $data
149+
* @param bool|int|float|string|resource|\Traversable<mixed>|array<string,
150+
* mixed,>|null $data
152151
*/
153152
protected function sendRequest(
154153
RequestInterface $req,

src/Core/Util.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ public static function streamIterator(StreamInterface $stream): \Iterator
165165
}
166166

167167
/**
168-
* @param bool|int|float|string|array<string, mixed>|resource|\Traversable<
169-
* mixed
170-
* >|null $body
168+
* @param bool|int|float|string|resource|\Traversable<mixed>|array<string,
169+
* mixed,>|null $body
171170
*
172171
* @return array{string, \Generator<string>}
173172
*/
@@ -202,9 +201,8 @@ public static function encodeMultipartStreaming(mixed $body): array
202201
}
203202

204203
/**
205-
* @param bool|int|float|string|array<string, mixed>|resource|\Traversable<
206-
* mixed
207-
* >|null $body
204+
* @param bool|int|float|string|resource|\Traversable<mixed>|array<string,
205+
* mixed,>|null $body
208206
*/
209207
public static function withSetBody(
210208
StreamFactoryInterface $factory,

src/Crawl/CrawlStartParams.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class CrawlStartParams implements BaseModel
4747
/**
4848
* Extraction prompt (required if extraction_mode is true).
4949
*/
50-
#[Api(optional: true)]
50+
#[Api(nullable: true, optional: true)]
5151
public ?string $prompt;
5252

5353
/**
@@ -62,7 +62,7 @@ final class CrawlStartParams implements BaseModel
6262
/**
6363
* Output schema for extraction.
6464
*/
65-
#[Api(optional: true)]
65+
#[Api(nullable: true, optional: true)]
6666
public mixed $schema;
6767

6868
/**

src/Crawl/CrawlStartParams/Rules.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Scrapegraphai\Core\Attributes\Api;
88
use Scrapegraphai\Core\Concerns\SdkModel;
99
use Scrapegraphai\Core\Contracts\BaseModel;
10-
use Scrapegraphai\Core\Conversion\ListOf;
1110

1211
final class Rules implements BaseModel
1312
{
@@ -18,7 +17,7 @@ final class Rules implements BaseModel
1817
*
1918
* @var list<string>|null $exclude
2019
*/
21-
#[Api(type: new ListOf('string'), optional: true)]
20+
#[Api(list: 'string', optional: true)]
2221
public ?array $exclude;
2322

2423
/**
@@ -38,7 +37,7 @@ public function __construct()
3837
*
3938
* You must use named parameters to construct any parameters with a default value.
4039
*
41-
* @param list<string>|null $exclude
40+
* @param list<string> $exclude
4241
*/
4342
public static function with(
4443
?array $exclude = null,

src/Feedback/FeedbackSubmitParams.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class FeedbackSubmitParams implements BaseModel
3232
/**
3333
* Optional feedback comments.
3434
*/
35-
#[Api('feedback_text', optional: true)]
35+
#[Api('feedback_text', nullable: true, optional: true)]
3636
public ?string $feedbackText;
3737

3838
/**

src/GenerateSchema/GenerateSchemaCreateParams.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class GenerateSchemaCreateParams implements BaseModel
2727
/**
2828
* Existing schema to modify or extend.
2929
*/
30-
#[Api('existing_schema', optional: true)]
30+
#[Api('existing_schema', nullable: true, optional: true)]
3131
public mixed $existingSchema;
3232

3333
/**

src/Markdownify/CompletedMarkdownify.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class CompletedMarkdownify implements BaseModel
2222
/**
2323
* Markdown content.
2424
*/
25-
#[Api(optional: true)]
25+
#[Api(nullable: true, optional: true)]
2626
public ?string $result;
2727

2828
/** @var Status::*|null $status */
@@ -43,7 +43,7 @@ public function __construct()
4343
*
4444
* You must use named parameters to construct any parameters with a default value.
4545
*
46-
* @param Status::*|null $status
46+
* @param Status::* $status
4747
*/
4848
public static function with(
4949
?string $error = null,

src/Markdownify/MarkdownifyConvertParams.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Scrapegraphai\Core\Concerns\SdkModel;
99
use Scrapegraphai\Core\Concerns\SdkParams;
1010
use Scrapegraphai\Core\Contracts\BaseModel;
11-
use Scrapegraphai\Core\Conversion\ListOf;
12-
use Scrapegraphai\Core\Conversion\MapOf;
1311

1412
/**
1513
* Convert web page content to clean Markdown format.
@@ -26,15 +24,15 @@ final class MarkdownifyConvertParams implements BaseModel
2624
public string $websiteURL;
2725

2826
/** @var array<string, string>|null $headers */
29-
#[Api(type: new MapOf('string'), optional: true)]
27+
#[Api(map: 'string', optional: true)]
3028
public ?array $headers;
3129

3230
/**
3331
* Interaction steps before conversion.
3432
*
3533
* @var list<string>|null $steps
3634
*/
37-
#[Api(type: new ListOf('string'), optional: true)]
35+
#[Api(list: 'string', optional: true)]
3836
public ?array $steps;
3937

4038
/**
@@ -62,8 +60,8 @@ public function __construct()
6260
*
6361
* You must use named parameters to construct any parameters with a default value.
6462
*
65-
* @param array<string, string>|null $headers
66-
* @param list<string>|null $steps
63+
* @param array<string, string> $headers
64+
* @param list<string> $steps
6765
*/
6866
public static function with(
6967
string $websiteURL,

src/Responses/Crawl/CrawlGetResultsResponse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class CrawlGetResultsResponse implements BaseModel
3232
/**
3333
* Error traceback for failed tasks.
3434
*/
35-
#[Api(optional: true)]
35+
#[Api(nullable: true, optional: true)]
3636
public ?string $traceback;
3737

3838
public function __construct()
@@ -46,8 +46,8 @@ public function __construct()
4646
*
4747
* You must use named parameters to construct any parameters with a default value.
4848
*
49-
* @param mixed|string|null $result
50-
* @param Status::*|null $status
49+
* @param mixed|string $result
50+
* @param Status::* $status
5151
*/
5252
public static function with(
5353
mixed $result = null,

0 commit comments

Comments
 (0)