Skip to content

Commit fb89e93

Browse files
committed
Handle V2 import when produces comes after responses
1 parent c73cf9b commit fb89e93

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ internal static OpenApiOperation LoadOperation(ParseNode node)
131131
operation.RequestBody = CreateFormBody(node.Context, formParameters);
132132
}
133133
}
134-
134+
135+
foreach (var response in operation.Responses.Values)
136+
{
137+
ProcessProduces(response, node.Context);
138+
}
139+
135140
return operation;
136141
}
137142

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,22 @@ private static void ProcessProduces(OpenApiResponse response, ParsingContext con
5353
var produces = context.GetFromTempStorage<List<string>>(TempStorageKeys.OperationProduces) ??
5454
context.GetFromTempStorage<List<string>>(TempStorageKeys.GlobalProduces) ?? new List<string>();
5555

56-
response.Content = new Dictionary<string, OpenApiMediaType>();
56+
if (response.Content == null)
57+
{
58+
response.Content = new Dictionary<string, OpenApiMediaType>();
59+
}
60+
5761
foreach (var produce in produces)
5862
{
59-
var mediaType = new OpenApiMediaType
63+
if (!response.Content.ContainsKey(produce))
6064
{
61-
Schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema)
62-
};
65+
var mediaType = new OpenApiMediaType
66+
{
67+
Schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema)
68+
};
6369

64-
response.Content.Add(produce, mediaType);
70+
response.Content.Add(produce, mediaType);
71+
}
6572
}
6673
}
6774

0 commit comments

Comments
 (0)