From 00653bcbabf976cabc53a46e0ad4c6045f559509 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 12 Aug 2025 10:40:59 +0000 Subject: [PATCH 01/21] chore: update SDK settings --- .release-please-manifest.json | 3 ++ .stats.yml | 2 +- README.md | 4 +- release-please-config.json | 71 ++++++++++++++++++++++++++ src/Scrapegraphai/Scrapegraphai.csproj | 2 +- 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 .release-please-manifest.json create mode 100644 release-please-config.json diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..1332969 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.0.1" +} \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 636c6f9..561b1cc 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/scrapegraphai%2Fscrapegraphai-969ebada41127057e4cda129b2e7206224743b5c7fd33aa8ae062ff71b775ac9.yml openapi_spec_hash: 2b2c2c684e6f6885398efca5f2b1f854 -config_hash: 30d69c79e34a1ea6a0405573ce30d927 +config_hash: 6889576ba0fdc14f2c71cea09a60a0f6 diff --git a/README.md b/README.md index 943581f..8d2d27e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ > > This library has not yet been exhaustively tested in production environments and may be missing some features you'd expect in a stable release. As we continue development, there may be breaking changes that require updates to your code. > -> **We'd love your feedback!** Please share any suggestions, bug reports, feature requests, or general thoughts by [filing an issue](https://www.github.com/stainless-sdks/scrapegraphai-csharp/issues/new). +> **We'd love your feedback!** Please share any suggestions, bug reports, feature requests, or general thoughts by [filing an issue](https://www.github.com/ScrapeGraphAI/scrapegraphai-c/issues/new). The Scrapegraphai C# SDK provides convenient access to the [Scrapegraphai REST API](https://scrapegraphai.com) from applications written in C#. @@ -91,4 +91,4 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience. -We are keen for your feedback; please open an [issue](https://www.github.com/stainless-sdks/scrapegraphai-csharp/issues) with questions, bugs, or suggestions. +We are keen for your feedback; please open an [issue](https://www.github.com/ScrapeGraphAI/scrapegraphai-c/issues) with questions, bugs, or suggestions. diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..bb36019 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,71 @@ +{ + "packages": { + ".": {} + }, + "$schema": "https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json", + "include-v-in-tag": true, + "include-component-in-tag": false, + "versioning": "prerelease", + "prerelease": true, + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": false, + "pull-request-header": "Automated Release PR", + "pull-request-title-pattern": "release: ${version}", + "changelog-sections": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "perf", + "section": "Performance Improvements" + }, + { + "type": "revert", + "section": "Reverts" + }, + { + "type": "chore", + "section": "Chores" + }, + { + "type": "docs", + "section": "Documentation" + }, + { + "type": "style", + "section": "Styles" + }, + { + "type": "refactor", + "section": "Refactors" + }, + { + "type": "test", + "section": "Tests", + "hidden": true + }, + { + "type": "build", + "section": "Build System" + }, + { + "type": "ci", + "section": "Continuous Integration", + "hidden": true + } + ], + "release-type": "simple", + "extra-files": [ + "README.md", + { + "type": "xml", + "path": "src/Scrapegraphai/Scrapegraphai.csproj", + "xpath": "//Project/PropertyGroup/VersionPrefix" + } + ] +} \ No newline at end of file diff --git a/src/Scrapegraphai/Scrapegraphai.csproj b/src/Scrapegraphai/Scrapegraphai.csproj index ab444f7..14da859 100644 --- a/src/Scrapegraphai/Scrapegraphai.csproj +++ b/src/Scrapegraphai/Scrapegraphai.csproj @@ -12,7 +12,7 @@ true README.md - https://www.github.com/stainless-sdks/scrapegraphai-csharp + https://www.github.com/ScrapeGraphAI/scrapegraphai-c git true From 30ebeb9bd332cb0a60dd013238811b8b7c2e781c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 13 Aug 2025 02:09:10 +0000 Subject: [PATCH 02/21] chore(internal): codegen related update --- src/Scrapegraphai/JsonConverters.cs | 68 ----------------- .../Crawl/CrawlRetrieveResultsParams.cs | 14 ++-- .../Crawl/CrawlRetrieveResultsResponse.cs | 21 +++-- .../Result.cs | 57 +++++++++++++- .../ResultVariants/All.cs | 3 - .../Status.cs | 5 +- .../Models/Crawl/CrawlStartParams.cs | 54 +++++++++---- .../Crawl/CrawlStartParamsProperties/Rules.cs | 15 +++- .../Models/Crawl/CrawlStartResponse.cs | 12 ++- .../Models/Credits/CreditRetrieveParams.cs | 14 ++-- .../Models/Credits/CreditRetrieveResponse.cs | 17 ++++- .../Models/Feedback/FeedbackSubmitParams.cs | 30 +++++--- .../Models/Feedback/FeedbackSubmitResponse.cs | 27 +++++-- .../GenerateSchemaCreateParams.cs | 25 ++++-- .../GenerateSchemaCreateResponse.cs | 34 ++++++--- .../Status.cs | 5 +- .../GenerateSchemaRetrieveParams.cs | 14 ++-- .../GenerateSchemaRetrieveResponse.cs | 76 ++++++++++++++++++- .../CompletedSchemaGenerationResponse.cs | 34 ++++++--- .../Status.cs | 5 +- .../FailedSchemaGenerationResponse.cs | 34 ++++++--- .../Status.cs | 5 +- .../All.cs | 13 ---- .../Models/Healthz/HealthzCheckParams.cs | 14 ++-- .../Models/Healthz/HealthzCheckResponse.cs | 14 +++- .../Markdownify/CompletedMarkdownify.cs | 29 +++++-- .../CompletedMarkdownifyProperties/Status.cs | 5 +- .../Markdownify/MarkdownifyConvertParams.cs | 27 ++++--- .../MarkdownifyRetrieveStatusParams.cs | 14 ++-- .../MarkdownifyRetrieveStatusResponse.cs | 76 ++++++++++++++++++- .../FailedMarkdownifyResponse.cs | 29 +++++-- .../Status.cs | 5 +- .../All.cs | 19 ++--- .../Searchscraper/CompletedSearchScraper.cs | 39 +++++++--- .../Status.cs | 5 +- .../SearchscraperCreateParams.cs | 32 +++++--- .../SearchscraperRetrieveStatusParams.cs | 14 ++-- .../SearchscraperRetrieveStatusResponse.cs | 76 ++++++++++++++++++- .../FailedSearchScraperResponse.cs | 39 +++++++--- .../Status.cs | 5 +- .../All.cs | 21 ++--- .../Smartscraper/CompletedSmartscraper.cs | 34 +++++++-- .../CompletedSmartscraperProperties/Status.cs | 5 +- .../Models/Smartscraper/FailedSmartscraper.cs | 34 +++++++-- .../FailedSmartscraperProperties/Status.cs | 5 +- .../Smartscraper/SmartscraperCreateParams.cs | 59 ++++++++++---- .../Smartscraper/SmartscraperListParams.cs | 14 ++-- .../Smartscraper/SmartscraperListResponse.cs | 70 ++++++++++++++++- .../SmartscraperListResponseVariants/All.cs | 20 +++-- .../SmartscraperRetrieveParams.cs | 14 ++-- .../SmartscraperRetrieveResponse.cs | 71 ++++++++++++++++- .../All.cs | 20 +++-- .../Models/Validate/ValidateAPIKeyParams.cs | 14 ++-- .../Models/Validate/ValidateAPIKeyResponse.cs | 12 ++- .../Services/Crawl/CrawlService.cs | 13 ++-- .../Services/Credits/CreditService.cs | 9 ++- .../Services/Feedback/FeedbackService.cs | 9 ++- .../GenerateSchema/GenerateSchemaService.cs | 13 ++-- .../Services/Healthz/HealthzService.cs | 9 ++- .../Markdownify/MarkdownifyService.cs | 13 ++-- .../Searchscraper/SearchscraperService.cs | 13 ++-- .../Smartscraper/SmartscraperService.cs | 17 +++-- .../Services/Validate/ValidateService.cs | 9 ++- 63 files changed, 1096 insertions(+), 426 deletions(-) diff --git a/src/Scrapegraphai/JsonConverters.cs b/src/Scrapegraphai/JsonConverters.cs index 7c466d6..a859c09 100644 --- a/src/Scrapegraphai/JsonConverters.cs +++ b/src/Scrapegraphai/JsonConverters.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Linq; -using System.Reflection; using System.Text.Json.Serialization; using Json = System.Text.Json; using System = System; @@ -56,69 +54,3 @@ public override void Write( Json::JsonSerializer.Serialize(writer, value.Raw(), options); } } - -sealed class UnionConverter : JsonConverter - where T : class -{ - readonly List _variantTypes = Enumerable.ToList( - Enumerable.Where( - Assembly.GetExecutingAssembly().GetTypes(), - type => type.BaseType == typeof(T) - ) - ); - - public override T? Read( - ref Json::Utf8JsonReader reader, - System::Type _typeToConvert, - Json::JsonSerializerOptions options - ) - { - List exceptions = []; - foreach (var variantType in _variantTypes) - { - try - { - return Json::JsonSerializer.Deserialize(ref reader, variantType, options) as T; - } - catch (Json::JsonException e) - { - exceptions.Add(e); - } - } - throw new System::AggregateException(exceptions); - } - - public override void Write( - Json::Utf8JsonWriter writer, - T value, - Json::JsonSerializerOptions options - ) - { - var variantType = - _variantTypes.Find(type => type == value.GetType()) - ?? throw new System::ArgumentOutOfRangeException(value.GetType().Name); - Json::JsonSerializer.Serialize(writer, value, variantType, options); - } -} - -sealed class VariantConverter : JsonConverter - where TVariant : IVariant -{ - public override TVariant Read( - ref Json::Utf8JsonReader reader, - System::Type _typeToConvert, - Json::JsonSerializerOptions options - ) - { - return TVariant.From(Json::JsonSerializer.Deserialize(ref reader, options)!); - } - - public override void Write( - Json::Utf8JsonWriter writer, - TVariant value, - Json::JsonSerializerOptions options - ) - { - Json::JsonSerializer.Serialize(writer, value.Value, options); - } -} diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs index c44186a..5033c31 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs @@ -1,4 +1,5 @@ using System.Net.Http; +using Scrapegraphai = Scrapegraphai; using System = System; namespace Scrapegraphai.Models.Crawl; @@ -6,11 +7,11 @@ namespace Scrapegraphai.Models.Crawl; /// /// Retrieve the status and results of a crawling job /// -public sealed record class CrawlRetrieveResultsParams : ParamsBase +public sealed record class CrawlRetrieveResultsParams : Scrapegraphai::ParamsBase { public required string TaskID; - public override System::Uri Url(IScrapegraphaiClient client) + public override System::Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new System::UriBuilder( client.BaseUrl.ToString().TrimEnd('/') + string.Format("/crawl/{0}", this.TaskID) @@ -20,12 +21,15 @@ public sealed record class CrawlRetrieveResultsParams : ParamsBase }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs index dbe2bf2..445f4e1 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs @@ -3,13 +3,14 @@ using System.Text.Json.Serialization; using CrawlRetrieveResultsResponseProperties = Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; using Json = System.Text.Json; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Crawl; -[JsonConverter(typeof(ModelConverter))] +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] public sealed record class CrawlRetrieveResultsResponse - : ModelBase, - IFromRaw + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { /// /// Successful crawl results @@ -23,7 +24,7 @@ public sealed record class CrawlRetrieveResultsResponse return Json::JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["result"] = Json::JsonSerializer.SerializeToElement(value); } @@ -38,7 +39,7 @@ public sealed record class CrawlRetrieveResultsResponse return Json::JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = Json::JsonSerializer.SerializeToElement(value); } @@ -51,7 +52,10 @@ public string? TaskID if (!this.Properties.TryGetValue("task_id", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["task_id"] = Json::JsonSerializer.SerializeToElement(value); } } @@ -66,7 +70,10 @@ public string? Traceback if (!this.Properties.TryGetValue("traceback", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["traceback"] = Json::JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs index 469461a..28df8c1 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs @@ -1,13 +1,15 @@ +using System.Collections.Generic; using System.Text.Json.Serialization; using Json = System.Text.Json; using ResultVariants = Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.ResultVariants; +using System = System; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; /// /// Successful crawl results /// -[JsonConverter(typeof(UnionConverter))] +[JsonConverter(typeof(ResultConverter))] public abstract record class Result { internal Result() { } @@ -19,3 +21,56 @@ public static implicit operator Result(Json::JsonElement value) => public abstract void Validate(); } + +sealed class ResultConverter : JsonConverter +{ + public override Result? Read( + ref Json::Utf8JsonReader reader, + System::Type _typeToConvert, + Json::JsonSerializerOptions options + ) + { + List exceptions = []; + + try + { + var deserialized = Json::JsonSerializer.Deserialize(ref reader, options); + if (deserialized != null) + { + return new ResultVariants::String(deserialized); + } + } + catch (Json::JsonException e) + { + exceptions.Add(e); + } + + try + { + return new ResultVariants::JsonElement( + Json::JsonSerializer.Deserialize(ref reader, options) + ); + } + catch (Json::JsonException e) + { + exceptions.Add(e); + } + + throw new System::AggregateException(exceptions); + } + + public override void Write( + Json::Utf8JsonWriter writer, + Result value, + Json::JsonSerializerOptions options + ) + { + object variant = value switch + { + ResultVariants::JsonElement(var jsonElement) => jsonElement, + ResultVariants::String(var string1) => string1, + _ => throw new System::ArgumentOutOfRangeException(nameof(value)), + }; + Json::JsonSerializer.Serialize(writer, variant, options); + } +} diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs index 98fdae0..8f94441 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs @@ -1,4 +1,3 @@ -using System.Text.Json.Serialization; using Json = System.Text.Json; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.ResultVariants; @@ -6,7 +5,6 @@ namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.Resu /// /// Successful crawl results /// -[JsonConverter(typeof(VariantConverter))] public sealed record class JsonElement(Json::JsonElement Value) : Result, IVariant @@ -22,7 +20,6 @@ public override void Validate() { } /// /// Error message /// -[JsonConverter(typeof(VariantConverter))] public sealed record class String(string Value) : Result, IVariant { public static String From(string value) diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs index 5c625f6..253c141 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs @@ -1,10 +1,11 @@ using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; using System = System; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Pending = new("PENDING"); diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs index 05a5112..903d762 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs @@ -3,6 +3,7 @@ using System.Text; using CrawlStartParamsProperties = Scrapegraphai.Models.Crawl.CrawlStartParamsProperties; using Json = System.Text.Json; +using Scrapegraphai = Scrapegraphai; using System = System; namespace Scrapegraphai.Models.Crawl; @@ -11,7 +12,7 @@ namespace Scrapegraphai.Models.Crawl; /// Initiate comprehensive website crawling with sitemap support. Supports both AI /// extraction mode and markdown conversion mode. Returns a task ID for async processing. /// -public sealed record class CrawlStartParams : ParamsBase +public sealed record class CrawlStartParams : Scrapegraphai::ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -25,8 +26,10 @@ public required string URL if (!this.BodyProperties.TryGetValue("url", out Json::JsonElement element)) throw new System::ArgumentOutOfRangeException("url", "Missing required argument"); - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new System::ArgumentNullException("url"); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ) ?? throw new System::ArgumentNullException("url"); } set { this.BodyProperties["url"] = Json::JsonSerializer.SerializeToElement(value); } } @@ -41,7 +44,10 @@ public long? Depth if (!this.BodyProperties.TryGetValue("depth", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["depth"] = Json::JsonSerializer.SerializeToElement(value); } } @@ -56,7 +62,10 @@ public bool? ExtractionMode if (!this.BodyProperties.TryGetValue("extraction_mode", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { @@ -74,7 +83,10 @@ public long? MaxPages if (!this.BodyProperties.TryGetValue("max_pages", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["max_pages"] = Json::JsonSerializer.SerializeToElement(value); } } @@ -89,7 +101,10 @@ public string? Prompt if (!this.BodyProperties.TryGetValue("prompt", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["prompt"] = Json::JsonSerializer.SerializeToElement(value); } } @@ -104,7 +119,10 @@ public bool? RenderHeavyJs if (!this.BodyProperties.TryGetValue("render_heavy_js", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { @@ -121,7 +139,7 @@ public bool? RenderHeavyJs return Json::JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.BodyProperties["rules"] = Json::JsonSerializer.SerializeToElement(value); } @@ -139,7 +157,7 @@ public bool? RenderHeavyJs return Json::JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.BodyProperties["schema"] = Json::JsonSerializer.SerializeToElement(value); } @@ -155,12 +173,15 @@ public bool? Sitemap if (!this.BodyProperties.TryGetValue("sitemap", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["sitemap"] = Json::JsonSerializer.SerializeToElement(value); } } - public override System::Uri Url(IScrapegraphaiClient client) + public override System::Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new System::UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/crawl") { @@ -177,12 +198,15 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs index 05f9ead..5820fca 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs @@ -2,11 +2,12 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Crawl.CrawlStartParamsProperties; -[JsonConverter(typeof(ModelConverter))] -public sealed record class Rules : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class Rules : Scrapegraphai::ModelBase, Scrapegraphai::IFromRaw { /// /// URL patterns to exclude from crawling @@ -18,7 +19,10 @@ public List? Exclude if (!this.Properties.TryGetValue("exclude", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["exclude"] = JsonSerializer.SerializeToElement(value); } } @@ -33,7 +37,10 @@ public bool? SameDomain if (!this.Properties.TryGetValue("same_domain", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["same_domain"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs index bdf8aa3..ff02f68 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs @@ -2,11 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; using Json = System.Text.Json; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Crawl; -[JsonConverter(typeof(ModelConverter))] -public sealed record class CrawlStartResponse : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class CrawlStartResponse + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { /// /// Celery task identifier @@ -18,7 +21,10 @@ public string? TaskID if (!this.Properties.TryGetValue("task_id", out Json::JsonElement element)) return null; - return Json::JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return Json::JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["task_id"] = Json::JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs b/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs index 1852494..3e5dc40 100644 --- a/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs +++ b/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs @@ -1,14 +1,15 @@ using System; using System.Net.Http; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Credits; /// /// Retrieve the current credit balance and usage for the authenticated user /// -public sealed record class CreditRetrieveParams : ParamsBase +public sealed record class CreditRetrieveParams : Scrapegraphai::ParamsBase { - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/credits") { @@ -16,12 +17,15 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs b/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs index 79ab16d..a8b1ac5 100644 --- a/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs @@ -2,11 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Credits; -[JsonConverter(typeof(ModelConverter))] -public sealed record class CreditRetrieveResponse : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class CreditRetrieveResponse + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { /// /// Number of credits remaining @@ -18,7 +21,10 @@ public long? RemainingCredits if (!this.Properties.TryGetValue("remaining_credits", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["remaining_credits"] = JsonSerializer.SerializeToElement(value); } } @@ -33,7 +39,10 @@ public long? TotalCreditsUsed if (!this.Properties.TryGetValue("total_credits_used", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["total_credits_used"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs index 8179ff6..5d60384 100644 --- a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs +++ b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs @@ -3,13 +3,14 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Feedback; /// /// Submit feedback for a specific request /// -public sealed record class FeedbackSubmitParams : ParamsBase +public sealed record class FeedbackSubmitParams : Scrapegraphai::ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -23,7 +24,10 @@ public required long Rating if (!this.BodyProperties.TryGetValue("rating", out JsonElement element)) throw new ArgumentOutOfRangeException("rating", "Missing required argument"); - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["rating"] = JsonSerializer.SerializeToElement(value); } } @@ -38,8 +42,10 @@ public required string RequestID if (!this.BodyProperties.TryGetValue("request_id", out JsonElement element)) throw new ArgumentOutOfRangeException("request_id", "Missing required argument"); - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("request_id"); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ) ?? throw new ArgumentNullException("request_id"); } set { this.BodyProperties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -54,12 +60,15 @@ public string? FeedbackText if (!this.BodyProperties.TryGetValue("feedback_text", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["feedback_text"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/feedback") { @@ -76,12 +85,15 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs index 6943d42..942cd33 100644 --- a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs +++ b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs @@ -3,11 +3,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Feedback; -[JsonConverter(typeof(ModelConverter))] -public sealed record class FeedbackSubmitResponse : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class FeedbackSubmitResponse + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? FeedbackID { @@ -16,7 +19,10 @@ public string? FeedbackID if (!this.Properties.TryGetValue("feedback_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["feedback_id"] = JsonSerializer.SerializeToElement(value); } } @@ -28,7 +34,10 @@ public DateTime? FeedbackTimestamp if (!this.Properties.TryGetValue("feedback_timestamp", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["feedback_timestamp"] = JsonSerializer.SerializeToElement(value); } } @@ -40,7 +49,10 @@ public string? Message if (!this.Properties.TryGetValue("message", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["message"] = JsonSerializer.SerializeToElement(value); } } @@ -52,7 +64,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs index caf49b9..0d1ba14 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs @@ -3,6 +3,7 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema; @@ -10,7 +11,7 @@ namespace Scrapegraphai.Models.GenerateSchema; /// Generate or modify JSON schemas based on natural language descriptions. Can create /// new schemas or extend existing ones. /// -public sealed record class GenerateSchemaCreateParams : ParamsBase +public sealed record class GenerateSchemaCreateParams : Scrapegraphai::ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -24,8 +25,10 @@ public required string UserPrompt if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("user_prompt"); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ) ?? throw new ArgumentNullException("user_prompt"); } set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -40,12 +43,15 @@ public JsonElement? ExistingSchema if (!this.BodyProperties.TryGetValue("existing_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["existing_schema"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/generate_schema") { @@ -62,12 +68,15 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs index 29ab8a5..0c678b4 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs @@ -3,13 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using GenerateSchemaCreateResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema; -[JsonConverter(typeof(ModelConverter))] +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] public sealed record class GenerateSchemaCreateResponse - : ModelBase, - IFromRaw + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? Error { @@ -18,7 +19,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -33,7 +37,10 @@ public JsonElement? GeneratedSchema if (!this.Properties.TryGetValue("generated_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } } @@ -48,7 +55,10 @@ public string? RefinedPrompt if (!this.Properties.TryGetValue("refined_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -60,7 +70,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -74,7 +87,7 @@ public string? RequestID return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -87,7 +100,10 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs index 4eca9ee..aad3c51 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs @@ -1,10 +1,11 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Completed = new("completed"); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs index 177ceda..c6841cf 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs @@ -1,16 +1,17 @@ using System; using System.Net.Http; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema; /// /// Retrieve the status and results of a schema generation request /// -public sealed record class GenerateSchemaRetrieveParams : ParamsBase +public sealed record class GenerateSchemaRetrieveParams : Scrapegraphai::ParamsBase { public required string RequestID; - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') @@ -21,12 +22,15 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs index 40674c7..7c7b0c9 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs @@ -1,10 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; using GenerateSchemaRetrieveResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; using GenerateSchemaRetrieveResponseVariants = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseVariants; namespace Scrapegraphai.Models.GenerateSchema; -[JsonConverter(typeof(UnionConverter))] +[JsonConverter(typeof(GenerateSchemaRetrieveResponseConverter))] public abstract record class GenerateSchemaRetrieveResponse { internal GenerateSchemaRetrieveResponse() { } @@ -19,3 +22,74 @@ public static implicit operator GenerateSchemaRetrieveResponse( public abstract void Validate(); } + +sealed class GenerateSchemaRetrieveResponseConverter : JsonConverter +{ + public override GenerateSchemaRetrieveResponse? Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) + { + List exceptions = []; + + try + { + var deserialized = + JsonSerializer.Deserialize( + ref reader, + options + ); + if (deserialized != null) + { + return new GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + try + { + var deserialized = + JsonSerializer.Deserialize( + ref reader, + options + ); + if (deserialized != null) + { + return new GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + throw new AggregateException(exceptions); + } + + public override void Write( + Utf8JsonWriter writer, + GenerateSchemaRetrieveResponse value, + JsonSerializerOptions options + ) + { + object variant = value switch + { + GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse( + var completedSchemaGenerationResponse + ) => completedSchemaGenerationResponse, + GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse( + var failedSchemaGenerationResponse + ) => failedSchemaGenerationResponse, + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }; + JsonSerializer.Serialize(writer, variant, options); + } +} diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs index 1ffd6f9..a5c987c 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs @@ -3,13 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using CompletedSchemaGenerationResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; -[JsonConverter(typeof(ModelConverter))] +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] public sealed record class CompletedSchemaGenerationResponse - : ModelBase, - IFromRaw + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? Error { @@ -18,7 +19,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -30,7 +34,10 @@ public JsonElement? GeneratedSchema if (!this.Properties.TryGetValue("generated_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } } @@ -42,7 +49,10 @@ public string? RefinedPrompt if (!this.Properties.TryGetValue("refined_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -54,7 +64,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -68,7 +81,7 @@ public string? RequestID return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -81,7 +94,10 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs index 4d483ab..6cacdbd 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs @@ -1,10 +1,11 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Completed = new("completed"); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs index 71a0b4b..1ef90b6 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs @@ -3,13 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using FailedSchemaGenerationResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; -[JsonConverter(typeof(ModelConverter))] +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] public sealed record class FailedSchemaGenerationResponse - : ModelBase, - IFromRaw + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? Error { @@ -18,7 +19,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -30,7 +34,10 @@ public JsonElement? GeneratedSchema if (!this.Properties.TryGetValue("generated_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } } @@ -42,7 +49,10 @@ public string? RefinedPrompt if (!this.Properties.TryGetValue("refined_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -54,7 +64,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -68,7 +81,7 @@ public string? RequestID return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -81,7 +94,10 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs index a48da7f..29596b6 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs @@ -1,10 +1,11 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Failed = new("failed"); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs index 34ed2bc..08d60fd 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs @@ -1,14 +1,7 @@ -using System.Text.Json.Serialization; using GenerateSchemaRetrieveResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseVariants; -[JsonConverter( - typeof(VariantConverter< - CompletedSchemaGenerationResponse, - GenerateSchemaRetrieveResponseProperties::CompletedSchemaGenerationResponse - >) -)] public sealed record class CompletedSchemaGenerationResponse( GenerateSchemaRetrieveResponseProperties::CompletedSchemaGenerationResponse Value ) @@ -31,12 +24,6 @@ public override void Validate() } } -[JsonConverter( - typeof(VariantConverter< - FailedSchemaGenerationResponse, - GenerateSchemaRetrieveResponseProperties::FailedSchemaGenerationResponse - >) -)] public sealed record class FailedSchemaGenerationResponse( GenerateSchemaRetrieveResponseProperties::FailedSchemaGenerationResponse Value ) diff --git a/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs b/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs index 380c72f..41fcbb4 100644 --- a/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs +++ b/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs @@ -1,14 +1,15 @@ using System; using System.Net.Http; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Healthz; /// /// Check the health status of the service /// -public sealed record class HealthzCheckParams : ParamsBase +public sealed record class HealthzCheckParams : Scrapegraphai::ParamsBase { - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/healthz") { @@ -16,12 +17,15 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs b/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs index c0add17..898a197 100644 --- a/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs +++ b/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs @@ -2,11 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Healthz; -[JsonConverter(typeof(ModelConverter))] -public sealed record class HealthzCheckResponse : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class HealthzCheckResponse + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public Dictionary? Services { @@ -17,7 +20,7 @@ public Dictionary? Services return JsonSerializer.Deserialize?>( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["services"] = JsonSerializer.SerializeToElement(value); } @@ -30,7 +33,10 @@ public string? Status if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs index 57e9bb3..a9c28e8 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs @@ -3,11 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using CompletedMarkdownifyProperties = Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify; -[JsonConverter(typeof(ModelConverter))] -public sealed record class CompletedMarkdownify : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class CompletedMarkdownify + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? Error { @@ -16,7 +19,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -28,7 +34,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -43,7 +52,10 @@ public string? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } @@ -57,7 +69,7 @@ public string? Result return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -70,7 +82,10 @@ public string? WebsiteURL if (!this.Properties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs index 120745c..6bf7fb3 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs @@ -1,10 +1,11 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Queued = new("queued"); diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs index d7116a1..fd3ae46 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs @@ -3,13 +3,14 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify; /// /// Convert web page content to clean Markdown format /// -public sealed record class MarkdownifyConvertParams : ParamsBase +public sealed record class MarkdownifyConvertParams : Scrapegraphai::ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -23,8 +24,10 @@ public required string WebsiteURL if (!this.BodyProperties.TryGetValue("website_url", out JsonElement element)) throw new ArgumentOutOfRangeException("website_url", "Missing required argument"); - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("website_url"); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ) ?? throw new ArgumentNullException("website_url"); } set { this.BodyProperties["website_url"] = JsonSerializer.SerializeToElement(value); } } @@ -38,7 +41,7 @@ public Dictionary? Headers return JsonSerializer.Deserialize?>( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } @@ -54,12 +57,15 @@ public List? Steps if (!this.BodyProperties.TryGetValue("steps", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["steps"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/markdownify") { @@ -76,12 +82,15 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs index d644411..a14db7f 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs @@ -1,16 +1,17 @@ using System; using System.Net.Http; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify; /// /// Retrieve the status and results of a markdown conversion /// -public sealed record class MarkdownifyRetrieveStatusParams : ParamsBase +public sealed record class MarkdownifyRetrieveStatusParams : Scrapegraphai::ParamsBase { public required string RequestID; - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') @@ -21,12 +22,15 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index 14cbb10..f98ba1d 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -1,10 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; using MarkdownifyRetrieveStatusResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; using MarkdownifyRetrieveStatusResponseVariants = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseVariants; namespace Scrapegraphai.Models.Markdownify; -[JsonConverter(typeof(UnionConverter))] +[JsonConverter(typeof(MarkdownifyRetrieveStatusResponseConverter))] public abstract record class MarkdownifyRetrieveStatusResponse { internal MarkdownifyRetrieveStatusResponse() { } @@ -18,3 +21,74 @@ public static implicit operator MarkdownifyRetrieveStatusResponse( public abstract void Validate(); } + +sealed class MarkdownifyRetrieveStatusResponseConverter + : JsonConverter +{ + public override MarkdownifyRetrieveStatusResponse? Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) + { + List exceptions = []; + + try + { + var deserialized = JsonSerializer.Deserialize( + ref reader, + options + ); + if (deserialized != null) + { + return new MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + try + { + var deserialized = + JsonSerializer.Deserialize( + ref reader, + options + ); + if (deserialized != null) + { + return new MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + throw new AggregateException(exceptions); + } + + public override void Write( + Utf8JsonWriter writer, + MarkdownifyRetrieveStatusResponse value, + JsonSerializerOptions options + ) + { + object variant = value switch + { + MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant( + var completedMarkdownify + ) => completedMarkdownify, + MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse( + var failedMarkdownifyResponse + ) => failedMarkdownifyResponse, + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }; + JsonSerializer.Serialize(writer, variant, options); + } +} diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs index d6c3a9f..c76175c 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs @@ -3,13 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using FailedMarkdownifyResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; -[JsonConverter(typeof(ModelConverter))] +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] public sealed record class FailedMarkdownifyResponse - : ModelBase, - IFromRaw + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? Error { @@ -18,7 +19,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -30,7 +34,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -42,7 +49,10 @@ public string? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } @@ -56,7 +66,7 @@ public string? Result return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -69,7 +79,10 @@ public string? WebsiteURL if (!this.Properties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs index 20130f5..4450555 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs @@ -1,10 +1,11 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Failed = new("failed"); diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs index 220c593..4c380dd 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs @@ -1,14 +1,13 @@ -using System.Text.Json.Serialization; +using Markdownify = Scrapegraphai.Models.Markdownify; using MarkdownifyRetrieveStatusResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseVariants; -[JsonConverter(typeof(VariantConverter))] -public sealed record class CompletedMarkdownifyVariant(CompletedMarkdownify Value) - : MarkdownifyRetrieveStatusResponse, - IVariant +public sealed record class CompletedMarkdownifyVariant(Markdownify::CompletedMarkdownify Value) + : Markdownify::MarkdownifyRetrieveStatusResponse, + IVariant { - public static CompletedMarkdownifyVariant From(CompletedMarkdownify value) + public static CompletedMarkdownifyVariant From(Markdownify::CompletedMarkdownify value) { return new(value); } @@ -19,16 +18,10 @@ public override void Validate() } } -[JsonConverter( - typeof(VariantConverter< - FailedMarkdownifyResponse, - MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse - >) -)] public sealed record class FailedMarkdownifyResponse( MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse Value ) - : MarkdownifyRetrieveStatusResponse, + : Markdownify::MarkdownifyRetrieveStatusResponse, IVariant< FailedMarkdownifyResponse, MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs index afc1c90..a6e4868 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs @@ -3,11 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using CompletedSearchScraperProperties = Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper; -[JsonConverter(typeof(ModelConverter))] -public sealed record class CompletedSearchScraper : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class CompletedSearchScraper + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? Error { @@ -16,7 +19,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -28,7 +34,10 @@ public long? NumResults if (!this.Properties.TryGetValue("num_results", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["num_results"] = JsonSerializer.SerializeToElement(value); } } @@ -43,7 +52,10 @@ public List? ReferenceURLs if (!this.Properties.TryGetValue("reference_urls", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["reference_urls"] = JsonSerializer.SerializeToElement(value); } } @@ -55,7 +67,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -70,7 +85,10 @@ public JsonElement? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } @@ -84,7 +102,7 @@ public JsonElement? Result return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -97,7 +115,10 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs index 30eca60..1651bff 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs @@ -1,10 +1,11 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Queued = new("queued"); diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs index bd23365..b7fe84e 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs @@ -3,6 +3,7 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper; @@ -11,7 +12,7 @@ namespace Scrapegraphai.Models.Searchscraper; /// multiple websites. Uses LLM to refine search queries and merge results from different /// sources. /// -public sealed record class SearchscraperCreateParams : ParamsBase +public sealed record class SearchscraperCreateParams : Scrapegraphai::ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -25,8 +26,10 @@ public required string UserPrompt if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("user_prompt"); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ) ?? throw new ArgumentNullException("user_prompt"); } set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -40,7 +43,7 @@ public Dictionary? Headers return JsonSerializer.Deserialize?>( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } @@ -56,7 +59,10 @@ public long? NumResults if (!this.BodyProperties.TryGetValue("num_results", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["num_results"] = JsonSerializer.SerializeToElement(value); } } @@ -71,12 +77,15 @@ public JsonElement? OutputSchema if (!this.BodyProperties.TryGetValue("output_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["output_schema"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/searchscraper") { @@ -93,12 +102,15 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs index a7f4d89..1cd0bfa 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs @@ -1,16 +1,17 @@ using System; using System.Net.Http; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper; /// /// Retrieve the status and results of a search scraping operation /// -public sealed record class SearchscraperRetrieveStatusParams : ParamsBase +public sealed record class SearchscraperRetrieveStatusParams : Scrapegraphai::ParamsBase { public required string RequestID; - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') @@ -21,12 +22,15 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index fa4cd94..205ca06 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -1,10 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; using SearchscraperRetrieveStatusResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; using SearchscraperRetrieveStatusResponseVariants = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseVariants; namespace Scrapegraphai.Models.Searchscraper; -[JsonConverter(typeof(UnionConverter))] +[JsonConverter(typeof(SearchscraperRetrieveStatusResponseConverter))] public abstract record class SearchscraperRetrieveStatusResponse { internal SearchscraperRetrieveStatusResponse() { } @@ -19,3 +22,74 @@ public static implicit operator SearchscraperRetrieveStatusResponse( public abstract void Validate(); } + +sealed class SearchscraperRetrieveStatusResponseConverter + : JsonConverter +{ + public override SearchscraperRetrieveStatusResponse? Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) + { + List exceptions = []; + + try + { + var deserialized = JsonSerializer.Deserialize( + ref reader, + options + ); + if (deserialized != null) + { + return new SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + try + { + var deserialized = + JsonSerializer.Deserialize( + ref reader, + options + ); + if (deserialized != null) + { + return new SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + throw new AggregateException(exceptions); + } + + public override void Write( + Utf8JsonWriter writer, + SearchscraperRetrieveStatusResponse value, + JsonSerializerOptions options + ) + { + object variant = value switch + { + SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant( + var completedSearchScraper + ) => completedSearchScraper, + SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse( + var failedSearchScraperResponse + ) => failedSearchScraperResponse, + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }; + JsonSerializer.Serialize(writer, variant, options); + } +} diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs index a851e8c..6cbc0cc 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs @@ -3,13 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using FailedSearchScraperResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; -[JsonConverter(typeof(ModelConverter))] +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] public sealed record class FailedSearchScraperResponse - : ModelBase, - IFromRaw + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? Error { @@ -18,7 +19,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -30,7 +34,10 @@ public long? NumResults if (!this.Properties.TryGetValue("num_results", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["num_results"] = JsonSerializer.SerializeToElement(value); } } @@ -42,7 +49,10 @@ public List? ReferenceURLs if (!this.Properties.TryGetValue("reference_urls", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["reference_urls"] = JsonSerializer.SerializeToElement(value); } } @@ -54,7 +64,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -66,7 +79,10 @@ public JsonElement? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } @@ -80,7 +96,7 @@ public JsonElement? Result return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -93,7 +109,10 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs index 90d596e..d061514 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs @@ -1,10 +1,11 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Failed = new("failed"); diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs index 0c442eb..a00a061 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs @@ -1,14 +1,15 @@ -using System.Text.Json.Serialization; +using Searchscraper = Scrapegraphai.Models.Searchscraper; using SearchscraperRetrieveStatusResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseVariants; -[JsonConverter(typeof(VariantConverter))] -public sealed record class CompletedSearchScraperVariant(CompletedSearchScraper Value) - : SearchscraperRetrieveStatusResponse, - IVariant +public sealed record class CompletedSearchScraperVariant( + Searchscraper::CompletedSearchScraper Value +) + : Searchscraper::SearchscraperRetrieveStatusResponse, + IVariant { - public static CompletedSearchScraperVariant From(CompletedSearchScraper value) + public static CompletedSearchScraperVariant From(Searchscraper::CompletedSearchScraper value) { return new(value); } @@ -19,16 +20,10 @@ public override void Validate() } } -[JsonConverter( - typeof(VariantConverter< - FailedSearchScraperResponse, - SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse - >) -)] public sealed record class FailedSearchScraperResponse( SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse Value ) - : SearchscraperRetrieveStatusResponse, + : Searchscraper::SearchscraperRetrieveStatusResponse, IVariant< FailedSearchScraperResponse, SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs index 0a92304..021c8e3 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs @@ -3,11 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using CompletedSmartscraperProperties = Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper; -[JsonConverter(typeof(ModelConverter))] -public sealed record class CompletedSmartscraper : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class CompletedSmartscraper + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { /// /// Error message (empty on success) @@ -19,7 +22,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -34,7 +40,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -49,7 +58,10 @@ public JsonElement? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } @@ -66,7 +78,7 @@ public JsonElement? Result return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -79,7 +91,10 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -91,7 +106,10 @@ public string? WebsiteURL if (!this.Properties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs index 4bf36cb..712ae52 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs @@ -1,13 +1,14 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; /// /// Processing status /// -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Queued = new("queued"); diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs index 0b05778..14867a3 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs @@ -3,11 +3,14 @@ using System.Text.Json; using System.Text.Json.Serialization; using FailedSmartscraperProperties = Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper; -[JsonConverter(typeof(ModelConverter))] -public sealed record class FailedSmartscraper : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class FailedSmartscraper + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { /// /// Error description @@ -19,7 +22,10 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -31,7 +37,10 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -43,7 +52,10 @@ public JsonElement? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } @@ -57,7 +69,7 @@ public JsonElement? Result return JsonSerializer.Deserialize( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } @@ -70,7 +82,10 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -82,7 +97,10 @@ public string? WebsiteURL if (!this.Properties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs index f38c89f..583366f 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs @@ -1,10 +1,11 @@ using System; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(Scrapegraphai::EnumConverter))] +public sealed record class Status(string value) : Scrapegraphai::IEnum { public static readonly Status Failed = new("failed"); diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs index ef8e33e..3c4b69f 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs @@ -3,6 +3,7 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper; @@ -10,7 +11,7 @@ namespace Scrapegraphai.Models.Smartscraper; /// Main scraping endpoint with LLM-powered content analysis. Supports various fetching /// providers, infinite scrolling, pagination, and custom output schemas. /// -public sealed record class SmartscraperCreateParams : ParamsBase +public sealed record class SmartscraperCreateParams : Scrapegraphai::ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -24,8 +25,10 @@ public required string UserPrompt if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("user_prompt"); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ) ?? throw new ArgumentNullException("user_prompt"); } set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -42,7 +45,7 @@ public Dictionary? Cookies return JsonSerializer.Deserialize?>( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.BodyProperties["cookies"] = JsonSerializer.SerializeToElement(value); } @@ -60,7 +63,7 @@ public Dictionary? Headers return JsonSerializer.Deserialize?>( element, - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ); } set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } @@ -76,7 +79,10 @@ public long? NumberOfScrolls if (!this.BodyProperties.TryGetValue("number_of_scrolls", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["number_of_scrolls"] = JsonSerializer.SerializeToElement(value); } } @@ -91,7 +97,10 @@ public JsonElement? OutputSchema if (!this.BodyProperties.TryGetValue("output_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["output_schema"] = JsonSerializer.SerializeToElement(value); } } @@ -106,7 +115,10 @@ public bool? RenderHeavyJs if (!this.BodyProperties.TryGetValue("render_heavy_js", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["render_heavy_js"] = JsonSerializer.SerializeToElement(value); } } @@ -121,7 +133,10 @@ public List? Steps if (!this.BodyProperties.TryGetValue("steps", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["steps"] = JsonSerializer.SerializeToElement(value); } } @@ -136,7 +151,10 @@ public long? TotalPages if (!this.BodyProperties.TryGetValue("total_pages", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["total_pages"] = JsonSerializer.SerializeToElement(value); } } @@ -151,7 +169,10 @@ public string? WebsiteHTML if (!this.BodyProperties.TryGetValue("website_html", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["website_html"] = JsonSerializer.SerializeToElement(value); } } @@ -166,12 +187,15 @@ public string? WebsiteURL if (!this.BodyProperties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.BodyProperties["website_url"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/smartscraper") { @@ -188,12 +212,15 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs index 01727b5..90e8388 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs @@ -1,14 +1,15 @@ using System; using System.Net.Http; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper; /// /// Retrieve the status and results of a scraping operation /// -public sealed record class SmartscraperListParams : ParamsBase +public sealed record class SmartscraperListParams : Scrapegraphai::ParamsBase { - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/smartscraper") { @@ -16,12 +17,15 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs index 1797ed7..060548e 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs @@ -1,9 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; using SmartscraperListResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; namespace Scrapegraphai.Models.Smartscraper; -[JsonConverter(typeof(UnionConverter))] +[JsonConverter(typeof(SmartscraperListResponseConverter))] public abstract record class SmartscraperListResponse { internal SmartscraperListResponse() { } @@ -16,3 +19,68 @@ public static implicit operator SmartscraperListResponse(FailedSmartscraper valu public abstract void Validate(); } + +sealed class SmartscraperListResponseConverter : JsonConverter +{ + public override SmartscraperListResponse? Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) + { + List exceptions = []; + + try + { + var deserialized = JsonSerializer.Deserialize( + ref reader, + options + ); + if (deserialized != null) + { + return new SmartscraperListResponseVariants::CompletedSmartscraperVariant( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + try + { + var deserialized = JsonSerializer.Deserialize(ref reader, options); + if (deserialized != null) + { + return new SmartscraperListResponseVariants::FailedSmartscraperVariant( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + throw new AggregateException(exceptions); + } + + public override void Write( + Utf8JsonWriter writer, + SmartscraperListResponse value, + JsonSerializerOptions options + ) + { + object variant = value switch + { + SmartscraperListResponseVariants::CompletedSmartscraperVariant( + var completedSmartscraper + ) => completedSmartscraper, + SmartscraperListResponseVariants::FailedSmartscraperVariant(var failedSmartscraper) => + failedSmartscraper, + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }; + JsonSerializer.Serialize(writer, variant, options); + } +} diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs index 5ccc0fa..0d0730a 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs @@ -1,13 +1,12 @@ -using System.Text.Json.Serialization; +using Smartscraper = Scrapegraphai.Models.Smartscraper; namespace Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; -[JsonConverter(typeof(VariantConverter))] -public sealed record class CompletedSmartscraperVariant(CompletedSmartscraper Value) - : SmartscraperListResponse, - IVariant +public sealed record class CompletedSmartscraperVariant(Smartscraper::CompletedSmartscraper Value) + : Smartscraper::SmartscraperListResponse, + IVariant { - public static CompletedSmartscraperVariant From(CompletedSmartscraper value) + public static CompletedSmartscraperVariant From(Smartscraper::CompletedSmartscraper value) { return new(value); } @@ -18,12 +17,11 @@ public override void Validate() } } -[JsonConverter(typeof(VariantConverter))] -public sealed record class FailedSmartscraperVariant(FailedSmartscraper Value) - : SmartscraperListResponse, - IVariant +public sealed record class FailedSmartscraperVariant(Smartscraper::FailedSmartscraper Value) + : Smartscraper::SmartscraperListResponse, + IVariant { - public static FailedSmartscraperVariant From(FailedSmartscraper value) + public static FailedSmartscraperVariant From(Smartscraper::FailedSmartscraper value) { return new(value); } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs index 68dcbce..b512fc2 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs @@ -1,16 +1,17 @@ using System; using System.Net.Http; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper; /// /// Retrieve the status and results of a scraping operation /// -public sealed record class SmartscraperRetrieveParams : ParamsBase +public sealed record class SmartscraperRetrieveParams : Scrapegraphai::ParamsBase { public required string RequestID; - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') @@ -21,12 +22,15 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs index a40547b..da938a8 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs @@ -1,9 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; using SmartscraperRetrieveResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; namespace Scrapegraphai.Models.Smartscraper; -[JsonConverter(typeof(UnionConverter))] +[JsonConverter(typeof(SmartscraperRetrieveResponseConverter))] public abstract record class SmartscraperRetrieveResponse { internal SmartscraperRetrieveResponse() { } @@ -16,3 +19,69 @@ public static implicit operator SmartscraperRetrieveResponse(FailedSmartscraper public abstract void Validate(); } + +sealed class SmartscraperRetrieveResponseConverter : JsonConverter +{ + public override SmartscraperRetrieveResponse? Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) + { + List exceptions = []; + + try + { + var deserialized = JsonSerializer.Deserialize( + ref reader, + options + ); + if (deserialized != null) + { + return new SmartscraperRetrieveResponseVariants::CompletedSmartscraperVariant( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + try + { + var deserialized = JsonSerializer.Deserialize(ref reader, options); + if (deserialized != null) + { + return new SmartscraperRetrieveResponseVariants::FailedSmartscraperVariant( + deserialized + ); + } + } + catch (JsonException e) + { + exceptions.Add(e); + } + + throw new AggregateException(exceptions); + } + + public override void Write( + Utf8JsonWriter writer, + SmartscraperRetrieveResponse value, + JsonSerializerOptions options + ) + { + object variant = value switch + { + SmartscraperRetrieveResponseVariants::CompletedSmartscraperVariant( + var completedSmartscraper + ) => completedSmartscraper, + SmartscraperRetrieveResponseVariants::FailedSmartscraperVariant( + var failedSmartscraper + ) => failedSmartscraper, + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }; + JsonSerializer.Serialize(writer, variant, options); + } +} diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs index b85460c..e3214d3 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs @@ -1,13 +1,12 @@ -using System.Text.Json.Serialization; +using Smartscraper = Scrapegraphai.Models.Smartscraper; namespace Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; -[JsonConverter(typeof(VariantConverter))] -public sealed record class CompletedSmartscraperVariant(CompletedSmartscraper Value) - : SmartscraperRetrieveResponse, - IVariant +public sealed record class CompletedSmartscraperVariant(Smartscraper::CompletedSmartscraper Value) + : Smartscraper::SmartscraperRetrieveResponse, + IVariant { - public static CompletedSmartscraperVariant From(CompletedSmartscraper value) + public static CompletedSmartscraperVariant From(Smartscraper::CompletedSmartscraper value) { return new(value); } @@ -18,12 +17,11 @@ public override void Validate() } } -[JsonConverter(typeof(VariantConverter))] -public sealed record class FailedSmartscraperVariant(FailedSmartscraper Value) - : SmartscraperRetrieveResponse, - IVariant +public sealed record class FailedSmartscraperVariant(Smartscraper::FailedSmartscraper Value) + : Smartscraper::SmartscraperRetrieveResponse, + IVariant { - public static FailedSmartscraperVariant From(FailedSmartscraper value) + public static FailedSmartscraperVariant From(Smartscraper::FailedSmartscraper value) { return new(value); } diff --git a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs index bd8cc21..a51adb0 100644 --- a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs +++ b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs @@ -1,14 +1,15 @@ using System; using System.Net.Http; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Validate; /// /// Validate the API key and retrieve associated user email /// -public sealed record class ValidateAPIKeyParams : ParamsBase +public sealed record class ValidateAPIKeyParams : Scrapegraphai::ParamsBase { - public override Uri Url(IScrapegraphaiClient client) + public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/validate") { @@ -16,12 +17,15 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + public void AddHeadersToRequest( + HttpRequestMessage request, + Scrapegraphai::IScrapegraphaiClient client + ) { - ParamsBase.AddDefaultHeaders(request, client); + Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs index 743d108..01b497d 100644 --- a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs +++ b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs @@ -2,11 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Validate; -[JsonConverter(typeof(ModelConverter))] -public sealed record class ValidateAPIKeyResponse : ModelBase, IFromRaw +[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +public sealed record class ValidateAPIKeyResponse + : Scrapegraphai::ModelBase, + Scrapegraphai::IFromRaw { public string? Email { @@ -15,7 +18,10 @@ public string? Email if (!this.Properties.TryGetValue("email", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize( + element, + Scrapegraphai::ModelBase.SerializerOptions + ); } set { this.Properties["email"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Services/Crawl/CrawlService.cs b/src/Scrapegraphai/Services/Crawl/CrawlService.cs index b15fba1..fe93cb6 100644 --- a/src/Scrapegraphai/Services/Crawl/CrawlService.cs +++ b/src/Scrapegraphai/Services/Crawl/CrawlService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Crawl; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Crawl; public sealed class CrawlService : ICrawlService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public CrawlService(IScrapegraphaiClient client) + public CrawlService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -26,7 +27,7 @@ CrawlRetrieveResultsParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -34,7 +35,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -50,7 +51,7 @@ public async Task Start(CrawlStartParams parameters) .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -58,7 +59,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Credits/CreditService.cs b/src/Scrapegraphai/Services/Credits/CreditService.cs index 5eb6b4e..0197a5c 100644 --- a/src/Scrapegraphai/Services/Credits/CreditService.cs +++ b/src/Scrapegraphai/Services/Credits/CreditService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Credits; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Credits; public sealed class CreditService : ICreditService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public CreditService(IScrapegraphaiClient client) + public CreditService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -24,7 +25,7 @@ public async Task Retrieve(CreditRetrieveParams paramete .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -32,7 +33,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Feedback/FeedbackService.cs b/src/Scrapegraphai/Services/Feedback/FeedbackService.cs index ab17e9a..a36b25b 100644 --- a/src/Scrapegraphai/Services/Feedback/FeedbackService.cs +++ b/src/Scrapegraphai/Services/Feedback/FeedbackService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Feedback; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Feedback; public sealed class FeedbackService : IFeedbackService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public FeedbackService(IScrapegraphaiClient client) + public FeedbackService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -27,7 +28,7 @@ public async Task Submit(FeedbackSubmitParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -35,7 +36,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs b/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs index db4a5e8..6c83147 100644 --- a/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs +++ b/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.GenerateSchema; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.GenerateSchema; public sealed class GenerateSchemaService : IGenerateSchemaService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public GenerateSchemaService(IScrapegraphaiClient client) + public GenerateSchemaService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -27,7 +28,7 @@ public async Task Create(GenerateSchemaCreateParam .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -35,7 +36,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -50,7 +51,7 @@ GenerateSchemaRetrieveParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -58,7 +59,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Healthz/HealthzService.cs b/src/Scrapegraphai/Services/Healthz/HealthzService.cs index 38caeb3..cb56362 100644 --- a/src/Scrapegraphai/Services/Healthz/HealthzService.cs +++ b/src/Scrapegraphai/Services/Healthz/HealthzService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Healthz; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Healthz; public sealed class HealthzService : IHealthzService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public HealthzService(IScrapegraphaiClient client) + public HealthzService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -24,7 +25,7 @@ public async Task Check(HealthzCheckParams parameters) .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -32,7 +33,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs b/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs index b102e9a..f18adb9 100644 --- a/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs +++ b/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Markdownify; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Markdownify; public sealed class MarkdownifyService : IMarkdownifyService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public MarkdownifyService(IScrapegraphaiClient client) + public MarkdownifyService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -27,7 +28,7 @@ public async Task Convert(MarkdownifyConvertParams paramet .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -35,7 +36,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -50,7 +51,7 @@ MarkdownifyRetrieveStatusParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -58,7 +59,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs b/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs index e033ae3..31ccb64 100644 --- a/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs +++ b/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Searchscraper; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Searchscraper; public sealed class SearchscraperService : ISearchscraperService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public SearchscraperService(IScrapegraphaiClient client) + public SearchscraperService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -27,7 +28,7 @@ public async Task Create(SearchscraperCreateParams param .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -35,7 +36,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -50,7 +51,7 @@ SearchscraperRetrieveStatusParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -58,7 +59,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs b/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs index 129d753..97848e0 100644 --- a/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs +++ b/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Smartscraper; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Smartscraper; public sealed class SmartscraperService : ISmartscraperService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public SmartscraperService(IScrapegraphaiClient client) + public SmartscraperService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -27,7 +28,7 @@ public async Task Create(SmartscraperCreateParams paramet .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -35,7 +36,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -48,7 +49,7 @@ public async Task Retrieve(SmartscraperRetrievePar .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -56,7 +57,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -69,7 +70,7 @@ public async Task List(SmartscraperListParams paramete .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -77,7 +78,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Validate/ValidateService.cs b/src/Scrapegraphai/Services/Validate/ValidateService.cs index 1f5aeb0..d152044 100644 --- a/src/Scrapegraphai/Services/Validate/ValidateService.cs +++ b/src/Scrapegraphai/Services/Validate/ValidateService.cs @@ -3,14 +3,15 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Validate; +using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Validate; public sealed class ValidateService : IValidateService { - readonly IScrapegraphaiClient _client; + readonly Scrapegraphai::IScrapegraphaiClient _client; - public ValidateService(IScrapegraphaiClient client) + public ValidateService(Scrapegraphai::IScrapegraphaiClient client) { _client = client; } @@ -24,7 +25,7 @@ public async Task APIKey(ValidateAPIKeyParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new HttpException( + throw new Scrapegraphai::HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -32,7 +33,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions + Scrapegraphai::ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } From 1529f4fa633537e3dfcf942d3898b400b074009c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 13 Aug 2025 18:38:15 +0000 Subject: [PATCH 03/21] fix(docs): re-order using statements --- .editorconfig | 2 +- README.md | 2 +- src/Scrapegraphai.Tests/Scrapegraphai.Tests.csproj | 2 ++ src/Scrapegraphai/Scrapegraphai.csproj | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0ba6c1e..b7feeac 100644 --- a/.editorconfig +++ b/.editorconfig @@ -23,4 +23,4 @@ insert_final_newline = true dotnet_diagnostic.IDE0060.severity = none # Caused by resource with no methods and no subresources dotnet_diagnostic.IDE1006.severity = none # Some names may not match up with C# conventions -dotnet_diagnostic.IDE0290.severity = none # Don't prefer primary constructors \ No newline at end of file +dotnet_diagnostic.IDE0290.severity = none # Don't prefer primary constructors diff --git a/README.md b/README.md index 8d2d27e..2cc123b 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,9 @@ This library requires .NET 8 or later. See the [`examples`](examples) directory for complete and runnable examples. ```csharp +using System; using Scrapegraphai; using Scrapegraphai.Models.Smartscraper; -using System; // Configured using the SCRAPEGRAPHAI_API_KEY and SCRAPEGRAPHAI_BASE_URL environment variables ScrapegraphaiClient client = new(); diff --git a/src/Scrapegraphai.Tests/Scrapegraphai.Tests.csproj b/src/Scrapegraphai.Tests/Scrapegraphai.Tests.csproj index ea0fc3b..16b86ea 100644 --- a/src/Scrapegraphai.Tests/Scrapegraphai.Tests.csproj +++ b/src/Scrapegraphai.Tests/Scrapegraphai.Tests.csproj @@ -4,6 +4,8 @@ false true disable + + $(NoWarn),xUnit1004 diff --git a/src/Scrapegraphai/Scrapegraphai.csproj b/src/Scrapegraphai/Scrapegraphai.csproj index 14da859..8118a1b 100644 --- a/src/Scrapegraphai/Scrapegraphai.csproj +++ b/src/Scrapegraphai/Scrapegraphai.csproj @@ -19,7 +19,7 @@ true $(NoWarn),1570,1573,1574,1591 - + $(NoWarn),IL2026,IL3050 Debug;Release Date: Sun, 17 Aug 2025 02:13:46 +0000 Subject: [PATCH 04/21] chore(internal): remove unnecessary internal aliasing --- src/Scrapegraphai/HttpException.cs | 4 +- src/Scrapegraphai/IScrapegraphaiClient.cs | 44 +++---- src/Scrapegraphai/JsonConverters.cs | 38 +++--- src/Scrapegraphai/ModelBase.cs | 12 +- .../Crawl/CrawlRetrieveResultsParams.cs | 18 +-- .../Crawl/CrawlRetrieveResultsResponse.cs | 55 +++----- .../Result.cs | 34 +++-- .../Status.cs | 9 +- .../Models/Crawl/CrawlStartParams.cs | 120 ++++++------------ .../Crawl/CrawlStartParamsProperties/Rules.cs | 15 +-- .../Models/Crawl/CrawlStartResponse.cs | 24 ++-- .../Models/Credits/CreditRetrieveParams.cs | 14 +- .../Models/Credits/CreditRetrieveResponse.cs | 17 +-- .../Models/Feedback/FeedbackSubmitParams.cs | 30 ++--- .../Models/Feedback/FeedbackSubmitResponse.cs | 27 +--- .../GenerateSchemaCreateParams.cs | 25 ++-- .../GenerateSchemaCreateResponse.cs | 41 ++---- .../Status.cs | 5 +- .../GenerateSchemaRetrieveParams.cs | 14 +- .../GenerateSchemaRetrieveResponse.cs | 24 ++-- .../CompletedSchemaGenerationResponse.cs | 41 ++---- .../Status.cs | 5 +- .../FailedSchemaGenerationResponse.cs | 41 ++---- .../Status.cs | 5 +- .../Models/Healthz/HealthzCheckParams.cs | 14 +- .../Models/Healthz/HealthzCheckResponse.cs | 14 +- .../Markdownify/CompletedMarkdownify.cs | 36 ++---- .../CompletedMarkdownifyProperties/Status.cs | 5 +- .../Markdownify/MarkdownifyConvertParams.cs | 27 ++-- .../MarkdownifyRetrieveStatusParams.cs | 14 +- .../MarkdownifyRetrieveStatusResponse.cs | 13 +- .../FailedMarkdownifyResponse.cs | 36 ++---- .../Status.cs | 5 +- .../All.cs | 11 +- .../Searchscraper/CompletedSearchScraper.cs | 46 ++----- .../Status.cs | 5 +- .../SearchscraperCreateParams.cs | 32 ++--- .../SearchscraperRetrieveStatusParams.cs | 14 +- .../SearchscraperRetrieveStatusResponse.cs | 13 +- .../FailedSearchScraperResponse.cs | 46 ++----- .../Status.cs | 5 +- .../All.cs | 13 +- .../Smartscraper/CompletedSmartscraper.cs | 41 ++---- .../CompletedSmartscraperProperties/Status.cs | 5 +- .../Models/Smartscraper/FailedSmartscraper.cs | 41 ++---- .../FailedSmartscraperProperties/Status.cs | 5 +- .../Smartscraper/SmartscraperCreateParams.cs | 59 +++------ .../Smartscraper/SmartscraperListParams.cs | 14 +- .../Smartscraper/SmartscraperListResponse.cs | 21 +-- .../SmartscraperListResponseVariants/All.cs | 18 ++- .../SmartscraperRetrieveParams.cs | 14 +- .../SmartscraperRetrieveResponse.cs | 22 +--- .../All.cs | 18 ++- .../Models/Validate/ValidateAPIKeyParams.cs | 14 +- .../Models/Validate/ValidateAPIKeyResponse.cs | 12 +- src/Scrapegraphai/ParamsBase.cs | 58 ++++----- src/Scrapegraphai/ScrapegraphaiClient.cs | 92 +++++++------- .../Services/Crawl/CrawlService.cs | 13 +- .../Services/Credits/CreditService.cs | 9 +- .../Services/Feedback/FeedbackService.cs | 9 +- .../GenerateSchema/GenerateSchemaService.cs | 13 +- .../Services/Healthz/HealthzService.cs | 9 +- .../Markdownify/MarkdownifyService.cs | 13 +- .../Searchscraper/SearchscraperService.cs | 13 +- .../Smartscraper/SmartscraperService.cs | 17 ++- .../Services/Validate/ValidateService.cs | 9 +- 66 files changed, 554 insertions(+), 996 deletions(-) diff --git a/src/Scrapegraphai/HttpException.cs b/src/Scrapegraphai/HttpException.cs index 58588dc..3cadf97 100644 --- a/src/Scrapegraphai/HttpException.cs +++ b/src/Scrapegraphai/HttpException.cs @@ -1,10 +1,10 @@ +using System; using System.Diagnostics.CodeAnalysis; using System.Net; -using System = System; namespace Scrapegraphai; -public sealed class HttpException : System::Exception +public sealed class HttpException : Exception { public required HttpStatusCode? StatusCode { get; set; } public required string ResponseBody { get; set; } diff --git a/src/Scrapegraphai/IScrapegraphaiClient.cs b/src/Scrapegraphai/IScrapegraphaiClient.cs index 7dde273..689eb27 100644 --- a/src/Scrapegraphai/IScrapegraphaiClient.cs +++ b/src/Scrapegraphai/IScrapegraphaiClient.cs @@ -1,43 +1,43 @@ -using Crawl = Scrapegraphai.Services.Crawl; -using Credits = Scrapegraphai.Services.Credits; -using Feedback = Scrapegraphai.Services.Feedback; -using GenerateSchema = Scrapegraphai.Services.GenerateSchema; -using Healthz = Scrapegraphai.Services.Healthz; -using Http = System.Net.Http; -using Markdownify = Scrapegraphai.Services.Markdownify; -using Searchscraper = Scrapegraphai.Services.Searchscraper; -using Smartscraper = Scrapegraphai.Services.Smartscraper; -using System = System; -using Validate = Scrapegraphai.Services.Validate; +using System; +using System.Net.Http; +using Scrapegraphai.Services.Crawl; +using Scrapegraphai.Services.Credits; +using Scrapegraphai.Services.Feedback; +using Scrapegraphai.Services.GenerateSchema; +using Scrapegraphai.Services.Healthz; +using Scrapegraphai.Services.Markdownify; +using Scrapegraphai.Services.Searchscraper; +using Scrapegraphai.Services.Smartscraper; +using Scrapegraphai.Services.Validate; namespace Scrapegraphai; public interface IScrapegraphaiClient { - Http::HttpClient HttpClient { get; init; } + HttpClient HttpClient { get; init; } - System::Uri BaseUrl { get; init; } + Uri BaseUrl { get; init; } /// /// API key for authentication /// string APIKey { get; init; } - Smartscraper::ISmartscraperService Smartscraper { get; } + ISmartscraperService Smartscraper { get; } - Markdownify::IMarkdownifyService Markdownify { get; } + IMarkdownifyService Markdownify { get; } - Searchscraper::ISearchscraperService Searchscraper { get; } + ISearchscraperService Searchscraper { get; } - GenerateSchema::IGenerateSchemaService GenerateSchema { get; } + IGenerateSchemaService GenerateSchema { get; } - Crawl::ICrawlService Crawl { get; } + ICrawlService Crawl { get; } - Credits::ICreditService Credits { get; } + ICreditService Credits { get; } - Validate::IValidateService Validate { get; } + IValidateService Validate { get; } - Feedback::IFeedbackService Feedback { get; } + IFeedbackService Feedback { get; } - Healthz::IHealthzService Healthz { get; } + IHealthzService Healthz { get; } } diff --git a/src/Scrapegraphai/JsonConverters.cs b/src/Scrapegraphai/JsonConverters.cs index a859c09..626113a 100644 --- a/src/Scrapegraphai/JsonConverters.cs +++ b/src/Scrapegraphai/JsonConverters.cs @@ -1,7 +1,7 @@ +using System; using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; -using Json = System.Text.Json; -using System = System; namespace Scrapegraphai; @@ -9,13 +9,13 @@ sealed class ModelConverter : JsonConverter where TModel : ModelBase, IFromRaw { public override TModel? Read( - ref Json::Utf8JsonReader reader, - System::Type _typeToConvert, - Json::JsonSerializerOptions options + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options ) { - Dictionary? properties = Json::JsonSerializer.Deserialize< - Dictionary + Dictionary? properties = JsonSerializer.Deserialize< + Dictionary >(ref reader, options); if (properties == null) return null; @@ -23,13 +23,9 @@ sealed class ModelConverter : JsonConverter return TModel.FromRawUnchecked(properties); } - public override void Write( - Json::Utf8JsonWriter writer, - TModel value, - Json::JsonSerializerOptions options - ) + public override void Write(Utf8JsonWriter writer, TModel value, JsonSerializerOptions options) { - Json::JsonSerializer.Serialize(writer, value.Properties, options); + JsonSerializer.Serialize(writer, value.Properties, options); } } @@ -37,20 +33,16 @@ sealed class EnumConverter : JsonConverter where TEnum : IEnum { public override TEnum Read( - ref Json::Utf8JsonReader reader, - System::Type _typeToConvert, - Json::JsonSerializerOptions options + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options ) { - return TEnum.FromRaw(Json::JsonSerializer.Deserialize(ref reader, options)!); + return TEnum.FromRaw(JsonSerializer.Deserialize(ref reader, options)!); } - public override void Write( - Json::Utf8JsonWriter writer, - TEnum value, - Json::JsonSerializerOptions options - ) + public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options) { - Json::JsonSerializer.Serialize(writer, value.Raw(), options); + JsonSerializer.Serialize(writer, value.Raw(), options); } } diff --git a/src/Scrapegraphai/ModelBase.cs b/src/Scrapegraphai/ModelBase.cs index 6fc7538..55b4f7b 100644 --- a/src/Scrapegraphai/ModelBase.cs +++ b/src/Scrapegraphai/ModelBase.cs @@ -1,22 +1,22 @@ using System.Collections.Generic; -using Json = System.Text.Json; +using System.Text.Json; namespace Scrapegraphai; public abstract record class ModelBase { - public Dictionary Properties { get; set; } = []; + public Dictionary Properties { get; set; } = []; - internal static readonly Json::JsonSerializerOptions SerializerOptions = new(); + internal static readonly JsonSerializerOptions SerializerOptions = new(); - static readonly Json::JsonSerializerOptions _toStringSerializerOptions = new(SerializerOptions) + static readonly JsonSerializerOptions _toStringSerializerOptions = new(SerializerOptions) { WriteIndented = true, }; public sealed override string? ToString() { - return Json::JsonSerializer.Serialize(this.Properties, _toStringSerializerOptions); + return JsonSerializer.Serialize(this.Properties, _toStringSerializerOptions); } public abstract void Validate(); @@ -24,5 +24,5 @@ public abstract record class ModelBase interface IFromRaw { - static abstract T FromRawUnchecked(Dictionary properties); + static abstract T FromRawUnchecked(Dictionary properties); } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs index 5033c31..1be6120 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs @@ -1,19 +1,18 @@ +using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; -using System = System; namespace Scrapegraphai.Models.Crawl; /// /// Retrieve the status and results of a crawling job /// -public sealed record class CrawlRetrieveResultsParams : Scrapegraphai::ParamsBase +public sealed record class CrawlRetrieveResultsParams : ParamsBase { public required string TaskID; - public override System::Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { - return new System::UriBuilder( + return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') + string.Format("/crawl/{0}", this.TaskID) ) { @@ -21,15 +20,12 @@ public sealed record class CrawlRetrieveResultsParams : Scrapegraphai::ParamsBas }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs index 445f4e1..e280129 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs @@ -1,63 +1,53 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Text.Json; using System.Text.Json.Serialization; -using CrawlRetrieveResultsResponseProperties = Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; -using Json = System.Text.Json; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; namespace Scrapegraphai.Models.Crawl; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +[JsonConverter(typeof(ModelConverter))] public sealed record class CrawlRetrieveResultsResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw + : ModelBase, + IFromRaw { /// /// Successful crawl results /// - public CrawlRetrieveResultsResponseProperties::Result? Result + public Result? Result { get { - if (!this.Properties.TryGetValue("result", out Json::JsonElement element)) + if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["result"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } - public CrawlRetrieveResultsResponseProperties::Status? Status + public Status? Status { get { - if (!this.Properties.TryGetValue("status", out Json::JsonElement element)) + if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["status"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? TaskID { get { - if (!this.Properties.TryGetValue("task_id", out Json::JsonElement element)) + if (!this.Properties.TryGetValue("task_id", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["task_id"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.Properties["task_id"] = JsonSerializer.SerializeToElement(value); } } /// @@ -67,15 +57,12 @@ public string? Traceback { get { - if (!this.Properties.TryGetValue("traceback", out Json::JsonElement element)) + if (!this.Properties.TryGetValue("traceback", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["traceback"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.Properties["traceback"] = JsonSerializer.SerializeToElement(value); } } public override void Validate() @@ -90,14 +77,14 @@ public CrawlRetrieveResultsResponse() { } #pragma warning disable CS8618 [SetsRequiredMembers] - CrawlRetrieveResultsResponse(Dictionary properties) + CrawlRetrieveResultsResponse(Dictionary properties) { Properties = properties; } #pragma warning restore CS8618 public static CrawlRetrieveResultsResponse FromRawUnchecked( - Dictionary properties + Dictionary properties ) { return new(properties); diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs index 28df8c1..b3d2864 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs @@ -1,8 +1,8 @@ +using System; using System.Collections.Generic; +using System.Text.Json; using System.Text.Json.Serialization; -using Json = System.Text.Json; using ResultVariants = Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.ResultVariants; -using System = System; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; @@ -14,7 +14,7 @@ public abstract record class Result { internal Result() { } - public static implicit operator Result(Json::JsonElement value) => + public static implicit operator Result(JsonElement value) => new ResultVariants::JsonElement(value); public static implicit operator Result(string value) => new ResultVariants::String(value); @@ -25,22 +25,22 @@ public static implicit operator Result(Json::JsonElement value) => sealed class ResultConverter : JsonConverter { public override Result? Read( - ref Json::Utf8JsonReader reader, - System::Type _typeToConvert, - Json::JsonSerializerOptions options + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options ) { - List exceptions = []; + List exceptions = []; try { - var deserialized = Json::JsonSerializer.Deserialize(ref reader, options); + var deserialized = JsonSerializer.Deserialize(ref reader, options); if (deserialized != null) { return new ResultVariants::String(deserialized); } } - catch (Json::JsonException e) + catch (JsonException e) { exceptions.Add(e); } @@ -48,29 +48,25 @@ sealed class ResultConverter : JsonConverter try { return new ResultVariants::JsonElement( - Json::JsonSerializer.Deserialize(ref reader, options) + JsonSerializer.Deserialize(ref reader, options) ); } - catch (Json::JsonException e) + catch (JsonException e) { exceptions.Add(e); } - throw new System::AggregateException(exceptions); + throw new AggregateException(exceptions); } - public override void Write( - Json::Utf8JsonWriter writer, - Result value, - Json::JsonSerializerOptions options - ) + public override void Write(Utf8JsonWriter writer, Result value, JsonSerializerOptions options) { object variant = value switch { ResultVariants::JsonElement(var jsonElement) => jsonElement, ResultVariants::String(var string1) => string1, - _ => throw new System::ArgumentOutOfRangeException(nameof(value)), + _ => throw new ArgumentOutOfRangeException(nameof(value)), }; - Json::JsonSerializer.Serialize(writer, variant, options); + JsonSerializer.Serialize(writer, variant, options); } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs index 253c141..69bfaac 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs @@ -1,11 +1,10 @@ +using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; -using System = System; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Pending = new("PENDING"); @@ -40,7 +39,7 @@ public Value Known() => "FAILURE" => Value.Failure, "RETRY" => Value.Retry, "REVOKED" => Value.Revoked, - _ => throw new System::ArgumentOutOfRangeException(nameof(_value)), + _ => throw new ArgumentOutOfRangeException(nameof(_value)), }; public string Raw() diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs index 903d762..cdca862 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs @@ -1,10 +1,9 @@ +using System; using System.Collections.Generic; using System.Net.Http; using System.Text; -using CrawlStartParamsProperties = Scrapegraphai.Models.Crawl.CrawlStartParamsProperties; -using Json = System.Text.Json; -using Scrapegraphai = Scrapegraphai; -using System = System; +using System.Text.Json; +using Scrapegraphai.Models.Crawl.CrawlStartParamsProperties; namespace Scrapegraphai.Models.Crawl; @@ -12,9 +11,9 @@ namespace Scrapegraphai.Models.Crawl; /// Initiate comprehensive website crawling with sitemap support. Supports both AI /// extraction mode and markdown conversion mode. Returns a task ID for async processing. /// -public sealed record class CrawlStartParams : Scrapegraphai::ParamsBase +public sealed record class CrawlStartParams : ParamsBase { - public Dictionary BodyProperties { get; set; } = []; + public Dictionary BodyProperties { get; set; } = []; /// /// Starting URL for crawling @@ -23,15 +22,13 @@ public required string URL { get { - if (!this.BodyProperties.TryGetValue("url", out Json::JsonElement element)) - throw new System::ArgumentOutOfRangeException("url", "Missing required argument"); + if (!this.BodyProperties.TryGetValue("url", out JsonElement element)) + throw new ArgumentOutOfRangeException("url", "Missing required argument"); - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ) ?? throw new System::ArgumentNullException("url"); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ArgumentNullException("url"); } - set { this.BodyProperties["url"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.BodyProperties["url"] = JsonSerializer.SerializeToElement(value); } } /// @@ -41,15 +38,12 @@ public long? Depth { get { - if (!this.BodyProperties.TryGetValue("depth", out Json::JsonElement element)) + if (!this.BodyProperties.TryGetValue("depth", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["depth"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.BodyProperties["depth"] = JsonSerializer.SerializeToElement(value); } } /// @@ -59,18 +53,12 @@ public bool? ExtractionMode { get { - if (!this.BodyProperties.TryGetValue("extraction_mode", out Json::JsonElement element)) + if (!this.BodyProperties.TryGetValue("extraction_mode", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); - } - set - { - this.BodyProperties["extraction_mode"] = Json::JsonSerializer.SerializeToElement(value); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } + set { this.BodyProperties["extraction_mode"] = JsonSerializer.SerializeToElement(value); } } /// @@ -80,15 +68,12 @@ public long? MaxPages { get { - if (!this.BodyProperties.TryGetValue("max_pages", out Json::JsonElement element)) + if (!this.BodyProperties.TryGetValue("max_pages", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["max_pages"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.BodyProperties["max_pages"] = JsonSerializer.SerializeToElement(value); } } /// @@ -98,15 +83,12 @@ public string? Prompt { get { - if (!this.BodyProperties.TryGetValue("prompt", out Json::JsonElement element)) + if (!this.BodyProperties.TryGetValue("prompt", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["prompt"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.BodyProperties["prompt"] = JsonSerializer.SerializeToElement(value); } } /// @@ -116,51 +98,39 @@ public bool? RenderHeavyJs { get { - if (!this.BodyProperties.TryGetValue("render_heavy_js", out Json::JsonElement element)) + if (!this.BodyProperties.TryGetValue("render_heavy_js", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); - } - set - { - this.BodyProperties["render_heavy_js"] = Json::JsonSerializer.SerializeToElement(value); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } + set { this.BodyProperties["render_heavy_js"] = JsonSerializer.SerializeToElement(value); } } - public CrawlStartParamsProperties::Rules? Rules + public Rules? Rules { get { - if (!this.BodyProperties.TryGetValue("rules", out Json::JsonElement element)) + if (!this.BodyProperties.TryGetValue("rules", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["rules"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.BodyProperties["rules"] = JsonSerializer.SerializeToElement(value); } } /// /// Output schema for extraction /// - public Json::JsonElement? Schema + public JsonElement? Schema { get { - if (!this.BodyProperties.TryGetValue("schema", out Json::JsonElement element)) + if (!this.BodyProperties.TryGetValue("schema", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["schema"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.BodyProperties["schema"] = JsonSerializer.SerializeToElement(value); } } /// @@ -170,20 +140,17 @@ public bool? Sitemap { get { - if (!this.BodyProperties.TryGetValue("sitemap", out Json::JsonElement element)) + if (!this.BodyProperties.TryGetValue("sitemap", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["sitemap"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.BodyProperties["sitemap"] = JsonSerializer.SerializeToElement(value); } } - public override System::Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { - return new System::UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/crawl") + return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/crawl") { Query = this.QueryString(client), }.Uri; @@ -192,21 +159,18 @@ public bool? Sitemap public StringContent BodyContent() { return new( - Json::JsonSerializer.Serialize(this.BodyProperties), + JsonSerializer.Serialize(this.BodyProperties), Encoding.UTF8, "application/json" ); } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs index 5820fca..05f9ead 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs @@ -2,12 +2,11 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Crawl.CrawlStartParamsProperties; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class Rules : Scrapegraphai::ModelBase, Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class Rules : ModelBase, IFromRaw { /// /// URL patterns to exclude from crawling @@ -19,10 +18,7 @@ public List? Exclude if (!this.Properties.TryGetValue("exclude", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } set { this.Properties["exclude"] = JsonSerializer.SerializeToElement(value); } } @@ -37,10 +33,7 @@ public bool? SameDomain if (!this.Properties.TryGetValue("same_domain", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["same_domain"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs index ff02f68..03bb95c 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs @@ -1,15 +1,12 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Text.Json; using System.Text.Json.Serialization; -using Json = System.Text.Json; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Crawl; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class CrawlStartResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class CrawlStartResponse : ModelBase, IFromRaw { /// /// Celery task identifier @@ -18,15 +15,12 @@ public string? TaskID { get { - if (!this.Properties.TryGetValue("task_id", out Json::JsonElement element)) + if (!this.Properties.TryGetValue("task_id", out JsonElement element)) return null; - return Json::JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["task_id"] = Json::JsonSerializer.SerializeToElement(value); } + set { this.Properties["task_id"] = JsonSerializer.SerializeToElement(value); } } public override void Validate() @@ -38,15 +32,13 @@ public CrawlStartResponse() { } #pragma warning disable CS8618 [SetsRequiredMembers] - CrawlStartResponse(Dictionary properties) + CrawlStartResponse(Dictionary properties) { Properties = properties; } #pragma warning restore CS8618 - public static CrawlStartResponse FromRawUnchecked( - Dictionary properties - ) + public static CrawlStartResponse FromRawUnchecked(Dictionary properties) { return new(properties); } diff --git a/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs b/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs index 3e5dc40..1852494 100644 --- a/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs +++ b/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs @@ -1,15 +1,14 @@ using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Credits; /// /// Retrieve the current credit balance and usage for the authenticated user /// -public sealed record class CreditRetrieveParams : Scrapegraphai::ParamsBase +public sealed record class CreditRetrieveParams : ParamsBase { - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/credits") { @@ -17,15 +16,12 @@ public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs b/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs index a8b1ac5..79ab16d 100644 --- a/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs @@ -2,14 +2,11 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Credits; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class CreditRetrieveResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class CreditRetrieveResponse : ModelBase, IFromRaw { /// /// Number of credits remaining @@ -21,10 +18,7 @@ public long? RemainingCredits if (!this.Properties.TryGetValue("remaining_credits", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["remaining_credits"] = JsonSerializer.SerializeToElement(value); } } @@ -39,10 +33,7 @@ public long? TotalCreditsUsed if (!this.Properties.TryGetValue("total_credits_used", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["total_credits_used"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs index 5d60384..8179ff6 100644 --- a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs +++ b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs @@ -3,14 +3,13 @@ using System.Net.Http; using System.Text; using System.Text.Json; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Feedback; /// /// Submit feedback for a specific request /// -public sealed record class FeedbackSubmitParams : Scrapegraphai::ParamsBase +public sealed record class FeedbackSubmitParams : ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -24,10 +23,7 @@ public required long Rating if (!this.BodyProperties.TryGetValue("rating", out JsonElement element)) throw new ArgumentOutOfRangeException("rating", "Missing required argument"); - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["rating"] = JsonSerializer.SerializeToElement(value); } } @@ -42,10 +38,8 @@ public required string RequestID if (!this.BodyProperties.TryGetValue("request_id", out JsonElement element)) throw new ArgumentOutOfRangeException("request_id", "Missing required argument"); - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ) ?? throw new ArgumentNullException("request_id"); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ArgumentNullException("request_id"); } set { this.BodyProperties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -60,15 +54,12 @@ public string? FeedbackText if (!this.BodyProperties.TryGetValue("feedback_text", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["feedback_text"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/feedback") { @@ -85,15 +76,12 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs index 942cd33..6943d42 100644 --- a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs +++ b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs @@ -3,14 +3,11 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Feedback; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class FeedbackSubmitResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class FeedbackSubmitResponse : ModelBase, IFromRaw { public string? FeedbackID { @@ -19,10 +16,7 @@ public string? FeedbackID if (!this.Properties.TryGetValue("feedback_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["feedback_id"] = JsonSerializer.SerializeToElement(value); } } @@ -34,10 +28,7 @@ public DateTime? FeedbackTimestamp if (!this.Properties.TryGetValue("feedback_timestamp", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["feedback_timestamp"] = JsonSerializer.SerializeToElement(value); } } @@ -49,10 +40,7 @@ public string? Message if (!this.Properties.TryGetValue("message", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["message"] = JsonSerializer.SerializeToElement(value); } } @@ -64,10 +52,7 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs index 0d1ba14..caf49b9 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Text; using System.Text.Json; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema; @@ -11,7 +10,7 @@ namespace Scrapegraphai.Models.GenerateSchema; /// Generate or modify JSON schemas based on natural language descriptions. Can create /// new schemas or extend existing ones. /// -public sealed record class GenerateSchemaCreateParams : Scrapegraphai::ParamsBase +public sealed record class GenerateSchemaCreateParams : ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -25,10 +24,8 @@ public required string UserPrompt if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ) ?? throw new ArgumentNullException("user_prompt"); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ArgumentNullException("user_prompt"); } set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -43,15 +40,12 @@ public JsonElement? ExistingSchema if (!this.BodyProperties.TryGetValue("existing_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["existing_schema"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/generate_schema") { @@ -68,15 +62,12 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs index 0c678b4..bbd088d 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs @@ -2,15 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using GenerateSchemaCreateResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; namespace Scrapegraphai.Models.GenerateSchema; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +[JsonConverter(typeof(ModelConverter))] public sealed record class GenerateSchemaCreateResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw + : ModelBase, + IFromRaw { public string? Error { @@ -19,10 +18,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -37,10 +33,7 @@ public JsonElement? GeneratedSchema if (!this.Properties.TryGetValue("generated_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } } @@ -55,10 +48,7 @@ public string? RefinedPrompt if (!this.Properties.TryGetValue("refined_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -70,25 +60,19 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } - public GenerateSchemaCreateResponseProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -100,10 +84,7 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs index aad3c51..4eca9ee 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs @@ -1,11 +1,10 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Completed = new("completed"); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs index c6841cf..177ceda 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs @@ -1,17 +1,16 @@ using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema; /// /// Retrieve the status and results of a schema generation request /// -public sealed record class GenerateSchemaRetrieveParams : Scrapegraphai::ParamsBase +public sealed record class GenerateSchemaRetrieveParams : ParamsBase { public required string RequestID; - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') @@ -22,15 +21,12 @@ public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs index 7c7b0c9..f499d7e 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using GenerateSchemaRetrieveResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; +using Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; using GenerateSchemaRetrieveResponseVariants = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseVariants; namespace Scrapegraphai.Models.GenerateSchema; @@ -13,11 +13,11 @@ public abstract record class GenerateSchemaRetrieveResponse internal GenerateSchemaRetrieveResponse() { } public static implicit operator GenerateSchemaRetrieveResponse( - GenerateSchemaRetrieveResponseProperties::CompletedSchemaGenerationResponse value + CompletedSchemaGenerationResponse value ) => new GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse(value); public static implicit operator GenerateSchemaRetrieveResponse( - GenerateSchemaRetrieveResponseProperties::FailedSchemaGenerationResponse value + FailedSchemaGenerationResponse value ) => new GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse(value); public abstract void Validate(); @@ -35,11 +35,10 @@ JsonSerializerOptions options try { - var deserialized = - JsonSerializer.Deserialize( - ref reader, - options - ); + var deserialized = JsonSerializer.Deserialize( + ref reader, + options + ); if (deserialized != null) { return new GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse( @@ -54,11 +53,10 @@ JsonSerializerOptions options try { - var deserialized = - JsonSerializer.Deserialize( - ref reader, - options - ); + var deserialized = JsonSerializer.Deserialize( + ref reader, + options + ); if (deserialized != null) { return new GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse( diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs index a5c987c..9c60171 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs @@ -2,15 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using CompletedSchemaGenerationResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +[JsonConverter(typeof(ModelConverter))] public sealed record class CompletedSchemaGenerationResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw + : ModelBase, + IFromRaw { public string? Error { @@ -19,10 +18,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -34,10 +30,7 @@ public JsonElement? GeneratedSchema if (!this.Properties.TryGetValue("generated_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } } @@ -49,10 +42,7 @@ public string? RefinedPrompt if (!this.Properties.TryGetValue("refined_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -64,25 +54,19 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } - public CompletedSchemaGenerationResponseProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -94,10 +78,7 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs index 6cacdbd..4d483ab 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs @@ -1,11 +1,10 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Completed = new("completed"); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs index 1ef90b6..a426aea 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs @@ -2,15 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using FailedSchemaGenerationResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +[JsonConverter(typeof(ModelConverter))] public sealed record class FailedSchemaGenerationResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw + : ModelBase, + IFromRaw { public string? Error { @@ -19,10 +18,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -34,10 +30,7 @@ public JsonElement? GeneratedSchema if (!this.Properties.TryGetValue("generated_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } } @@ -49,10 +42,7 @@ public string? RefinedPrompt if (!this.Properties.TryGetValue("refined_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -64,25 +54,19 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } - public FailedSchemaGenerationResponseProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -94,10 +78,7 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs index 29596b6..a48da7f 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs @@ -1,11 +1,10 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Failed = new("failed"); diff --git a/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs b/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs index 41fcbb4..380c72f 100644 --- a/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs +++ b/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs @@ -1,15 +1,14 @@ using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Healthz; /// /// Check the health status of the service /// -public sealed record class HealthzCheckParams : Scrapegraphai::ParamsBase +public sealed record class HealthzCheckParams : ParamsBase { - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/healthz") { @@ -17,15 +16,12 @@ public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs b/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs index 898a197..c0add17 100644 --- a/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs +++ b/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs @@ -2,14 +2,11 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Healthz; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class HealthzCheckResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class HealthzCheckResponse : ModelBase, IFromRaw { public Dictionary? Services { @@ -20,7 +17,7 @@ public Dictionary? Services return JsonSerializer.Deserialize?>( element, - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ); } set { this.Properties["services"] = JsonSerializer.SerializeToElement(value); } @@ -33,10 +30,7 @@ public string? Status if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs index a9c28e8..6e04941 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs @@ -2,15 +2,12 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using CompletedMarkdownifyProperties = Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; namespace Scrapegraphai.Models.Markdownify; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class CompletedMarkdownify - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class CompletedMarkdownify : ModelBase, IFromRaw { public string? Error { @@ -19,10 +16,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -34,10 +28,7 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -52,25 +43,19 @@ public string? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } - public CompletedMarkdownifyProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -82,10 +67,7 @@ public string? WebsiteURL if (!this.Properties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs index 6bf7fb3..120745c 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs @@ -1,11 +1,10 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Queued = new("queued"); diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs index fd3ae46..d7116a1 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs @@ -3,14 +3,13 @@ using System.Net.Http; using System.Text; using System.Text.Json; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify; /// /// Convert web page content to clean Markdown format /// -public sealed record class MarkdownifyConvertParams : Scrapegraphai::ParamsBase +public sealed record class MarkdownifyConvertParams : ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -24,10 +23,8 @@ public required string WebsiteURL if (!this.BodyProperties.TryGetValue("website_url", out JsonElement element)) throw new ArgumentOutOfRangeException("website_url", "Missing required argument"); - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ) ?? throw new ArgumentNullException("website_url"); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ArgumentNullException("website_url"); } set { this.BodyProperties["website_url"] = JsonSerializer.SerializeToElement(value); } } @@ -41,7 +38,7 @@ public Dictionary? Headers return JsonSerializer.Deserialize?>( element, - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ); } set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } @@ -57,15 +54,12 @@ public List? Steps if (!this.BodyProperties.TryGetValue("steps", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } set { this.BodyProperties["steps"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/markdownify") { @@ -82,15 +76,12 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs index a14db7f..d644411 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs @@ -1,17 +1,16 @@ using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify; /// /// Retrieve the status and results of a markdown conversion /// -public sealed record class MarkdownifyRetrieveStatusParams : Scrapegraphai::ParamsBase +public sealed record class MarkdownifyRetrieveStatusParams : ParamsBase { public required string RequestID; - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') @@ -22,15 +21,12 @@ public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index f98ba1d..74c02f1 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using MarkdownifyRetrieveStatusResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; +using Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; using MarkdownifyRetrieveStatusResponseVariants = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseVariants; namespace Scrapegraphai.Models.Markdownify; @@ -16,7 +16,7 @@ public static implicit operator MarkdownifyRetrieveStatusResponse(CompletedMarkd new MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant(value); public static implicit operator MarkdownifyRetrieveStatusResponse( - MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse value + FailedMarkdownifyResponse value ) => new MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse(value); public abstract void Validate(); @@ -53,11 +53,10 @@ JsonSerializerOptions options try { - var deserialized = - JsonSerializer.Deserialize( - ref reader, - options - ); + var deserialized = JsonSerializer.Deserialize( + ref reader, + options + ); if (deserialized != null) { return new MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse( diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs index c76175c..ad4f435 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs @@ -2,15 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using FailedMarkdownifyResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +[JsonConverter(typeof(ModelConverter))] public sealed record class FailedMarkdownifyResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw + : ModelBase, + IFromRaw { public string? Error { @@ -19,10 +18,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -34,10 +30,7 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -49,25 +42,19 @@ public string? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } - public FailedMarkdownifyResponseProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -79,10 +66,7 @@ public string? WebsiteURL if (!this.Properties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs index 4450555..20130f5 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs @@ -1,11 +1,10 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Failed = new("failed"); diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs index 4c380dd..45c8fad 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs @@ -1,13 +1,12 @@ -using Markdownify = Scrapegraphai.Models.Markdownify; using MarkdownifyRetrieveStatusResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseVariants; -public sealed record class CompletedMarkdownifyVariant(Markdownify::CompletedMarkdownify Value) - : Markdownify::MarkdownifyRetrieveStatusResponse, - IVariant +public sealed record class CompletedMarkdownifyVariant(CompletedMarkdownify Value) + : MarkdownifyRetrieveStatusResponse, + IVariant { - public static CompletedMarkdownifyVariant From(Markdownify::CompletedMarkdownify value) + public static CompletedMarkdownifyVariant From(CompletedMarkdownify value) { return new(value); } @@ -21,7 +20,7 @@ public override void Validate() public sealed record class FailedMarkdownifyResponse( MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse Value ) - : Markdownify::MarkdownifyRetrieveStatusResponse, + : MarkdownifyRetrieveStatusResponse, IVariant< FailedMarkdownifyResponse, MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs index a6e4868..955b92f 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs @@ -2,15 +2,12 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using CompletedSearchScraperProperties = Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; namespace Scrapegraphai.Models.Searchscraper; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class CompletedSearchScraper - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class CompletedSearchScraper : ModelBase, IFromRaw { public string? Error { @@ -19,10 +16,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -34,10 +28,7 @@ public long? NumResults if (!this.Properties.TryGetValue("num_results", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["num_results"] = JsonSerializer.SerializeToElement(value); } } @@ -52,10 +43,7 @@ public List? ReferenceURLs if (!this.Properties.TryGetValue("reference_urls", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } set { this.Properties["reference_urls"] = JsonSerializer.SerializeToElement(value); } } @@ -67,10 +55,7 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -85,25 +70,19 @@ public JsonElement? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } - public CompletedSearchScraperProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -115,10 +94,7 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs index 1651bff..30eca60 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs @@ -1,11 +1,10 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Queued = new("queued"); diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs index b7fe84e..bd23365 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Text; using System.Text.Json; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper; @@ -12,7 +11,7 @@ namespace Scrapegraphai.Models.Searchscraper; /// multiple websites. Uses LLM to refine search queries and merge results from different /// sources. /// -public sealed record class SearchscraperCreateParams : Scrapegraphai::ParamsBase +public sealed record class SearchscraperCreateParams : ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -26,10 +25,8 @@ public required string UserPrompt if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ) ?? throw new ArgumentNullException("user_prompt"); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ArgumentNullException("user_prompt"); } set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -43,7 +40,7 @@ public Dictionary? Headers return JsonSerializer.Deserialize?>( element, - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ); } set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } @@ -59,10 +56,7 @@ public long? NumResults if (!this.BodyProperties.TryGetValue("num_results", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["num_results"] = JsonSerializer.SerializeToElement(value); } } @@ -77,15 +71,12 @@ public JsonElement? OutputSchema if (!this.BodyProperties.TryGetValue("output_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["output_schema"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/searchscraper") { @@ -102,15 +93,12 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs index 1cd0bfa..a7f4d89 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs @@ -1,17 +1,16 @@ using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper; /// /// Retrieve the status and results of a search scraping operation /// -public sealed record class SearchscraperRetrieveStatusParams : Scrapegraphai::ParamsBase +public sealed record class SearchscraperRetrieveStatusParams : ParamsBase { public required string RequestID; - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') @@ -22,15 +21,12 @@ public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index 205ca06..49df8e9 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using SearchscraperRetrieveStatusResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; +using Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; using SearchscraperRetrieveStatusResponseVariants = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseVariants; namespace Scrapegraphai.Models.Searchscraper; @@ -17,7 +17,7 @@ CompletedSearchScraper value ) => new SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant(value); public static implicit operator SearchscraperRetrieveStatusResponse( - SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse value + FailedSearchScraperResponse value ) => new SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse(value); public abstract void Validate(); @@ -54,11 +54,10 @@ JsonSerializerOptions options try { - var deserialized = - JsonSerializer.Deserialize( - ref reader, - options - ); + var deserialized = JsonSerializer.Deserialize( + ref reader, + options + ); if (deserialized != null) { return new SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse( diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs index 6cbc0cc..478bbdc 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs @@ -2,15 +2,14 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using FailedSearchScraperResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] +[JsonConverter(typeof(ModelConverter))] public sealed record class FailedSearchScraperResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw + : ModelBase, + IFromRaw { public string? Error { @@ -19,10 +18,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -34,10 +30,7 @@ public long? NumResults if (!this.Properties.TryGetValue("num_results", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["num_results"] = JsonSerializer.SerializeToElement(value); } } @@ -49,10 +42,7 @@ public List? ReferenceURLs if (!this.Properties.TryGetValue("reference_urls", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } set { this.Properties["reference_urls"] = JsonSerializer.SerializeToElement(value); } } @@ -64,10 +54,7 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -79,25 +66,19 @@ public JsonElement? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } - public FailedSearchScraperResponseProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -109,10 +90,7 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs index d061514..90d596e 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs @@ -1,11 +1,10 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Failed = new("failed"); diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs index a00a061..7e4aa70 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs @@ -1,15 +1,12 @@ -using Searchscraper = Scrapegraphai.Models.Searchscraper; using SearchscraperRetrieveStatusResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseVariants; -public sealed record class CompletedSearchScraperVariant( - Searchscraper::CompletedSearchScraper Value -) - : Searchscraper::SearchscraperRetrieveStatusResponse, - IVariant +public sealed record class CompletedSearchScraperVariant(CompletedSearchScraper Value) + : SearchscraperRetrieveStatusResponse, + IVariant { - public static CompletedSearchScraperVariant From(Searchscraper::CompletedSearchScraper value) + public static CompletedSearchScraperVariant From(CompletedSearchScraper value) { return new(value); } @@ -23,7 +20,7 @@ public override void Validate() public sealed record class FailedSearchScraperResponse( SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse Value ) - : Searchscraper::SearchscraperRetrieveStatusResponse, + : SearchscraperRetrieveStatusResponse, IVariant< FailedSearchScraperResponse, SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs index 021c8e3..005d2cd 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs @@ -2,15 +2,12 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using CompletedSmartscraperProperties = Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; namespace Scrapegraphai.Models.Smartscraper; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class CompletedSmartscraper - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class CompletedSmartscraper : ModelBase, IFromRaw { /// /// Error message (empty on success) @@ -22,10 +19,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -40,10 +34,7 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -58,10 +49,7 @@ public JsonElement? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } @@ -69,17 +57,14 @@ public JsonElement? Result /// /// Processing status /// - public CompletedSmartscraperProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -91,10 +76,7 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -106,10 +88,7 @@ public string? WebsiteURL if (!this.Properties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs index 712ae52..4bf36cb 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs @@ -1,14 +1,13 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; /// /// Processing status /// -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Queued = new("queued"); diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs index 14867a3..fddf44c 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs @@ -2,15 +2,12 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using FailedSmartscraperProperties = Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; -using Scrapegraphai = Scrapegraphai; +using Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; namespace Scrapegraphai.Models.Smartscraper; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class FailedSmartscraper - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class FailedSmartscraper : ModelBase, IFromRaw { /// /// Error description @@ -22,10 +19,7 @@ public string? Error if (!this.Properties.TryGetValue("error", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } } @@ -37,10 +31,7 @@ public string? RequestID if (!this.Properties.TryGetValue("request_id", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } } @@ -52,25 +43,19 @@ public JsonElement? Result if (!this.Properties.TryGetValue("result", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } } - public FailedSmartscraperProperties::Status? Status + public Status? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } @@ -82,10 +67,7 @@ public string? UserPrompt if (!this.Properties.TryGetValue("user_prompt", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -97,10 +79,7 @@ public string? WebsiteURL if (!this.Properties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs index 583366f..f38c89f 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs @@ -1,11 +1,10 @@ using System; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; -[JsonConverter(typeof(Scrapegraphai::EnumConverter))] -public sealed record class Status(string value) : Scrapegraphai::IEnum +[JsonConverter(typeof(EnumConverter))] +public sealed record class Status(string value) : IEnum { public static readonly Status Failed = new("failed"); diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs index 3c4b69f..ef8e33e 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Text; using System.Text.Json; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper; @@ -11,7 +10,7 @@ namespace Scrapegraphai.Models.Smartscraper; /// Main scraping endpoint with LLM-powered content analysis. Supports various fetching /// providers, infinite scrolling, pagination, and custom output schemas. /// -public sealed record class SmartscraperCreateParams : Scrapegraphai::ParamsBase +public sealed record class SmartscraperCreateParams : ParamsBase { public Dictionary BodyProperties { get; set; } = []; @@ -25,10 +24,8 @@ public required string UserPrompt if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ) ?? throw new ArgumentNullException("user_prompt"); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) + ?? throw new ArgumentNullException("user_prompt"); } set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } } @@ -45,7 +42,7 @@ public Dictionary? Cookies return JsonSerializer.Deserialize?>( element, - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ); } set { this.BodyProperties["cookies"] = JsonSerializer.SerializeToElement(value); } @@ -63,7 +60,7 @@ public Dictionary? Headers return JsonSerializer.Deserialize?>( element, - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ); } set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } @@ -79,10 +76,7 @@ public long? NumberOfScrolls if (!this.BodyProperties.TryGetValue("number_of_scrolls", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["number_of_scrolls"] = JsonSerializer.SerializeToElement(value); } } @@ -97,10 +91,7 @@ public JsonElement? OutputSchema if (!this.BodyProperties.TryGetValue("output_schema", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["output_schema"] = JsonSerializer.SerializeToElement(value); } } @@ -115,10 +106,7 @@ public bool? RenderHeavyJs if (!this.BodyProperties.TryGetValue("render_heavy_js", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["render_heavy_js"] = JsonSerializer.SerializeToElement(value); } } @@ -133,10 +121,7 @@ public List? Steps if (!this.BodyProperties.TryGetValue("steps", out JsonElement element)) return null; - return JsonSerializer.Deserialize?>( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } set { this.BodyProperties["steps"] = JsonSerializer.SerializeToElement(value); } } @@ -151,10 +136,7 @@ public long? TotalPages if (!this.BodyProperties.TryGetValue("total_pages", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["total_pages"] = JsonSerializer.SerializeToElement(value); } } @@ -169,10 +151,7 @@ public string? WebsiteHTML if (!this.BodyProperties.TryGetValue("website_html", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["website_html"] = JsonSerializer.SerializeToElement(value); } } @@ -187,15 +166,12 @@ public string? WebsiteURL if (!this.BodyProperties.TryGetValue("website_url", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.BodyProperties["website_url"] = JsonSerializer.SerializeToElement(value); } } - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/smartscraper") { @@ -212,15 +188,12 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs index 90e8388..01727b5 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs @@ -1,15 +1,14 @@ using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper; /// /// Retrieve the status and results of a scraping operation /// -public sealed record class SmartscraperListParams : Scrapegraphai::ParamsBase +public sealed record class SmartscraperListParams : ParamsBase { - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/smartscraper") { @@ -17,15 +16,12 @@ public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs index 060548e..782d22f 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using SmartscraperListResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; +using Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; namespace Scrapegraphai.Models.Smartscraper; @@ -12,10 +12,10 @@ public abstract record class SmartscraperListResponse internal SmartscraperListResponse() { } public static implicit operator SmartscraperListResponse(CompletedSmartscraper value) => - new SmartscraperListResponseVariants::CompletedSmartscraperVariant(value); + new CompletedSmartscraperVariant(value); public static implicit operator SmartscraperListResponse(FailedSmartscraper value) => - new SmartscraperListResponseVariants::FailedSmartscraperVariant(value); + new FailedSmartscraperVariant(value); public abstract void Validate(); } @@ -38,9 +38,7 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new SmartscraperListResponseVariants::CompletedSmartscraperVariant( - deserialized - ); + return new CompletedSmartscraperVariant(deserialized); } } catch (JsonException e) @@ -53,9 +51,7 @@ JsonSerializerOptions options var deserialized = JsonSerializer.Deserialize(ref reader, options); if (deserialized != null) { - return new SmartscraperListResponseVariants::FailedSmartscraperVariant( - deserialized - ); + return new FailedSmartscraperVariant(deserialized); } } catch (JsonException e) @@ -74,11 +70,8 @@ JsonSerializerOptions options { object variant = value switch { - SmartscraperListResponseVariants::CompletedSmartscraperVariant( - var completedSmartscraper - ) => completedSmartscraper, - SmartscraperListResponseVariants::FailedSmartscraperVariant(var failedSmartscraper) => - failedSmartscraper, + CompletedSmartscraperVariant(var completedSmartscraper) => completedSmartscraper, + FailedSmartscraperVariant(var failedSmartscraper) => failedSmartscraper, _ => throw new ArgumentOutOfRangeException(nameof(value)), }; JsonSerializer.Serialize(writer, variant, options); diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs index 0d0730a..ad8b962 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs @@ -1,12 +1,10 @@ -using Smartscraper = Scrapegraphai.Models.Smartscraper; - namespace Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; -public sealed record class CompletedSmartscraperVariant(Smartscraper::CompletedSmartscraper Value) - : Smartscraper::SmartscraperListResponse, - IVariant +public sealed record class CompletedSmartscraperVariant(CompletedSmartscraper Value) + : SmartscraperListResponse, + IVariant { - public static CompletedSmartscraperVariant From(Smartscraper::CompletedSmartscraper value) + public static CompletedSmartscraperVariant From(CompletedSmartscraper value) { return new(value); } @@ -17,11 +15,11 @@ public override void Validate() } } -public sealed record class FailedSmartscraperVariant(Smartscraper::FailedSmartscraper Value) - : Smartscraper::SmartscraperListResponse, - IVariant +public sealed record class FailedSmartscraperVariant(FailedSmartscraper Value) + : SmartscraperListResponse, + IVariant { - public static FailedSmartscraperVariant From(Smartscraper::FailedSmartscraper value) + public static FailedSmartscraperVariant From(FailedSmartscraper value) { return new(value); } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs index b512fc2..68dcbce 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs @@ -1,17 +1,16 @@ using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Smartscraper; /// /// Retrieve the status and results of a scraping operation /// -public sealed record class SmartscraperRetrieveParams : Scrapegraphai::ParamsBase +public sealed record class SmartscraperRetrieveParams : ParamsBase { public required string RequestID; - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder( client.BaseUrl.ToString().TrimEnd('/') @@ -22,15 +21,12 @@ public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs index da938a8..6d272ca 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text.Json; using System.Text.Json.Serialization; -using SmartscraperRetrieveResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; +using Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; namespace Scrapegraphai.Models.Smartscraper; @@ -12,10 +12,10 @@ public abstract record class SmartscraperRetrieveResponse internal SmartscraperRetrieveResponse() { } public static implicit operator SmartscraperRetrieveResponse(CompletedSmartscraper value) => - new SmartscraperRetrieveResponseVariants::CompletedSmartscraperVariant(value); + new CompletedSmartscraperVariant(value); public static implicit operator SmartscraperRetrieveResponse(FailedSmartscraper value) => - new SmartscraperRetrieveResponseVariants::FailedSmartscraperVariant(value); + new FailedSmartscraperVariant(value); public abstract void Validate(); } @@ -38,9 +38,7 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new SmartscraperRetrieveResponseVariants::CompletedSmartscraperVariant( - deserialized - ); + return new CompletedSmartscraperVariant(deserialized); } } catch (JsonException e) @@ -53,9 +51,7 @@ JsonSerializerOptions options var deserialized = JsonSerializer.Deserialize(ref reader, options); if (deserialized != null) { - return new SmartscraperRetrieveResponseVariants::FailedSmartscraperVariant( - deserialized - ); + return new FailedSmartscraperVariant(deserialized); } } catch (JsonException e) @@ -74,12 +70,8 @@ JsonSerializerOptions options { object variant = value switch { - SmartscraperRetrieveResponseVariants::CompletedSmartscraperVariant( - var completedSmartscraper - ) => completedSmartscraper, - SmartscraperRetrieveResponseVariants::FailedSmartscraperVariant( - var failedSmartscraper - ) => failedSmartscraper, + CompletedSmartscraperVariant(var completedSmartscraper) => completedSmartscraper, + FailedSmartscraperVariant(var failedSmartscraper) => failedSmartscraper, _ => throw new ArgumentOutOfRangeException(nameof(value)), }; JsonSerializer.Serialize(writer, variant, options); diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs index e3214d3..29fbb81 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs @@ -1,12 +1,10 @@ -using Smartscraper = Scrapegraphai.Models.Smartscraper; - namespace Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; -public sealed record class CompletedSmartscraperVariant(Smartscraper::CompletedSmartscraper Value) - : Smartscraper::SmartscraperRetrieveResponse, - IVariant +public sealed record class CompletedSmartscraperVariant(CompletedSmartscraper Value) + : SmartscraperRetrieveResponse, + IVariant { - public static CompletedSmartscraperVariant From(Smartscraper::CompletedSmartscraper value) + public static CompletedSmartscraperVariant From(CompletedSmartscraper value) { return new(value); } @@ -17,11 +15,11 @@ public override void Validate() } } -public sealed record class FailedSmartscraperVariant(Smartscraper::FailedSmartscraper Value) - : Smartscraper::SmartscraperRetrieveResponse, - IVariant +public sealed record class FailedSmartscraperVariant(FailedSmartscraper Value) + : SmartscraperRetrieveResponse, + IVariant { - public static FailedSmartscraperVariant From(Smartscraper::FailedSmartscraper value) + public static FailedSmartscraperVariant From(FailedSmartscraper value) { return new(value); } diff --git a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs index a51adb0..bd8cc21 100644 --- a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs +++ b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs @@ -1,15 +1,14 @@ using System; using System.Net.Http; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Validate; /// /// Validate the API key and retrieve associated user email /// -public sealed record class ValidateAPIKeyParams : Scrapegraphai::ParamsBase +public sealed record class ValidateAPIKeyParams : ParamsBase { - public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) + public override Uri Url(IScrapegraphaiClient client) { return new UriBuilder(client.BaseUrl.ToString().TrimEnd('/') + "/validate") { @@ -17,15 +16,12 @@ public override Uri Url(Scrapegraphai::IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest( - HttpRequestMessage request, - Scrapegraphai::IScrapegraphaiClient client - ) + public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) { - Scrapegraphai::ParamsBase.AddDefaultHeaders(request, client); + ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) { - Scrapegraphai::ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); + ParamsBase.AddHeaderElementToRequest(request, item.Key, item.Value); } } } diff --git a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs index 01b497d..743d108 100644 --- a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs +++ b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs @@ -2,14 +2,11 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Models.Validate; -[JsonConverter(typeof(Scrapegraphai::ModelConverter))] -public sealed record class ValidateAPIKeyResponse - : Scrapegraphai::ModelBase, - Scrapegraphai::IFromRaw +[JsonConverter(typeof(ModelConverter))] +public sealed record class ValidateAPIKeyResponse : ModelBase, IFromRaw { public string? Email { @@ -18,10 +15,7 @@ public string? Email if (!this.Properties.TryGetValue("email", out JsonElement element)) return null; - return JsonSerializer.Deserialize( - element, - Scrapegraphai::ModelBase.SerializerOptions - ); + return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } set { this.Properties["email"] = JsonSerializer.SerializeToElement(value); } } diff --git a/src/Scrapegraphai/ParamsBase.cs b/src/Scrapegraphai/ParamsBase.cs index 355eaff..a168bff 100644 --- a/src/Scrapegraphai/ParamsBase.cs +++ b/src/Scrapegraphai/ParamsBase.cs @@ -1,45 +1,45 @@ +using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Net.Http; using System.Text; -using Json = System.Text.Json; -using System = System; +using System.Text.Json; using Web = System.Web; namespace Scrapegraphai; public abstract record class ParamsBase { - public Dictionary QueryProperties { get; set; } = []; + public Dictionary QueryProperties { get; set; } = []; - public Dictionary HeaderProperties { get; set; } = []; + public Dictionary HeaderProperties { get; set; } = []; - public abstract System::Uri Url(IScrapegraphaiClient client); + public abstract Uri Url(IScrapegraphaiClient client); protected static void AddQueryElementToCollection( NameValueCollection collection, string key, - Json::JsonElement element + JsonElement element ) { switch (element.ValueKind) { - case Json::JsonValueKind.Undefined: - case Json::JsonValueKind.Null: + case JsonValueKind.Undefined: + case JsonValueKind.Null: collection.Add(key, ""); break; - case Json::JsonValueKind.String: - case Json::JsonValueKind.Number: + case JsonValueKind.String: + case JsonValueKind.Number: collection.Add(key, element.ToString()); break; - case Json::JsonValueKind.True: + case JsonValueKind.True: collection.Add(key, "true"); break; - case Json::JsonValueKind.False: + case JsonValueKind.False: collection.Add(key, "false"); break; - case Json::JsonValueKind.Object: + case JsonValueKind.Object: foreach (var item in element.EnumerateObject()) { AddQueryElementToCollection( @@ -49,7 +49,7 @@ protected static void AddQueryElementToCollection( ); } break; - case Json::JsonValueKind.Array: + case JsonValueKind.Array: collection.Add( key, string.Join( @@ -59,9 +59,9 @@ protected static void AddQueryElementToCollection( x => x.ValueKind switch { - Json::JsonValueKind.Null => "", - Json::JsonValueKind.True => "true", - Json::JsonValueKind.False => "false", + JsonValueKind.Null => "", + JsonValueKind.True => "true", + JsonValueKind.False => "false", _ => x.GetString(), } ) @@ -74,26 +74,26 @@ protected static void AddQueryElementToCollection( protected static void AddHeaderElementToRequest( HttpRequestMessage request, string key, - Json::JsonElement element + JsonElement element ) { switch (element.ValueKind) { - case Json::JsonValueKind.Undefined: - case Json::JsonValueKind.Null: + case JsonValueKind.Undefined: + case JsonValueKind.Null: request.Headers.Add(key, ""); break; - case Json::JsonValueKind.String: - case Json::JsonValueKind.Number: + case JsonValueKind.String: + case JsonValueKind.Number: request.Headers.Add(key, element.ToString()); break; - case Json::JsonValueKind.True: + case JsonValueKind.True: request.Headers.Add(key, "true"); break; - case Json::JsonValueKind.False: + case JsonValueKind.False: request.Headers.Add(key, "false"); break; - case Json::JsonValueKind.Object: + case JsonValueKind.Object: foreach (var item in element.EnumerateObject()) { AddHeaderElementToRequest( @@ -103,16 +103,16 @@ protected static void AddHeaderElementToRequest( ); } break; - case Json::JsonValueKind.Array: + case JsonValueKind.Array: foreach (var item in element.EnumerateArray()) { request.Headers.Add( key, item.ValueKind switch { - Json::JsonValueKind.Null => "", - Json::JsonValueKind.True => "true", - Json::JsonValueKind.False => "false", + JsonValueKind.Null => "", + JsonValueKind.True => "true", + JsonValueKind.False => "false", _ => item.GetString(), } ); diff --git a/src/Scrapegraphai/ScrapegraphaiClient.cs b/src/Scrapegraphai/ScrapegraphaiClient.cs index 33d5942..c5f9b81 100644 --- a/src/Scrapegraphai/ScrapegraphaiClient.cs +++ b/src/Scrapegraphai/ScrapegraphaiClient.cs @@ -1,36 +1,36 @@ -using Crawl = Scrapegraphai.Services.Crawl; -using Credits = Scrapegraphai.Services.Credits; -using Feedback = Scrapegraphai.Services.Feedback; -using GenerateSchema = Scrapegraphai.Services.GenerateSchema; -using Healthz = Scrapegraphai.Services.Healthz; -using Http = System.Net.Http; -using Markdownify = Scrapegraphai.Services.Markdownify; -using Searchscraper = Scrapegraphai.Services.Searchscraper; -using Smartscraper = Scrapegraphai.Services.Smartscraper; -using System = System; -using Validate = Scrapegraphai.Services.Validate; +using System; +using System.Net.Http; +using Scrapegraphai.Services.Crawl; +using Scrapegraphai.Services.Credits; +using Scrapegraphai.Services.Feedback; +using Scrapegraphai.Services.GenerateSchema; +using Scrapegraphai.Services.Healthz; +using Scrapegraphai.Services.Markdownify; +using Scrapegraphai.Services.Searchscraper; +using Scrapegraphai.Services.Smartscraper; +using Scrapegraphai.Services.Validate; namespace Scrapegraphai; public sealed class ScrapegraphaiClient : IScrapegraphaiClient { - public Http::HttpClient HttpClient { get; init; } = new(); + public HttpClient HttpClient { get; init; } = new(); - System::Lazy _baseUrl = new(() => - new System::Uri( - System::Environment.GetEnvironmentVariable("SCRAPEGRAPHAI_BASE_URL") + Lazy _baseUrl = new(() => + new Uri( + Environment.GetEnvironmentVariable("SCRAPEGRAPHAI_BASE_URL") ?? "https://api.scrapegraphai.com/v1" ) ); - public System::Uri BaseUrl + public Uri BaseUrl { get { return _baseUrl.Value; } init { _baseUrl = new(() => value); } } - System::Lazy _apiKey = new(() => - System::Environment.GetEnvironmentVariable("SCRAPEGRAPHAI_API_KEY") - ?? throw new System::ArgumentNullException(nameof(APIKey)) + Lazy _apiKey = new(() => + Environment.GetEnvironmentVariable("SCRAPEGRAPHAI_API_KEY") + ?? throw new ArgumentNullException(nameof(APIKey)) ); public string APIKey { @@ -38,70 +38,70 @@ public string APIKey init { _apiKey = new(() => value); } } - readonly System::Lazy _smartscraper; - public Smartscraper::ISmartscraperService Smartscraper + readonly Lazy _smartscraper; + public ISmartscraperService Smartscraper { get { return _smartscraper.Value; } } - readonly System::Lazy _markdownify; - public Markdownify::IMarkdownifyService Markdownify + readonly Lazy _markdownify; + public IMarkdownifyService Markdownify { get { return _markdownify.Value; } } - readonly System::Lazy _searchscraper; - public Searchscraper::ISearchscraperService Searchscraper + readonly Lazy _searchscraper; + public ISearchscraperService Searchscraper { get { return _searchscraper.Value; } } - readonly System::Lazy _generateSchema; - public GenerateSchema::IGenerateSchemaService GenerateSchema + readonly Lazy _generateSchema; + public IGenerateSchemaService GenerateSchema { get { return _generateSchema.Value; } } - readonly System::Lazy _crawl; - public Crawl::ICrawlService Crawl + readonly Lazy _crawl; + public ICrawlService Crawl { get { return _crawl.Value; } } - readonly System::Lazy _credits; - public Credits::ICreditService Credits + readonly Lazy _credits; + public ICreditService Credits { get { return _credits.Value; } } - readonly System::Lazy _validate; - public Validate::IValidateService Validate + readonly Lazy _validate; + public IValidateService Validate { get { return _validate.Value; } } - readonly System::Lazy _feedback; - public Feedback::IFeedbackService Feedback + readonly Lazy _feedback; + public IFeedbackService Feedback { get { return _feedback.Value; } } - readonly System::Lazy _healthz; - public Healthz::IHealthzService Healthz + readonly Lazy _healthz; + public IHealthzService Healthz { get { return _healthz.Value; } } public ScrapegraphaiClient() { - _smartscraper = new(() => new Smartscraper::SmartscraperService(this)); - _markdownify = new(() => new Markdownify::MarkdownifyService(this)); - _searchscraper = new(() => new Searchscraper::SearchscraperService(this)); - _generateSchema = new(() => new GenerateSchema::GenerateSchemaService(this)); - _crawl = new(() => new Crawl::CrawlService(this)); - _credits = new(() => new Credits::CreditService(this)); - _validate = new(() => new Validate::ValidateService(this)); - _feedback = new(() => new Feedback::FeedbackService(this)); - _healthz = new(() => new Healthz::HealthzService(this)); + _smartscraper = new(() => new SmartscraperService(this)); + _markdownify = new(() => new MarkdownifyService(this)); + _searchscraper = new(() => new SearchscraperService(this)); + _generateSchema = new(() => new GenerateSchemaService(this)); + _crawl = new(() => new CrawlService(this)); + _credits = new(() => new CreditService(this)); + _validate = new(() => new ValidateService(this)); + _feedback = new(() => new FeedbackService(this)); + _healthz = new(() => new HealthzService(this)); } } diff --git a/src/Scrapegraphai/Services/Crawl/CrawlService.cs b/src/Scrapegraphai/Services/Crawl/CrawlService.cs index fe93cb6..b15fba1 100644 --- a/src/Scrapegraphai/Services/Crawl/CrawlService.cs +++ b/src/Scrapegraphai/Services/Crawl/CrawlService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Crawl; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Crawl; public sealed class CrawlService : ICrawlService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public CrawlService(Scrapegraphai::IScrapegraphaiClient client) + public CrawlService(IScrapegraphaiClient client) { _client = client; } @@ -27,7 +26,7 @@ CrawlRetrieveResultsParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -35,7 +34,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -51,7 +50,7 @@ public async Task Start(CrawlStartParams parameters) .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -59,7 +58,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Credits/CreditService.cs b/src/Scrapegraphai/Services/Credits/CreditService.cs index 0197a5c..5eb6b4e 100644 --- a/src/Scrapegraphai/Services/Credits/CreditService.cs +++ b/src/Scrapegraphai/Services/Credits/CreditService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Credits; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Credits; public sealed class CreditService : ICreditService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public CreditService(Scrapegraphai::IScrapegraphaiClient client) + public CreditService(IScrapegraphaiClient client) { _client = client; } @@ -25,7 +24,7 @@ public async Task Retrieve(CreditRetrieveParams paramete .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -33,7 +32,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Feedback/FeedbackService.cs b/src/Scrapegraphai/Services/Feedback/FeedbackService.cs index a36b25b..ab17e9a 100644 --- a/src/Scrapegraphai/Services/Feedback/FeedbackService.cs +++ b/src/Scrapegraphai/Services/Feedback/FeedbackService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Feedback; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Feedback; public sealed class FeedbackService : IFeedbackService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public FeedbackService(Scrapegraphai::IScrapegraphaiClient client) + public FeedbackService(IScrapegraphaiClient client) { _client = client; } @@ -28,7 +27,7 @@ public async Task Submit(FeedbackSubmitParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -36,7 +35,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs b/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs index 6c83147..db4a5e8 100644 --- a/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs +++ b/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.GenerateSchema; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.GenerateSchema; public sealed class GenerateSchemaService : IGenerateSchemaService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public GenerateSchemaService(Scrapegraphai::IScrapegraphaiClient client) + public GenerateSchemaService(IScrapegraphaiClient client) { _client = client; } @@ -28,7 +27,7 @@ public async Task Create(GenerateSchemaCreateParam .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -36,7 +35,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -51,7 +50,7 @@ GenerateSchemaRetrieveParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -59,7 +58,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Healthz/HealthzService.cs b/src/Scrapegraphai/Services/Healthz/HealthzService.cs index cb56362..38caeb3 100644 --- a/src/Scrapegraphai/Services/Healthz/HealthzService.cs +++ b/src/Scrapegraphai/Services/Healthz/HealthzService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Healthz; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Healthz; public sealed class HealthzService : IHealthzService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public HealthzService(Scrapegraphai::IScrapegraphaiClient client) + public HealthzService(IScrapegraphaiClient client) { _client = client; } @@ -25,7 +24,7 @@ public async Task Check(HealthzCheckParams parameters) .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -33,7 +32,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs b/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs index f18adb9..b102e9a 100644 --- a/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs +++ b/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Markdownify; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Markdownify; public sealed class MarkdownifyService : IMarkdownifyService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public MarkdownifyService(Scrapegraphai::IScrapegraphaiClient client) + public MarkdownifyService(IScrapegraphaiClient client) { _client = client; } @@ -28,7 +27,7 @@ public async Task Convert(MarkdownifyConvertParams paramet .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -36,7 +35,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -51,7 +50,7 @@ MarkdownifyRetrieveStatusParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -59,7 +58,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs b/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs index 31ccb64..e033ae3 100644 --- a/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs +++ b/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Searchscraper; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Searchscraper; public sealed class SearchscraperService : ISearchscraperService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public SearchscraperService(Scrapegraphai::IScrapegraphaiClient client) + public SearchscraperService(IScrapegraphaiClient client) { _client = client; } @@ -28,7 +27,7 @@ public async Task Create(SearchscraperCreateParams param .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -36,7 +35,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -51,7 +50,7 @@ SearchscraperRetrieveStatusParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -59,7 +58,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs b/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs index 97848e0..129d753 100644 --- a/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs +++ b/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Smartscraper; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Smartscraper; public sealed class SmartscraperService : ISmartscraperService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public SmartscraperService(Scrapegraphai::IScrapegraphaiClient client) + public SmartscraperService(IScrapegraphaiClient client) { _client = client; } @@ -28,7 +27,7 @@ public async Task Create(SmartscraperCreateParams paramet .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -36,7 +35,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -49,7 +48,7 @@ public async Task Retrieve(SmartscraperRetrievePar .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -57,7 +56,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } @@ -70,7 +69,7 @@ public async Task List(SmartscraperListParams paramete .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -78,7 +77,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } diff --git a/src/Scrapegraphai/Services/Validate/ValidateService.cs b/src/Scrapegraphai/Services/Validate/ValidateService.cs index d152044..1f5aeb0 100644 --- a/src/Scrapegraphai/Services/Validate/ValidateService.cs +++ b/src/Scrapegraphai/Services/Validate/ValidateService.cs @@ -3,15 +3,14 @@ using System.Text.Json; using System.Threading.Tasks; using Scrapegraphai.Models.Validate; -using Scrapegraphai = Scrapegraphai; namespace Scrapegraphai.Services.Validate; public sealed class ValidateService : IValidateService { - readonly Scrapegraphai::IScrapegraphaiClient _client; + readonly IScrapegraphaiClient _client; - public ValidateService(Scrapegraphai::IScrapegraphaiClient client) + public ValidateService(IScrapegraphaiClient client) { _client = client; } @@ -25,7 +24,7 @@ public async Task APIKey(ValidateAPIKeyParams parameters .ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - throw new Scrapegraphai::HttpException( + throw new HttpException( response.StatusCode, await response.Content.ReadAsStringAsync().ConfigureAwait(false) ); @@ -33,7 +32,7 @@ await response.Content.ReadAsStringAsync().ConfigureAwait(false) return JsonSerializer.Deserialize( await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - Scrapegraphai::ModelBase.SerializerOptions + ModelBase.SerializerOptions ) ?? throw new NullReferenceException(); } } From 3d5969023ab80e6e87b6770f15de1c4248fe5cf1 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 17 Aug 2025 02:14:16 +0000 Subject: [PATCH 05/21] docs: fix installation instructions --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cc123b..fc80c6e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ The REST API documentation can be found on [scrapegraphai.com](https://scrapegra ## Installation ```bash -dotnet add package Scrapegraphai +git clone git@github.com:ScrapeGraphAI/scrapegraphai-c.git +dotnet add reference scrapegraphai-c/src/Scrapegraphai ``` ## Requirements From ccad1993a305c58d2595477e5ecc171dd798de9d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 20 Aug 2025 04:24:00 +0000 Subject: [PATCH 06/21] feat(client): add switch and match helpers for unions --- .../Result.cs | 45 ++++++++++++++- .../GenerateSchemaRetrieveResponse.cs | 57 +++++++++++++++++++ .../MarkdownifyRetrieveStatusResponse.cs | 55 ++++++++++++++++++ .../SearchscraperRetrieveStatusResponse.cs | 55 ++++++++++++++++++ .../Smartscraper/SmartscraperListResponse.cs | 43 ++++++++++++++ .../SmartscraperRetrieveResponse.cs | 43 ++++++++++++++ 6 files changed, 297 insertions(+), 1 deletion(-) diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs index b3d2864..15e09a5 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs @@ -19,6 +19,49 @@ public static implicit operator Result(JsonElement value) => public static implicit operator Result(string value) => new ResultVariants::String(value); + public bool TryPickJsonElement(out JsonElement? value) + { + value = (this as ResultVariants::JsonElement)?.Value; + return value != null; + } + + public bool TryPickString(out string? value) + { + value = (this as ResultVariants::String)?.Value; + return value != null; + } + + public void Switch( + Action jsonElement, + Action @string + ) + { + switch (this) + { + case ResultVariants::JsonElement inner: + jsonElement(inner); + break; + case ResultVariants::String inner: + @string(inner); + break; + default: + throw new InvalidOperationException(); + } + } + + public T Match( + Func jsonElement, + Func @string + ) + { + return this switch + { + ResultVariants::JsonElement inner => jsonElement(inner), + ResultVariants::String inner => @string(inner), + _ => throw new InvalidOperationException(), + }; + } + public abstract void Validate(); } @@ -64,7 +107,7 @@ public override void Write(Utf8JsonWriter writer, Result value, JsonSerializerOp object variant = value switch { ResultVariants::JsonElement(var jsonElement) => jsonElement, - ResultVariants::String(var string1) => string1, + ResultVariants::String(var @string) => @string, _ => throw new ArgumentOutOfRangeException(nameof(value)), }; JsonSerializer.Serialize(writer, variant, options); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs index f499d7e..478177d 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs @@ -20,6 +20,63 @@ public static implicit operator GenerateSchemaRetrieveResponse( FailedSchemaGenerationResponse value ) => new GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse(value); + public bool TryPickCompletedSchemaGenerationResponse( + out CompletedSchemaGenerationResponse? value + ) + { + value = ( + this as GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse + )?.Value; + return value != null; + } + + public bool TryPickFailedSchemaGenerationResponse(out FailedSchemaGenerationResponse? value) + { + value = ( + this as GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse + )?.Value; + return value != null; + } + + public void Switch( + Action completedSchemaGenerationResponse, + Action failedSchemaGenerationResponse + ) + { + switch (this) + { + case GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse inner: + completedSchemaGenerationResponse(inner); + break; + case GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse inner: + failedSchemaGenerationResponse(inner); + break; + default: + throw new InvalidOperationException(); + } + } + + public T Match( + Func< + GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse, + T + > completedSchemaGenerationResponse, + Func< + GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse, + T + > failedSchemaGenerationResponse + ) + { + return this switch + { + GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse inner => + completedSchemaGenerationResponse(inner), + GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse inner => + failedSchemaGenerationResponse(inner), + _ => throw new InvalidOperationException(), + }; + } + public abstract void Validate(); } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index 74c02f1..8d063d3 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -19,6 +19,61 @@ public static implicit operator MarkdownifyRetrieveStatusResponse( FailedMarkdownifyResponse value ) => new MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse(value); + public bool TryPickCompletedMarkdownifyVariant(out CompletedMarkdownify? value) + { + value = ( + this as MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant + )?.Value; + return value != null; + } + + public bool TryPickFailedMarkdownifyResponse(out FailedMarkdownifyResponse? value) + { + value = ( + this as MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse + )?.Value; + return value != null; + } + + public void Switch( + Action completedMarkdownify, + Action failedMarkdownifyResponse + ) + { + switch (this) + { + case MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant inner: + completedMarkdownify(inner); + break; + case MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner: + failedMarkdownifyResponse(inner); + break; + default: + throw new InvalidOperationException(); + } + } + + public T Match( + Func< + MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant, + T + > completedMarkdownify, + Func< + MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse, + T + > failedMarkdownifyResponse + ) + { + return this switch + { + MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant inner => + completedMarkdownify(inner), + MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner => + failedMarkdownifyResponse(inner), + _ => throw new InvalidOperationException(), + }; + } + public abstract void Validate(); } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index 49df8e9..7c82173 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -20,6 +20,61 @@ public static implicit operator SearchscraperRetrieveStatusResponse( FailedSearchScraperResponse value ) => new SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse(value); + public bool TryPickCompletedSearchScraperVariant(out CompletedSearchScraper? value) + { + value = ( + this as SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant + )?.Value; + return value != null; + } + + public bool TryPickFailedSearchScraperResponse(out FailedSearchScraperResponse? value) + { + value = ( + this as SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse + )?.Value; + return value != null; + } + + public void Switch( + Action completedSearchScraper, + Action failedSearchScraperResponse + ) + { + switch (this) + { + case SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant inner: + completedSearchScraper(inner); + break; + case SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner: + failedSearchScraperResponse(inner); + break; + default: + throw new InvalidOperationException(); + } + } + + public T Match( + Func< + SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant, + T + > completedSearchScraper, + Func< + SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse, + T + > failedSearchScraperResponse + ) + { + return this switch + { + SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant inner => + completedSearchScraper(inner), + SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner => + failedSearchScraperResponse(inner), + _ => throw new InvalidOperationException(), + }; + } + public abstract void Validate(); } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs index 782d22f..7e71e2b 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs @@ -17,6 +17,49 @@ public static implicit operator SmartscraperListResponse(CompletedSmartscraper v public static implicit operator SmartscraperListResponse(FailedSmartscraper value) => new FailedSmartscraperVariant(value); + public bool TryPickCompletedSmartscraperVariant(out CompletedSmartscraper? value) + { + value = (this as CompletedSmartscraperVariant)?.Value; + return value != null; + } + + public bool TryPickFailedSmartscraperVariant(out FailedSmartscraper? value) + { + value = (this as FailedSmartscraperVariant)?.Value; + return value != null; + } + + public void Switch( + Action completedSmartscraper, + Action failedSmartscraper + ) + { + switch (this) + { + case CompletedSmartscraperVariant inner: + completedSmartscraper(inner); + break; + case FailedSmartscraperVariant inner: + failedSmartscraper(inner); + break; + default: + throw new InvalidOperationException(); + } + } + + public T Match( + Func completedSmartscraper, + Func failedSmartscraper + ) + { + return this switch + { + CompletedSmartscraperVariant inner => completedSmartscraper(inner), + FailedSmartscraperVariant inner => failedSmartscraper(inner), + _ => throw new InvalidOperationException(), + }; + } + public abstract void Validate(); } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs index 6d272ca..28defb3 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs @@ -17,6 +17,49 @@ public static implicit operator SmartscraperRetrieveResponse(CompletedSmartscrap public static implicit operator SmartscraperRetrieveResponse(FailedSmartscraper value) => new FailedSmartscraperVariant(value); + public bool TryPickCompletedSmartscraperVariant(out CompletedSmartscraper? value) + { + value = (this as CompletedSmartscraperVariant)?.Value; + return value != null; + } + + public bool TryPickFailedSmartscraperVariant(out FailedSmartscraper? value) + { + value = (this as FailedSmartscraperVariant)?.Value; + return value != null; + } + + public void Switch( + Action completedSmartscraper, + Action failedSmartscraper + ) + { + switch (this) + { + case CompletedSmartscraperVariant inner: + completedSmartscraper(inner); + break; + case FailedSmartscraperVariant inner: + failedSmartscraper(inner); + break; + default: + throw new InvalidOperationException(); + } + } + + public T Match( + Func completedSmartscraper, + Func failedSmartscraper + ) + { + return this switch + { + CompletedSmartscraperVariant inner => completedSmartscraper(inner), + FailedSmartscraperVariant inner => failedSmartscraper(inner), + _ => throw new InvalidOperationException(), + }; + } + public abstract void Validate(); } From f427733d982b19d0cc1012be19978f34ae729f6f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 20 Aug 2025 04:25:42 +0000 Subject: [PATCH 07/21] refactor(client): refine enum representation docs(client): add more property comments --- src/Scrapegraphai/ApiEnum.cs | 56 +++++++++++++ src/Scrapegraphai/IEnum.cs | 8 -- src/Scrapegraphai/ModelBase.cs | 27 +++++- .../{JsonConverters.cs => ModelConverter.cs} | 18 ---- .../Crawl/CrawlRetrieveResultsResponse.cs | 39 +++++++-- .../Status.cs | 84 +++++++++---------- .../Models/Crawl/CrawlStartParams.cs | 72 ++++++++++++++-- .../Crawl/CrawlStartParamsProperties/Rules.cs | 16 +++- .../Models/Crawl/CrawlStartResponse.cs | 8 +- .../Models/Credits/CreditRetrieveResponse.cs | 16 +++- .../Models/Feedback/FeedbackSubmitParams.cs | 24 +++++- .../Models/Feedback/FeedbackSubmitResponse.cs | 32 ++++++- .../GenerateSchemaCreateParams.cs | 16 +++- .../GenerateSchemaCreateResponse.cs | 55 ++++++++++-- .../Status.cs | 49 +++++------ .../CompletedSchemaGenerationResponse.cs | 55 ++++++++++-- .../Status.cs | 49 +++++------ .../FailedSchemaGenerationResponse.cs | 55 ++++++++++-- .../Status.cs | 49 +++++------ .../Models/Healthz/HealthzCheckResponse.cs | 16 +++- .../Markdownify/CompletedMarkdownify.cs | 47 +++++++++-- .../CompletedMarkdownifyProperties/Status.cs | 63 +++++++------- .../Markdownify/MarkdownifyConvertParams.cs | 24 +++++- .../FailedMarkdownifyResponse.cs | 47 +++++++++-- .../Status.cs | 49 +++++------ .../Searchscraper/CompletedSearchScraper.cs | 63 ++++++++++++-- .../Status.cs | 63 +++++++------- .../SearchscraperCreateParams.cs | 32 ++++++- .../FailedSearchScraperResponse.cs | 63 ++++++++++++-- .../Status.cs | 49 +++++------ .../Smartscraper/CompletedSmartscraper.cs | 55 ++++++++++-- .../CompletedSmartscraperProperties/Status.cs | 63 +++++++------- .../Models/Smartscraper/FailedSmartscraper.cs | 55 ++++++++++-- .../FailedSmartscraperProperties/Status.cs | 49 +++++------ .../Smartscraper/SmartscraperCreateParams.cs | 80 +++++++++++++++--- .../Models/Validate/ValidateAPIKeyResponse.cs | 8 +- 36 files changed, 1122 insertions(+), 432 deletions(-) create mode 100644 src/Scrapegraphai/ApiEnum.cs delete mode 100644 src/Scrapegraphai/IEnum.cs rename src/Scrapegraphai/{JsonConverters.cs => ModelConverter.cs} (59%) diff --git a/src/Scrapegraphai/ApiEnum.cs b/src/Scrapegraphai/ApiEnum.cs new file mode 100644 index 0000000..ea28e2e --- /dev/null +++ b/src/Scrapegraphai/ApiEnum.cs @@ -0,0 +1,56 @@ +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Scrapegraphai; + +public record struct ApiEnum(JsonElement Json) + where TEnum : struct, Enum +{ + public readonly TRaw Raw() => + JsonSerializer.Deserialize(this.Json, ModelBase.SerializerOptions) + ?? throw new NullReferenceException(nameof(this.Json)); + + public readonly TEnum Value() => + JsonSerializer.Deserialize(this.Json, ModelBase.SerializerOptions); + + public readonly void Validate() + { + if (!Enum.IsDefined(Value())) + { + throw new Exception(); + } + } + + public static implicit operator TRaw(ApiEnum value) => value.Raw(); + + public static implicit operator TEnum(ApiEnum value) => value.Value(); + + public static implicit operator ApiEnum(TRaw value) => + new(JsonSerializer.SerializeToElement(value, ModelBase.SerializerOptions)); + + public static implicit operator ApiEnum(TEnum value) => + new(JsonSerializer.SerializeToElement(value, ModelBase.SerializerOptions)); +} + +sealed class ApiEnumConverter : JsonConverter> + where TEnum : struct, Enum +{ + public override ApiEnum Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) + { + return new(JsonSerializer.Deserialize(ref reader, options)); + } + + public override void Write( + Utf8JsonWriter writer, + ApiEnum value, + JsonSerializerOptions options + ) + { + JsonSerializer.Serialize(writer, value.Json, options); + } +} diff --git a/src/Scrapegraphai/IEnum.cs b/src/Scrapegraphai/IEnum.cs deleted file mode 100644 index 297e516..0000000 --- a/src/Scrapegraphai/IEnum.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Scrapegraphai; - -interface IEnum - where TEnum : IEnum -{ - static abstract TEnum FromRaw(TValue value); - TValue Raw(); -} diff --git a/src/Scrapegraphai/ModelBase.cs b/src/Scrapegraphai/ModelBase.cs index 55b4f7b..bc1939f 100644 --- a/src/Scrapegraphai/ModelBase.cs +++ b/src/Scrapegraphai/ModelBase.cs @@ -1,5 +1,15 @@ using System.Collections.Generic; using System.Text.Json; +using Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; +using CompletedMarkdownifyProperties = Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; +using CompletedSchemaGenerationResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; +using CompletedSearchScraperProperties = Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; +using CrawlRetrieveResultsResponseProperties = Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; +using FailedMarkdownifyResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; +using FailedSchemaGenerationResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; +using FailedSearchScraperResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; +using FailedSmartscraperProperties = Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; +using GenerateSchemaCreateResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; namespace Scrapegraphai; @@ -7,7 +17,22 @@ public abstract record class ModelBase { public Dictionary Properties { get; set; } = []; - internal static readonly JsonSerializerOptions SerializerOptions = new(); + internal static readonly JsonSerializerOptions SerializerOptions = new() + { + Converters = + { + new ApiEnumConverter(), + new ApiEnumConverter(), + new ApiEnumConverter(), + new ApiEnumConverter(), + new ApiEnumConverter(), + new ApiEnumConverter(), + new ApiEnumConverter(), + new ApiEnumConverter(), + new ApiEnumConverter(), + new ApiEnumConverter(), + }, + }; static readonly JsonSerializerOptions _toStringSerializerOptions = new(SerializerOptions) { diff --git a/src/Scrapegraphai/JsonConverters.cs b/src/Scrapegraphai/ModelConverter.cs similarity index 59% rename from src/Scrapegraphai/JsonConverters.cs rename to src/Scrapegraphai/ModelConverter.cs index 626113a..e5a9051 100644 --- a/src/Scrapegraphai/JsonConverters.cs +++ b/src/Scrapegraphai/ModelConverter.cs @@ -28,21 +28,3 @@ public override void Write(Utf8JsonWriter writer, TModel value, JsonSerializerOp JsonSerializer.Serialize(writer, value.Properties, options); } } - -sealed class EnumConverter : JsonConverter - where TEnum : IEnum -{ - public override TEnum Read( - ref Utf8JsonReader reader, - Type _typeToConvert, - JsonSerializerOptions options - ) - { - return TEnum.FromRaw(JsonSerializer.Deserialize(ref reader, options)!); - } - - public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options) - { - JsonSerializer.Serialize(writer, value.Raw(), options); - } -} diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs index e280129..f094b97 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs @@ -23,19 +23,34 @@ public Result? Result return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["result"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? TaskID @@ -47,7 +62,13 @@ public string? TaskID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["task_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["task_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -62,7 +83,13 @@ public string? Traceback return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["traceback"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["traceback"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs index 69bfaac..ad3b1d1 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs @@ -1,59 +1,55 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Pending = new("PENDING"); - - public static readonly Status Started = new("STARTED"); - - public static readonly Status Success = new("SUCCESS"); - - public static readonly Status Failure = new("FAILURE"); - - public static readonly Status Retry = new("RETRY"); - - public static readonly Status Revoked = new("REVOKED"); - - readonly string _value = value; + Pending, + Started, + Success, + Failure, + Retry, + Revoked, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Pending, - Started, - Success, - Failure, - Retry, - Revoked, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "PENDING" => Value.Pending, - "STARTED" => Value.Started, - "SUCCESS" => Value.Success, - "FAILURE" => Value.Failure, - "RETRY" => Value.Retry, - "REVOKED" => Value.Revoked, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "PENDING" => Status.Pending, + "STARTED" => Status.Started, + "SUCCESS" => Status.Success, + "FAILURE" => Status.Failure, + "RETRY" => Status.Retry, + "REVOKED" => Status.Revoked, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Pending => "PENDING", + Status.Started => "STARTED", + Status.Success => "SUCCESS", + Status.Failure => "FAILURE", + Status.Retry => "RETRY", + Status.Revoked => "REVOKED", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs index cdca862..bc57576 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs @@ -28,7 +28,13 @@ public required string URL return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) ?? throw new ArgumentNullException("url"); } - set { this.BodyProperties["url"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["url"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -43,7 +49,13 @@ public long? Depth return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["depth"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["depth"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -58,7 +70,13 @@ public bool? ExtractionMode return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["extraction_mode"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["extraction_mode"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -73,7 +91,13 @@ public long? MaxPages return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["max_pages"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["max_pages"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -88,7 +112,13 @@ public string? Prompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -103,7 +133,13 @@ public bool? RenderHeavyJs return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["render_heavy_js"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["render_heavy_js"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public Rules? Rules @@ -115,7 +151,13 @@ public Rules? Rules return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["rules"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["rules"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -130,7 +172,13 @@ public JsonElement? Schema return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["schema"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["schema"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -145,7 +193,13 @@ public bool? Sitemap return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["sitemap"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["sitemap"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override Uri Url(IScrapegraphaiClient client) diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs index 05f9ead..a5a2574 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs @@ -20,7 +20,13 @@ public List? Exclude return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } - set { this.Properties["exclude"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["exclude"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -35,7 +41,13 @@ public bool? SameDomain return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["same_domain"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["same_domain"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs index 03bb95c..ea96632 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs @@ -20,7 +20,13 @@ public string? TaskID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["task_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["task_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs b/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs index 79ab16d..5f92748 100644 --- a/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs @@ -20,7 +20,13 @@ public long? RemainingCredits return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["remaining_credits"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["remaining_credits"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -35,7 +41,13 @@ public long? TotalCreditsUsed return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["total_credits_used"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["total_credits_used"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs index 8179ff6..ea38ed7 100644 --- a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs +++ b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs @@ -25,7 +25,13 @@ public required long Rating return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["rating"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["rating"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -41,7 +47,13 @@ public required string RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) ?? throw new ArgumentNullException("request_id"); } - set { this.BodyProperties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -56,7 +68,13 @@ public string? FeedbackText return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["feedback_text"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["feedback_text"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override Uri Url(IScrapegraphaiClient client) diff --git a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs index 6943d42..fc53ee3 100644 --- a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs +++ b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs @@ -18,7 +18,13 @@ public string? FeedbackID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["feedback_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["feedback_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public DateTime? FeedbackTimestamp @@ -30,7 +36,13 @@ public DateTime? FeedbackTimestamp return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["feedback_timestamp"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["feedback_timestamp"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? Message @@ -42,7 +54,13 @@ public string? Message return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["message"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["message"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -54,7 +72,13 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs index caf49b9..f108377 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs @@ -27,7 +27,13 @@ public required string UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) ?? throw new ArgumentNullException("user_prompt"); } - set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -42,7 +48,13 @@ public JsonElement? ExistingSchema return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["existing_schema"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["existing_schema"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override Uri Url(IScrapegraphaiClient client) diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs index bbd088d..094164e 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs @@ -20,7 +20,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -35,7 +41,13 @@ public JsonElement? GeneratedSchema return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["generated_schema"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -50,7 +62,13 @@ public string? RefinedPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -62,19 +80,34 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? UserPrompt @@ -86,7 +119,13 @@ public string? UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs index 4eca9ee..122ce61 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs @@ -1,39 +1,40 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Completed = new("completed"); - - readonly string _value = value; + Completed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Completed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "completed" => Value.Completed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "completed" => Status.Completed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Completed => "completed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs index 9c60171..e754788 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs @@ -20,7 +20,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public JsonElement? GeneratedSchema @@ -32,7 +38,13 @@ public JsonElement? GeneratedSchema return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["generated_schema"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RefinedPrompt @@ -44,7 +56,13 @@ public string? RefinedPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -56,19 +74,34 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? UserPrompt @@ -80,7 +113,13 @@ public string? UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs index 4d483ab..e96c71f 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs @@ -1,39 +1,40 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Completed = new("completed"); - - readonly string _value = value; + Completed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Completed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "completed" => Value.Completed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "completed" => Status.Completed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Completed => "completed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs index a426aea..9249278 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs @@ -20,7 +20,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public JsonElement? GeneratedSchema @@ -32,7 +38,13 @@ public JsonElement? GeneratedSchema return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["generated_schema"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["generated_schema"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RefinedPrompt @@ -44,7 +56,13 @@ public string? RefinedPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["refined_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -56,19 +74,34 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? UserPrompt @@ -80,7 +113,13 @@ public string? UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs index a48da7f..2f20ded 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs @@ -1,39 +1,40 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Failed = new("failed"); - - readonly string _value = value; + Failed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Failed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "failed" => Value.Failed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "failed" => Status.Failed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Failed => "failed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs b/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs index c0add17..db7b0ff 100644 --- a/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs +++ b/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs @@ -20,7 +20,13 @@ public Dictionary? Services ModelBase.SerializerOptions ); } - set { this.Properties["services"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["services"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? Status @@ -32,7 +38,13 @@ public string? Status return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs index 6e04941..3da8a70 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs @@ -18,7 +18,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -30,7 +36,13 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -45,19 +57,34 @@ public string? Result return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["result"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? WebsiteURL @@ -69,7 +96,13 @@ public string? WebsiteURL return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["website_url"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs index 120745c..62b3d61 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs @@ -1,47 +1,46 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Queued = new("queued"); - - public static readonly Status Processing = new("processing"); - - public static readonly Status Completed = new("completed"); - - readonly string _value = value; + Queued, + Processing, + Completed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Queued, - Processing, - Completed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "queued" => Value.Queued, - "processing" => Value.Processing, - "completed" => Value.Completed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "queued" => Status.Queued, + "processing" => Status.Processing, + "completed" => Status.Completed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Queued => "queued", + Status.Processing => "processing", + Status.Completed => "completed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs index d7116a1..40334ec 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs @@ -26,7 +26,13 @@ public required string WebsiteURL return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) ?? throw new ArgumentNullException("website_url"); } - set { this.BodyProperties["website_url"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["website_url"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public Dictionary? Headers @@ -41,7 +47,13 @@ public Dictionary? Headers ModelBase.SerializerOptions ); } - set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["headers"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -56,7 +68,13 @@ public List? Steps return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["steps"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["steps"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override Uri Url(IScrapegraphaiClient client) diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs index ad4f435..84349bf 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs @@ -20,7 +20,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -32,7 +38,13 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? Result @@ -44,19 +56,34 @@ public string? Result return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["result"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? WebsiteURL @@ -68,7 +95,13 @@ public string? WebsiteURL return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["website_url"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs index 20130f5..a9ee4fb 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs @@ -1,39 +1,40 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Failed = new("failed"); - - readonly string _value = value; + Failed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Failed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "failed" => Value.Failed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "failed" => Status.Failed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Failed => "failed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs index 955b92f..af07cd1 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs @@ -18,7 +18,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public long? NumResults @@ -30,7 +36,13 @@ public long? NumResults return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["num_results"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["num_results"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -45,7 +57,13 @@ public List? ReferenceURLs return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } - set { this.Properties["reference_urls"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["reference_urls"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -57,7 +75,13 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -72,19 +96,34 @@ public JsonElement? Result return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["result"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? UserPrompt @@ -96,7 +135,13 @@ public string? UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs index 30eca60..d3bc571 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs @@ -1,47 +1,46 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Queued = new("queued"); - - public static readonly Status Processing = new("processing"); - - public static readonly Status Completed = new("completed"); - - readonly string _value = value; + Queued, + Processing, + Completed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Queued, - Processing, - Completed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "queued" => Value.Queued, - "processing" => Value.Processing, - "completed" => Value.Completed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "queued" => Status.Queued, + "processing" => Status.Processing, + "completed" => Status.Completed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Queued => "queued", + Status.Processing => "processing", + Status.Completed => "completed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs index bd23365..0b3ae3f 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs @@ -28,7 +28,13 @@ public required string UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) ?? throw new ArgumentNullException("user_prompt"); } - set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public Dictionary? Headers @@ -43,7 +49,13 @@ public Dictionary? Headers ModelBase.SerializerOptions ); } - set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["headers"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -58,7 +70,13 @@ public long? NumResults return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["num_results"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["num_results"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -73,7 +91,13 @@ public JsonElement? OutputSchema return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["output_schema"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["output_schema"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override Uri Url(IScrapegraphaiClient client) diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs index 478bbdc..fd77c26 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs @@ -20,7 +20,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public long? NumResults @@ -32,7 +38,13 @@ public long? NumResults return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["num_results"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["num_results"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public List? ReferenceURLs @@ -44,7 +56,13 @@ public List? ReferenceURLs return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } - set { this.Properties["reference_urls"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["reference_urls"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -56,7 +74,13 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public JsonElement? Result @@ -68,19 +92,34 @@ public JsonElement? Result return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["result"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? UserPrompt @@ -92,7 +131,13 @@ public string? UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs index 90d596e..238a3b3 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs @@ -1,39 +1,40 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Failed = new("failed"); - - readonly string _value = value; + Failed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Failed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "failed" => Value.Failed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "failed" => Status.Failed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Failed => "failed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs index 005d2cd..a624905 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs @@ -21,7 +21,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -36,7 +42,13 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -51,22 +63,37 @@ public JsonElement? Result return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["result"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// /// Processing status /// - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? UserPrompt @@ -78,7 +105,13 @@ public string? UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? WebsiteURL @@ -90,7 +123,13 @@ public string? WebsiteURL return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["website_url"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs index 4bf36cb..4dde124 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs @@ -1,4 +1,5 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; @@ -6,45 +7,43 @@ namespace Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; /// /// Processing status /// -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Queued = new("queued"); - - public static readonly Status Processing = new("processing"); - - public static readonly Status Completed = new("completed"); - - readonly string _value = value; + Queued, + Processing, + Completed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Queued, - Processing, - Completed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "queued" => Value.Queued, - "processing" => Value.Processing, - "completed" => Value.Completed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "queued" => Status.Queued, + "processing" => Status.Processing, + "completed" => Status.Completed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Queued => "queued", + Status.Processing => "processing", + Status.Completed => "completed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs index fddf44c..d96e794 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs @@ -21,7 +21,13 @@ public string? Error return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["error"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["error"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? RequestID @@ -33,7 +39,13 @@ public string? RequestID return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["request_id"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["request_id"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public JsonElement? Result @@ -45,19 +57,34 @@ public JsonElement? Result return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["result"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["result"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } - public Status? Status + public ApiEnum? Status { get { if (!this.Properties.TryGetValue("status", out JsonElement element)) return null; - return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); + return JsonSerializer.Deserialize?>( + element, + ModelBase.SerializerOptions + ); + } + set + { + this.Properties["status"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); } - set { this.Properties["status"] = JsonSerializer.SerializeToElement(value); } } public string? UserPrompt @@ -69,7 +96,13 @@ public string? UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public string? WebsiteURL @@ -81,7 +114,13 @@ public string? WebsiteURL return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["website_url"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["website_url"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs index f38c89f..786bec4 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs @@ -1,39 +1,40 @@ using System; +using System.Text.Json; using System.Text.Json.Serialization; namespace Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; -[JsonConverter(typeof(EnumConverter))] -public sealed record class Status(string value) : IEnum +[JsonConverter(typeof(StatusConverter))] +public enum Status { - public static readonly Status Failed = new("failed"); - - readonly string _value = value; + Failed, +} - public enum Value +sealed class StatusConverter : JsonConverter +{ + public override Status Read( + ref Utf8JsonReader reader, + Type _typeToConvert, + JsonSerializerOptions options + ) { - Failed, - } - - public Value Known() => - _value switch + return JsonSerializer.Deserialize(ref reader, options) switch { - "failed" => Value.Failed, - _ => throw new ArgumentOutOfRangeException(nameof(_value)), + "failed" => Status.Failed, + _ => (Status)(-1), }; - - public string Raw() - { - return _value; - } - - public void Validate() - { - Known(); } - public static Status FromRaw(string value) + public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOptions options) { - return new(value); + JsonSerializer.Serialize( + writer, + value switch + { + Status.Failed => "failed", + _ => throw new ArgumentOutOfRangeException(nameof(value)), + }, + options + ); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs index ef8e33e..89da30e 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs @@ -27,7 +27,13 @@ public required string UserPrompt return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) ?? throw new ArgumentNullException("user_prompt"); } - set { this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["user_prompt"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -45,7 +51,13 @@ public Dictionary? Cookies ModelBase.SerializerOptions ); } - set { this.BodyProperties["cookies"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["cookies"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -63,7 +75,13 @@ public Dictionary? Headers ModelBase.SerializerOptions ); } - set { this.BodyProperties["headers"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["headers"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -78,7 +96,13 @@ public long? NumberOfScrolls return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["number_of_scrolls"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["number_of_scrolls"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -93,7 +117,13 @@ public JsonElement? OutputSchema return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["output_schema"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["output_schema"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -108,7 +138,13 @@ public bool? RenderHeavyJs return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["render_heavy_js"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["render_heavy_js"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -123,7 +159,13 @@ public List? Steps return JsonSerializer.Deserialize?>(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["steps"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["steps"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -138,7 +180,13 @@ public long? TotalPages return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["total_pages"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["total_pages"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -153,7 +201,13 @@ public string? WebsiteHTML return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["website_html"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["website_html"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } /// @@ -168,7 +222,13 @@ public string? WebsiteURL return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.BodyProperties["website_url"] = JsonSerializer.SerializeToElement(value); } + set + { + this.BodyProperties["website_url"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override Uri Url(IScrapegraphaiClient client) diff --git a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs index 743d108..9123ea0 100644 --- a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs +++ b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs @@ -17,7 +17,13 @@ public string? Email return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } - set { this.Properties["email"] = JsonSerializer.SerializeToElement(value); } + set + { + this.Properties["email"] = JsonSerializer.SerializeToElement( + value, + ModelBase.SerializerOptions + ); + } } public override void Validate() From 647255852b82fe43015b8e4c00fa0627b096c061 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 20 Aug 2025 13:41:20 +0000 Subject: [PATCH 08/21] codegen metadata --- .stats.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.stats.yml b/.stats.yml index 561b1cc..6804ffb 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 15 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/scrapegraphai%2Fscrapegraphai-969ebada41127057e4cda129b2e7206224743b5c7fd33aa8ae062ff71b775ac9.yml -openapi_spec_hash: 2b2c2c684e6f6885398efca5f2b1f854 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/scrapegraphai%2Fscrapegraphai-633fdeab6abaefbe666099e8f86ce6b2acc9dacff1c33a80813bb04e8e437229.yml +openapi_spec_hash: f41ec90694ca8e7233bd20cc7ff1afbf config_hash: 6889576ba0fdc14f2c71cea09a60a0f6 From 3af2386fb58dc706227669f721e42ef5f45c72f6 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 03:53:30 +0000 Subject: [PATCH 09/21] feat(client): improve signature of `trypickx` methods --- .../CrawlRetrieveResultsResponseProperties/Result.cs | 5 +++-- .../GenerateSchema/GenerateSchemaRetrieveResponse.cs | 7 +++++-- .../Markdownify/MarkdownifyRetrieveStatusResponse.cs | 9 +++++++-- .../Searchscraper/SearchscraperRetrieveStatusResponse.cs | 9 +++++++-- .../Models/Smartscraper/SmartscraperListResponse.cs | 7 +++++-- .../Models/Smartscraper/SmartscraperRetrieveResponse.cs | 7 +++++-- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs index 15e09a5..24da8e2 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; using ResultVariants = Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.ResultVariants; @@ -19,13 +20,13 @@ public static implicit operator Result(JsonElement value) => public static implicit operator Result(string value) => new ResultVariants::String(value); - public bool TryPickJsonElement(out JsonElement? value) + public bool TryPickJsonElement([NotNullWhen(true)] out JsonElement? value) { value = (this as ResultVariants::JsonElement)?.Value; return value != null; } - public bool TryPickString(out string? value) + public bool TryPickString([NotNullWhen(true)] out string? value) { value = (this as ResultVariants::String)?.Value; return value != null; diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs index 478177d..2d8de39 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; using Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; @@ -21,7 +22,7 @@ FailedSchemaGenerationResponse value ) => new GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse(value); public bool TryPickCompletedSchemaGenerationResponse( - out CompletedSchemaGenerationResponse? value + [NotNullWhen(true)] out CompletedSchemaGenerationResponse? value ) { value = ( @@ -30,7 +31,9 @@ out CompletedSchemaGenerationResponse? value return value != null; } - public bool TryPickFailedSchemaGenerationResponse(out FailedSchemaGenerationResponse? value) + public bool TryPickFailedSchemaGenerationResponse( + [NotNullWhen(true)] out FailedSchemaGenerationResponse? value + ) { value = ( this as GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index 8d063d3..6b4bd38 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; using Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; @@ -19,7 +20,9 @@ public static implicit operator MarkdownifyRetrieveStatusResponse( FailedMarkdownifyResponse value ) => new MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse(value); - public bool TryPickCompletedMarkdownifyVariant(out CompletedMarkdownify? value) + public bool TryPickCompletedMarkdownifyVariant( + [NotNullWhen(true)] out CompletedMarkdownify? value + ) { value = ( this as MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant @@ -27,7 +30,9 @@ public bool TryPickCompletedMarkdownifyVariant(out CompletedMarkdownify? value) return value != null; } - public bool TryPickFailedMarkdownifyResponse(out FailedMarkdownifyResponse? value) + public bool TryPickFailedMarkdownifyResponse( + [NotNullWhen(true)] out FailedMarkdownifyResponse? value + ) { value = ( this as MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index 7c82173..8ca591a 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; using Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; @@ -20,7 +21,9 @@ public static implicit operator SearchscraperRetrieveStatusResponse( FailedSearchScraperResponse value ) => new SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse(value); - public bool TryPickCompletedSearchScraperVariant(out CompletedSearchScraper? value) + public bool TryPickCompletedSearchScraperVariant( + [NotNullWhen(true)] out CompletedSearchScraper? value + ) { value = ( this as SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant @@ -28,7 +31,9 @@ public bool TryPickCompletedSearchScraperVariant(out CompletedSearchScraper? val return value != null; } - public bool TryPickFailedSearchScraperResponse(out FailedSearchScraperResponse? value) + public bool TryPickFailedSearchScraperResponse( + [NotNullWhen(true)] out FailedSearchScraperResponse? value + ) { value = ( this as SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs index 7e71e2b..6e99a46 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; using Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; @@ -17,13 +18,15 @@ public static implicit operator SmartscraperListResponse(CompletedSmartscraper v public static implicit operator SmartscraperListResponse(FailedSmartscraper value) => new FailedSmartscraperVariant(value); - public bool TryPickCompletedSmartscraperVariant(out CompletedSmartscraper? value) + public bool TryPickCompletedSmartscraperVariant( + [NotNullWhen(true)] out CompletedSmartscraper? value + ) { value = (this as CompletedSmartscraperVariant)?.Value; return value != null; } - public bool TryPickFailedSmartscraperVariant(out FailedSmartscraper? value) + public bool TryPickFailedSmartscraperVariant([NotNullWhen(true)] out FailedSmartscraper? value) { value = (this as FailedSmartscraperVariant)?.Value; return value != null; diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs index 28defb3..c9a67e6 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; using Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; @@ -17,13 +18,15 @@ public static implicit operator SmartscraperRetrieveResponse(CompletedSmartscrap public static implicit operator SmartscraperRetrieveResponse(FailedSmartscraper value) => new FailedSmartscraperVariant(value); - public bool TryPickCompletedSmartscraperVariant(out CompletedSmartscraper? value) + public bool TryPickCompletedSmartscraperVariant( + [NotNullWhen(true)] out CompletedSmartscraper? value + ) { value = (this as CompletedSmartscraperVariant)?.Value; return value != null; } - public bool TryPickFailedSmartscraperVariant(out FailedSmartscraper? value) + public bool TryPickFailedSmartscraperVariant([NotNullWhen(true)] out FailedSmartscraper? value) { value = (this as FailedSmartscraperVariant)?.Value; return value != null; From 19debc832713e17708c2524bb9a09c1b967b36e5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 03:56:18 +0000 Subject: [PATCH 10/21] feat(internal): add dedicated build job in ci --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c17e75..accaea7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,23 @@ jobs: - name: Run lints run: ./scripts/lint + build: + timeout-minutes: 10 + name: build + runs-on: ${{ github.repository == 'stainless-sdks/scrapegraphai-csharp' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} + if: github.event_name == 'push' || github.event.pull_request.head.repo.fork + + steps: + - uses: actions/checkout@v4 + + - name: Set up .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Build SDK + run: ./scripts/build + test: timeout-minutes: 10 name: test From cf7d535c8802a1328e22dbccd58bff9186029827 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 04:01:21 +0000 Subject: [PATCH 11/21] feat(client): allow omitting all params object when all optional --- src/Scrapegraphai.Tests/Services/Credits/CreditServiceTest.cs | 2 +- .../Services/Healthz/HealthzServiceTest.cs | 2 +- .../Services/Smartscraper/SmartscraperServiceTest.cs | 2 +- .../Services/Validate/ValidateServiceTest.cs | 2 +- src/Scrapegraphai/Services/Credits/CreditService.cs | 4 +++- src/Scrapegraphai/Services/Credits/ICreditService.cs | 2 +- src/Scrapegraphai/Services/Healthz/HealthzService.cs | 4 +++- src/Scrapegraphai/Services/Healthz/IHealthzService.cs | 2 +- .../Services/Smartscraper/ISmartscraperService.cs | 2 +- .../Services/Smartscraper/SmartscraperService.cs | 4 +++- src/Scrapegraphai/Services/Validate/IValidateService.cs | 2 +- src/Scrapegraphai/Services/Validate/ValidateService.cs | 4 +++- 12 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Scrapegraphai.Tests/Services/Credits/CreditServiceTest.cs b/src/Scrapegraphai.Tests/Services/Credits/CreditServiceTest.cs index eea6fa1..98b7dfc 100644 --- a/src/Scrapegraphai.Tests/Services/Credits/CreditServiceTest.cs +++ b/src/Scrapegraphai.Tests/Services/Credits/CreditServiceTest.cs @@ -7,7 +7,7 @@ public class CreditServiceTest : TestBase [Fact(Skip = "Prism tests are disabled")] public async Task Retrieve_Works() { - var credit = await this.client.Credits.Retrieve(new()); + var credit = await this.client.Credits.Retrieve(); credit.Validate(); } } diff --git a/src/Scrapegraphai.Tests/Services/Healthz/HealthzServiceTest.cs b/src/Scrapegraphai.Tests/Services/Healthz/HealthzServiceTest.cs index ef8f743..f8750e4 100644 --- a/src/Scrapegraphai.Tests/Services/Healthz/HealthzServiceTest.cs +++ b/src/Scrapegraphai.Tests/Services/Healthz/HealthzServiceTest.cs @@ -7,7 +7,7 @@ public class HealthzServiceTest : TestBase [Fact(Skip = "Prism tests are disabled")] public async Task Check_Works() { - var response = await this.client.Healthz.Check(new()); + var response = await this.client.Healthz.Check(); response.Validate(); } } diff --git a/src/Scrapegraphai.Tests/Services/Smartscraper/SmartscraperServiceTest.cs b/src/Scrapegraphai.Tests/Services/Smartscraper/SmartscraperServiceTest.cs index 709bdae..14496ae 100644 --- a/src/Scrapegraphai.Tests/Services/Smartscraper/SmartscraperServiceTest.cs +++ b/src/Scrapegraphai.Tests/Services/Smartscraper/SmartscraperServiceTest.cs @@ -25,7 +25,7 @@ public async Task Retrieve_Works() [Fact(Skip = "Prism tests are disabled")] public async Task List_Works() { - var smartscrapers = await this.client.Smartscraper.List(new()); + var smartscrapers = await this.client.Smartscraper.List(); smartscrapers.Validate(); } } diff --git a/src/Scrapegraphai.Tests/Services/Validate/ValidateServiceTest.cs b/src/Scrapegraphai.Tests/Services/Validate/ValidateServiceTest.cs index 160441d..ac9ab72 100644 --- a/src/Scrapegraphai.Tests/Services/Validate/ValidateServiceTest.cs +++ b/src/Scrapegraphai.Tests/Services/Validate/ValidateServiceTest.cs @@ -7,7 +7,7 @@ public class ValidateServiceTest : TestBase [Fact(Skip = "Prism tests are disabled")] public async Task APIKey_Works() { - var response = await this.client.Validate.APIKey(new()); + var response = await this.client.Validate.APIKey(); response.Validate(); } } diff --git a/src/Scrapegraphai/Services/Credits/CreditService.cs b/src/Scrapegraphai/Services/Credits/CreditService.cs index 5eb6b4e..961f132 100644 --- a/src/Scrapegraphai/Services/Credits/CreditService.cs +++ b/src/Scrapegraphai/Services/Credits/CreditService.cs @@ -15,8 +15,10 @@ public CreditService(IScrapegraphaiClient client) _client = client; } - public async Task Retrieve(CreditRetrieveParams parameters) + public async Task Retrieve(CreditRetrieveParams? parameters = null) { + parameters ??= new(); + using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); parameters.AddHeadersToRequest(request, this._client); using HttpResponseMessage response = await this diff --git a/src/Scrapegraphai/Services/Credits/ICreditService.cs b/src/Scrapegraphai/Services/Credits/ICreditService.cs index c251b59..ad3c09d 100644 --- a/src/Scrapegraphai/Services/Credits/ICreditService.cs +++ b/src/Scrapegraphai/Services/Credits/ICreditService.cs @@ -8,5 +8,5 @@ public interface ICreditService /// /// Retrieve the current credit balance and usage for the authenticated user /// - Task Retrieve(CreditRetrieveParams parameters); + Task Retrieve(CreditRetrieveParams? parameters = null); } diff --git a/src/Scrapegraphai/Services/Healthz/HealthzService.cs b/src/Scrapegraphai/Services/Healthz/HealthzService.cs index 38caeb3..d06dafa 100644 --- a/src/Scrapegraphai/Services/Healthz/HealthzService.cs +++ b/src/Scrapegraphai/Services/Healthz/HealthzService.cs @@ -15,8 +15,10 @@ public HealthzService(IScrapegraphaiClient client) _client = client; } - public async Task Check(HealthzCheckParams parameters) + public async Task Check(HealthzCheckParams? parameters = null) { + parameters ??= new(); + using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); parameters.AddHeadersToRequest(request, this._client); using HttpResponseMessage response = await this diff --git a/src/Scrapegraphai/Services/Healthz/IHealthzService.cs b/src/Scrapegraphai/Services/Healthz/IHealthzService.cs index a6d84cd..e6ea316 100644 --- a/src/Scrapegraphai/Services/Healthz/IHealthzService.cs +++ b/src/Scrapegraphai/Services/Healthz/IHealthzService.cs @@ -8,5 +8,5 @@ public interface IHealthzService /// /// Check the health status of the service /// - Task Check(HealthzCheckParams parameters); + Task Check(HealthzCheckParams? parameters = null); } diff --git a/src/Scrapegraphai/Services/Smartscraper/ISmartscraperService.cs b/src/Scrapegraphai/Services/Smartscraper/ISmartscraperService.cs index 3249a9b..ef2fde4 100644 --- a/src/Scrapegraphai/Services/Smartscraper/ISmartscraperService.cs +++ b/src/Scrapegraphai/Services/Smartscraper/ISmartscraperService.cs @@ -19,5 +19,5 @@ public interface ISmartscraperService /// /// Retrieve the status and results of a scraping operation /// - Task List(SmartscraperListParams parameters); + Task List(SmartscraperListParams? parameters = null); } diff --git a/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs b/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs index 129d753..3af256f 100644 --- a/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs +++ b/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs @@ -60,8 +60,10 @@ await response.Content.ReadAsStreamAsync().ConfigureAwait(false), ) ?? throw new NullReferenceException(); } - public async Task List(SmartscraperListParams parameters) + public async Task List(SmartscraperListParams? parameters = null) { + parameters ??= new(); + using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); parameters.AddHeadersToRequest(request, this._client); using HttpResponseMessage response = await this diff --git a/src/Scrapegraphai/Services/Validate/IValidateService.cs b/src/Scrapegraphai/Services/Validate/IValidateService.cs index f91bd1c..ecfeaf4 100644 --- a/src/Scrapegraphai/Services/Validate/IValidateService.cs +++ b/src/Scrapegraphai/Services/Validate/IValidateService.cs @@ -8,5 +8,5 @@ public interface IValidateService /// /// Validate the API key and retrieve associated user email /// - Task APIKey(ValidateAPIKeyParams parameters); + Task APIKey(ValidateAPIKeyParams? parameters = null); } diff --git a/src/Scrapegraphai/Services/Validate/ValidateService.cs b/src/Scrapegraphai/Services/Validate/ValidateService.cs index 1f5aeb0..d2b4e94 100644 --- a/src/Scrapegraphai/Services/Validate/ValidateService.cs +++ b/src/Scrapegraphai/Services/Validate/ValidateService.cs @@ -15,8 +15,10 @@ public ValidateService(IScrapegraphaiClient client) _client = client; } - public async Task APIKey(ValidateAPIKeyParams parameters) + public async Task APIKey(ValidateAPIKeyParams? parameters = null) { + parameters ??= new(); + using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); parameters.AddHeadersToRequest(request, this._client); using HttpResponseMessage response = await this From 136affb4677cc727730d120abf6f9232eda5d9b8 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 04:05:00 +0000 Subject: [PATCH 12/21] chore(internal): rename parameters --- src/Scrapegraphai/ApiEnum.cs | 2 +- src/Scrapegraphai/ModelConverter.cs | 2 +- .../Crawl/CrawlRetrieveResultsResponseProperties/Result.cs | 2 +- .../Crawl/CrawlRetrieveResultsResponseProperties/Status.cs | 2 +- .../GenerateSchemaCreateResponseProperties/Status.cs | 2 +- .../Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs | 2 +- .../CompletedSchemaGenerationResponseProperties/Status.cs | 2 +- .../FailedSchemaGenerationResponseProperties/Status.cs | 2 +- .../Models/Markdownify/CompletedMarkdownifyProperties/Status.cs | 2 +- .../Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs | 2 +- .../FailedMarkdownifyResponseProperties/Status.cs | 2 +- .../Searchscraper/CompletedSearchScraperProperties/Status.cs | 2 +- .../Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs | 2 +- .../FailedSearchScraperResponseProperties/Status.cs | 2 +- .../Smartscraper/CompletedSmartscraperProperties/Status.cs | 2 +- .../Models/Smartscraper/FailedSmartscraperProperties/Status.cs | 2 +- .../Models/Smartscraper/SmartscraperListResponse.cs | 2 +- .../Models/Smartscraper/SmartscraperRetrieveResponse.cs | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Scrapegraphai/ApiEnum.cs b/src/Scrapegraphai/ApiEnum.cs index ea28e2e..a506e06 100644 --- a/src/Scrapegraphai/ApiEnum.cs +++ b/src/Scrapegraphai/ApiEnum.cs @@ -38,7 +38,7 @@ sealed class ApiEnumConverter : JsonConverter> { public override ApiEnum Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/ModelConverter.cs b/src/Scrapegraphai/ModelConverter.cs index e5a9051..a1d83bb 100644 --- a/src/Scrapegraphai/ModelConverter.cs +++ b/src/Scrapegraphai/ModelConverter.cs @@ -10,7 +10,7 @@ sealed class ModelConverter : JsonConverter { public override TModel? Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs index 24da8e2..cf6fea6 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs @@ -70,7 +70,7 @@ sealed class ResultConverter : JsonConverter { public override Result? Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs index ad3b1d1..9e64fe0 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs @@ -19,7 +19,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs index 122ce61..1b50bda 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs @@ -14,7 +14,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs index 2d8de39..6d46818 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs @@ -87,7 +87,7 @@ sealed class GenerateSchemaRetrieveResponseConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs index 2f20ded..7a7d4c6 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs @@ -14,7 +14,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs index 62b3d61..30e9d31 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs @@ -16,7 +16,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index 6b4bd38..dec6e22 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -87,7 +87,7 @@ sealed class MarkdownifyRetrieveStatusResponseConverter { public override MarkdownifyRetrieveStatusResponse? Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs index a9ee4fb..536d594 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs @@ -14,7 +14,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs index d3bc571..61d4c33 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs @@ -16,7 +16,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index 8ca591a..9a32088 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -88,7 +88,7 @@ sealed class SearchscraperRetrieveStatusResponseConverter { public override SearchscraperRetrieveStatusResponse? Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs index 238a3b3..ebb57e2 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs @@ -14,7 +14,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs index 4dde124..d329e70 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs @@ -19,7 +19,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs index 786bec4..bbb4167 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs @@ -14,7 +14,7 @@ sealed class StatusConverter : JsonConverter { public override Status Read( ref Utf8JsonReader reader, - Type _typeToConvert, + Type typeToConvert, JsonSerializerOptions options ) { diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs index 6e99a46..240d18c 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs @@ -70,7 +70,7 @@ sealed class SmartscraperListResponseConverter : JsonConverter Date: Sat, 23 Aug 2025 03:30:42 +0000 Subject: [PATCH 13/21] fix(client): better type names --- .../MarkdownifyRetrieveStatusResponse.cs | 22 ++++----- .../All.cs | 11 +++-- .../SearchscraperRetrieveStatusResponse.cs | 20 ++++---- .../All.cs | 11 +++-- .../Smartscraper/SmartscraperListResponse.cs | 44 +++++++++-------- .../SmartscraperListResponseVariants/All.cs | 18 +++---- .../SmartscraperRetrieveResponse.cs | 48 +++++++++++-------- .../All.cs | 18 +++---- 8 files changed, 100 insertions(+), 92 deletions(-) diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index dec6e22..a550981 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -14,19 +14,15 @@ public abstract record class MarkdownifyRetrieveStatusResponse internal MarkdownifyRetrieveStatusResponse() { } public static implicit operator MarkdownifyRetrieveStatusResponse(CompletedMarkdownify value) => - new MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant(value); + new MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify(value); public static implicit operator MarkdownifyRetrieveStatusResponse( FailedMarkdownifyResponse value ) => new MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse(value); - public bool TryPickCompletedMarkdownifyVariant( - [NotNullWhen(true)] out CompletedMarkdownify? value - ) + public bool TryPickCompletedMarkdownify([NotNullWhen(true)] out CompletedMarkdownify? value) { - value = ( - this as MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant - )?.Value; + value = (this as MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify)?.Value; return value != null; } @@ -41,13 +37,13 @@ public bool TryPickFailedMarkdownifyResponse( } public void Switch( - Action completedMarkdownify, + Action completedMarkdownify, Action failedMarkdownifyResponse ) { switch (this) { - case MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant inner: + case MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify inner: completedMarkdownify(inner); break; case MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner: @@ -60,7 +56,7 @@ public void Switch( public T Match( Func< - MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant, + MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify, T > completedMarkdownify, Func< @@ -71,7 +67,7 @@ public T Match( { return this switch { - MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant inner => + MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify inner => completedMarkdownify(inner), MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner => failedMarkdownifyResponse(inner), @@ -101,7 +97,7 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant( + return new MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify( deserialized ); } @@ -140,7 +136,7 @@ JsonSerializerOptions options { object variant = value switch { - MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownifyVariant( + MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify( var completedMarkdownify ) => completedMarkdownify, MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse( diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs index 45c8fad..9a0335a 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs @@ -1,12 +1,13 @@ +using Markdownify = Scrapegraphai.Models.Markdownify; using MarkdownifyRetrieveStatusResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseVariants; -public sealed record class CompletedMarkdownifyVariant(CompletedMarkdownify Value) - : MarkdownifyRetrieveStatusResponse, - IVariant +public sealed record class CompletedMarkdownify(Markdownify::CompletedMarkdownify Value) + : Markdownify::MarkdownifyRetrieveStatusResponse, + IVariant { - public static CompletedMarkdownifyVariant From(CompletedMarkdownify value) + public static CompletedMarkdownify From(Markdownify::CompletedMarkdownify value) { return new(value); } @@ -20,7 +21,7 @@ public override void Validate() public sealed record class FailedMarkdownifyResponse( MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse Value ) - : MarkdownifyRetrieveStatusResponse, + : Markdownify::MarkdownifyRetrieveStatusResponse, IVariant< FailedMarkdownifyResponse, MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index 9a32088..5e2d1d3 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -15,18 +15,16 @@ internal SearchscraperRetrieveStatusResponse() { } public static implicit operator SearchscraperRetrieveStatusResponse( CompletedSearchScraper value - ) => new SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant(value); + ) => new SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper(value); public static implicit operator SearchscraperRetrieveStatusResponse( FailedSearchScraperResponse value ) => new SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse(value); - public bool TryPickCompletedSearchScraperVariant( - [NotNullWhen(true)] out CompletedSearchScraper? value - ) + public bool TryPickCompletedSearchScraper([NotNullWhen(true)] out CompletedSearchScraper? value) { value = ( - this as SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant + this as SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper )?.Value; return value != null; } @@ -42,13 +40,13 @@ public bool TryPickFailedSearchScraperResponse( } public void Switch( - Action completedSearchScraper, + Action completedSearchScraper, Action failedSearchScraperResponse ) { switch (this) { - case SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant inner: + case SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper inner: completedSearchScraper(inner); break; case SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner: @@ -61,7 +59,7 @@ public void Switch( public T Match( Func< - SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant, + SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper, T > completedSearchScraper, Func< @@ -72,7 +70,7 @@ public T Match( { return this switch { - SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant inner => + SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper inner => completedSearchScraper(inner), SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner => failedSearchScraperResponse(inner), @@ -102,7 +100,7 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant( + return new SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper( deserialized ); } @@ -141,7 +139,7 @@ JsonSerializerOptions options { object variant = value switch { - SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraperVariant( + SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper( var completedSearchScraper ) => completedSearchScraper, SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse( diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs index 7e4aa70..dca8b7c 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs @@ -1,12 +1,13 @@ +using Searchscraper = Scrapegraphai.Models.Searchscraper; using SearchscraperRetrieveStatusResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseVariants; -public sealed record class CompletedSearchScraperVariant(CompletedSearchScraper Value) - : SearchscraperRetrieveStatusResponse, - IVariant +public sealed record class CompletedSearchScraper(Searchscraper::CompletedSearchScraper Value) + : Searchscraper::SearchscraperRetrieveStatusResponse, + IVariant { - public static CompletedSearchScraperVariant From(CompletedSearchScraper value) + public static CompletedSearchScraper From(Searchscraper::CompletedSearchScraper value) { return new(value); } @@ -20,7 +21,7 @@ public override void Validate() public sealed record class FailedSearchScraperResponse( SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse Value ) - : SearchscraperRetrieveStatusResponse, + : Searchscraper::SearchscraperRetrieveStatusResponse, IVariant< FailedSearchScraperResponse, SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs index 240d18c..811efd6 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs @@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; +using SmartscraperListResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; namespace Scrapegraphai.Models.Smartscraper; @@ -13,36 +13,34 @@ public abstract record class SmartscraperListResponse internal SmartscraperListResponse() { } public static implicit operator SmartscraperListResponse(CompletedSmartscraper value) => - new CompletedSmartscraperVariant(value); + new SmartscraperListResponseVariants::CompletedSmartscraper(value); public static implicit operator SmartscraperListResponse(FailedSmartscraper value) => - new FailedSmartscraperVariant(value); + new SmartscraperListResponseVariants::FailedSmartscraper(value); - public bool TryPickCompletedSmartscraperVariant( - [NotNullWhen(true)] out CompletedSmartscraper? value - ) + public bool TryPickCompletedSmartscraper([NotNullWhen(true)] out CompletedSmartscraper? value) { - value = (this as CompletedSmartscraperVariant)?.Value; + value = (this as SmartscraperListResponseVariants::CompletedSmartscraper)?.Value; return value != null; } - public bool TryPickFailedSmartscraperVariant([NotNullWhen(true)] out FailedSmartscraper? value) + public bool TryPickFailedSmartscraper([NotNullWhen(true)] out FailedSmartscraper? value) { - value = (this as FailedSmartscraperVariant)?.Value; + value = (this as SmartscraperListResponseVariants::FailedSmartscraper)?.Value; return value != null; } public void Switch( - Action completedSmartscraper, - Action failedSmartscraper + Action completedSmartscraper, + Action failedSmartscraper ) { switch (this) { - case CompletedSmartscraperVariant inner: + case SmartscraperListResponseVariants::CompletedSmartscraper inner: completedSmartscraper(inner); break; - case FailedSmartscraperVariant inner: + case SmartscraperListResponseVariants::FailedSmartscraper inner: failedSmartscraper(inner); break; default: @@ -51,14 +49,16 @@ Action failedSmartscraper } public T Match( - Func completedSmartscraper, - Func failedSmartscraper + Func completedSmartscraper, + Func failedSmartscraper ) { return this switch { - CompletedSmartscraperVariant inner => completedSmartscraper(inner), - FailedSmartscraperVariant inner => failedSmartscraper(inner), + SmartscraperListResponseVariants::CompletedSmartscraper inner => completedSmartscraper( + inner + ), + SmartscraperListResponseVariants::FailedSmartscraper inner => failedSmartscraper(inner), _ => throw new InvalidOperationException(), }; } @@ -84,7 +84,7 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new CompletedSmartscraperVariant(deserialized); + return new SmartscraperListResponseVariants::CompletedSmartscraper(deserialized); } } catch (JsonException e) @@ -97,7 +97,7 @@ JsonSerializerOptions options var deserialized = JsonSerializer.Deserialize(ref reader, options); if (deserialized != null) { - return new FailedSmartscraperVariant(deserialized); + return new SmartscraperListResponseVariants::FailedSmartscraper(deserialized); } } catch (JsonException e) @@ -116,8 +116,10 @@ JsonSerializerOptions options { object variant = value switch { - CompletedSmartscraperVariant(var completedSmartscraper) => completedSmartscraper, - FailedSmartscraperVariant(var failedSmartscraper) => failedSmartscraper, + SmartscraperListResponseVariants::CompletedSmartscraper(var completedSmartscraper) => + completedSmartscraper, + SmartscraperListResponseVariants::FailedSmartscraper(var failedSmartscraper) => + failedSmartscraper, _ => throw new ArgumentOutOfRangeException(nameof(value)), }; JsonSerializer.Serialize(writer, variant, options); diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs index ad8b962..fe6e3a9 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs @@ -1,10 +1,12 @@ +using Smartscraper = Scrapegraphai.Models.Smartscraper; + namespace Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; -public sealed record class CompletedSmartscraperVariant(CompletedSmartscraper Value) - : SmartscraperListResponse, - IVariant +public sealed record class CompletedSmartscraper(Smartscraper::CompletedSmartscraper Value) + : Smartscraper::SmartscraperListResponse, + IVariant { - public static CompletedSmartscraperVariant From(CompletedSmartscraper value) + public static CompletedSmartscraper From(Smartscraper::CompletedSmartscraper value) { return new(value); } @@ -15,11 +17,11 @@ public override void Validate() } } -public sealed record class FailedSmartscraperVariant(FailedSmartscraper Value) - : SmartscraperListResponse, - IVariant +public sealed record class FailedSmartscraper(Smartscraper::FailedSmartscraper Value) + : Smartscraper::SmartscraperListResponse, + IVariant { - public static FailedSmartscraperVariant From(FailedSmartscraper value) + public static FailedSmartscraper From(Smartscraper::FailedSmartscraper value) { return new(value); } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs index f443b4a..89945c2 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs @@ -3,7 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; -using Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; +using SmartscraperRetrieveResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; namespace Scrapegraphai.Models.Smartscraper; @@ -13,36 +13,34 @@ public abstract record class SmartscraperRetrieveResponse internal SmartscraperRetrieveResponse() { } public static implicit operator SmartscraperRetrieveResponse(CompletedSmartscraper value) => - new CompletedSmartscraperVariant(value); + new SmartscraperRetrieveResponseVariants::CompletedSmartscraper(value); public static implicit operator SmartscraperRetrieveResponse(FailedSmartscraper value) => - new FailedSmartscraperVariant(value); + new SmartscraperRetrieveResponseVariants::FailedSmartscraper(value); - public bool TryPickCompletedSmartscraperVariant( - [NotNullWhen(true)] out CompletedSmartscraper? value - ) + public bool TryPickCompletedSmartscraper([NotNullWhen(true)] out CompletedSmartscraper? value) { - value = (this as CompletedSmartscraperVariant)?.Value; + value = (this as SmartscraperRetrieveResponseVariants::CompletedSmartscraper)?.Value; return value != null; } - public bool TryPickFailedSmartscraperVariant([NotNullWhen(true)] out FailedSmartscraper? value) + public bool TryPickFailedSmartscraper([NotNullWhen(true)] out FailedSmartscraper? value) { - value = (this as FailedSmartscraperVariant)?.Value; + value = (this as SmartscraperRetrieveResponseVariants::FailedSmartscraper)?.Value; return value != null; } public void Switch( - Action completedSmartscraper, - Action failedSmartscraper + Action completedSmartscraper, + Action failedSmartscraper ) { switch (this) { - case CompletedSmartscraperVariant inner: + case SmartscraperRetrieveResponseVariants::CompletedSmartscraper inner: completedSmartscraper(inner); break; - case FailedSmartscraperVariant inner: + case SmartscraperRetrieveResponseVariants::FailedSmartscraper inner: failedSmartscraper(inner); break; default: @@ -51,14 +49,17 @@ Action failedSmartscraper } public T Match( - Func completedSmartscraper, - Func failedSmartscraper + Func completedSmartscraper, + Func failedSmartscraper ) { return this switch { - CompletedSmartscraperVariant inner => completedSmartscraper(inner), - FailedSmartscraperVariant inner => failedSmartscraper(inner), + SmartscraperRetrieveResponseVariants::CompletedSmartscraper inner => + completedSmartscraper(inner), + SmartscraperRetrieveResponseVariants::FailedSmartscraper inner => failedSmartscraper( + inner + ), _ => throw new InvalidOperationException(), }; } @@ -84,7 +85,9 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new CompletedSmartscraperVariant(deserialized); + return new SmartscraperRetrieveResponseVariants::CompletedSmartscraper( + deserialized + ); } } catch (JsonException e) @@ -97,7 +100,7 @@ JsonSerializerOptions options var deserialized = JsonSerializer.Deserialize(ref reader, options); if (deserialized != null) { - return new FailedSmartscraperVariant(deserialized); + return new SmartscraperRetrieveResponseVariants::FailedSmartscraper(deserialized); } } catch (JsonException e) @@ -116,8 +119,11 @@ JsonSerializerOptions options { object variant = value switch { - CompletedSmartscraperVariant(var completedSmartscraper) => completedSmartscraper, - FailedSmartscraperVariant(var failedSmartscraper) => failedSmartscraper, + SmartscraperRetrieveResponseVariants::CompletedSmartscraper( + var completedSmartscraper + ) => completedSmartscraper, + SmartscraperRetrieveResponseVariants::FailedSmartscraper(var failedSmartscraper) => + failedSmartscraper, _ => throw new ArgumentOutOfRangeException(nameof(value)), }; JsonSerializer.Serialize(writer, variant, options); diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs index 29fbb81..1b59bff 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs @@ -1,10 +1,12 @@ +using Smartscraper = Scrapegraphai.Models.Smartscraper; + namespace Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; -public sealed record class CompletedSmartscraperVariant(CompletedSmartscraper Value) - : SmartscraperRetrieveResponse, - IVariant +public sealed record class CompletedSmartscraper(Smartscraper::CompletedSmartscraper Value) + : Smartscraper::SmartscraperRetrieveResponse, + IVariant { - public static CompletedSmartscraperVariant From(CompletedSmartscraper value) + public static CompletedSmartscraper From(Smartscraper::CompletedSmartscraper value) { return new(value); } @@ -15,11 +17,11 @@ public override void Validate() } } -public sealed record class FailedSmartscraperVariant(FailedSmartscraper Value) - : SmartscraperRetrieveResponse, - IVariant +public sealed record class FailedSmartscraper(Smartscraper::FailedSmartscraper Value) + : Smartscraper::SmartscraperRetrieveResponse, + IVariant { - public static FailedSmartscraperVariant From(FailedSmartscraper value) + public static FailedSmartscraper From(Smartscraper::FailedSmartscraper value) { return new(value); } From 5d8fbc62da23aadf61ee88248acb409fec9c8bad Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 23 Aug 2025 03:37:31 +0000 Subject: [PATCH 14/21] feat(client): shorten union variant names --- .../GenerateSchemaRetrieveResponse.cs | 28 +++++++++---------- .../MarkdownifyRetrieveStatusResponse.cs | 16 +++++------ .../SearchscraperRetrieveStatusResponse.cs | 14 +++++----- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs index 6d46818..484144d 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs @@ -21,7 +21,7 @@ public static implicit operator GenerateSchemaRetrieveResponse( FailedSchemaGenerationResponse value ) => new GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse(value); - public bool TryPickCompletedSchemaGenerationResponse( + public bool TryPickCompletedSchemaGeneration( [NotNullWhen(true)] out CompletedSchemaGenerationResponse? value ) { @@ -31,7 +31,7 @@ public bool TryPickCompletedSchemaGenerationResponse( return value != null; } - public bool TryPickFailedSchemaGenerationResponse( + public bool TryPickFailedSchemaGeneration( [NotNullWhen(true)] out FailedSchemaGenerationResponse? value ) { @@ -42,17 +42,17 @@ public bool TryPickFailedSchemaGenerationResponse( } public void Switch( - Action completedSchemaGenerationResponse, - Action failedSchemaGenerationResponse + Action completedSchemaGeneration, + Action failedSchemaGeneration ) { switch (this) { case GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse inner: - completedSchemaGenerationResponse(inner); + completedSchemaGeneration(inner); break; case GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse inner: - failedSchemaGenerationResponse(inner); + failedSchemaGeneration(inner); break; default: throw new InvalidOperationException(); @@ -63,19 +63,19 @@ public T Match( Func< GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse, T - > completedSchemaGenerationResponse, + > completedSchemaGeneration, Func< GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse, T - > failedSchemaGenerationResponse + > failedSchemaGeneration ) { return this switch { GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse inner => - completedSchemaGenerationResponse(inner), + completedSchemaGeneration(inner), GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse inner => - failedSchemaGenerationResponse(inner), + failedSchemaGeneration(inner), _ => throw new InvalidOperationException(), }; } @@ -141,11 +141,11 @@ JsonSerializerOptions options object variant = value switch { GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse( - var completedSchemaGenerationResponse - ) => completedSchemaGenerationResponse, + var completedSchemaGeneration + ) => completedSchemaGeneration, GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse( - var failedSchemaGenerationResponse - ) => failedSchemaGenerationResponse, + var failedSchemaGeneration + ) => failedSchemaGeneration, _ => throw new ArgumentOutOfRangeException(nameof(value)), }; JsonSerializer.Serialize(writer, variant, options); diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index a550981..cc52c8e 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -26,9 +26,7 @@ public bool TryPickCompletedMarkdownify([NotNullWhen(true)] out CompletedMarkdow return value != null; } - public bool TryPickFailedMarkdownifyResponse( - [NotNullWhen(true)] out FailedMarkdownifyResponse? value - ) + public bool TryPickFailedMarkdownify([NotNullWhen(true)] out FailedMarkdownifyResponse? value) { value = ( this as MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse @@ -38,7 +36,7 @@ public bool TryPickFailedMarkdownifyResponse( public void Switch( Action completedMarkdownify, - Action failedMarkdownifyResponse + Action failedMarkdownify ) { switch (this) @@ -47,7 +45,7 @@ public void Switch( completedMarkdownify(inner); break; case MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner: - failedMarkdownifyResponse(inner); + failedMarkdownify(inner); break; default: throw new InvalidOperationException(); @@ -62,7 +60,7 @@ public T Match( Func< MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse, T - > failedMarkdownifyResponse + > failedMarkdownify ) { return this switch @@ -70,7 +68,7 @@ public T Match( MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify inner => completedMarkdownify(inner), MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner => - failedMarkdownifyResponse(inner), + failedMarkdownify(inner), _ => throw new InvalidOperationException(), }; } @@ -140,8 +138,8 @@ JsonSerializerOptions options var completedMarkdownify ) => completedMarkdownify, MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse( - var failedMarkdownifyResponse - ) => failedMarkdownifyResponse, + var failedMarkdownify + ) => failedMarkdownify, _ => throw new ArgumentOutOfRangeException(nameof(value)), }; JsonSerializer.Serialize(writer, variant, options); diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index 5e2d1d3..876a0a6 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -29,7 +29,7 @@ public bool TryPickCompletedSearchScraper([NotNullWhen(true)] out CompletedSearc return value != null; } - public bool TryPickFailedSearchScraperResponse( + public bool TryPickFailedSearchScraper( [NotNullWhen(true)] out FailedSearchScraperResponse? value ) { @@ -41,7 +41,7 @@ public bool TryPickFailedSearchScraperResponse( public void Switch( Action completedSearchScraper, - Action failedSearchScraperResponse + Action failedSearchScraper ) { switch (this) @@ -50,7 +50,7 @@ public void Switch( completedSearchScraper(inner); break; case SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner: - failedSearchScraperResponse(inner); + failedSearchScraper(inner); break; default: throw new InvalidOperationException(); @@ -65,7 +65,7 @@ public T Match( Func< SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse, T - > failedSearchScraperResponse + > failedSearchScraper ) { return this switch @@ -73,7 +73,7 @@ public T Match( SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper inner => completedSearchScraper(inner), SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner => - failedSearchScraperResponse(inner), + failedSearchScraper(inner), _ => throw new InvalidOperationException(), }; } @@ -143,8 +143,8 @@ JsonSerializerOptions options var completedSearchScraper ) => completedSearchScraper, SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse( - var failedSearchScraperResponse - ) => failedSearchScraperResponse, + var failedSearchScraper + ) => failedSearchScraper, _ => throw new ArgumentOutOfRangeException(nameof(value)), }; JsonSerializer.Serialize(writer, variant, options); From 4625b19d0f56f102c6e2a7cb8e953e8f83956e37 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 23 Aug 2025 03:37:54 +0000 Subject: [PATCH 15/21] fix(internal): remove unused null class --- src/Scrapegraphai/Null.cs | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/Scrapegraphai/Null.cs diff --git a/src/Scrapegraphai/Null.cs b/src/Scrapegraphai/Null.cs deleted file mode 100644 index 925b4e2..0000000 --- a/src/Scrapegraphai/Null.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Scrapegraphai; - -public sealed record class Null -{ - Null() { } -} From fc4a26933e1a20388a8102170fac78b3f74e2c22 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 11 Sep 2025 02:27:28 +0000 Subject: [PATCH 16/21] fix(client): handle multiple auth options gracefully --- src/Scrapegraphai/ParamsBase.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Scrapegraphai/ParamsBase.cs b/src/Scrapegraphai/ParamsBase.cs index a168bff..3733d67 100644 --- a/src/Scrapegraphai/ParamsBase.cs +++ b/src/Scrapegraphai/ParamsBase.cs @@ -149,6 +149,9 @@ protected string QueryString(IScrapegraphaiClient client) protected static void AddDefaultHeaders(HttpRequestMessage request, IScrapegraphaiClient client) { - request.Headers.Add("SGAI-APIKEY", client.APIKey); + if (client.APIKey != null) + { + request.Headers.Add("SGAI-APIKEY", client.APIKey); + } } } From 29c70b55ea868332d230cba9fa9978f46db01301 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 18 Sep 2025 02:16:38 +0000 Subject: [PATCH 17/21] fix(internal): remove example csproj --- examples/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/.keep diff --git a/examples/.keep b/examples/.keep new file mode 100644 index 0000000..e69de29 From 223ca7f992e4c17f97aa5ab7a16ec15cb1557aa9 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 2 Oct 2025 02:23:28 +0000 Subject: [PATCH 18/21] feat(client): refactor exceptions --- README.md | 27 +++++++ src/Scrapegraphai/{ => Core}/ApiEnum.cs | 9 ++- src/Scrapegraphai/Core/HttpRequest.cs | 11 +++ src/Scrapegraphai/Core/HttpResponse.cs | 32 +++++++++ src/Scrapegraphai/{ => Core}/IVariant.cs | 2 +- src/Scrapegraphai/{ => Core}/ModelBase.cs | 2 +- .../{ => Core}/ModelConverter.cs | 2 +- src/Scrapegraphai/{ => Core}/ParamsBase.cs | 12 +++- .../Exceptions/Scrapegraphai4xxException.cs | 9 +++ .../Exceptions/Scrapegraphai5xxException.cs | 9 +++ .../Exceptions/ScrapegraphaiApiException.cs | 35 ++++++++++ .../ScrapegraphaiBadRequestException.cs | 9 +++ .../Exceptions/ScrapegraphaiException.cs | 13 ++++ .../ScrapegraphaiExceptionFactory.cs | 61 ++++++++++++++++ .../ScrapegraphaiForbiddenException.cs | 9 +++ .../Exceptions/ScrapegraphaiIOException.cs | 22 ++++++ .../ScrapegraphaiInvalidDataException.cs | 9 +++ .../ScrapegraphaiNotFoundException.cs | 9 +++ .../ScrapegraphaiRateLimitException.cs | 9 +++ .../ScrapegraphaiUnauthorizedException.cs | 9 +++ ...apegraphaiUnexpectedStatusCodeException.cs | 9 +++ ...rapegraphaiUnprocessableEntityException.cs | 9 +++ src/Scrapegraphai/HttpException.cs | 29 -------- src/Scrapegraphai/IScrapegraphaiClient.cs | 5 ++ .../Crawl/CrawlRetrieveResultsParams.cs | 6 +- .../Crawl/CrawlRetrieveResultsResponse.cs | 1 + .../Result.cs | 29 ++++++-- .../ResultVariants/All.cs | 1 + .../Status.cs | 5 +- .../Models/Crawl/CrawlStartParams.cs | 19 +++-- .../Crawl/CrawlStartParamsProperties/Rules.cs | 1 + .../Models/Crawl/CrawlStartResponse.cs | 1 + .../Models/Credits/CreditRetrieveParams.cs | 6 +- .../Models/Credits/CreditRetrieveResponse.cs | 1 + .../Models/Feedback/FeedbackSubmitParams.cs | 24 +++++-- .../Models/Feedback/FeedbackSubmitResponse.cs | 1 + .../GenerateSchemaCreateParams.cs | 19 +++-- .../GenerateSchemaCreateResponse.cs | 1 + .../Status.cs | 5 +- .../GenerateSchemaRetrieveParams.cs | 6 +- .../GenerateSchemaRetrieveResponse.cs | 29 ++++++-- .../CompletedSchemaGenerationResponse.cs | 1 + .../Status.cs | 5 +- .../FailedSchemaGenerationResponse.cs | 1 + .../Status.cs | 5 +- .../All.cs | 1 + .../Models/Healthz/HealthzCheckParams.cs | 6 +- .../Models/Healthz/HealthzCheckResponse.cs | 1 + .../Markdownify/CompletedMarkdownify.cs | 1 + .../CompletedMarkdownifyProperties/Status.cs | 5 +- .../Markdownify/MarkdownifyConvertParams.cs | 19 +++-- .../MarkdownifyRetrieveStatusParams.cs | 6 +- .../MarkdownifyRetrieveStatusResponse.cs | 29 ++++++-- .../FailedMarkdownifyResponse.cs | 1 + .../Status.cs | 5 +- .../All.cs | 1 + .../Searchscraper/CompletedSearchScraper.cs | 1 + .../Status.cs | 5 +- .../SearchscraperCreateParams.cs | 19 +++-- .../SearchscraperRetrieveStatusParams.cs | 6 +- .../SearchscraperRetrieveStatusResponse.cs | 29 ++++++-- .../FailedSearchScraperResponse.cs | 1 + .../Status.cs | 5 +- .../All.cs | 1 + .../Smartscraper/CompletedSmartscraper.cs | 1 + .../CompletedSmartscraperProperties/Status.cs | 5 +- .../Models/Smartscraper/FailedSmartscraper.cs | 1 + .../FailedSmartscraperProperties/Status.cs | 5 +- .../Smartscraper/SmartscraperCreateParams.cs | 19 +++-- .../Smartscraper/SmartscraperListParams.cs | 6 +- .../Smartscraper/SmartscraperListResponse.cs | 29 ++++++-- .../SmartscraperListResponseVariants/All.cs | 1 + .../SmartscraperRetrieveParams.cs | 6 +- .../SmartscraperRetrieveResponse.cs | 29 ++++++-- .../All.cs | 1 + .../Models/Validate/ValidateAPIKeyParams.cs | 6 +- .../Models/Validate/ValidateAPIKeyResponse.cs | 1 + src/Scrapegraphai/ScrapegraphaiClient.cs | 48 ++++++++++++- .../Services/Crawl/CrawlService.cs | 48 ++++--------- .../Services/Credits/CreditService.cs | 25 ++----- .../Services/Feedback/FeedbackService.cs | 26 ++----- .../GenerateSchema/GenerateSchemaService.cs | 48 ++++--------- .../Services/Healthz/HealthzService.cs | 25 ++----- .../Markdownify/MarkdownifyService.cs | 50 ++++--------- .../Searchscraper/SearchscraperService.cs | 50 ++++--------- .../Smartscraper/SmartscraperService.cs | 70 +++++-------------- .../Services/Validate/ValidateService.cs | 25 ++----- 87 files changed, 799 insertions(+), 387 deletions(-) rename src/Scrapegraphai/{ => Core}/ApiEnum.cs (82%) create mode 100644 src/Scrapegraphai/Core/HttpRequest.cs create mode 100644 src/Scrapegraphai/Core/HttpResponse.cs rename src/Scrapegraphai/{ => Core}/IVariant.cs (81%) rename src/Scrapegraphai/{ => Core}/ModelBase.cs (97%) rename src/Scrapegraphai/{ => Core}/ModelConverter.cs (93%) rename src/Scrapegraphai/{ => Core}/ParamsBase.cs (92%) create mode 100644 src/Scrapegraphai/Exceptions/Scrapegraphai4xxException.cs create mode 100644 src/Scrapegraphai/Exceptions/Scrapegraphai5xxException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiApiException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiBadRequestException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiExceptionFactory.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiForbiddenException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiIOException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiInvalidDataException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiNotFoundException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiRateLimitException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiUnauthorizedException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiUnexpectedStatusCodeException.cs create mode 100644 src/Scrapegraphai/Exceptions/ScrapegraphaiUnprocessableEntityException.cs delete mode 100644 src/Scrapegraphai/HttpException.cs diff --git a/README.md b/README.md index fc80c6e..fc86bfc 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,33 @@ To send a request to the Scrapegraphai API, build an instance of some `Params` c For example, `client.Smartscraper.Create` should be called with an instance of `SmartscraperCreateParams`, and it will return an instance of `Task`. +## Error handling + +The SDK throws custom unchecked exception types: + +- `ScrapegraphaiApiException`: Base class for API errors. See this table for which exception subclass is thrown for each HTTP status code: + +| Status | Exception | +| ------ | -------------------------------------------- | +| 400 | `ScrapegraphaiBadRequestException` | +| 401 | `ScrapegraphaiUnauthorizedException` | +| 403 | `ScrapegraphaiForbiddenException` | +| 404 | `ScrapegraphaiNotFoundException` | +| 422 | `ScrapegraphaiUnprocessableEntityException` | +| 429 | `ScrapegraphaiRateLimitException` | +| 5xx | `Scrapegraphai5xxException` | +| others | `ScrapegraphaiUnexpectedStatusCodeException` | + +Additionally, all 4xx errors inherit from `Scrapegraphai4xxException`. + +false + +- `ScrapegraphaiIOException`: I/O networking errors. + +- `ScrapegraphaiInvalidDataException`: Failure to interpret successfully parsed data. For example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it from the response. + +- `ScrapegraphaiException`: Base class for all exceptions. + ## Semantic versioning This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions: diff --git a/src/Scrapegraphai/ApiEnum.cs b/src/Scrapegraphai/Core/ApiEnum.cs similarity index 82% rename from src/Scrapegraphai/ApiEnum.cs rename to src/Scrapegraphai/Core/ApiEnum.cs index a506e06..52276c7 100644 --- a/src/Scrapegraphai/ApiEnum.cs +++ b/src/Scrapegraphai/Core/ApiEnum.cs @@ -1,15 +1,18 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; -namespace Scrapegraphai; +namespace Scrapegraphai.Core; public record struct ApiEnum(JsonElement Json) where TEnum : struct, Enum { public readonly TRaw Raw() => JsonSerializer.Deserialize(this.Json, ModelBase.SerializerOptions) - ?? throw new NullReferenceException(nameof(this.Json)); + ?? throw new ScrapegraphaiInvalidDataException( + string.Format("{0} cannot be null", nameof(this.Json)) + ); public readonly TEnum Value() => JsonSerializer.Deserialize(this.Json, ModelBase.SerializerOptions); @@ -18,7 +21,7 @@ public readonly void Validate() { if (!Enum.IsDefined(Value())) { - throw new Exception(); + throw new ScrapegraphaiInvalidDataException("Invalid enum value"); } } diff --git a/src/Scrapegraphai/Core/HttpRequest.cs b/src/Scrapegraphai/Core/HttpRequest.cs new file mode 100644 index 0000000..4b30f85 --- /dev/null +++ b/src/Scrapegraphai/Core/HttpRequest.cs @@ -0,0 +1,11 @@ +using System.Net.Http; + +namespace Scrapegraphai.Core; + +public sealed class HttpRequest

+ where P : ParamsBase +{ + public required HttpMethod Method { get; init; } + + public required P Params { get; init; } +} diff --git a/src/Scrapegraphai/Core/HttpResponse.cs b/src/Scrapegraphai/Core/HttpResponse.cs new file mode 100644 index 0000000..1577205 --- /dev/null +++ b/src/Scrapegraphai/Core/HttpResponse.cs @@ -0,0 +1,32 @@ +using System; +using System.Net.Http; +using System.Text.Json; +using System.Threading.Tasks; +using Scrapegraphai.Exceptions; + +namespace Scrapegraphai.Core; + +public sealed class HttpResponse : IDisposable +{ + public required HttpResponseMessage Message { get; init; } + + public async Task Deserialize() + { + try + { + return JsonSerializer.Deserialize( + await Message.Content.ReadAsStreamAsync().ConfigureAwait(false), + ModelBase.SerializerOptions + ) ?? throw new ScrapegraphaiInvalidDataException("Response cannot be null"); + } + catch (HttpRequestException e) + { + throw new ScrapegraphaiIOException("I/O Exception", e); + } + } + + public void Dispose() + { + this.Message.Dispose(); + } +} diff --git a/src/Scrapegraphai/IVariant.cs b/src/Scrapegraphai/Core/IVariant.cs similarity index 81% rename from src/Scrapegraphai/IVariant.cs rename to src/Scrapegraphai/Core/IVariant.cs index 3928b0d..2517cd1 100644 --- a/src/Scrapegraphai/IVariant.cs +++ b/src/Scrapegraphai/Core/IVariant.cs @@ -1,4 +1,4 @@ -namespace Scrapegraphai; +namespace Scrapegraphai.Core; interface IVariant where TVariant : IVariant diff --git a/src/Scrapegraphai/ModelBase.cs b/src/Scrapegraphai/Core/ModelBase.cs similarity index 97% rename from src/Scrapegraphai/ModelBase.cs rename to src/Scrapegraphai/Core/ModelBase.cs index bc1939f..b562ae5 100644 --- a/src/Scrapegraphai/ModelBase.cs +++ b/src/Scrapegraphai/Core/ModelBase.cs @@ -11,7 +11,7 @@ using FailedSmartscraperProperties = Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; using GenerateSchemaCreateResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; -namespace Scrapegraphai; +namespace Scrapegraphai.Core; public abstract record class ModelBase { diff --git a/src/Scrapegraphai/ModelConverter.cs b/src/Scrapegraphai/Core/ModelConverter.cs similarity index 93% rename from src/Scrapegraphai/ModelConverter.cs rename to src/Scrapegraphai/Core/ModelConverter.cs index a1d83bb..ac5e38e 100644 --- a/src/Scrapegraphai/ModelConverter.cs +++ b/src/Scrapegraphai/Core/ModelConverter.cs @@ -3,7 +3,7 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace Scrapegraphai; +namespace Scrapegraphai.Core; sealed class ModelConverter : JsonConverter where TModel : ModelBase, IFromRaw diff --git a/src/Scrapegraphai/ParamsBase.cs b/src/Scrapegraphai/Core/ParamsBase.cs similarity index 92% rename from src/Scrapegraphai/ParamsBase.cs rename to src/Scrapegraphai/Core/ParamsBase.cs index 3733d67..a7a4d88 100644 --- a/src/Scrapegraphai/ParamsBase.cs +++ b/src/Scrapegraphai/Core/ParamsBase.cs @@ -7,7 +7,7 @@ using System.Text.Json; using Web = System.Web; -namespace Scrapegraphai; +namespace Scrapegraphai.Core; public abstract record class ParamsBase { @@ -147,6 +147,16 @@ protected string QueryString(IScrapegraphaiClient client) return sb.ToString(); } + internal abstract void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ); + + internal virtual StringContent? BodyContent() + { + return null; + } + protected static void AddDefaultHeaders(HttpRequestMessage request, IScrapegraphaiClient client) { if (client.APIKey != null) diff --git a/src/Scrapegraphai/Exceptions/Scrapegraphai4xxException.cs b/src/Scrapegraphai/Exceptions/Scrapegraphai4xxException.cs new file mode 100644 index 0000000..2ac569e --- /dev/null +++ b/src/Scrapegraphai/Exceptions/Scrapegraphai4xxException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class Scrapegraphai4xxException : ScrapegraphaiApiException +{ + public Scrapegraphai4xxException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/Scrapegraphai5xxException.cs b/src/Scrapegraphai/Exceptions/Scrapegraphai5xxException.cs new file mode 100644 index 0000000..5d89502 --- /dev/null +++ b/src/Scrapegraphai/Exceptions/Scrapegraphai5xxException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class Scrapegraphai5xxException : ScrapegraphaiApiException +{ + public Scrapegraphai5xxException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiApiException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiApiException.cs new file mode 100644 index 0000000..6bd5fbc --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiApiException.cs @@ -0,0 +1,35 @@ +using System; +using System.Net; +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiApiException : ScrapegraphaiException +{ + public new HttpRequestException InnerException + { + get + { + if (base.InnerException == null) + { + throw new ArgumentNullException(); + } + return (HttpRequestException)base.InnerException; + } + } + + public ScrapegraphaiApiException(string message, HttpRequestException? innerException = null) + : base(message, innerException) { } + + protected ScrapegraphaiApiException(HttpRequestException? innerException) + : base(innerException) { } + + public required HttpStatusCode StatusCode { get; init; } + + public required string ResponseBody { get; init; } + + public override string Message + { + get { return string.Format("Status Code: {0}\n{1}", StatusCode, ResponseBody); } + } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiBadRequestException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiBadRequestException.cs new file mode 100644 index 0000000..6bf15c9 --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiBadRequestException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiBadRequestException : Scrapegraphai4xxException +{ + public ScrapegraphaiBadRequestException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiException.cs new file mode 100644 index 0000000..dda98e2 --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiException.cs @@ -0,0 +1,13 @@ +using System; +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiException : Exception +{ + public ScrapegraphaiException(string message, Exception? innerException = null) + : base(message, innerException) { } + + protected ScrapegraphaiException(HttpRequestException? innerException) + : base(null, innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiExceptionFactory.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiExceptionFactory.cs new file mode 100644 index 0000000..98c27db --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiExceptionFactory.cs @@ -0,0 +1,61 @@ +using System.Net; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiExceptionFactory +{ + public static ScrapegraphaiApiException CreateApiException( + HttpStatusCode statusCode, + string responseBody + ) + { + return (int)statusCode switch + { + 400 => new ScrapegraphaiBadRequestException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + 401 => new ScrapegraphaiUnauthorizedException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + 403 => new ScrapegraphaiForbiddenException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + 404 => new ScrapegraphaiNotFoundException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + 422 => new ScrapegraphaiUnprocessableEntityException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + 429 => new ScrapegraphaiRateLimitException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + >= 400 and <= 499 => new Scrapegraphai4xxException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + >= 500 and <= 599 => new Scrapegraphai5xxException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + _ => new ScrapegraphaiUnexpectedStatusCodeException() + { + StatusCode = statusCode, + ResponseBody = responseBody, + }, + }; + } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiForbiddenException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiForbiddenException.cs new file mode 100644 index 0000000..04c0c88 --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiForbiddenException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiForbiddenException : Scrapegraphai4xxException +{ + public ScrapegraphaiForbiddenException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiIOException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiIOException.cs new file mode 100644 index 0000000..9f359e5 --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiIOException.cs @@ -0,0 +1,22 @@ +using System; +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiIOException : ScrapegraphaiException +{ + public new HttpRequestException InnerException + { + get + { + if (base.InnerException == null) + { + throw new ArgumentNullException(); + } + return (HttpRequestException)base.InnerException; + } + } + + public ScrapegraphaiIOException(string message, HttpRequestException? innerException = null) + : base(message, innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiInvalidDataException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiInvalidDataException.cs new file mode 100644 index 0000000..db28f3f --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiInvalidDataException.cs @@ -0,0 +1,9 @@ +using System; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiInvalidDataException : ScrapegraphaiException +{ + public ScrapegraphaiInvalidDataException(string message, Exception? innerException = null) + : base(message, innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiNotFoundException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiNotFoundException.cs new file mode 100644 index 0000000..6ed60bc --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiNotFoundException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiNotFoundException : Scrapegraphai4xxException +{ + public ScrapegraphaiNotFoundException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiRateLimitException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiRateLimitException.cs new file mode 100644 index 0000000..61f2ab8 --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiRateLimitException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiRateLimitException : Scrapegraphai4xxException +{ + public ScrapegraphaiRateLimitException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiUnauthorizedException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiUnauthorizedException.cs new file mode 100644 index 0000000..c2d2add --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiUnauthorizedException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiUnauthorizedException : Scrapegraphai4xxException +{ + public ScrapegraphaiUnauthorizedException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiUnexpectedStatusCodeException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiUnexpectedStatusCodeException.cs new file mode 100644 index 0000000..a82b14d --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiUnexpectedStatusCodeException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiUnexpectedStatusCodeException : ScrapegraphaiApiException +{ + public ScrapegraphaiUnexpectedStatusCodeException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/Exceptions/ScrapegraphaiUnprocessableEntityException.cs b/src/Scrapegraphai/Exceptions/ScrapegraphaiUnprocessableEntityException.cs new file mode 100644 index 0000000..48b20bd --- /dev/null +++ b/src/Scrapegraphai/Exceptions/ScrapegraphaiUnprocessableEntityException.cs @@ -0,0 +1,9 @@ +using System.Net.Http; + +namespace Scrapegraphai.Exceptions; + +public class ScrapegraphaiUnprocessableEntityException : Scrapegraphai4xxException +{ + public ScrapegraphaiUnprocessableEntityException(HttpRequestException? innerException = null) + : base(innerException) { } +} diff --git a/src/Scrapegraphai/HttpException.cs b/src/Scrapegraphai/HttpException.cs deleted file mode 100644 index 3cadf97..0000000 --- a/src/Scrapegraphai/HttpException.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Diagnostics.CodeAnalysis; -using System.Net; - -namespace Scrapegraphai; - -public sealed class HttpException : Exception -{ - public required HttpStatusCode? StatusCode { get; set; } - public required string ResponseBody { get; set; } - public override string Message - { - get - { - return string.Format( - "Status Code: {0}\n{1}", - this.StatusCode?.ToString() ?? "Unknown", - this.ResponseBody - ); - } - } - - [SetsRequiredMembers] - public HttpException(HttpStatusCode? statusCode, string responseBody) - { - this.StatusCode = statusCode; - this.ResponseBody = responseBody; - } -} diff --git a/src/Scrapegraphai/IScrapegraphaiClient.cs b/src/Scrapegraphai/IScrapegraphaiClient.cs index 689eb27..87d79c7 100644 --- a/src/Scrapegraphai/IScrapegraphaiClient.cs +++ b/src/Scrapegraphai/IScrapegraphaiClient.cs @@ -1,5 +1,7 @@ using System; using System.Net.Http; +using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Services.Crawl; using Scrapegraphai.Services.Credits; using Scrapegraphai.Services.Feedback; @@ -40,4 +42,7 @@ public interface IScrapegraphaiClient IFeedbackService Feedback { get; } IHealthzService Healthz { get; } + + Task Execute(HttpRequest request) + where T : ParamsBase; } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs index 1be6120..f3a4b68 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Crawl; @@ -20,7 +21,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs index f094b97..42117f7 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; namespace Scrapegraphai.Models.Crawl; diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs index cf6fea6..10ee3ee 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; using ResultVariants = Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.ResultVariants; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; @@ -46,7 +47,9 @@ public void Switch( @string(inner); break; default: - throw new InvalidOperationException(); + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of Result" + ); } } @@ -59,7 +62,9 @@ public T Match( { ResultVariants::JsonElement inner => jsonElement(inner), ResultVariants::String inner => @string(inner), - _ => throw new InvalidOperationException(), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of Result" + ), }; } @@ -74,7 +79,7 @@ sealed class ResultConverter : JsonConverter JsonSerializerOptions options ) { - List exceptions = []; + List exceptions = []; try { @@ -86,7 +91,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant ResultVariants::String", + e + ) + ); } try @@ -97,7 +107,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant ResultVariants::JsonElement", + e + ) + ); } throw new AggregateException(exceptions); @@ -109,7 +124,9 @@ public override void Write(Utf8JsonWriter writer, Result value, JsonSerializerOp { ResultVariants::JsonElement(var jsonElement) => jsonElement, ResultVariants::String(var @string) => @string, - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of Result" + ), }; JsonSerializer.Serialize(writer, variant, options); } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs index 8f94441..d06cb03 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs @@ -1,3 +1,4 @@ +using Scrapegraphai.Core; using Json = System.Text.Json; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.ResultVariants; diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs index 9e64fe0..b4da48c 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; @@ -47,7 +48,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp Status.Failure => "FAILURE", Status.Retry => "RETRY", Status.Revoked => "REVOKED", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs index bc57576..59bd4fc 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartParams.cs @@ -3,6 +3,8 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai.Core; +using Scrapegraphai.Exceptions; using Scrapegraphai.Models.Crawl.CrawlStartParamsProperties; namespace Scrapegraphai.Models.Crawl; @@ -23,10 +25,16 @@ public required string URL get { if (!this.BodyProperties.TryGetValue("url", out JsonElement element)) - throw new ArgumentOutOfRangeException("url", "Missing required argument"); + throw new ScrapegraphaiInvalidDataException( + "'url' cannot be null", + new ArgumentOutOfRangeException("url", "Missing required argument") + ); return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("url"); + ?? throw new ScrapegraphaiInvalidDataException( + "'url' cannot be null", + new ArgumentNullException("url") + ); } set { @@ -210,7 +218,7 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public StringContent BodyContent() + internal override StringContent? BodyContent() { return new( JsonSerializer.Serialize(this.BodyProperties), @@ -219,7 +227,10 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs index a5a2574..1dc8b5f 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartParamsProperties/Rules.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Crawl.CrawlStartParamsProperties; diff --git a/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs b/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs index ea96632..8941006 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlStartResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Crawl; diff --git a/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs b/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs index 1852494..256e100 100644 --- a/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs +++ b/src/Scrapegraphai/Models/Credits/CreditRetrieveParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Credits; @@ -16,7 +17,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs b/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs index 5f92748..c68c463 100644 --- a/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Credits/CreditRetrieveResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Credits; diff --git a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs index ea38ed7..ab1a7c2 100644 --- a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs +++ b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitParams.cs @@ -3,6 +3,8 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai.Core; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Feedback; @@ -21,7 +23,10 @@ public required long Rating get { if (!this.BodyProperties.TryGetValue("rating", out JsonElement element)) - throw new ArgumentOutOfRangeException("rating", "Missing required argument"); + throw new ScrapegraphaiInvalidDataException( + "'rating' cannot be null", + new ArgumentOutOfRangeException("rating", "Missing required argument") + ); return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions); } @@ -42,10 +47,16 @@ public required string RequestID get { if (!this.BodyProperties.TryGetValue("request_id", out JsonElement element)) - throw new ArgumentOutOfRangeException("request_id", "Missing required argument"); + throw new ScrapegraphaiInvalidDataException( + "'request_id' cannot be null", + new ArgumentOutOfRangeException("request_id", "Missing required argument") + ); return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("request_id"); + ?? throw new ScrapegraphaiInvalidDataException( + "'request_id' cannot be null", + new ArgumentNullException("request_id") + ); } set { @@ -85,7 +96,7 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public StringContent BodyContent() + internal override StringContent? BodyContent() { return new( JsonSerializer.Serialize(this.BodyProperties), @@ -94,7 +105,10 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs index fc53ee3..cc31b3e 100644 --- a/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs +++ b/src/Scrapegraphai/Models/Feedback/FeedbackSubmitResponse.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Feedback; diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs index f108377..257fecc 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateParams.cs @@ -3,6 +3,8 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai.Core; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.GenerateSchema; @@ -22,10 +24,16 @@ public required string UserPrompt get { if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) - throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); + throw new ScrapegraphaiInvalidDataException( + "'user_prompt' cannot be null", + new ArgumentOutOfRangeException("user_prompt", "Missing required argument") + ); return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("user_prompt"); + ?? throw new ScrapegraphaiInvalidDataException( + "'user_prompt' cannot be null", + new ArgumentNullException("user_prompt") + ); } set { @@ -65,7 +73,7 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public StringContent BodyContent() + internal override StringContent? BodyContent() { return new( JsonSerializer.Serialize(this.BodyProperties), @@ -74,7 +82,10 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs index 094164e..d8df0a1 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; namespace Scrapegraphai.Models.GenerateSchema; diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs index 1b50bda..be065bf 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaCreateResponseProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaCreateResponseProperties; @@ -32,7 +33,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp value switch { Status.Completed => "completed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs index 177ceda..5d81aea 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.GenerateSchema; @@ -21,7 +22,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs index 484144d..b821ab7 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; using Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; using GenerateSchemaRetrieveResponseVariants = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseVariants; @@ -55,7 +56,9 @@ public void Switch( failedSchemaGeneration(inner); break; default: - throw new InvalidOperationException(); + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of GenerateSchemaRetrieveResponse" + ); } } @@ -76,7 +79,9 @@ public T Match( completedSchemaGeneration(inner), GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse inner => failedSchemaGeneration(inner), - _ => throw new InvalidOperationException(), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of GenerateSchemaRetrieveResponse" + ), }; } @@ -91,7 +96,7 @@ sealed class GenerateSchemaRetrieveResponseConverter : JsonConverter exceptions = []; + List exceptions = []; try { @@ -108,7 +113,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse", + e + ) + ); } try @@ -126,7 +136,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse", + e + ) + ); } throw new AggregateException(exceptions); @@ -146,7 +161,9 @@ var completedSchemaGeneration GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse( var failedSchemaGeneration ) => failedSchemaGeneration, - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of GenerateSchemaRetrieveResponse" + ), }; JsonSerializer.Serialize(writer, variant, options); } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs index e754788..fdeab25 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs index 3a1b062..22b0cc4 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/CompletedSchemaGenerationResponseProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.CompletedSchemaGenerationResponseProperties; @@ -32,7 +33,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp value switch { Status.Completed => "completed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs index 9249278..025a8ab 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs index 7a7d4c6..f2442c5 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseProperties/FailedSchemaGenerationResponseProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties.FailedSchemaGenerationResponseProperties; @@ -32,7 +33,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp value switch { Status.Failed => "failed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs index 08d60fd..5b526e3 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs @@ -1,3 +1,4 @@ +using Scrapegraphai.Core; using GenerateSchemaRetrieveResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseVariants; diff --git a/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs b/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs index 380c72f..6f53ad8 100644 --- a/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs +++ b/src/Scrapegraphai/Models/Healthz/HealthzCheckParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Healthz; @@ -16,7 +17,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs b/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs index db7b0ff..b923c3a 100644 --- a/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs +++ b/src/Scrapegraphai/Models/Healthz/HealthzCheckResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Healthz; diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs index 3da8a70..2bb137d 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownify.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; namespace Scrapegraphai.Models.Markdownify; diff --git a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs index 30e9d31..580c705 100644 --- a/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/CompletedMarkdownifyProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Markdownify.CompletedMarkdownifyProperties; @@ -38,7 +39,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp Status.Queued => "queued", Status.Processing => "processing", Status.Completed => "completed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs index 40334ec..4a08534 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyConvertParams.cs @@ -3,6 +3,8 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai.Core; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Markdownify; @@ -21,10 +23,16 @@ public required string WebsiteURL get { if (!this.BodyProperties.TryGetValue("website_url", out JsonElement element)) - throw new ArgumentOutOfRangeException("website_url", "Missing required argument"); + throw new ScrapegraphaiInvalidDataException( + "'website_url' cannot be null", + new ArgumentOutOfRangeException("website_url", "Missing required argument") + ); return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("website_url"); + ?? throw new ScrapegraphaiInvalidDataException( + "'website_url' cannot be null", + new ArgumentNullException("website_url") + ); } set { @@ -85,7 +93,7 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public StringContent BodyContent() + internal override StringContent? BodyContent() { return new( JsonSerializer.Serialize(this.BodyProperties), @@ -94,7 +102,10 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs index d644411..f72aace 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Markdownify; @@ -21,7 +22,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index cc52c8e..0c81bec 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; using Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; using MarkdownifyRetrieveStatusResponseVariants = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseVariants; @@ -48,7 +49,9 @@ public void Switch( failedMarkdownify(inner); break; default: - throw new InvalidOperationException(); + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of MarkdownifyRetrieveStatusResponse" + ); } } @@ -69,7 +72,9 @@ public T Match( completedMarkdownify(inner), MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner => failedMarkdownify(inner), - _ => throw new InvalidOperationException(), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of MarkdownifyRetrieveStatusResponse" + ), }; } @@ -85,7 +90,7 @@ sealed class MarkdownifyRetrieveStatusResponseConverter JsonSerializerOptions options ) { - List exceptions = []; + List exceptions = []; try { @@ -102,7 +107,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify", + e + ) + ); } try @@ -120,7 +130,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse", + e + ) + ); } throw new AggregateException(exceptions); @@ -140,7 +155,9 @@ var completedMarkdownify MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse( var failedMarkdownify ) => failedMarkdownify, - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of MarkdownifyRetrieveStatusResponse" + ), }; JsonSerializer.Serialize(writer, variant, options); } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs index 84349bf..10a2b2a 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs index 536d594..d819cbc 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseProperties/FailedMarkdownifyResponseProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties.FailedMarkdownifyResponseProperties; @@ -32,7 +33,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp value switch { Status.Failed => "failed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs index 9a0335a..49a7151 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs @@ -1,3 +1,4 @@ +using Scrapegraphai.Core; using Markdownify = Scrapegraphai.Models.Markdownify; using MarkdownifyRetrieveStatusResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs index af07cd1..557f8f4 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraper.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; namespace Scrapegraphai.Models.Searchscraper; diff --git a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs index 61d4c33..b7030d3 100644 --- a/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/CompletedSearchScraperProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Searchscraper.CompletedSearchScraperProperties; @@ -38,7 +39,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp Status.Queued => "queued", Status.Processing => "processing", Status.Completed => "completed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs index 0b3ae3f..f98bb84 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperCreateParams.cs @@ -3,6 +3,8 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai.Core; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Searchscraper; @@ -23,10 +25,16 @@ public required string UserPrompt get { if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) - throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); + throw new ScrapegraphaiInvalidDataException( + "'user_prompt' cannot be null", + new ArgumentOutOfRangeException("user_prompt", "Missing required argument") + ); return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("user_prompt"); + ?? throw new ScrapegraphaiInvalidDataException( + "'user_prompt' cannot be null", + new ArgumentNullException("user_prompt") + ); } set { @@ -108,7 +116,7 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public StringContent BodyContent() + internal override StringContent? BodyContent() { return new( JsonSerializer.Serialize(this.BodyProperties), @@ -117,7 +125,10 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs index a7f4d89..858b969 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Searchscraper; @@ -21,7 +22,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index 876a0a6..530be8a 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; using Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; using SearchscraperRetrieveStatusResponseVariants = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseVariants; @@ -53,7 +54,9 @@ public void Switch( failedSearchScraper(inner); break; default: - throw new InvalidOperationException(); + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SearchscraperRetrieveStatusResponse" + ); } } @@ -74,7 +77,9 @@ public T Match( completedSearchScraper(inner), SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner => failedSearchScraper(inner), - _ => throw new InvalidOperationException(), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SearchscraperRetrieveStatusResponse" + ), }; } @@ -90,7 +95,7 @@ sealed class SearchscraperRetrieveStatusResponseConverter JsonSerializerOptions options ) { - List exceptions = []; + List exceptions = []; try { @@ -107,7 +112,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper", + e + ) + ); } try @@ -125,7 +135,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse", + e + ) + ); } throw new AggregateException(exceptions); @@ -145,7 +160,9 @@ var completedSearchScraper SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse( var failedSearchScraper ) => failedSearchScraper, - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SearchscraperRetrieveStatusResponse" + ), }; JsonSerializer.Serialize(writer, variant, options); } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs index fd77c26..2bb410e 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs index ebb57e2..35572ef 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseProperties/FailedSearchScraperResponseProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties.FailedSearchScraperResponseProperties; @@ -32,7 +33,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp value switch { Status.Failed => "failed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs index dca8b7c..47aab92 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs @@ -1,3 +1,4 @@ +using Scrapegraphai.Core; using Searchscraper = Scrapegraphai.Models.Searchscraper; using SearchscraperRetrieveStatusResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs index a624905..5cd2b5e 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraper.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; namespace Scrapegraphai.Models.Smartscraper; diff --git a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs index d329e70..3b0d148 100644 --- a/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/CompletedSmartscraperProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Smartscraper.CompletedSmartscraperProperties; @@ -41,7 +42,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp Status.Queued => "queued", Status.Processing => "processing", Status.Completed => "completed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs index d96e794..1ce23ab 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraper.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; using Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; namespace Scrapegraphai.Models.Smartscraper; diff --git a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs index bbb4167..8dbcab4 100644 --- a/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs +++ b/src/Scrapegraphai/Models/Smartscraper/FailedSmartscraperProperties/Status.cs @@ -1,6 +1,7 @@ using System; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Smartscraper.FailedSmartscraperProperties; @@ -32,7 +33,9 @@ public override void Write(Utf8JsonWriter writer, Status value, JsonSerializerOp value switch { Status.Failed => "failed", - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + string.Format("Invalid value '{0}' in {1}", value, nameof(value)) + ), }, options ); diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs index 89da30e..424e715 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperCreateParams.cs @@ -3,6 +3,8 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using Scrapegraphai.Core; +using Scrapegraphai.Exceptions; namespace Scrapegraphai.Models.Smartscraper; @@ -22,10 +24,16 @@ public required string UserPrompt get { if (!this.BodyProperties.TryGetValue("user_prompt", out JsonElement element)) - throw new ArgumentOutOfRangeException("user_prompt", "Missing required argument"); + throw new ScrapegraphaiInvalidDataException( + "'user_prompt' cannot be null", + new ArgumentOutOfRangeException("user_prompt", "Missing required argument") + ); return JsonSerializer.Deserialize(element, ModelBase.SerializerOptions) - ?? throw new ArgumentNullException("user_prompt"); + ?? throw new ScrapegraphaiInvalidDataException( + "'user_prompt' cannot be null", + new ArgumentNullException("user_prompt") + ); } set { @@ -239,7 +247,7 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public StringContent BodyContent() + internal override StringContent? BodyContent() { return new( JsonSerializer.Serialize(this.BodyProperties), @@ -248,7 +256,10 @@ public StringContent BodyContent() ); } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs index 01727b5..7b83f44 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Smartscraper; @@ -16,7 +17,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs index 811efd6..571fed0 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; using SmartscraperListResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; namespace Scrapegraphai.Models.Smartscraper; @@ -44,7 +45,9 @@ public void Switch( failedSmartscraper(inner); break; default: - throw new InvalidOperationException(); + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SmartscraperListResponse" + ); } } @@ -59,7 +62,9 @@ public T Match( inner ), SmartscraperListResponseVariants::FailedSmartscraper inner => failedSmartscraper(inner), - _ => throw new InvalidOperationException(), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SmartscraperListResponse" + ), }; } @@ -74,7 +79,7 @@ sealed class SmartscraperListResponseConverter : JsonConverter exceptions = []; + List exceptions = []; try { @@ -89,7 +94,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant SmartscraperListResponseVariants::CompletedSmartscraper", + e + ) + ); } try @@ -102,7 +112,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant SmartscraperListResponseVariants::FailedSmartscraper", + e + ) + ); } throw new AggregateException(exceptions); @@ -120,7 +135,9 @@ JsonSerializerOptions options completedSmartscraper, SmartscraperListResponseVariants::FailedSmartscraper(var failedSmartscraper) => failedSmartscraper, - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SmartscraperListResponse" + ), }; JsonSerializer.Serialize(writer, variant, options); } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs index fe6e3a9..c797f30 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs @@ -1,3 +1,4 @@ +using Scrapegraphai.Core; using Smartscraper = Scrapegraphai.Models.Smartscraper; namespace Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs index 68dcbce..9e3f89e 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Smartscraper; @@ -21,7 +22,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs index 89945c2..cd1a220 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Exceptions; using SmartscraperRetrieveResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; namespace Scrapegraphai.Models.Smartscraper; @@ -44,7 +45,9 @@ public void Switch( failedSmartscraper(inner); break; default: - throw new InvalidOperationException(); + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SmartscraperRetrieveResponse" + ); } } @@ -60,7 +63,9 @@ public T Match( SmartscraperRetrieveResponseVariants::FailedSmartscraper inner => failedSmartscraper( inner ), - _ => throw new InvalidOperationException(), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SmartscraperRetrieveResponse" + ), }; } @@ -75,7 +80,7 @@ sealed class SmartscraperRetrieveResponseConverter : JsonConverter exceptions = []; + List exceptions = []; try { @@ -92,7 +97,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant SmartscraperRetrieveResponseVariants::CompletedSmartscraper", + e + ) + ); } try @@ -105,7 +115,12 @@ JsonSerializerOptions options } catch (JsonException e) { - exceptions.Add(e); + exceptions.Add( + new ScrapegraphaiInvalidDataException( + "Data does not match union variant SmartscraperRetrieveResponseVariants::FailedSmartscraper", + e + ) + ); } throw new AggregateException(exceptions); @@ -124,7 +139,9 @@ var completedSmartscraper ) => completedSmartscraper, SmartscraperRetrieveResponseVariants::FailedSmartscraper(var failedSmartscraper) => failedSmartscraper, - _ => throw new ArgumentOutOfRangeException(nameof(value)), + _ => throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SmartscraperRetrieveResponse" + ), }; JsonSerializer.Serialize(writer, variant, options); } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs index 1b59bff..567aa57 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs @@ -1,3 +1,4 @@ +using Scrapegraphai.Core; using Smartscraper = Scrapegraphai.Models.Smartscraper; namespace Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; diff --git a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs index bd8cc21..a3ce9eb 100644 --- a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs +++ b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyParams.cs @@ -1,5 +1,6 @@ using System; using System.Net.Http; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Validate; @@ -16,7 +17,10 @@ public override Uri Url(IScrapegraphaiClient client) }.Uri; } - public void AddHeadersToRequest(HttpRequestMessage request, IScrapegraphaiClient client) + internal override void AddHeadersToRequest( + HttpRequestMessage request, + IScrapegraphaiClient client + ) { ParamsBase.AddDefaultHeaders(request, client); foreach (var item in this.HeaderProperties) diff --git a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs index 9123ea0..4d5e286 100644 --- a/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs +++ b/src/Scrapegraphai/Models/Validate/ValidateAPIKeyResponse.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Serialization; +using Scrapegraphai.Core; namespace Scrapegraphai.Models.Validate; diff --git a/src/Scrapegraphai/ScrapegraphaiClient.cs b/src/Scrapegraphai/ScrapegraphaiClient.cs index c5f9b81..e76c681 100644 --- a/src/Scrapegraphai/ScrapegraphaiClient.cs +++ b/src/Scrapegraphai/ScrapegraphaiClient.cs @@ -1,5 +1,8 @@ using System; using System.Net.Http; +using System.Threading.Tasks; +using Scrapegraphai.Core; +using Scrapegraphai.Exceptions; using Scrapegraphai.Services.Crawl; using Scrapegraphai.Services.Credits; using Scrapegraphai.Services.Feedback; @@ -30,7 +33,10 @@ public Uri BaseUrl Lazy _apiKey = new(() => Environment.GetEnvironmentVariable("SCRAPEGRAPHAI_API_KEY") - ?? throw new ArgumentNullException(nameof(APIKey)) + ?? throw new ScrapegraphaiInvalidDataException( + string.Format("{0} cannot be null", nameof(APIKey)), + new ArgumentNullException(nameof(APIKey)) + ) ); public string APIKey { @@ -92,6 +98,46 @@ public IHealthzService Healthz get { return _healthz.Value; } } + public async Task Execute(HttpRequest request) + where T : ParamsBase + { + using HttpRequestMessage requestMessage = new(request.Method, request.Params.Url(this)) + { + Content = request.Params.BodyContent(), + }; + request.Params.AddHeadersToRequest(requestMessage, this); + HttpResponseMessage responseMessage; + try + { + responseMessage = await this + .HttpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead) + .ConfigureAwait(false); + } + catch (HttpRequestException e1) + { + throw new ScrapegraphaiIOException("I/O exception", e1); + } + if (!responseMessage.IsSuccessStatusCode) + { + try + { + throw ScrapegraphaiExceptionFactory.CreateApiException( + responseMessage.StatusCode, + await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false) + ); + } + catch (HttpRequestException e) + { + throw new ScrapegraphaiIOException("I/O Exception", e); + } + finally + { + responseMessage.Dispose(); + } + } + return new() { Message = responseMessage }; + } + public ScrapegraphaiClient() { _smartscraper = new(() => new SmartscraperService(this)); diff --git a/src/Scrapegraphai/Services/Crawl/CrawlService.cs b/src/Scrapegraphai/Services/Crawl/CrawlService.cs index b15fba1..947c729 100644 --- a/src/Scrapegraphai/Services/Crawl/CrawlService.cs +++ b/src/Scrapegraphai/Services/Crawl/CrawlService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.Crawl; namespace Scrapegraphai.Services.Crawl; @@ -19,46 +18,23 @@ public async Task RetrieveResults( CrawlRetrieveResultsParams parameters ) { - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } public async Task Start(CrawlStartParams parameters) { - using HttpRequestMessage request = new(HttpMethod.Post, parameters.Url(this._client)) + HttpRequest request = new() { - Content = parameters.BodyContent(), + Method = HttpMethod.Post, + Params = parameters, }; - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) - { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } } diff --git a/src/Scrapegraphai/Services/Credits/CreditService.cs b/src/Scrapegraphai/Services/Credits/CreditService.cs index 961f132..88f1c8b 100644 --- a/src/Scrapegraphai/Services/Credits/CreditService.cs +++ b/src/Scrapegraphai/Services/Credits/CreditService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.Credits; namespace Scrapegraphai.Services.Credits; @@ -19,22 +18,12 @@ public async Task Retrieve(CreditRetrieveParams? paramet { parameters ??= new(); - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } } diff --git a/src/Scrapegraphai/Services/Feedback/FeedbackService.cs b/src/Scrapegraphai/Services/Feedback/FeedbackService.cs index ab17e9a..efc1838 100644 --- a/src/Scrapegraphai/Services/Feedback/FeedbackService.cs +++ b/src/Scrapegraphai/Services/Feedback/FeedbackService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.Feedback; namespace Scrapegraphai.Services.Feedback; @@ -17,25 +16,12 @@ public FeedbackService(IScrapegraphaiClient client) public async Task Submit(FeedbackSubmitParams parameters) { - using HttpRequestMessage request = new(HttpMethod.Post, parameters.Url(this._client)) + HttpRequest request = new() { - Content = parameters.BodyContent(), + Method = HttpMethod.Post, + Params = parameters, }; - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) - { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } } diff --git a/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs b/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs index db4a5e8..4b41eb2 100644 --- a/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs +++ b/src/Scrapegraphai/Services/GenerateSchema/GenerateSchemaService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.GenerateSchema; namespace Scrapegraphai.Services.GenerateSchema; @@ -17,48 +16,25 @@ public GenerateSchemaService(IScrapegraphaiClient client) public async Task Create(GenerateSchemaCreateParams parameters) { - using HttpRequestMessage request = new(HttpMethod.Post, parameters.Url(this._client)) + HttpRequest request = new() { - Content = parameters.BodyContent(), + Method = HttpMethod.Post, + Params = parameters, }; - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) - { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } public async Task Retrieve( GenerateSchemaRetrieveParams parameters ) { - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } } diff --git a/src/Scrapegraphai/Services/Healthz/HealthzService.cs b/src/Scrapegraphai/Services/Healthz/HealthzService.cs index d06dafa..f884f83 100644 --- a/src/Scrapegraphai/Services/Healthz/HealthzService.cs +++ b/src/Scrapegraphai/Services/Healthz/HealthzService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.Healthz; namespace Scrapegraphai.Services.Healthz; @@ -19,22 +18,12 @@ public async Task Check(HealthzCheckParams? parameters = n { parameters ??= new(); - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } } diff --git a/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs b/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs index b102e9a..94b37da 100644 --- a/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs +++ b/src/Scrapegraphai/Services/Markdownify/MarkdownifyService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.Markdownify; namespace Scrapegraphai.Services.Markdownify; @@ -17,48 +16,27 @@ public MarkdownifyService(IScrapegraphaiClient client) public async Task Convert(MarkdownifyConvertParams parameters) { - using HttpRequestMessage request = new(HttpMethod.Post, parameters.Url(this._client)) + HttpRequest request = new() { - Content = parameters.BodyContent(), + Method = HttpMethod.Post, + Params = parameters, }; - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) - { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } public async Task RetrieveStatus( MarkdownifyRetrieveStatusParams parameters ) { - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response + .Deserialize() + .ConfigureAwait(false); } } diff --git a/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs b/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs index e033ae3..2ef1448 100644 --- a/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs +++ b/src/Scrapegraphai/Services/Searchscraper/SearchscraperService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.Searchscraper; namespace Scrapegraphai.Services.Searchscraper; @@ -17,48 +16,27 @@ public SearchscraperService(IScrapegraphaiClient client) public async Task Create(SearchscraperCreateParams parameters) { - using HttpRequestMessage request = new(HttpMethod.Post, parameters.Url(this._client)) + HttpRequest request = new() { - Content = parameters.BodyContent(), + Method = HttpMethod.Post, + Params = parameters, }; - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) - { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } public async Task RetrieveStatus( SearchscraperRetrieveStatusParams parameters ) { - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response + .Deserialize() + .ConfigureAwait(false); } } diff --git a/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs b/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs index 3af256f..bebaeac 100644 --- a/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs +++ b/src/Scrapegraphai/Services/Smartscraper/SmartscraperService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.Smartscraper; namespace Scrapegraphai.Services.Smartscraper; @@ -17,69 +16,36 @@ public SmartscraperService(IScrapegraphaiClient client) public async Task Create(SmartscraperCreateParams parameters) { - using HttpRequestMessage request = new(HttpMethod.Post, parameters.Url(this._client)) + HttpRequest request = new() { - Content = parameters.BodyContent(), + Method = HttpMethod.Post, + Params = parameters, }; - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) - { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } public async Task Retrieve(SmartscraperRetrieveParams parameters) { - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } public async Task List(SmartscraperListParams? parameters = null) { parameters ??= new(); - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } } diff --git a/src/Scrapegraphai/Services/Validate/ValidateService.cs b/src/Scrapegraphai/Services/Validate/ValidateService.cs index d2b4e94..30e8222 100644 --- a/src/Scrapegraphai/Services/Validate/ValidateService.cs +++ b/src/Scrapegraphai/Services/Validate/ValidateService.cs @@ -1,7 +1,6 @@ -using System; using System.Net.Http; -using System.Text.Json; using System.Threading.Tasks; +using Scrapegraphai.Core; using Scrapegraphai.Models.Validate; namespace Scrapegraphai.Services.Validate; @@ -19,22 +18,12 @@ public async Task APIKey(ValidateAPIKeyParams? parameter { parameters ??= new(); - using HttpRequestMessage request = new(HttpMethod.Get, parameters.Url(this._client)); - parameters.AddHeadersToRequest(request, this._client); - using HttpResponseMessage response = await this - ._client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead) - .ConfigureAwait(false); - if (!response.IsSuccessStatusCode) + HttpRequest request = new() { - throw new HttpException( - response.StatusCode, - await response.Content.ReadAsStringAsync().ConfigureAwait(false) - ); - } - - return JsonSerializer.Deserialize( - await response.Content.ReadAsStreamAsync().ConfigureAwait(false), - ModelBase.SerializerOptions - ) ?? throw new NullReferenceException(); + Method = HttpMethod.Get, + Params = parameters, + }; + using var response = await this._client.Execute(request).ConfigureAwait(false); + return await response.Deserialize().ConfigureAwait(false); } } From 09e44c597ff8074834cc50dc8ee291ec649f22f4 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 02:34:54 +0000 Subject: [PATCH 19/21] feat(internal): add dev container --- .devcontainer/devcontainer.json | 8 ++++++++ .vscode/extensions.json | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .vscode/extensions.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..a503ddd --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,8 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet +{ + "name": "C# (.NET)", + "image": "mcr.microsoft.com/devcontainers/dotnet:1-9.0-noble", + "postAttachCommand": "cat .vscode/extensions.json | jq -r .recommendations[] | xargs -n 1 code --install-extension", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}" +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..921dd6d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "ms-dotnettools.csharp", + "editorconfig.editorconfig", + "github.vscode-github-actions", + "ms-dotnettools.vscode-dotnet-runtime", + "ms-dotnettools.csdevkit" + ], + "unwantedRecommendations": [] +} From 67d49b454eb8aa021ccaadf2f55e82352b9e61a5 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 8 Oct 2025 02:18:28 +0000 Subject: [PATCH 20/21] feat(client): refactor unions --- .../Result.cs | 89 +++++----- .../ResultVariants/All.cs | 32 ---- .../GenerateSchemaRetrieveResponse.cs | 167 ++++++++++++------ .../All.cs | 48 ----- .../MarkdownifyRetrieveStatusResponse.cs | 153 ++++++++++------ .../All.cs | 42 ----- .../SearchscraperRetrieveStatusResponse.cs | 167 ++++++++++++------ .../All.cs | 42 ----- .../Smartscraper/SmartscraperListResponse.cs | 149 +++++++++++----- .../SmartscraperListResponseVariants/All.cs | 34 ---- .../SmartscraperRetrieveResponse.cs | 153 +++++++++++----- .../All.cs | 34 ---- src/Scrapegraphai/Scrapegraphai.csproj | 3 + 13 files changed, 585 insertions(+), 528 deletions(-) delete mode 100644 src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs delete mode 100644 src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs delete mode 100644 src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs delete mode 100644 src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs delete mode 100644 src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs delete mode 100644 src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs index 10ee3ee..2bccf0d 100644 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs +++ b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/Result.cs @@ -4,7 +4,6 @@ using System.Text.Json; using System.Text.Json.Serialization; using Scrapegraphai.Exceptions; -using ResultVariants = Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.ResultVariants; namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; @@ -12,39 +11,51 @@ namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties; /// Successful crawl results ///

[JsonConverter(typeof(ResultConverter))] -public abstract record class Result +public record class Result { - internal Result() { } + public object Value { get; private init; } - public static implicit operator Result(JsonElement value) => - new ResultVariants::JsonElement(value); + public Result(JsonElement value) + { + Value = value; + } + + public Result(string value) + { + Value = value; + } + + Result(UnknownVariant value) + { + Value = value; + } - public static implicit operator Result(string value) => new ResultVariants::String(value); + public static Result CreateUnknownVariant(JsonElement value) + { + return new(new UnknownVariant(value)); + } public bool TryPickJsonElement([NotNullWhen(true)] out JsonElement? value) { - value = (this as ResultVariants::JsonElement)?.Value; + value = this.Value as JsonElement?; return value != null; } public bool TryPickString([NotNullWhen(true)] out string? value) { - value = (this as ResultVariants::String)?.Value; + value = this.Value as string; return value != null; } - public void Switch( - Action jsonElement, - Action @string - ) + public void Switch(Action jsonElement, Action @string) { - switch (this) + switch (this.Value) { - case ResultVariants::JsonElement inner: - jsonElement(inner); + case JsonElement value: + jsonElement(value); break; - case ResultVariants::String inner: - @string(inner); + case string value: + @string(value); break; default: throw new ScrapegraphaiInvalidDataException( @@ -53,22 +64,27 @@ public void Switch( } } - public T Match( - Func jsonElement, - Func @string - ) + public T Match(Func jsonElement, Func @string) { - return this switch + return this.Value switch { - ResultVariants::JsonElement inner => jsonElement(inner), - ResultVariants::String inner => @string(inner), + JsonElement value => jsonElement(value), + string value => @string(value), _ => throw new ScrapegraphaiInvalidDataException( "Data did not match any variant of Result" ), }; } - public abstract void Validate(); + public void Validate() + { + if (this.Value is not UnknownVariant) + { + throw new ScrapegraphaiInvalidDataException("Data did not match any variant of Result"); + } + } + + private record struct UnknownVariant(JsonElement value); } sealed class ResultConverter : JsonConverter @@ -86,14 +102,14 @@ JsonSerializerOptions options var deserialized = JsonSerializer.Deserialize(ref reader, options); if (deserialized != null) { - return new ResultVariants::String(deserialized); + return new Result(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant ResultVariants::String", + "Data does not match union variant 'string'", e ) ); @@ -101,15 +117,13 @@ JsonSerializerOptions options try { - return new ResultVariants::JsonElement( - JsonSerializer.Deserialize(ref reader, options) - ); + return new Result(JsonSerializer.Deserialize(ref reader, options)); } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant ResultVariants::JsonElement", + "Data does not match union variant 'JsonElement'", e ) ); @@ -120,14 +134,7 @@ JsonSerializerOptions options public override void Write(Utf8JsonWriter writer, Result value, JsonSerializerOptions options) { - object variant = value switch - { - ResultVariants::JsonElement(var jsonElement) => jsonElement, - ResultVariants::String(var @string) => @string, - _ => throw new ScrapegraphaiInvalidDataException( - "Data did not match any variant of Result" - ), - }; + object variant = value.Value; JsonSerializer.Serialize(writer, variant, options); } } diff --git a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs b/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs deleted file mode 100644 index d06cb03..0000000 --- a/src/Scrapegraphai/Models/Crawl/CrawlRetrieveResultsResponseProperties/ResultVariants/All.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Scrapegraphai.Core; -using Json = System.Text.Json; - -namespace Scrapegraphai.Models.Crawl.CrawlRetrieveResultsResponseProperties.ResultVariants; - -/// -/// Successful crawl results -/// -public sealed record class JsonElement(Json::JsonElement Value) - : Result, - IVariant -{ - public static JsonElement From(Json::JsonElement value) - { - return new(value); - } - - public override void Validate() { } -} - -/// -/// Error message -/// -public sealed record class String(string Value) : Result, IVariant -{ - public static String From(string value) - { - return new(value); - } - - public override void Validate() { } -} diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs index b821ab7..5c11f97 100644 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponse.cs @@ -5,30 +5,94 @@ using System.Text.Json.Serialization; using Scrapegraphai.Exceptions; using Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; -using GenerateSchemaRetrieveResponseVariants = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseVariants; namespace Scrapegraphai.Models.GenerateSchema; [JsonConverter(typeof(GenerateSchemaRetrieveResponseConverter))] -public abstract record class GenerateSchemaRetrieveResponse +public record class GenerateSchemaRetrieveResponse { - internal GenerateSchemaRetrieveResponse() { } + public object Value { get; private init; } - public static implicit operator GenerateSchemaRetrieveResponse( - CompletedSchemaGenerationResponse value - ) => new GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse(value); + public string? Error + { + get + { + return Match( + completedSchemaGeneration: (x) => x.Error, + failedSchemaGeneration: (x) => x.Error + ); + } + } + + public JsonElement? GeneratedSchema + { + get + { + return Match( + completedSchemaGeneration: (x) => x.GeneratedSchema, + failedSchemaGeneration: (x) => x.GeneratedSchema + ); + } + } + + public string? RefinedPrompt + { + get + { + return Match( + completedSchemaGeneration: (x) => x.RefinedPrompt, + failedSchemaGeneration: (x) => x.RefinedPrompt + ); + } + } + + public string? RequestID + { + get + { + return Match( + completedSchemaGeneration: (x) => x.RequestID, + failedSchemaGeneration: (x) => x.RequestID + ); + } + } + + public string? UserPrompt + { + get + { + return Match( + completedSchemaGeneration: (x) => x.UserPrompt, + failedSchemaGeneration: (x) => x.UserPrompt + ); + } + } + + public GenerateSchemaRetrieveResponse(CompletedSchemaGenerationResponse value) + { + Value = value; + } + + public GenerateSchemaRetrieveResponse(FailedSchemaGenerationResponse value) + { + Value = value; + } - public static implicit operator GenerateSchemaRetrieveResponse( - FailedSchemaGenerationResponse value - ) => new GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse(value); + GenerateSchemaRetrieveResponse(UnknownVariant value) + { + Value = value; + } + + public static GenerateSchemaRetrieveResponse CreateUnknownVariant(JsonElement value) + { + return new(new UnknownVariant(value)); + } public bool TryPickCompletedSchemaGeneration( [NotNullWhen(true)] out CompletedSchemaGenerationResponse? value ) { - value = ( - this as GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse - )?.Value; + value = this.Value as CompletedSchemaGenerationResponse; return value != null; } @@ -36,24 +100,22 @@ public bool TryPickFailedSchemaGeneration( [NotNullWhen(true)] out FailedSchemaGenerationResponse? value ) { - value = ( - this as GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse - )?.Value; + value = this.Value as FailedSchemaGenerationResponse; return value != null; } public void Switch( - Action completedSchemaGeneration, - Action failedSchemaGeneration + Action completedSchemaGeneration, + Action failedSchemaGeneration ) { - switch (this) + switch (this.Value) { - case GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse inner: - completedSchemaGeneration(inner); + case CompletedSchemaGenerationResponse value: + completedSchemaGeneration(value); break; - case GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse inner: - failedSchemaGeneration(inner); + case FailedSchemaGenerationResponse value: + failedSchemaGeneration(value); break; default: throw new ScrapegraphaiInvalidDataException( @@ -63,29 +125,31 @@ public void Switch( } public T Match( - Func< - GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse, - T - > completedSchemaGeneration, - Func< - GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse, - T - > failedSchemaGeneration + Func completedSchemaGeneration, + Func failedSchemaGeneration ) { - return this switch + return this.Value switch { - GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse inner => - completedSchemaGeneration(inner), - GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse inner => - failedSchemaGeneration(inner), + CompletedSchemaGenerationResponse value => completedSchemaGeneration(value), + FailedSchemaGenerationResponse value => failedSchemaGeneration(value), _ => throw new ScrapegraphaiInvalidDataException( "Data did not match any variant of GenerateSchemaRetrieveResponse" ), }; } - public abstract void Validate(); + public void Validate() + { + if (this.Value is not UnknownVariant) + { + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of GenerateSchemaRetrieveResponse" + ); + } + } + + private record struct UnknownVariant(JsonElement value); } sealed class GenerateSchemaRetrieveResponseConverter : JsonConverter @@ -106,16 +170,15 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse( - deserialized - ); + deserialized.Validate(); + return new GenerateSchemaRetrieveResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse", + "Data does not match union variant 'CompletedSchemaGenerationResponse'", e ) ); @@ -129,16 +192,15 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse( - deserialized - ); + deserialized.Validate(); + return new GenerateSchemaRetrieveResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse", + "Data does not match union variant 'FailedSchemaGenerationResponse'", e ) ); @@ -153,18 +215,7 @@ public override void Write( JsonSerializerOptions options ) { - object variant = value switch - { - GenerateSchemaRetrieveResponseVariants::CompletedSchemaGenerationResponse( - var completedSchemaGeneration - ) => completedSchemaGeneration, - GenerateSchemaRetrieveResponseVariants::FailedSchemaGenerationResponse( - var failedSchemaGeneration - ) => failedSchemaGeneration, - _ => throw new ScrapegraphaiInvalidDataException( - "Data did not match any variant of GenerateSchemaRetrieveResponse" - ), - }; + object variant = value.Value; JsonSerializer.Serialize(writer, variant, options); } } diff --git a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs b/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs deleted file mode 100644 index 5b526e3..0000000 --- a/src/Scrapegraphai/Models/GenerateSchema/GenerateSchemaRetrieveResponseVariants/All.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Scrapegraphai.Core; -using GenerateSchemaRetrieveResponseProperties = Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseProperties; - -namespace Scrapegraphai.Models.GenerateSchema.GenerateSchemaRetrieveResponseVariants; - -public sealed record class CompletedSchemaGenerationResponse( - GenerateSchemaRetrieveResponseProperties::CompletedSchemaGenerationResponse Value -) - : GenerateSchemaRetrieveResponse, - IVariant< - CompletedSchemaGenerationResponse, - GenerateSchemaRetrieveResponseProperties::CompletedSchemaGenerationResponse - > -{ - public static CompletedSchemaGenerationResponse From( - GenerateSchemaRetrieveResponseProperties::CompletedSchemaGenerationResponse value - ) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} - -public sealed record class FailedSchemaGenerationResponse( - GenerateSchemaRetrieveResponseProperties::FailedSchemaGenerationResponse Value -) - : GenerateSchemaRetrieveResponse, - IVariant< - FailedSchemaGenerationResponse, - GenerateSchemaRetrieveResponseProperties::FailedSchemaGenerationResponse - > -{ - public static FailedSchemaGenerationResponse From( - GenerateSchemaRetrieveResponseProperties::FailedSchemaGenerationResponse value - ) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs index 0c81bec..a48eb78 100644 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponse.cs @@ -5,48 +5,102 @@ using System.Text.Json.Serialization; using Scrapegraphai.Exceptions; using Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; -using MarkdownifyRetrieveStatusResponseVariants = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseVariants; namespace Scrapegraphai.Models.Markdownify; [JsonConverter(typeof(MarkdownifyRetrieveStatusResponseConverter))] -public abstract record class MarkdownifyRetrieveStatusResponse +public record class MarkdownifyRetrieveStatusResponse { - internal MarkdownifyRetrieveStatusResponse() { } + public object Value { get; private init; } - public static implicit operator MarkdownifyRetrieveStatusResponse(CompletedMarkdownify value) => - new MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify(value); + public string? Error + { + get + { + return Match( + completedMarkdownify: (x) => x.Error, + failedMarkdownify: (x) => x.Error + ); + } + } + + public string? RequestID + { + get + { + return Match( + completedMarkdownify: (x) => x.RequestID, + failedMarkdownify: (x) => x.RequestID + ); + } + } + + public string? Result + { + get + { + return Match( + completedMarkdownify: (x) => x.Result, + failedMarkdownify: (x) => x.Result + ); + } + } + + public string? WebsiteURL + { + get + { + return Match( + completedMarkdownify: (x) => x.WebsiteURL, + failedMarkdownify: (x) => x.WebsiteURL + ); + } + } + + public MarkdownifyRetrieveStatusResponse(CompletedMarkdownify value) + { + Value = value; + } + + public MarkdownifyRetrieveStatusResponse(FailedMarkdownifyResponse value) + { + Value = value; + } + + MarkdownifyRetrieveStatusResponse(UnknownVariant value) + { + Value = value; + } - public static implicit operator MarkdownifyRetrieveStatusResponse( - FailedMarkdownifyResponse value - ) => new MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse(value); + public static MarkdownifyRetrieveStatusResponse CreateUnknownVariant(JsonElement value) + { + return new(new UnknownVariant(value)); + } public bool TryPickCompletedMarkdownify([NotNullWhen(true)] out CompletedMarkdownify? value) { - value = (this as MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify)?.Value; + value = this.Value as CompletedMarkdownify; return value != null; } public bool TryPickFailedMarkdownify([NotNullWhen(true)] out FailedMarkdownifyResponse? value) { - value = ( - this as MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse - )?.Value; + value = this.Value as FailedMarkdownifyResponse; return value != null; } public void Switch( - Action completedMarkdownify, - Action failedMarkdownify + Action completedMarkdownify, + Action failedMarkdownify ) { - switch (this) + switch (this.Value) { - case MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify inner: - completedMarkdownify(inner); + case CompletedMarkdownify value: + completedMarkdownify(value); break; - case MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner: - failedMarkdownify(inner); + case FailedMarkdownifyResponse value: + failedMarkdownify(value); break; default: throw new ScrapegraphaiInvalidDataException( @@ -56,29 +110,31 @@ public void Switch( } public T Match( - Func< - MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify, - T - > completedMarkdownify, - Func< - MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse, - T - > failedMarkdownify + Func completedMarkdownify, + Func failedMarkdownify ) { - return this switch + return this.Value switch { - MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify inner => - completedMarkdownify(inner), - MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse inner => - failedMarkdownify(inner), + CompletedMarkdownify value => completedMarkdownify(value), + FailedMarkdownifyResponse value => failedMarkdownify(value), _ => throw new ScrapegraphaiInvalidDataException( "Data did not match any variant of MarkdownifyRetrieveStatusResponse" ), }; } - public abstract void Validate(); + public void Validate() + { + if (this.Value is not UnknownVariant) + { + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of MarkdownifyRetrieveStatusResponse" + ); + } + } + + private record struct UnknownVariant(JsonElement value); } sealed class MarkdownifyRetrieveStatusResponseConverter @@ -100,16 +156,15 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify( - deserialized - ); + deserialized.Validate(); + return new MarkdownifyRetrieveStatusResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify", + "Data does not match union variant 'CompletedMarkdownify'", e ) ); @@ -123,16 +178,15 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse( - deserialized - ); + deserialized.Validate(); + return new MarkdownifyRetrieveStatusResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse", + "Data does not match union variant 'FailedMarkdownifyResponse'", e ) ); @@ -147,18 +201,7 @@ public override void Write( JsonSerializerOptions options ) { - object variant = value switch - { - MarkdownifyRetrieveStatusResponseVariants::CompletedMarkdownify( - var completedMarkdownify - ) => completedMarkdownify, - MarkdownifyRetrieveStatusResponseVariants::FailedMarkdownifyResponse( - var failedMarkdownify - ) => failedMarkdownify, - _ => throw new ScrapegraphaiInvalidDataException( - "Data did not match any variant of MarkdownifyRetrieveStatusResponse" - ), - }; + object variant = value.Value; JsonSerializer.Serialize(writer, variant, options); } } diff --git a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs deleted file mode 100644 index 49a7151..0000000 --- a/src/Scrapegraphai/Models/Markdownify/MarkdownifyRetrieveStatusResponseVariants/All.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Scrapegraphai.Core; -using Markdownify = Scrapegraphai.Models.Markdownify; -using MarkdownifyRetrieveStatusResponseProperties = Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseProperties; - -namespace Scrapegraphai.Models.Markdownify.MarkdownifyRetrieveStatusResponseVariants; - -public sealed record class CompletedMarkdownify(Markdownify::CompletedMarkdownify Value) - : Markdownify::MarkdownifyRetrieveStatusResponse, - IVariant -{ - public static CompletedMarkdownify From(Markdownify::CompletedMarkdownify value) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} - -public sealed record class FailedMarkdownifyResponse( - MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse Value -) - : Markdownify::MarkdownifyRetrieveStatusResponse, - IVariant< - FailedMarkdownifyResponse, - MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse - > -{ - public static FailedMarkdownifyResponse From( - MarkdownifyRetrieveStatusResponseProperties::FailedMarkdownifyResponse value - ) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs index 530be8a..d01735b 100644 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs +++ b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponse.cs @@ -5,28 +5,92 @@ using System.Text.Json.Serialization; using Scrapegraphai.Exceptions; using Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; -using SearchscraperRetrieveStatusResponseVariants = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseVariants; namespace Scrapegraphai.Models.Searchscraper; [JsonConverter(typeof(SearchscraperRetrieveStatusResponseConverter))] -public abstract record class SearchscraperRetrieveStatusResponse +public record class SearchscraperRetrieveStatusResponse { - internal SearchscraperRetrieveStatusResponse() { } + public object Value { get; private init; } - public static implicit operator SearchscraperRetrieveStatusResponse( - CompletedSearchScraper value - ) => new SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper(value); + public string? Error + { + get + { + return Match( + completedSearchScraper: (x) => x.Error, + failedSearchScraper: (x) => x.Error + ); + } + } + + public long? NumResults + { + get + { + return Match( + completedSearchScraper: (x) => x.NumResults, + failedSearchScraper: (x) => x.NumResults + ); + } + } + + public string? RequestID + { + get + { + return Match( + completedSearchScraper: (x) => x.RequestID, + failedSearchScraper: (x) => x.RequestID + ); + } + } + + public JsonElement? Result + { + get + { + return Match( + completedSearchScraper: (x) => x.Result, + failedSearchScraper: (x) => x.Result + ); + } + } + + public string? UserPrompt + { + get + { + return Match( + completedSearchScraper: (x) => x.UserPrompt, + failedSearchScraper: (x) => x.UserPrompt + ); + } + } + + public SearchscraperRetrieveStatusResponse(CompletedSearchScraper value) + { + Value = value; + } + + public SearchscraperRetrieveStatusResponse(FailedSearchScraperResponse value) + { + Value = value; + } - public static implicit operator SearchscraperRetrieveStatusResponse( - FailedSearchScraperResponse value - ) => new SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse(value); + SearchscraperRetrieveStatusResponse(UnknownVariant value) + { + Value = value; + } + + public static SearchscraperRetrieveStatusResponse CreateUnknownVariant(JsonElement value) + { + return new(new UnknownVariant(value)); + } public bool TryPickCompletedSearchScraper([NotNullWhen(true)] out CompletedSearchScraper? value) { - value = ( - this as SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper - )?.Value; + value = this.Value as CompletedSearchScraper; return value != null; } @@ -34,24 +98,22 @@ public bool TryPickFailedSearchScraper( [NotNullWhen(true)] out FailedSearchScraperResponse? value ) { - value = ( - this as SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse - )?.Value; + value = this.Value as FailedSearchScraperResponse; return value != null; } public void Switch( - Action completedSearchScraper, - Action failedSearchScraper + Action completedSearchScraper, + Action failedSearchScraper ) { - switch (this) + switch (this.Value) { - case SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper inner: - completedSearchScraper(inner); + case CompletedSearchScraper value: + completedSearchScraper(value); break; - case SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner: - failedSearchScraper(inner); + case FailedSearchScraperResponse value: + failedSearchScraper(value); break; default: throw new ScrapegraphaiInvalidDataException( @@ -61,29 +123,31 @@ public void Switch( } public T Match( - Func< - SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper, - T - > completedSearchScraper, - Func< - SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse, - T - > failedSearchScraper + Func completedSearchScraper, + Func failedSearchScraper ) { - return this switch + return this.Value switch { - SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper inner => - completedSearchScraper(inner), - SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse inner => - failedSearchScraper(inner), + CompletedSearchScraper value => completedSearchScraper(value), + FailedSearchScraperResponse value => failedSearchScraper(value), _ => throw new ScrapegraphaiInvalidDataException( "Data did not match any variant of SearchscraperRetrieveStatusResponse" ), }; } - public abstract void Validate(); + public void Validate() + { + if (this.Value is not UnknownVariant) + { + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SearchscraperRetrieveStatusResponse" + ); + } + } + + private record struct UnknownVariant(JsonElement value); } sealed class SearchscraperRetrieveStatusResponseConverter @@ -105,16 +169,15 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper( - deserialized - ); + deserialized.Validate(); + return new SearchscraperRetrieveStatusResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper", + "Data does not match union variant 'CompletedSearchScraper'", e ) ); @@ -128,16 +191,15 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse( - deserialized - ); + deserialized.Validate(); + return new SearchscraperRetrieveStatusResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse", + "Data does not match union variant 'FailedSearchScraperResponse'", e ) ); @@ -152,18 +214,7 @@ public override void Write( JsonSerializerOptions options ) { - object variant = value switch - { - SearchscraperRetrieveStatusResponseVariants::CompletedSearchScraper( - var completedSearchScraper - ) => completedSearchScraper, - SearchscraperRetrieveStatusResponseVariants::FailedSearchScraperResponse( - var failedSearchScraper - ) => failedSearchScraper, - _ => throw new ScrapegraphaiInvalidDataException( - "Data did not match any variant of SearchscraperRetrieveStatusResponse" - ), - }; + object variant = value.Value; JsonSerializer.Serialize(writer, variant, options); } } diff --git a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs b/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs deleted file mode 100644 index 47aab92..0000000 --- a/src/Scrapegraphai/Models/Searchscraper/SearchscraperRetrieveStatusResponseVariants/All.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Scrapegraphai.Core; -using Searchscraper = Scrapegraphai.Models.Searchscraper; -using SearchscraperRetrieveStatusResponseProperties = Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseProperties; - -namespace Scrapegraphai.Models.Searchscraper.SearchscraperRetrieveStatusResponseVariants; - -public sealed record class CompletedSearchScraper(Searchscraper::CompletedSearchScraper Value) - : Searchscraper::SearchscraperRetrieveStatusResponse, - IVariant -{ - public static CompletedSearchScraper From(Searchscraper::CompletedSearchScraper value) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} - -public sealed record class FailedSearchScraperResponse( - SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse Value -) - : Searchscraper::SearchscraperRetrieveStatusResponse, - IVariant< - FailedSearchScraperResponse, - SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse - > -{ - public static FailedSearchScraperResponse From( - SearchscraperRetrieveStatusResponseProperties::FailedSearchScraperResponse value - ) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs index 571fed0..3b0cbb3 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponse.cs @@ -4,45 +4,113 @@ using System.Text.Json; using System.Text.Json.Serialization; using Scrapegraphai.Exceptions; -using SmartscraperListResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; namespace Scrapegraphai.Models.Smartscraper; [JsonConverter(typeof(SmartscraperListResponseConverter))] -public abstract record class SmartscraperListResponse +public record class SmartscraperListResponse { - internal SmartscraperListResponse() { } + public object Value { get; private init; } - public static implicit operator SmartscraperListResponse(CompletedSmartscraper value) => - new SmartscraperListResponseVariants::CompletedSmartscraper(value); + public string? Error + { + get + { + return Match( + completedSmartscraper: (x) => x.Error, + failedSmartscraper: (x) => x.Error + ); + } + } - public static implicit operator SmartscraperListResponse(FailedSmartscraper value) => - new SmartscraperListResponseVariants::FailedSmartscraper(value); + public string? RequestID + { + get + { + return Match( + completedSmartscraper: (x) => x.RequestID, + failedSmartscraper: (x) => x.RequestID + ); + } + } + + public JsonElement? Result + { + get + { + return Match( + completedSmartscraper: (x) => x.Result, + failedSmartscraper: (x) => x.Result + ); + } + } + + public string? UserPrompt + { + get + { + return Match( + completedSmartscraper: (x) => x.UserPrompt, + failedSmartscraper: (x) => x.UserPrompt + ); + } + } + + public string? WebsiteURL + { + get + { + return Match( + completedSmartscraper: (x) => x.WebsiteURL, + failedSmartscraper: (x) => x.WebsiteURL + ); + } + } + + public SmartscraperListResponse(CompletedSmartscraper value) + { + Value = value; + } + + public SmartscraperListResponse(FailedSmartscraper value) + { + Value = value; + } + + SmartscraperListResponse(UnknownVariant value) + { + Value = value; + } + + public static SmartscraperListResponse CreateUnknownVariant(JsonElement value) + { + return new(new UnknownVariant(value)); + } public bool TryPickCompletedSmartscraper([NotNullWhen(true)] out CompletedSmartscraper? value) { - value = (this as SmartscraperListResponseVariants::CompletedSmartscraper)?.Value; + value = this.Value as CompletedSmartscraper; return value != null; } public bool TryPickFailedSmartscraper([NotNullWhen(true)] out FailedSmartscraper? value) { - value = (this as SmartscraperListResponseVariants::FailedSmartscraper)?.Value; + value = this.Value as FailedSmartscraper; return value != null; } public void Switch( - Action completedSmartscraper, - Action failedSmartscraper + Action completedSmartscraper, + Action failedSmartscraper ) { - switch (this) + switch (this.Value) { - case SmartscraperListResponseVariants::CompletedSmartscraper inner: - completedSmartscraper(inner); + case CompletedSmartscraper value: + completedSmartscraper(value); break; - case SmartscraperListResponseVariants::FailedSmartscraper inner: - failedSmartscraper(inner); + case FailedSmartscraper value: + failedSmartscraper(value); break; default: throw new ScrapegraphaiInvalidDataException( @@ -52,23 +120,31 @@ public void Switch( } public T Match( - Func completedSmartscraper, - Func failedSmartscraper + Func completedSmartscraper, + Func failedSmartscraper ) { - return this switch + return this.Value switch { - SmartscraperListResponseVariants::CompletedSmartscraper inner => completedSmartscraper( - inner - ), - SmartscraperListResponseVariants::FailedSmartscraper inner => failedSmartscraper(inner), + CompletedSmartscraper value => completedSmartscraper(value), + FailedSmartscraper value => failedSmartscraper(value), _ => throw new ScrapegraphaiInvalidDataException( "Data did not match any variant of SmartscraperListResponse" ), }; } - public abstract void Validate(); + public void Validate() + { + if (this.Value is not UnknownVariant) + { + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SmartscraperListResponse" + ); + } + } + + private record struct UnknownVariant(JsonElement value); } sealed class SmartscraperListResponseConverter : JsonConverter @@ -89,14 +165,15 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new SmartscraperListResponseVariants::CompletedSmartscraper(deserialized); + deserialized.Validate(); + return new SmartscraperListResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant SmartscraperListResponseVariants::CompletedSmartscraper", + "Data does not match union variant 'CompletedSmartscraper'", e ) ); @@ -107,14 +184,15 @@ JsonSerializerOptions options var deserialized = JsonSerializer.Deserialize(ref reader, options); if (deserialized != null) { - return new SmartscraperListResponseVariants::FailedSmartscraper(deserialized); + deserialized.Validate(); + return new SmartscraperListResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant SmartscraperListResponseVariants::FailedSmartscraper", + "Data does not match union variant 'FailedSmartscraper'", e ) ); @@ -129,16 +207,7 @@ public override void Write( JsonSerializerOptions options ) { - object variant = value switch - { - SmartscraperListResponseVariants::CompletedSmartscraper(var completedSmartscraper) => - completedSmartscraper, - SmartscraperListResponseVariants::FailedSmartscraper(var failedSmartscraper) => - failedSmartscraper, - _ => throw new ScrapegraphaiInvalidDataException( - "Data did not match any variant of SmartscraperListResponse" - ), - }; + object variant = value.Value; JsonSerializer.Serialize(writer, variant, options); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs deleted file mode 100644 index c797f30..0000000 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperListResponseVariants/All.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Scrapegraphai.Core; -using Smartscraper = Scrapegraphai.Models.Smartscraper; - -namespace Scrapegraphai.Models.Smartscraper.SmartscraperListResponseVariants; - -public sealed record class CompletedSmartscraper(Smartscraper::CompletedSmartscraper Value) - : Smartscraper::SmartscraperListResponse, - IVariant -{ - public static CompletedSmartscraper From(Smartscraper::CompletedSmartscraper value) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} - -public sealed record class FailedSmartscraper(Smartscraper::FailedSmartscraper Value) - : Smartscraper::SmartscraperListResponse, - IVariant -{ - public static FailedSmartscraper From(Smartscraper::FailedSmartscraper value) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs index cd1a220..4c73cd0 100644 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs +++ b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponse.cs @@ -4,45 +4,113 @@ using System.Text.Json; using System.Text.Json.Serialization; using Scrapegraphai.Exceptions; -using SmartscraperRetrieveResponseVariants = Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; namespace Scrapegraphai.Models.Smartscraper; [JsonConverter(typeof(SmartscraperRetrieveResponseConverter))] -public abstract record class SmartscraperRetrieveResponse +public record class SmartscraperRetrieveResponse { - internal SmartscraperRetrieveResponse() { } + public object Value { get; private init; } - public static implicit operator SmartscraperRetrieveResponse(CompletedSmartscraper value) => - new SmartscraperRetrieveResponseVariants::CompletedSmartscraper(value); + public string? Error + { + get + { + return Match( + completedSmartscraper: (x) => x.Error, + failedSmartscraper: (x) => x.Error + ); + } + } + + public string? RequestID + { + get + { + return Match( + completedSmartscraper: (x) => x.RequestID, + failedSmartscraper: (x) => x.RequestID + ); + } + } + + public JsonElement? Result + { + get + { + return Match( + completedSmartscraper: (x) => x.Result, + failedSmartscraper: (x) => x.Result + ); + } + } + + public string? UserPrompt + { + get + { + return Match( + completedSmartscraper: (x) => x.UserPrompt, + failedSmartscraper: (x) => x.UserPrompt + ); + } + } + + public string? WebsiteURL + { + get + { + return Match( + completedSmartscraper: (x) => x.WebsiteURL, + failedSmartscraper: (x) => x.WebsiteURL + ); + } + } + + public SmartscraperRetrieveResponse(CompletedSmartscraper value) + { + Value = value; + } + + public SmartscraperRetrieveResponse(FailedSmartscraper value) + { + Value = value; + } - public static implicit operator SmartscraperRetrieveResponse(FailedSmartscraper value) => - new SmartscraperRetrieveResponseVariants::FailedSmartscraper(value); + SmartscraperRetrieveResponse(UnknownVariant value) + { + Value = value; + } + + public static SmartscraperRetrieveResponse CreateUnknownVariant(JsonElement value) + { + return new(new UnknownVariant(value)); + } public bool TryPickCompletedSmartscraper([NotNullWhen(true)] out CompletedSmartscraper? value) { - value = (this as SmartscraperRetrieveResponseVariants::CompletedSmartscraper)?.Value; + value = this.Value as CompletedSmartscraper; return value != null; } public bool TryPickFailedSmartscraper([NotNullWhen(true)] out FailedSmartscraper? value) { - value = (this as SmartscraperRetrieveResponseVariants::FailedSmartscraper)?.Value; + value = this.Value as FailedSmartscraper; return value != null; } public void Switch( - Action completedSmartscraper, - Action failedSmartscraper + Action completedSmartscraper, + Action failedSmartscraper ) { - switch (this) + switch (this.Value) { - case SmartscraperRetrieveResponseVariants::CompletedSmartscraper inner: - completedSmartscraper(inner); + case CompletedSmartscraper value: + completedSmartscraper(value); break; - case SmartscraperRetrieveResponseVariants::FailedSmartscraper inner: - failedSmartscraper(inner); + case FailedSmartscraper value: + failedSmartscraper(value); break; default: throw new ScrapegraphaiInvalidDataException( @@ -52,24 +120,31 @@ public void Switch( } public T Match( - Func completedSmartscraper, - Func failedSmartscraper + Func completedSmartscraper, + Func failedSmartscraper ) { - return this switch + return this.Value switch { - SmartscraperRetrieveResponseVariants::CompletedSmartscraper inner => - completedSmartscraper(inner), - SmartscraperRetrieveResponseVariants::FailedSmartscraper inner => failedSmartscraper( - inner - ), + CompletedSmartscraper value => completedSmartscraper(value), + FailedSmartscraper value => failedSmartscraper(value), _ => throw new ScrapegraphaiInvalidDataException( "Data did not match any variant of SmartscraperRetrieveResponse" ), }; } - public abstract void Validate(); + public void Validate() + { + if (this.Value is not UnknownVariant) + { + throw new ScrapegraphaiInvalidDataException( + "Data did not match any variant of SmartscraperRetrieveResponse" + ); + } + } + + private record struct UnknownVariant(JsonElement value); } sealed class SmartscraperRetrieveResponseConverter : JsonConverter @@ -90,16 +165,15 @@ JsonSerializerOptions options ); if (deserialized != null) { - return new SmartscraperRetrieveResponseVariants::CompletedSmartscraper( - deserialized - ); + deserialized.Validate(); + return new SmartscraperRetrieveResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant SmartscraperRetrieveResponseVariants::CompletedSmartscraper", + "Data does not match union variant 'CompletedSmartscraper'", e ) ); @@ -110,14 +184,15 @@ JsonSerializerOptions options var deserialized = JsonSerializer.Deserialize(ref reader, options); if (deserialized != null) { - return new SmartscraperRetrieveResponseVariants::FailedSmartscraper(deserialized); + deserialized.Validate(); + return new SmartscraperRetrieveResponse(deserialized); } } - catch (JsonException e) + catch (Exception e) when (e is JsonException || e is ScrapegraphaiInvalidDataException) { exceptions.Add( new ScrapegraphaiInvalidDataException( - "Data does not match union variant SmartscraperRetrieveResponseVariants::FailedSmartscraper", + "Data does not match union variant 'FailedSmartscraper'", e ) ); @@ -132,17 +207,7 @@ public override void Write( JsonSerializerOptions options ) { - object variant = value switch - { - SmartscraperRetrieveResponseVariants::CompletedSmartscraper( - var completedSmartscraper - ) => completedSmartscraper, - SmartscraperRetrieveResponseVariants::FailedSmartscraper(var failedSmartscraper) => - failedSmartscraper, - _ => throw new ScrapegraphaiInvalidDataException( - "Data did not match any variant of SmartscraperRetrieveResponse" - ), - }; + object variant = value.Value; JsonSerializer.Serialize(writer, variant, options); } } diff --git a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs b/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs deleted file mode 100644 index 567aa57..0000000 --- a/src/Scrapegraphai/Models/Smartscraper/SmartscraperRetrieveResponseVariants/All.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Scrapegraphai.Core; -using Smartscraper = Scrapegraphai.Models.Smartscraper; - -namespace Scrapegraphai.Models.Smartscraper.SmartscraperRetrieveResponseVariants; - -public sealed record class CompletedSmartscraper(Smartscraper::CompletedSmartscraper Value) - : Smartscraper::SmartscraperRetrieveResponse, - IVariant -{ - public static CompletedSmartscraper From(Smartscraper::CompletedSmartscraper value) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} - -public sealed record class FailedSmartscraper(Smartscraper::FailedSmartscraper Value) - : Smartscraper::SmartscraperRetrieveResponse, - IVariant -{ - public static FailedSmartscraper From(Smartscraper::FailedSmartscraper value) - { - return new(value); - } - - public override void Validate() - { - this.Value.Validate(); - } -} diff --git a/src/Scrapegraphai/Scrapegraphai.csproj b/src/Scrapegraphai/Scrapegraphai.csproj index 8118a1b..59629ea 100644 --- a/src/Scrapegraphai/Scrapegraphai.csproj +++ b/src/Scrapegraphai/Scrapegraphai.csproj @@ -35,4 +35,7 @@ + + + From 6488efb6079f96d6eae71788d8ba669b8cfdb179 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 8 Oct 2025 02:18:45 +0000 Subject: [PATCH 21/21] release: 0.1.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 46 ++++++++++++++++++++++++++ src/Scrapegraphai/Scrapegraphai.csproj | 16 +++------ 3 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 1332969..3d2ac0b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.0.1" + ".": "0.1.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f07a5c5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,46 @@ +# Changelog + +## 0.1.0 (2025-10-08) + +Full Changelog: [v0.0.1...v0.1.0](https://github.com/ScrapeGraphAI/scrapegraphai-c/compare/v0.0.1...v0.1.0) + +### Features + +* add files ([d02f336](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/d02f3362c13702753d986b0d0c35a753e3d28136)) +* **client:** add switch and match helpers for unions ([ccad199](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/ccad1993a305c58d2595477e5ecc171dd798de9d)) +* **client:** allow omitting all params object when all optional ([cf7d535](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/cf7d535c8802a1328e22dbccd58bff9186029827)) +* **client:** improve signature of `trypickx` methods ([3af2386](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/3af2386fb58dc706227669f721e42ef5f45c72f6)) +* **client:** refactor exceptions ([223ca7f](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/223ca7f992e4c17f97aa5ab7a16ec15cb1557aa9)) +* **client:** refactor unions ([67d49b4](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/67d49b454eb8aa021ccaadf2f55e82352b9e61a5)) +* **client:** shorten union variant names ([5d8fbc6](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/5d8fbc62da23aadf61ee88248acb409fec9c8bad)) +* **internal:** add dedicated build job in ci ([19debc8](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/19debc832713e17708c2524bb9a09c1b967b36e5)) +* **internal:** add dev container ([09e44c5](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/09e44c597ff8074834cc50dc8ee291ec649f22f4)) + + +### Bug Fixes + +* **client:** better type names ([198d17a](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/198d17a1e81f613235b5de7413ebe317c0965af0)) +* **client:** handle multiple auth options gracefully ([fc4a269](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/fc4a26933e1a20388a8102170fac78b3f74e2c22)) +* **docs:** re-order using statements ([1529f4f](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/1529f4fa633537e3dfcf942d3898b400b074009c)) +* **internal:** remove example csproj ([29c70b5](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/29c70b55ea868332d230cba9fa9978f46db01301)) +* **internal:** remove unused null class ([4625b19](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/4625b19d0f56f102c6e2a7cb8e953e8f83956e37)) + + +### Chores + +* configure new SDK language ([f87e130](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/f87e1302fbf8f0911a99c6ac94b704df8952798b)) +* **internal:** codegen related update ([30ebeb9](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/30ebeb9bd332cb0a60dd013238811b8b7c2e781c)) +* **internal:** remove unnecessary internal aliasing ([da2adae](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/da2adaed4478e4c9dea6629e9d5f30a1c1693267)) +* **internal:** rename parameters ([136affb](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/136affb4677cc727730d120abf6f9232eda5d9b8)) +* update SDK settings ([00653bc](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/00653bcbabf976cabc53a46e0ad4c6045f559509)) + + +### Documentation + +* **client:** add more property comments ([f427733](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/f427733d982b19d0cc1012be19978f34ae729f6f)) +* fix installation instructions ([3d59690](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/3d5969023ab80e6e87b6770f15de1c4248fe5cf1)) + + +### Refactors + +* **client:** refine enum representation ([f427733](https://github.com/ScrapeGraphAI/scrapegraphai-c/commit/f427733d982b19d0cc1012be19978f34ae729f6f)) diff --git a/src/Scrapegraphai/Scrapegraphai.csproj b/src/Scrapegraphai/Scrapegraphai.csproj index 59629ea..53162f0 100644 --- a/src/Scrapegraphai/Scrapegraphai.csproj +++ b/src/Scrapegraphai/Scrapegraphai.csproj @@ -6,7 +6,7 @@ SDK Code Generation Scrapegraphai C# Apache-2.0 enable - 0.0.1 + 0.1.0 net8.0 latest @@ -22,20 +22,14 @@ $(NoWarn),IL2026,IL3050 Debug;Release - true - true + true + true disable - + - +