From 974ed586e1226d6d130ccc0bf16c580c7944545b Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Mon, 16 Oct 2023 11:49:01 -0400 Subject: [PATCH 1/3] Build options is an arbitrary json object rather than a string --- src/Serval.Client/Client.g.cs | 10 +++++----- .../Contracts/TranslationBuildConfigDto.cs | 2 +- .../Controllers/TranslationEnginesController.cs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Serval.Client/Client.g.cs b/src/Serval.Client/Client.g.cs index fbe0c85e..84d0dc27 100644 --- a/src/Serval.Client/Client.g.cs +++ b/src/Serval.Client/Client.g.cs @@ -1015,8 +1015,8 @@ public partial interface ITranslationEnginesClient ///
you may flag a subset of books for pretranslation by including their [abbreviations](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Canon.cs) ///
in the textIds parameter. If the engine does not support pretranslation, these fields have no effect. ///
- ///
The `"options"` parameter of the build config provides the ability to pass build configuration parameters as a JSON string. - ///
A typical use case would be to set `"options"` to `"{\"max_steps\":10}"` in order to configure the maximum + ///
The `"options"` parameter of the build config provides the ability to pass build configuration parameters as a JSON object. + ///
A typical use case would be to set `"options"` to `{"max_steps":10}` in order to configure the maximum ///
number of training iterations in order to reduce turnaround time for testing purposes. /// /// The translation engine id @@ -2918,8 +2918,8 @@ public string BaseUrl ///
you may flag a subset of books for pretranslation by including their [abbreviations](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Canon.cs) ///
in the textIds parameter. If the engine does not support pretranslation, these fields have no effect. ///
- ///
The `"options"` parameter of the build config provides the ability to pass build configuration parameters as a JSON string. - ///
A typical use case would be to set `"options"` to `"{\"max_steps\":10}"` in order to configure the maximum + ///
The `"options"` parameter of the build config provides the ability to pass build configuration parameters as a JSON object. + ///
A typical use case would be to set `"options"` to `{"max_steps":10}` in order to configure the maximum ///
number of training iterations in order to reduce turnaround time for testing purposes. /// /// The translation engine id @@ -4504,7 +4504,7 @@ public partial class TranslationBuildConfig public System.Collections.Generic.IList? Pretranslate { get; set; } = default!; [Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Options { get; set; } = default!; + public object? Options { get; set; } = default!; } diff --git a/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs b/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs index 14e1d2c4..871366e3 100644 --- a/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs +++ b/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs @@ -5,5 +5,5 @@ public class TranslationBuildConfigDto public string? Name { get; set; } public IList? Pretranslate { get; set; } - public string? Options { get; set; } + public object? Options { get; set; } } diff --git a/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval.Translation/Controllers/TranslationEnginesController.cs index e23e8128..d5ce7516 100644 --- a/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -772,8 +772,8 @@ CancellationToken cancellationToken /// you may flag a subset of books for pretranslation by including their [abbreviations](https://github.com/sillsdev/libpalaso/blob/master/SIL.Scripture/Canon.cs) /// in the textIds parameter. If the engine does not support pretranslation, these fields have no effect. /// - /// The `"options"` parameter of the build config provides the ability to pass build configuration parameters as a JSON string. - /// A typical use case would be to set `"options"` to `"{\"max_steps\":10}"` in order to configure the maximum + /// The `"options"` parameter of the build config provides the ability to pass build configuration parameters as a JSON object. + /// A typical use case would be to set `"options"` to `{"max_steps":10}` in order to configure the maximum /// number of training iterations in order to reduce turnaround time for testing purposes. /// /// The translation engine id @@ -1020,7 +1020,7 @@ private static Build Map(Engine engine, TranslationBuildConfigDto source) var jsonSerializerOptions = new JsonSerializerOptions(); jsonSerializerOptions.Converters.Add(new ObjectToInferredTypesConverter()); build.Options = JsonSerializer.Deserialize>( - source.Options ?? "{}", + source.Options?.ToString() ?? "{}", jsonSerializerOptions ); } From 78bb04f55e02df366d5e886c841f6b7cd5bb72d2 Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Mon, 16 Oct 2023 12:32:21 -0400 Subject: [PATCH 2/3] Review fixes --- src/Serval.Client/Client.g.cs | 2 +- .../Contracts/TranslationBuildConfigDto.cs | 5 +++++ src/Serval.Translation/Contracts/TranslationBuildDto.cs | 2 +- .../Controllers/TranslationEnginesController.cs | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Serval.Client/Client.g.cs b/src/Serval.Client/Client.g.cs index 84d0dc27..54515b40 100644 --- a/src/Serval.Client/Client.g.cs +++ b/src/Serval.Client/Client.g.cs @@ -4457,7 +4457,7 @@ public partial class TranslationBuild public System.DateTimeOffset? DateFinished { get; set; } = default!; [Newtonsoft.Json.JsonProperty("options", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] - public string? Options { get; set; } = default!; + public object? Options { get; set; } = default!; } diff --git a/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs b/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs index 871366e3..51297a9e 100644 --- a/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs +++ b/src/Serval.Translation/Contracts/TranslationBuildConfigDto.cs @@ -5,5 +5,10 @@ public class TranslationBuildConfigDto public string? Name { get; set; } public IList? Pretranslate { get; set; } + /// + /// { + /// "property" : "value" + /// } + /// public object? Options { get; set; } } diff --git a/src/Serval.Translation/Contracts/TranslationBuildDto.cs b/src/Serval.Translation/Contracts/TranslationBuildDto.cs index 65fa4558..ce56193a 100644 --- a/src/Serval.Translation/Contracts/TranslationBuildDto.cs +++ b/src/Serval.Translation/Contracts/TranslationBuildDto.cs @@ -19,5 +19,5 @@ public class TranslationBuildDto /// public JobState State { get; set; } public DateTime? DateFinished { get; set; } - public string? Options { get; set; } + public object? Options { get; set; } } diff --git a/src/Serval.Translation/Controllers/TranslationEnginesController.cs b/src/Serval.Translation/Controllers/TranslationEnginesController.cs index d5ce7516..7a363cca 100644 --- a/src/Serval.Translation/Controllers/TranslationEnginesController.cs +++ b/src/Serval.Translation/Controllers/TranslationEnginesController.cs @@ -1070,7 +1070,7 @@ private TranslationBuildDto Map(Build source) QueueDepth = source.QueueDepth, State = source.State, DateFinished = source.DateFinished, - Options = JsonSerializer.Serialize(source.Options) + Options = source.Options }; } From 8e082a69e69be28b68ca42ad902cade0e6506f29 Mon Sep 17 00:00:00 2001 From: Enkidu93 Date: Mon, 16 Oct 2023 13:17:17 -0400 Subject: [PATCH 3/3] Add example to build dto --- src/Serval.Translation/Contracts/TranslationBuildDto.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Serval.Translation/Contracts/TranslationBuildDto.cs b/src/Serval.Translation/Contracts/TranslationBuildDto.cs index ce56193a..9d9fa190 100644 --- a/src/Serval.Translation/Contracts/TranslationBuildDto.cs +++ b/src/Serval.Translation/Contracts/TranslationBuildDto.cs @@ -19,5 +19,11 @@ public class TranslationBuildDto /// public JobState State { get; set; } public DateTime? DateFinished { get; set; } + + /// + /// { + /// "property" : "value" + /// } + /// public object? Options { get; set; } }