1
- using Json . Schema ;
2
- using Microsoft . OpenApi . Any ;
1
+ using Microsoft . OpenApi . Any ;
3
2
using Microsoft . OpenApi . Hidi . Formatters ;
4
3
using Microsoft . OpenApi . Interfaces ;
5
4
using Microsoft . OpenApi . Models ;
6
5
using Microsoft . OpenApi . Services ;
7
6
using Xunit ;
8
- using Microsoft . OpenApi . Extensions ;
9
7
10
8
namespace Microsoft . OpenApi . Hidi . Tests . Formatters
11
9
{
@@ -60,18 +58,18 @@ public void RemoveAnyOfAndOneOfFromSchema()
60
58
walker . Walk ( openApiDocument ) ;
61
59
62
60
var testSchema = openApiDocument . Components . Schemas [ "TestSchema" ] ;
63
- var averageAudioDegradationProperty = testSchema . GetProperties ( ) ? . GetValueOrDefault ( "averageAudioDegradation" ) ;
64
- var defaultPriceProperty = testSchema . GetProperties ( ) ? . GetValueOrDefault ( "defaultPrice" ) ;
61
+ var averageAudioDegradationProperty = testSchema . Properties [ "averageAudioDegradation" ] ;
62
+ var defaultPriceProperty = testSchema . Properties [ "defaultPrice" ] ;
65
63
66
64
// Assert
67
- Assert . Null ( averageAudioDegradationProperty ? . GetAnyOf ( ) ) ;
68
- Assert . Equal ( SchemaValueType . Number , averageAudioDegradationProperty ? . GetJsonType ( ) ) ;
69
- Assert . Equal ( "float" , averageAudioDegradationProperty ? . GetFormat ( ) ? . Key ) ;
70
- Assert . True ( averageAudioDegradationProperty ? . GetNullable ( ) ) ;
71
- Assert . Null ( defaultPriceProperty ? . GetOneOf ( ) ) ;
72
- Assert . Equal ( SchemaValueType . Number , defaultPriceProperty ? . GetJsonType ( ) ) ;
73
- Assert . Equal ( "double" , defaultPriceProperty ? . GetFormat ( ) ? . Key ) ;
74
- Assert . NotNull ( testSchema . GetAdditionalProperties ( ) ) ;
65
+ Assert . Null ( averageAudioDegradationProperty . AnyOf ) ;
66
+ Assert . Equal ( "number" , averageAudioDegradationProperty . Type ) ;
67
+ Assert . Equal ( "float" , averageAudioDegradationProperty . Format ) ;
68
+ Assert . True ( averageAudioDegradationProperty . Nullable ) ;
69
+ Assert . Null ( defaultPriceProperty . OneOf ) ;
70
+ Assert . Equal ( "number" , defaultPriceProperty . Type ) ;
71
+ Assert . Equal ( "double" , defaultPriceProperty . Format ) ;
72
+ Assert . NotNull ( testSchema . AdditionalProperties ) ;
75
73
}
76
74
77
75
[ Fact ]
@@ -90,7 +88,7 @@ public void ResolveFunctionParameters()
90
88
// Assert
91
89
Assert . Null ( idsParameter ? . Content ) ;
92
90
Assert . NotNull ( idsParameter ? . Schema ) ;
93
- Assert . Equal ( SchemaValueType . Array , idsParameter ? . Schema . GetJsonType ( ) ) ;
91
+ Assert . Equal ( "array" , idsParameter ? . Schema . Type ) ;
94
92
}
95
93
96
94
private static OpenApiDocument GetSampleOpenApiDocument ( )
@@ -120,10 +118,14 @@ private static OpenApiDocument GetSampleOpenApiDocument()
120
118
"application/json" ,
121
119
new OpenApiMediaType
122
120
{
123
- Schema = new JsonSchemaBuilder ( )
124
- . Type ( SchemaValueType . Array )
125
- . Items ( new JsonSchemaBuilder ( )
126
- . Type ( SchemaValueType . String ) )
121
+ Schema = new ( )
122
+ {
123
+ Type = "array" ,
124
+ Items = new ( )
125
+ {
126
+ Type = "string"
127
+ }
128
+ }
127
129
}
128
130
}
129
131
}
@@ -143,22 +145,38 @@ private static OpenApiDocument GetSampleOpenApiDocument()
143
145
} ,
144
146
Components = new ( )
145
147
{
146
- Schemas = new Dictionary < string , JsonSchema >
148
+ Schemas = new Dictionary < string , OpenApiSchema >
147
149
{
148
- { "TestSchema" , new JsonSchemaBuilder ( )
149
- . Type ( SchemaValueType . Object )
150
- . Properties ( ( "averageAudioDegradation" , new JsonSchemaBuilder ( )
151
- . AnyOf (
152
- new JsonSchemaBuilder ( ) . Type ( SchemaValueType . Number ) ,
153
- new JsonSchemaBuilder ( ) . Type ( SchemaValueType . String ) )
154
- . Format ( "float" )
155
- . Nullable ( true ) ) ,
156
-
157
- ( "defaultPrice" , new JsonSchemaBuilder ( )
158
- . OneOf (
159
- new JsonSchemaBuilder ( ) . Type ( SchemaValueType . Number ) . Format ( "double" ) ,
160
- new JsonSchemaBuilder ( ) . Type ( SchemaValueType . String ) ) ) )
161
- }
150
+ { "TestSchema" , new OpenApiSchema
151
+ {
152
+ Type = "object" ,
153
+ Properties = new Dictionary < string , OpenApiSchema >
154
+ {
155
+ {
156
+ "averageAudioDegradation" , new OpenApiSchema
157
+ {
158
+ AnyOf = new List < OpenApiSchema >
159
+ {
160
+ new ( ) { Type = "number" } ,
161
+ new ( ) { Type = "string" }
162
+ } ,
163
+ Format = "float" ,
164
+ Nullable = true
165
+ }
166
+ } ,
167
+ {
168
+ "defaultPrice" , new OpenApiSchema
169
+ {
170
+ OneOf = new List < OpenApiSchema >
171
+ {
172
+ new ( ) { Type = "number" , Format = "double" } ,
173
+ new ( ) { Type = "string" }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
162
180
}
163
181
}
164
182
} ;
0 commit comments