Skip to content

Commit 11d9f68

Browse files
committed
Revert previous fix
1 parent 66c3e5c commit 11d9f68

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal static partial class OpenApiV2Deserializer
6767
{
6868
"produces", (o, n) => {
6969
var produces = n.CreateSimpleList(s => s.GetScalarValue());
70-
if (produces.Count > 0) {
70+
if (produces != null) {
7171
n.Context.SetTempStorage(TempStorageKeys.OperationProduces, produces);
7272
}
7373
}

src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,47 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
7373
}
7474

7575
var produces = context.GetFromTempStorage<List<string>>(TempStorageKeys.OperationProduces)
76-
?? new List<string> { "application/octet-stream" };
76+
?? context.GetFromTempStorage<List<string>>(TempStorageKeys.GlobalProduces);
7777

78-
var schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema, response);
79-
80-
foreach (var produce in produces)
78+
if (produces != null)
8179
{
80+
var schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema, response);
8281

83-
if (response.Content.ContainsKey(produce) && response.Content[produce] != null)
84-
{
85-
if (schema != null)
86-
{
87-
response.Content[produce].Schema = schema;
88-
ProcessAnyFields(mapNode, response.Content[produce], _mediaTypeAnyFields);
89-
}
90-
}
91-
else
82+
if (produces.Count == 0 && schema != null)
9283
{
9384
var mediaType = new OpenApiMediaType
9485
{
9586
Schema = schema
9687
};
9788

98-
response.Content.Add(produce, mediaType);
89+
response.Content.Add(string.Empty, mediaType);
9990
}
100-
}
10191

102-
context.SetTempStorage(TempStorageKeys.ResponseSchema, null, response);
103-
context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response);
92+
foreach (var produce in produces)
93+
{
94+
95+
if (response.Content.ContainsKey(produce) && response.Content[produce] != null)
96+
{
97+
if (schema != null)
98+
{
99+
response.Content[produce].Schema = schema;
100+
ProcessAnyFields(mapNode, response.Content[produce], _mediaTypeAnyFields);
101+
}
102+
}
103+
else
104+
{
105+
var mediaType = new OpenApiMediaType
106+
{
107+
Schema = schema
108+
};
109+
110+
response.Content.Add(produce, mediaType);
111+
}
112+
}
113+
114+
context.SetTempStorage(TempStorageKeys.ResponseSchema, null, response);
115+
context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response);
116+
}
104117
}
105118

106119
private static void LoadExamples(OpenApiResponse response, ParseNode node)

0 commit comments

Comments
 (0)