-
Notifications
You must be signed in to change notification settings - Fork 681
Expand file tree
/
Copy pathElicitRequestParams.cs
More file actions
972 lines (864 loc) · 37.4 KB
/
ElicitRequestParams.cs
File metadata and controls
972 lines (864 loc) · 37.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents a message issued from the server to elicit additional information from the user via the client.
/// </summary>
public sealed class ElicitRequestParams : RequestParams
{
/// <summary>
/// Gets or sets the elicitation mode: "form" for in-band data collection or "url" for out-of-band URL navigation.
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item><description><b>form</b>: Client collects structured data via a form interface. Data is exposed to the client.</description></item>
/// <item><description><b>url</b>: Client navigates user to a URL for out-of-band interaction. Sensitive data is not exposed to the client.</description></item>
/// </list>
/// </remarks>
/// <exception cref="ArgumentException">The value is not "form" or "url".</exception>
[JsonPropertyName("mode")]
[field: MaybeNull]
public string Mode
{
get => field ??= "form";
set
{
if (value is not ("form" or "url"))
{
throw new ArgumentException("Mode must be 'form' or 'url'.", nameof(value));
}
field = value;
}
}
/// <summary>
/// Gets or sets a unique identifier for this elicitation request.
/// </summary>
/// <remarks>
/// <para>
/// Used to track and correlate the elicitation across multiple messages, especially for out-of-band flows
/// that may complete asynchronously.
/// </para>
/// <para>
/// Required for url mode elicitation to enable progress tracking and completion detection.
/// </para>
/// </remarks>
[JsonPropertyName("elicitationId")]
public string? ElicitationId { get; set; }
/// <summary>
/// Gets or sets the URL to navigate to for out-of-band elicitation.
/// </summary>
/// <remarks>
/// <para>
/// Required when <see cref="Mode"/> is "url". The client should prompt the user for consent
/// and then navigate to this URL in a user-agent (browser) where the user completes
/// the required interaction.
/// </para>
/// <para>
/// URLs must not appear in any other field of the elicitation request for security reasons.
/// </para>
/// </remarks>
[JsonPropertyName("url")]
public string? Url { get; set; }
/// <summary>
/// Gets or sets the message to present to the user.
/// </summary>
/// <remarks>
/// For form mode, this describes what information is being requested.
/// For url mode, this explains why the user needs to navigate to the URL.
/// </remarks>
[JsonPropertyName("message")]
public required string Message { get; set; }
/// <summary>
/// Gets or sets the requested schema for form mode elicitation.
/// </summary>
/// <remarks>
/// Only applicable when <see cref="Mode"/> is "form".
/// </remarks>
/// <value>
/// Possible values are <see cref="StringSchema"/>, <see cref="NumberSchema"/>, <see cref="BooleanSchema"/>,
/// <see cref="UntitledSingleSelectEnumSchema"/>, <see cref="TitledSingleSelectEnumSchema"/>,
/// <see cref="UntitledMultiSelectEnumSchema"/>, and <see cref="TitledMultiSelectEnumSchema"/>.
/// </value>
[JsonPropertyName("requestedSchema")]
public RequestSchema? RequestedSchema { get; set; }
/// <summary>
/// Gets or sets optional task metadata to augment this request with task execution.
/// </summary>
/// <remarks>
/// When present, indicates that the requestor wants this operation executed as a task.
/// The receiver must support task augmentation for this specific request type.
/// </remarks>
[JsonPropertyName("task")]
public McpTaskMetadata? Task { get; set; }
/// <summary>Represents a request schema used in a form mode elicitation request.</summary>
public sealed class RequestSchema
{
/// <summary>Gets the type of the schema.</summary>
/// <remarks>This value is always "object".</remarks>
[JsonPropertyName("type")]
public string Type => "object";
/// <summary>Gets or sets the properties of the schema.</summary>
[JsonPropertyName("properties")]
[field: MaybeNull]
public IDictionary<string, PrimitiveSchemaDefinition> Properties
{
get => field ??= new Dictionary<string, PrimitiveSchemaDefinition>();
set
{
Throw.IfNull(value);
field = value;
}
}
/// <summary>Gets or sets the required properties of the schema.</summary>
[JsonPropertyName("required")]
public IList<string>? Required { get; set; }
}
/// <summary>
/// Represents a restricted subset of JSON Schema:
/// <see cref="StringSchema"/>, <see cref="NumberSchema"/>, <see cref="BooleanSchema"/>,
/// <see cref="UntitledSingleSelectEnumSchema"/>, <see cref="TitledSingleSelectEnumSchema"/>,
/// <see cref="UntitledMultiSelectEnumSchema"/>, or <see cref="TitledMultiSelectEnumSchema"/>.
/// </summary>
[JsonConverter(typeof(Converter))]
public abstract class PrimitiveSchemaDefinition
{
/// <summary>Prevents external derivations.</summary>
protected private PrimitiveSchemaDefinition()
{
}
/// <summary>Gets the default value for this schema as a <see cref="JsonElement"/>, if one is defined.</summary>
internal JsonElement? GetDefaultAsJsonElement() => this switch
{
StringSchema { Default: { } s } => JsonSerializer.SerializeToElement(s, McpJsonUtilities.JsonContext.Default.String),
NumberSchema { Default: { } n } => JsonSerializer.SerializeToElement(n, McpJsonUtilities.JsonContext.Default.Double),
BooleanSchema { Default: { } b } => JsonSerializer.SerializeToElement(b, McpJsonUtilities.JsonContext.Default.Boolean),
UntitledSingleSelectEnumSchema { Default: { } s } => JsonSerializer.SerializeToElement(s, McpJsonUtilities.JsonContext.Default.String),
TitledSingleSelectEnumSchema { Default: { } s } => JsonSerializer.SerializeToElement(s, McpJsonUtilities.JsonContext.Default.String),
UntitledMultiSelectEnumSchema { Default: { } a } => JsonSerializer.SerializeToElement(a, McpJsonUtilities.JsonContext.Default.IListString),
TitledMultiSelectEnumSchema { Default: { } a } => JsonSerializer.SerializeToElement(a, McpJsonUtilities.JsonContext.Default.IListString),
_ => null,
};
/// <summary>Gets or sets the type of the schema.</summary>
[JsonPropertyName("type")]
public abstract string Type { get; set; }
/// <summary>Gets or sets a title for the schema.</summary>
[JsonPropertyName("title")]
public string? Title { get; set; }
/// <summary>Gets or sets a description for the schema.</summary>
[JsonPropertyName("description")]
public string? Description { get; set; }
/// <summary>
/// Provides a <see cref="JsonConverter"/> for <see cref="ResourceContents"/>.
/// </summary>
/// Provides a polymorphic converter for the <see cref="PrimitiveSchemaDefinition"/> class that doesn't require
/// setting <see cref="JsonSerializerOptions.AllowOutOfOrderMetadataProperties"/> explicitly.
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class Converter : JsonConverter<PrimitiveSchemaDefinition>
{
/// <inheritdoc/>
public override PrimitiveSchemaDefinition? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
{
return null;
}
if (reader.TokenType != JsonTokenType.StartObject)
{
throw new JsonException();
}
string? type = null;
string? title = null;
string? description = null;
int? minLength = null;
int? maxLength = null;
string? format = null;
double? minimum = null;
double? maximum = null;
bool? defaultBool = null;
double? defaultNumber = null;
string? defaultString = null;
IList<string>? defaultStringArray = null;
IList<string>? enumValues = null;
IList<string>? enumNames = null;
IList<EnumSchemaOption>? oneOf = null;
int? minItems = null;
int? maxItems = null;
object? items = null; // Can be UntitledEnumItemsSchema or TitledEnumItemsSchema
while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
{
if (reader.TokenType != JsonTokenType.PropertyName)
{
continue;
}
string? propertyName = reader.GetString();
bool success = reader.Read();
Debug.Assert(success, "STJ must have buffered the entire object for us.");
switch (propertyName)
{
case "type":
type = reader.GetString();
break;
case "title":
title = reader.GetString();
break;
case "description":
description = reader.GetString();
break;
case "minLength":
minLength = reader.GetInt32();
break;
case "maxLength":
maxLength = reader.GetInt32();
break;
case "format":
format = reader.GetString();
break;
case "minimum":
minimum = reader.GetDouble();
break;
case "maximum":
maximum = reader.GetDouble();
break;
case "minItems":
minItems = reader.GetInt32();
break;
case "maxItems":
maxItems = reader.GetInt32();
break;
case "default":
// We need to handle different types for default values
// Store the value based on the JSON token type
switch (reader.TokenType)
{
case JsonTokenType.True:
defaultBool = true;
break;
case JsonTokenType.False:
defaultBool = false;
break;
case JsonTokenType.Number:
defaultNumber = reader.GetDouble();
break;
case JsonTokenType.String:
defaultString = reader.GetString();
break;
case JsonTokenType.StartArray:
defaultStringArray = JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.IListString);
break;
}
break;
case "enum":
enumValues = JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.IListString);
break;
case "enumNames":
enumNames = JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.IListString);
break;
case "oneOf":
oneOf = DeserializeEnumOptions(ref reader);
break;
case "items":
items = DeserializeEnumItemsSchema(ref reader);
break;
default:
reader.Skip();
break;
}
}
if (type is null)
{
throw new JsonException("The 'type' property is required.");
}
PrimitiveSchemaDefinition? psd = null;
switch (type)
{
case "string":
if (oneOf is not null)
{
// TitledSingleSelectEnumSchema
psd = new TitledSingleSelectEnumSchema
{
OneOf = oneOf,
Default = defaultString,
};
}
else if (enumValues is not null)
{
// UntitledSingleSelectEnumSchema (enumNames is ignored if present)
psd = new UntitledSingleSelectEnumSchema
{
Enum = enumValues,
Default = defaultString,
};
}
else
{
psd = new StringSchema
{
MinLength = minLength,
MaxLength = maxLength,
Format = format,
Default = defaultString,
};
}
break;
case "array":
if (items is TitledEnumItemsSchema titledItems)
{
// TitledMultiSelectEnumSchema
psd = new TitledMultiSelectEnumSchema
{
MinItems = minItems,
MaxItems = maxItems,
Items = titledItems,
Default = defaultStringArray,
};
}
else if (items is UntitledEnumItemsSchema untitledItems)
{
// UntitledMultiSelectEnumSchema
psd = new UntitledMultiSelectEnumSchema
{
MinItems = minItems,
MaxItems = maxItems,
Items = untitledItems,
Default = defaultStringArray,
};
}
break;
case "integer":
case "number":
psd = new NumberSchema
{
Minimum = minimum,
Maximum = maximum,
Default = defaultNumber,
};
break;
case "boolean":
psd = new BooleanSchema
{
Default = defaultBool,
};
break;
}
if (psd is not null)
{
psd.Type = type;
psd.Title = title;
psd.Description = description;
}
return psd;
}
private static List<EnumSchemaOption> DeserializeEnumOptions(ref Utf8JsonReader reader)
{
if (reader.TokenType != JsonTokenType.StartArray)
{
throw new JsonException("Expected array for oneOf property.");
}
var options = new List<EnumSchemaOption>();
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
if (reader.TokenType != JsonTokenType.StartObject)
{
throw new JsonException("Expected object in oneOf array.");
}
string? constValue = null;
string? titleValue = null;
while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
{
if (reader.TokenType == JsonTokenType.PropertyName)
{
string? propertyName = reader.GetString();
reader.Read();
switch (propertyName)
{
case "const":
constValue = reader.GetString();
break;
case "title":
titleValue = reader.GetString();
break;
default:
reader.Skip();
break;
}
}
}
if (constValue is null || titleValue is null)
{
throw new JsonException("Each option in oneOf must have both 'const' and 'title' properties.");
}
options.Add(new EnumSchemaOption { Const = constValue, Title = titleValue });
}
return options;
}
private static object DeserializeEnumItemsSchema(ref Utf8JsonReader reader)
{
if (reader.TokenType != JsonTokenType.StartObject)
{
throw new JsonException("Expected object for items property.");
}
string? type = null;
IList<string>? enumValues = null;
IList<EnumSchemaOption>? anyOf = null;
while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
{
if (reader.TokenType == JsonTokenType.PropertyName)
{
string? propertyName = reader.GetString();
reader.Read();
switch (propertyName)
{
case "type":
type = reader.GetString();
break;
case "enum":
enumValues = JsonSerializer.Deserialize(ref reader, McpJsonUtilities.JsonContext.Default.IListString);
break;
case "anyOf":
anyOf = DeserializeEnumOptions(ref reader);
break;
default:
reader.Skip();
break;
}
}
}
// Determine which type to create based on the properties
if (anyOf is not null)
{
return new TitledEnumItemsSchema { AnyOf = anyOf };
}
else if (enumValues is not null)
{
return new UntitledEnumItemsSchema { Type = type ?? "string", Enum = enumValues };
}
else
{
throw new JsonException("Items schema must have either 'enum' or 'anyOf' property.");
}
}
/// <inheritdoc/>
public override void Write(Utf8JsonWriter writer, PrimitiveSchemaDefinition value, JsonSerializerOptions options)
{
if (value is null)
{
writer.WriteNullValue();
return;
}
writer.WriteStartObject();
writer.WriteString("type", value.Type);
if (value.Title is not null)
{
writer.WriteString("title", value.Title);
}
if (value.Description is not null)
{
writer.WriteString("description", value.Description);
}
switch (value)
{
case StringSchema stringSchema:
if (stringSchema.MinLength.HasValue)
{
writer.WriteNumber("minLength", stringSchema.MinLength.Value);
}
if (stringSchema.MaxLength.HasValue)
{
writer.WriteNumber("maxLength", stringSchema.MaxLength.Value);
}
if (stringSchema.Format is not null)
{
writer.WriteString("format", stringSchema.Format);
}
if (stringSchema.Default is not null)
{
writer.WriteString("default", stringSchema.Default);
}
break;
case NumberSchema numberSchema:
if (numberSchema.Minimum.HasValue)
{
writer.WriteNumber("minimum", numberSchema.Minimum.Value);
}
if (numberSchema.Maximum.HasValue)
{
writer.WriteNumber("maximum", numberSchema.Maximum.Value);
}
if (numberSchema.Default is not null)
{
writer.WriteNumber("default", numberSchema.Default.Value);
}
break;
case BooleanSchema booleanSchema:
if (booleanSchema.Default is not null)
{
writer.WriteBoolean("default", booleanSchema.Default.Value);
}
break;
case UntitledSingleSelectEnumSchema untitledSingleSelect:
if (untitledSingleSelect.Enum is not null)
{
writer.WritePropertyName("enum");
JsonSerializer.Serialize(writer, untitledSingleSelect.Enum, McpJsonUtilities.JsonContext.Default.IListString);
}
if (untitledSingleSelect.Default is not null)
{
writer.WriteString("default", untitledSingleSelect.Default);
}
break;
case TitledSingleSelectEnumSchema titledSingleSelect:
if (titledSingleSelect.OneOf is not null && titledSingleSelect.OneOf.Count > 0)
{
writer.WritePropertyName("oneOf");
SerializeEnumOptions(writer, titledSingleSelect.OneOf);
}
if (titledSingleSelect.Default is not null)
{
writer.WriteString("default", titledSingleSelect.Default);
}
break;
case UntitledMultiSelectEnumSchema untitledMultiSelect:
if (untitledMultiSelect.MinItems.HasValue)
{
writer.WriteNumber("minItems", untitledMultiSelect.MinItems.Value);
}
if (untitledMultiSelect.MaxItems.HasValue)
{
writer.WriteNumber("maxItems", untitledMultiSelect.MaxItems.Value);
}
writer.WritePropertyName("items");
SerializeUntitledEnumItemsSchema(writer, untitledMultiSelect.Items);
if (untitledMultiSelect.Default is not null)
{
writer.WritePropertyName("default");
JsonSerializer.Serialize(writer, untitledMultiSelect.Default, McpJsonUtilities.JsonContext.Default.IListString);
}
break;
case TitledMultiSelectEnumSchema titledMultiSelect:
if (titledMultiSelect.MinItems.HasValue)
{
writer.WriteNumber("minItems", titledMultiSelect.MinItems.Value);
}
if (titledMultiSelect.MaxItems.HasValue)
{
writer.WriteNumber("maxItems", titledMultiSelect.MaxItems.Value);
}
writer.WritePropertyName("items");
SerializeTitledEnumItemsSchema(writer, titledMultiSelect.Items);
if (titledMultiSelect.Default is not null)
{
writer.WritePropertyName("default");
JsonSerializer.Serialize(writer, titledMultiSelect.Default, McpJsonUtilities.JsonContext.Default.IListString);
}
break;
default:
throw new JsonException($"Unexpected schema type: {value.GetType().Name}");
}
writer.WriteEndObject();
}
private static void SerializeEnumOptions(Utf8JsonWriter writer, IList<EnumSchemaOption> options)
{
writer.WriteStartArray();
foreach (var option in options)
{
writer.WriteStartObject();
writer.WriteString("const", option.Const);
writer.WriteString("title", option.Title);
writer.WriteEndObject();
}
writer.WriteEndArray();
}
private static void SerializeUntitledEnumItemsSchema(Utf8JsonWriter writer, UntitledEnumItemsSchema itemsSchema)
{
writer.WriteStartObject();
writer.WriteString("type", itemsSchema.Type);
writer.WritePropertyName("enum");
JsonSerializer.Serialize(writer, itemsSchema.Enum, McpJsonUtilities.JsonContext.Default.IListString);
writer.WriteEndObject();
}
private static void SerializeTitledEnumItemsSchema(Utf8JsonWriter writer, TitledEnumItemsSchema itemsSchema)
{
writer.WriteStartObject();
writer.WritePropertyName("anyOf");
SerializeEnumOptions(writer, itemsSchema.AnyOf);
writer.WriteEndObject();
}
}
}
/// <summary>Represents a schema for a string type.</summary>
public sealed class StringSchema : PrimitiveSchemaDefinition
{
/// <inheritdoc/>
[JsonPropertyName("type")]
public override string Type
{
get => "string";
set
{
if (value is not "string")
{
throw new ArgumentException("Type must be 'string'.", nameof(value));
}
}
}
/// <summary>Gets or sets the minimum length for the string.</summary>
[JsonPropertyName("minLength")]
public int? MinLength
{
get => field;
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "Minimum length cannot be negative.");
}
field = value;
}
}
/// <summary>Gets or sets the maximum length for the string.</summary>
[JsonPropertyName("maxLength")]
public int? MaxLength
{
get => field;
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "Maximum length cannot be negative.");
}
field = value;
}
}
/// <summary>Gets or sets a specific format for the string ("email", "uri", "date", or "date-time").</summary>
[JsonPropertyName("format")]
public string? Format
{
get => field;
set
{
if (value is not (null or "email" or "uri" or "date" or "date-time"))
{
throw new ArgumentException("Format must be 'email', 'uri', 'date', or 'date-time'.", nameof(value));
}
field = value;
}
}
/// <summary>Gets or sets the default value for the string.</summary>
[JsonPropertyName("default")]
public string? Default { get; set; }
}
/// <summary>Represents a schema for a number or integer type.</summary>
public sealed class NumberSchema : PrimitiveSchemaDefinition
{
/// <inheritdoc/>
[field: MaybeNull]
public override string Type
{
get => field ??= "number";
set
{
if (value is not ("number" or "integer"))
{
throw new ArgumentException("Type must be 'number' or 'integer'.", nameof(value));
}
field = value;
}
}
/// <summary>Gets or sets the minimum allowed value.</summary>
[JsonPropertyName("minimum")]
public double? Minimum { get; set; }
/// <summary>Gets or sets the maximum allowed value.</summary>
[JsonPropertyName("maximum")]
public double? Maximum { get; set; }
/// <summary>Gets or sets the default value for the number.</summary>
[JsonPropertyName("default")]
public double? Default { get; set; }
}
/// <summary>Represents a schema for a Boolean type.</summary>
public sealed class BooleanSchema : PrimitiveSchemaDefinition
{
/// <inheritdoc/>
[JsonPropertyName("type")]
public override string Type
{
get => "boolean";
set
{
if (value is not "boolean")
{
throw new ArgumentException("Type must be 'boolean'.", nameof(value));
}
}
}
/// <summary>Gets or sets the default value for the Boolean.</summary>
[JsonPropertyName("default")]
public bool? Default { get; set; }
}
/// <summary>
/// Represents a schema for single-selection enumeration without display titles for options.
/// </summary>
public sealed class UntitledSingleSelectEnumSchema : PrimitiveSchemaDefinition
{
/// <inheritdoc/>
[JsonPropertyName("type")]
public override string Type
{
get => "string";
set
{
if (value is not "string")
{
throw new ArgumentException("Type must be 'string'.", nameof(value));
}
}
}
/// <summary>Gets or sets the list of allowed string values for the enum.</summary>
[JsonPropertyName("enum")]
[field: MaybeNull]
public IList<string> Enum
{
get => field ??= [];
set
{
Throw.IfNull(value);
field = value;
}
}
/// <summary>Gets or sets the default value for the enum.</summary>
[JsonPropertyName("default")]
public string? Default { get; set; }
}
/// <summary>
/// Represents a single option in a titled enum schema with a constant value and display title.
/// </summary>
public sealed class EnumSchemaOption
{
/// <summary>Gets or sets the constant value for this option.</summary>
[JsonPropertyName("const")]
public required string Const { get; set; }
/// <summary>Gets or sets the display title for this option.</summary>
[JsonPropertyName("title")]
public required string Title { get; set; }
}
/// <summary>
/// Represents a schema for single-selection enumeration with display titles for each option.
/// </summary>
public sealed class TitledSingleSelectEnumSchema : PrimitiveSchemaDefinition
{
/// <inheritdoc/>
[JsonPropertyName("type")]
public override string Type
{
get => "string";
set
{
if (value is not "string")
{
throw new ArgumentException("Type must be 'string'.", nameof(value));
}
}
}
/// <summary>Gets or sets the list of enum options with their constant values and display titles.</summary>
[JsonPropertyName("oneOf")]
[field: MaybeNull]
public IList<EnumSchemaOption> OneOf
{
get => field ??= [];
set
{
Throw.IfNull(value);
field = value;
}
}
/// <summary>Gets or sets the default value for the enum.</summary>
[JsonPropertyName("default")]
public string? Default { get; set; }
}
/// <summary>
/// Represents the items schema for untitled multi-select enum arrays.
/// </summary>
public sealed class UntitledEnumItemsSchema
{
/// <summary>Gets or sets the type of the items.</summary>
[JsonPropertyName("type")]
public string Type { get; set; } = "string";
/// <summary>Gets or sets the list of allowed string values.</summary>
[JsonPropertyName("enum")]
public required IList<string> Enum { get; set; }
}
/// <summary>
/// Represents the items schema for titled multi-select enum arrays.
/// </summary>
public sealed class TitledEnumItemsSchema
{
/// <summary>Gets or sets the list of enum options with constant values and display titles.</summary>
[JsonPropertyName("anyOf")]
public required IList<EnumSchemaOption> AnyOf { get; set; }
}
/// <summary>
/// Represents a schema for multiple-selection enumeration without display titles for options.
/// </summary>
public sealed class UntitledMultiSelectEnumSchema : PrimitiveSchemaDefinition
{
/// <inheritdoc/>
[JsonPropertyName("type")]
public override string Type
{
get => "array";
set
{
if (value is not "array")
{
throw new ArgumentException("Type must be 'array'.", nameof(value));
}
}
}
/// <summary>Gets or sets the minimum number of items that can be selected.</summary>
[JsonPropertyName("minItems")]
public int? MinItems { get; set; }
/// <summary>Gets or sets the maximum number of items that can be selected.</summary>
[JsonPropertyName("maxItems")]
public int? MaxItems { get; set; }
/// <summary>Gets or sets the schema for items in the array.</summary>
[JsonPropertyName("items")]
public required UntitledEnumItemsSchema Items { get; set; }
/// <summary>Gets or sets the default values for the enum.</summary>
[JsonPropertyName("default")]
public IList<string>? Default { get; set; }
}
/// <summary>
/// Represents a schema for multiple-selection enumeration with display titles for each option.
/// </summary>
public sealed class TitledMultiSelectEnumSchema : PrimitiveSchemaDefinition
{
/// <inheritdoc/>
[JsonPropertyName("type")]
public override string Type
{
get => "array";
set
{
if (value is not "array")
{
throw new ArgumentException("Type must be 'array'.", nameof(value));
}
}
}
/// <summary>Gets or sets the minimum number of items that can be selected.</summary>
[JsonPropertyName("minItems")]
public int? MinItems { get; set; }
/// <summary>Gets or sets the maximum number of items that can be selected.</summary>
[JsonPropertyName("maxItems")]
public int? MaxItems { get; set; }
/// <summary>Gets or sets the schema for items in the array.</summary>
[JsonPropertyName("items")]
public required TitledEnumItemsSchema Items { get; set; }
/// <summary>Gets or sets the default values for the enum.</summary>
[JsonPropertyName("default")]
public IList<string>? Default { get; set; }
}
}