-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathOpenApiSchemaTests.cs
More file actions
709 lines (618 loc) · 25.6 KB
/
OpenApiSchemaTests.cs
File metadata and controls
709 lines (618 loc) · 25.6 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Equivalency;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Tests;
using Xunit;
using System;
namespace Microsoft.OpenApi.Readers.Tests.V31Tests
{
public class OpenApiSchemaTests
{
private const string SampleFolderPath = "V31Tests/Samples/OpenApiSchema/";
public static MemoryStream GetMemoryStream(string fileName)
{
var filePath = Path.Combine(SampleFolderPath, fileName);
var fileBytes = File.ReadAllBytes(filePath);
return new MemoryStream(fileBytes);
}
[Fact]
public async Task ParseBasicV31SchemaShouldSucceed()
{
var expectedObject = new OpenApiSchema()
{
Id = "https://example.com/arrays.schema.json",
Schema = new Uri("https://json-schema.org/draft/2020-12/schema"),
Description = "A representation of a person, company, organization, or place",
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema>()
{
["fruits"] = new OpenApiSchema
{
Type = JsonSchemaType.Array,
Items = new OpenApiSchema
{
Type = JsonSchemaType.String
}
},
["vegetables"] = new OpenApiSchema
{
Type = JsonSchemaType.Array
}
},
Definitions = new Dictionary<string, IOpenApiSchema>
{
["veggie"] = new OpenApiSchema
{
Type = JsonSchemaType.Object,
Required = new HashSet<string>
{
"veggieName",
"veggieLike"
},
DependentRequired = new Dictionary<string, HashSet<string>>
{
{ "veggieType", new HashSet<string> { "veggieColor", "veggieSize" } }
},
Properties = new Dictionary<string, IOpenApiSchema>()
{
["veggieName"] = new OpenApiSchema
{
Type = JsonSchemaType.String,
Description = "The name of the vegetable."
},
["veggieLike"] = new OpenApiSchema
{
Type = JsonSchemaType.Boolean,
Description = "Do I like this vegetable?"
},
["veggieType"] = new OpenApiSchema
{
Type = JsonSchemaType.String,
Description = "The type of vegetable (e.g., root, leafy, etc.)."
},
["veggieColor"] = new OpenApiSchema
{
Type = JsonSchemaType.String,
Description = "The color of the vegetable."
},
["veggieSize"] = new OpenApiSchema
{
Type = JsonSchemaType.String,
Description = "The size of the vegetable."
}
}
}
}
};
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(
Path.Combine(SampleFolderPath, "jsonSchema.json"), OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
// Assert
Assert.Equivalent(expectedObject, schema);
}
[Fact]
public void ParseSchemaWithTypeArrayWorks()
{
// Arrange
var schema = @"{
""$id"": ""https://example.com/arrays.schema.json"",
""$schema"": ""https://json-schema.org/draft/2020-12/schema"",
""description"": ""A representation of a person, company, organization, or place"",
""type"": [""object"", ""null""]
}";
var expected = new OpenApiSchema()
{
Id = "https://example.com/arrays.schema.json",
Schema = new Uri("https://json-schema.org/draft/2020-12/schema"),
Description = "A representation of a person, company, organization, or place",
Type = JsonSchemaType.Object | JsonSchemaType.Null
};
// Act
var actual = OpenApiModelFactory.Parse<OpenApiSchema>(schema, OpenApiSpecVersion.OpenApi3_1, new(), out _);
// Assert
Assert.Equivalent(expected, actual);
}
[Fact]
public void TestSchemaCopyConstructorWithTypeArrayWorks()
{
/* Arrange
* Test schema's copy constructor for deep-cloning type array
*/
var schemaWithTypeArray = new OpenApiSchema()
{
Type = JsonSchemaType.Array | JsonSchemaType.Null,
Items = new OpenApiSchema
{
Type = JsonSchemaType.String
}
};
var simpleSchema = new OpenApiSchema()
{
Type = JsonSchemaType.String
};
// Act
var schemaWithArrayCopy = schemaWithTypeArray.CreateShallowCopy() as OpenApiSchema;
schemaWithArrayCopy.Type = JsonSchemaType.String;
var simpleSchemaCopy = simpleSchema.CreateShallowCopy() as OpenApiSchema;
simpleSchemaCopy.Type = JsonSchemaType.String | JsonSchemaType.Null;
// Assert
Assert.NotEqual(schemaWithTypeArray.Type, schemaWithArrayCopy.Type);
schemaWithTypeArray.Type = JsonSchemaType.String | JsonSchemaType.Null;
Assert.NotEqual(simpleSchema.Type, simpleSchemaCopy.Type);
simpleSchema.Type = JsonSchemaType.String;
}
[Fact]
public async Task ParseV31SchemaShouldSucceed()
{
var path = Path.Combine(SampleFolderPath, "schema.yaml");
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
var expectedSchema = new OpenApiSchema
{
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema>()
{
["one"] = new OpenApiSchema()
{
Description = "type array",
Type = JsonSchemaType.Integer | JsonSchemaType.String
}
}
};
// Assert
Assert.Equivalent(expectedSchema, schema);
}
[Fact]
public async Task ParseAdvancedV31SchemaShouldSucceed()
{
// Arrange and Act
var path = Path.Combine(SampleFolderPath, "advancedSchema.yaml");
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
var expectedSchema = new OpenApiSchema
{
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema>()
{
["one"] = new OpenApiSchema()
{
Description = "type array",
Type = JsonSchemaType.Integer | JsonSchemaType.String
},
["two"] = new OpenApiSchema()
{
Description = "type 'null'",
Type = JsonSchemaType.Null
},
["three"] = new OpenApiSchema()
{
Description = "type array including 'null'",
Type = JsonSchemaType.String | JsonSchemaType.Null
},
["four"] = new OpenApiSchema()
{
Description = "array with no items",
Type = JsonSchemaType.Array
},
["five"] = new OpenApiSchema()
{
Description = "singular example",
Type = JsonSchemaType.String,
Examples = new List<JsonNode>
{
"exampleValue"
}
},
["six"] = new OpenApiSchema()
{
Description = "exclusiveMinimum true",
ExclusiveMinimum = "10"
},
["seven"] = new OpenApiSchema()
{
Description = "exclusiveMinimum false",
Minimum = "10"
},
["eight"] = new OpenApiSchema()
{
Description = "exclusiveMaximum true",
ExclusiveMaximum = "20"
},
["nine"] = new OpenApiSchema()
{
Description = "exclusiveMaximum false",
Maximum = "20"
},
["ten"] = new OpenApiSchema()
{
Description = "nullable string",
Type = JsonSchemaType.String | JsonSchemaType.Null
},
["eleven"] = new OpenApiSchema()
{
Description = "x-nullable string",
Type = JsonSchemaType.String | JsonSchemaType.Null
},
["twelve"] = new OpenApiSchema()
{
Description = "file/binary"
}
}
};
// Assert
schema.Should().BeEquivalentTo(expectedSchema, options => options
.IgnoringCyclicReferences()
.Excluding((IMemberInfo memberInfo) =>
memberInfo.Path.EndsWith("Parent")));
}
[Fact]
public void ParseSchemaWithExamplesShouldSucceed()
{
// Arrange
var input = @"
type: string
examples:
- fedora
- ubuntu
";
// Act
var schema = OpenApiModelFactory.Parse<OpenApiSchema>(input, OpenApiSpecVersion.OpenApi3_1, new(), out _, "yaml", SettingsFixture.ReaderSettings);
// Assert
Assert.Equal(2, schema.Examples.Count);
}
[Fact]
public void CloningSchemaWithExamplesAndEnumsShouldSucceed()
{
// Arrange
var schema = new OpenApiSchema
{
Type = JsonSchemaType.Integer,
Default = 5,
Examples = [2, 3],
Enum = [1, 2, 3]
};
var clone = schema.CreateShallowCopy() as OpenApiSchema;
clone.Examples.Add(4);
clone.Enum.Add(4);
clone.Default = 6;
// Assert
Assert.Equivalent(new int[] { 1, 2, 3, 4 }, clone.Enum.Select(static x => x.GetValue<int>()).ToArray());
Assert.Equivalent(new int[] { 2, 3, 4 }, clone.Examples.Select(static x => x.GetValue<int>()).ToArray());
Assert.Equivalent(6, clone.Default.GetValue<int>());
}
[Fact]
public void DefaultEmptyCollectionShouldRoundTrip()
{
// Given
var serializedSchema =
"""
{
"type": "array",
"items": {
"type": "string",
"default": []
}
}
""";
using var textWriter = new StringWriter();
var writer = new OpenApiJsonWriter(textWriter);
// When
var schema = OpenApiModelFactory.Parse<OpenApiSchema>(serializedSchema, OpenApiSpecVersion.OpenApi3_1, new(), out _, "json", SettingsFixture.ReaderSettings);
var deserializedArray = Assert.IsType<JsonArray>(schema.Items.Default);
Assert.Empty(deserializedArray);
schema.SerializeAsV31(writer);
var roundTrippedSchema = textWriter.ToString();
// Then
var parsedResult = JsonNode.Parse(roundTrippedSchema);
var parsedExpected = JsonNode.Parse(serializedSchema);
Assert.True(JsonNode.DeepEquals(parsedExpected, parsedResult));
var resultingArray = Assert.IsType<JsonArray>(parsedResult["items"]?["default"]);
Assert.Empty(resultingArray);
}
[Fact]
public void DefaultNullIsLossyDuringRoundTripJson()
{
// Given
var serializedSchema =
"""
{
"type": ["string", "null"],
"default": null
}
""";
using var textWriter = new StringWriter();
var writer = new OpenApiJsonWriter(textWriter);
// When
var schema = OpenApiModelFactory.Parse<OpenApiSchema>(serializedSchema, OpenApiSpecVersion.OpenApi3_1, new(), out _, "json", SettingsFixture.ReaderSettings);
Assert.Null(schema.Default);
schema.SerializeAsV31(writer);
var roundTrippedSchema = textWriter.ToString();
// Then
var parsedResult = JsonNode.Parse(roundTrippedSchema);
var parsedExpected = JsonNode.Parse(serializedSchema);
Assert.False(JsonNode.DeepEquals(parsedExpected, parsedResult));
var resultingDefault = parsedResult["default"];
Assert.Null(resultingDefault);
}
[Fact]
public void DefaultNullIsLossyDuringRoundTripYaml()
{
// Given
var serializedSchema =
"""
type:
- string
- 'null'
default: null
""";
using var textWriter = new StringWriter();
var writer = new OpenApiYamlWriter(textWriter);
// When
var schema = OpenApiModelFactory.Parse<OpenApiSchema>(serializedSchema, OpenApiSpecVersion.OpenApi3_1, new(), out _, "yaml", SettingsFixture.ReaderSettings);
Assert.Null(schema.Default);
schema.SerializeAsV31(writer);
var roundTrippedSchema = textWriter.ToString();
// Then
Assert.Equal(
"""
type:
- 'null'
- string
""".MakeLineBreaksEnvironmentNeutral(),
roundTrippedSchema.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
public async Task SerializeV31SchemaWithMultipleTypesAsV3Works()
{
// Arrange
var expected = @"type: string
nullable: true";
var path = Path.Combine(SampleFolderPath, "schemaWithTypeArray.yaml");
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
var writer = new StringWriter();
schema.SerializeAsV3(new OpenApiYamlWriter(writer));
var schema1String = writer.ToString();
Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schema1String.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
public async Task SerializeV31SchemaWithMultipleTypesAsV2Works()
{
// Arrange
var expected = @"type: string
x-nullable: true";
var path = Path.Combine(SampleFolderPath, "schemaWithTypeArray.yaml");
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
var writer = new StringWriter();
schema.SerializeAsV2(new OpenApiYamlWriter(writer));
var schema1String = writer.ToString();
Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schema1String.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
public async Task SerializeV3SchemaWithNullableAsV31Works()
{
// Arrange
var expected = @"type:
- 'null'
- string";
var path = Path.Combine(SampleFolderPath, "schemaWithNullable.yaml");
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings);
var writer = new StringWriter();
schema.SerializeAsV31(new OpenApiYamlWriter(writer));
var schemaString = writer.ToString();
Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
public async Task SerializeV2SchemaWithNullableExtensionAsV31Works()
{
// Arrange
var expected = @"type:
- 'null'
- string";
var path = Path.Combine(SampleFolderPath, "schemaWithNullableExtension.yaml");
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi2_0, new(), SettingsFixture.ReaderSettings);
var writer = new StringWriter();
schema.SerializeAsV31(new OpenApiYamlWriter(writer));
var schemaString = writer.ToString();
Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
public void SerializeSchemaWithTypeArrayAndNullableDoesntEmitType()
{
var input = @"type:
- ""string""
- ""int""
nullable: true";
var expected = @"x-nullable: true";
var schema = OpenApiModelFactory.Parse<OpenApiSchema>(input, OpenApiSpecVersion.OpenApi3_1, new(), out _, "yaml", SettingsFixture.ReaderSettings);
var writer = new StringWriter();
schema.SerializeAsV2(new OpenApiYamlWriter(writer));
var schemaString = writer.ToString();
Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral());
}
[Theory]
[InlineData("schemaWithNullable.yaml")]
[InlineData("schemaWithNullableExtension.yaml")]
public async Task LoadSchemaWithNullableExtensionAsV31Works(string filePath)
{
// Arrange
var path = Path.Combine(SampleFolderPath, filePath);
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
// Assert
Assert.Equal(JsonSchemaType.String | JsonSchemaType.Null, schema.Type);
}
[Fact]
public async Task SerializeSchemaWithJsonSchemaKeywordsWorks()
{
// Arrange
var expected = @"$id: https://example.com/schemas/person.schema.yaml
$schema: https://json-schema.org/draft/2020-12/schema
$comment: A schema defining a person object with optional references to dynamic components.
$vocabulary:
https://json-schema.org/draft/2020-12/vocab/core: true
https://json-schema.org/draft/2020-12/vocab/applicator: true
https://json-schema.org/draft/2020-12/vocab/validation: true
https://json-schema.org/draft/2020-12/vocab/meta-data: false
https://json-schema.org/draft/2020-12/vocab/format-annotation: false
$dynamicAnchor: addressDef
title: Person
required:
- name
type: object
properties:
name:
$comment: The person's full name
type: string
age:
$comment: Age must be a non-negative integer
minimum: 0
type: integer
address:
$comment: Reference to an address definition which can change dynamically
$dynamicRef: '#addressDef'
description: Schema for a person object
";
var path = Path.Combine(SampleFolderPath, "schemaWithJsonSchemaKeywords.yaml");
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
// serialization
var writer = new StringWriter();
schema.SerializeAsV31(new OpenApiYamlWriter(writer));
var schemaString = writer.ToString();
// Assert
Assert.Equal(5, schema.Vocabulary.Keys.Count);
Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
public async Task ParseSchemaWithConstWorks()
{
var expected = @"{
""$schema"": ""https://json-schema.org/draft/2020-12/schema"",
""required"": [
""status""
],
""type"": ""object"",
""properties"": {
""status"": {
""const"": ""active"",
""type"": ""string""
},
""user"": {
""required"": [
""role""
],
""type"": ""object"",
""properties"": {
""role"": {
""const"": ""admin"",
""type"": ""string""
}
}
}
}
}";
var path = Path.Combine(SampleFolderPath, "schemaWithConst.json");
// Act
var schema = await OpenApiModelFactory.LoadAsync<OpenApiSchema>(path, OpenApiSpecVersion.OpenApi3_1, new(), SettingsFixture.ReaderSettings);
Assert.Equal("active", schema.Properties["status"].Const);
Assert.Equal("admin", schema.Properties["user"].Properties["role"].Const);
// serialization
var writer = new StringWriter();
schema.SerializeAsV31(new OpenApiJsonWriter(writer));
var schemaString = writer.ToString();
Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
public void ParseSchemaWithUnrecognizedKeywordsWorks()
{
var input = @"{
""type"": ""string"",
""format"": ""date-time"",
""customKeyword"": ""customValue"",
""anotherKeyword"": 42,
""x-test"": ""test""
}
";
var schema = OpenApiModelFactory.Parse<OpenApiSchema>(input, OpenApiSpecVersion.OpenApi3_1, new(), out _, "json");
Assert.Equal(2, schema.UnrecognizedKeywords.Count);
}
[Fact]
public void ParseSchemaExampleWithPrimitivesWorks()
{
var expected1 = @"{
""type"": ""string"",
""example"": ""2024-01-02""
}";
var expected2 = @"{
""type"": ""string"",
""example"": ""3.14""
}";
var schema = new OpenApiSchema()
{
Type = JsonSchemaType.String,
Example = JsonValue.Create("2024-01-02")
};
var schema2 = new OpenApiSchema()
{
Type = JsonSchemaType.String,
Example = JsonValue.Create("3.14")
};
var textWriter = new StringWriter();
var writer = new OpenApiJsonWriter(textWriter);
schema.SerializeAsV31(writer);
var actual1 = textWriter.ToString();
Assert.Equal(expected1.MakeLineBreaksEnvironmentNeutral(), actual1.MakeLineBreaksEnvironmentNeutral());
textWriter = new StringWriter();
writer = new OpenApiJsonWriter(textWriter);
schema2.SerializeAsV31(writer);
var actual2 = textWriter.ToString();
Assert.Equal(expected2.MakeLineBreaksEnvironmentNeutral(), actual2.MakeLineBreaksEnvironmentNeutral());
}
[Theory]
[InlineData(JsonSchemaType.Integer | JsonSchemaType.String, new[] { "integer", "string" })]
[InlineData(JsonSchemaType.Integer | JsonSchemaType.Null, new[] { "integer", "null" })]
[InlineData(JsonSchemaType.Integer, new[] { "integer" })]
public void NormalizeFlaggableJsonSchemaTypeEnumWorks(JsonSchemaType type, string[] expected)
{
var schema = new OpenApiSchema
{
Type = type
};
var actual = schema.Type.ToIdentifiers();
Assert.Equal(expected, actual);
}
[Theory]
[InlineData(new[] { "integer", "string" }, JsonSchemaType.Integer | JsonSchemaType.String)]
[InlineData(new[] { "integer", "null" }, JsonSchemaType.Integer | JsonSchemaType.Null)]
[InlineData(new[] { "integer" }, JsonSchemaType.Integer)]
public void ArrayIdentifierToEnumConversionWorks(string[] type, JsonSchemaType expected)
{
var actual = type.ToJsonSchemaType();
Assert.Equal(expected, actual);
}
[Fact]
public void StringIdentifierToEnumConversionWorks()
{
var actual = "integer".ToJsonSchemaType();
Assert.Equal(JsonSchemaType.Integer, actual);
}
[Fact]
public void ReturnSingleIdentifierWorks()
{
var type = JsonSchemaType.Integer;
var types = JsonSchemaType.Integer | JsonSchemaType.Null;
Assert.Equal("integer", type.ToSingleIdentifier());
Assert.Throws<InvalidOperationException>(() => types.ToSingleIdentifier());
}
}
}