File tree 3 files changed +68
-2
lines changed
src/Microsoft.OpenApi/Reader/V2
test/Microsoft.OpenApi.Readers.Tests/V2Tests
3 files changed +68
-2
lines changed Original file line number Diff line number Diff line change @@ -72,8 +72,13 @@ internal static partial class OpenApiV2Deserializer
72
72
{
73
73
var type = n . GetScalarValue ( ) ;
74
74
if ( type != null )
75
- {
76
- GetOrCreateSchema ( o ) . Type = type . ToJsonSchemaType ( ) ;
75
+ {
76
+ var schema = GetOrCreateSchema ( o ) ;
77
+ schema . Type = type . ToJsonSchemaType ( ) ;
78
+ if ( "file" . Equals ( type , StringComparison . OrdinalIgnoreCase ) )
79
+ {
80
+ schema . Format = "binary" ;
81
+ }
77
82
}
78
83
}
79
84
} ,
Original file line number Diff line number Diff line change 8
8
using Microsoft . OpenApi . Models ;
9
9
using Microsoft . OpenApi . Reader . ParseNodes ;
10
10
using Microsoft . OpenApi . Reader . V2 ;
11
+ using Microsoft . OpenApi . Tests ;
12
+ using Microsoft . OpenApi . Writers ;
11
13
using Xunit ;
12
14
13
15
namespace Microsoft . OpenApi . Readers . Tests . V2Tests
@@ -279,5 +281,32 @@ public void ParseParameterWithEnumShouldSucceed()
279
281
. Excluding ( ( IMemberInfo memberInfo ) =>
280
282
memberInfo . Path . EndsWith ( "Parent" ) ) ) ;
281
283
}
284
+
285
+ [ Fact ]
286
+ public void ParseFormDataParameterShouldSucceed ( )
287
+ {
288
+ // Arrange
289
+ var expected = @"{
290
+ ""type"": ""string"",
291
+ ""description"": ""file to upload"",
292
+ ""format"": ""binary""
293
+ }" ;
294
+ MapNode node ;
295
+ using ( var stream = Resources . GetStream ( Path . Combine ( SampleFolderPath , "formDataParameter.json" ) ) )
296
+ {
297
+ node = TestHelper . CreateYamlMapNode ( stream ) ;
298
+ }
299
+
300
+ // Act
301
+ var operation = OpenApiV2Deserializer . LoadOperation ( node , new ( ) ) ;
302
+ var schema = operation . RequestBody ? . Content [ "multipart/form-data" ] . Schema . Properties [ "file" ] ;
303
+ var writer = new StringWriter ( ) ;
304
+ schema . SerializeAsV2 ( new OpenApiJsonWriter ( writer ) ) ;
305
+ var json = writer . ToString ( ) ;
306
+
307
+ // Assert
308
+ Assert . Equal ( "binary" , schema . Format ) ;
309
+ Assert . Equal ( expected . MakeLineBreaksEnvironmentNeutral ( ) , json . MakeLineBreaksEnvironmentNeutral ( ) ) ;
310
+ }
282
311
}
283
312
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "tags" : [ " pet" ],
3
+ "summary" : " uploads an image" ,
4
+ "description" : " " ,
5
+ "operationId" : " uploadFile" ,
6
+ "consumes" : [ " multipart/form-data" ],
7
+ "produces" : [ " application/json" ],
8
+ "parameters" : [
9
+ {
10
+ "name" : " petId" ,
11
+ "in" : " path" ,
12
+ "description" : " ID of pet to update" ,
13
+ "required" : true ,
14
+ "type" : " integer" ,
15
+ "format" : " int64"
16
+ },
17
+ {
18
+ "name" : " additionalMetadata" ,
19
+ "in" : " formData" ,
20
+ "description" : " Additional data to pass to server" ,
21
+ "required" : false ,
22
+ "type" : " string"
23
+ },
24
+ {
25
+ "name" : " file" ,
26
+ "in" : " formData" ,
27
+ "description" : " file to upload" ,
28
+ "required" : false ,
29
+ "type" : " file"
30
+ }
31
+ ]
32
+ }
You can’t perform that action at this time.
0 commit comments