Skip to content

Commit 73a457b

Browse files
Tests improved, produces override bug fixed
1 parent f0a2eb0 commit 73a457b

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ internal static OpenApiOperation LoadOperation(ParseNode node)
136136
ProcessProduces(node.CheckMapNode("responses"), response, node.Context);
137137
}
138138

139+
// Reset so that it's not picked up later
140+
node.Context.SetTempStorage(TempStorageKeys.OperationProduces, null);
141+
139142
return operation;
140143
}
141144

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public void ShouldParseProducesInAnyOrder()
179179
}
180180
}
181181
};
182+
182183
var errorSchema = new OpenApiSchema()
183184
{
184185
Properties = new Dictionary<string, OpenApiSchema>()
@@ -206,6 +207,7 @@ public void ShouldParseProducesInAnyOrder()
206207
Id = "Error"
207208
}
208209
};
210+
209211
foreach (var operation in doc.Paths["/items"].Operations)
210212
{
211213
Assert.Equal(2, operation.Value.Responses.Count);
@@ -215,37 +217,30 @@ public void ShouldParseProducesInAnyOrder()
215217
new OpenApiResponse()
216218
{
217219
Description = "An OK response",
218-
Content =
219-
{
220-
["application/json"] = new OpenApiMediaType()
221-
{
222-
Schema = successSchema,
223-
},
224-
["application/xml"] = new OpenApiMediaType()
225-
{
226-
Schema = successSchema,
227-
}
228-
}
220+
Content = GetMediaTypes(successSchema, operation.Key != OperationType.Post)
229221
});
230222

231223
var errorResponse = operation.Value.Responses["default"];
232224
errorResponse.ShouldBeEquivalentTo(
233225
new OpenApiResponse()
234226
{
235227
Description = "An error response",
236-
Content =
237-
{
238-
["application/json"] = new OpenApiMediaType()
239-
{
240-
Schema = errorSchema,
241-
},
242-
["application/xml"] = new OpenApiMediaType()
243-
{
244-
Schema = errorSchema,
245-
}
246-
}
228+
Content = GetMediaTypes(errorSchema, operation.Key != OperationType.Post)
247229
});
248230
}
231+
232+
IDictionary<string, OpenApiMediaType> GetMediaTypes(OpenApiSchema schema, bool includeXml)
233+
{
234+
var mediaTypes = new Dictionary<string, OpenApiMediaType>
235+
{
236+
["application/json"] = new OpenApiMediaType() { Schema = schema }
237+
};
238+
if (includeXml)
239+
{
240+
mediaTypes["application/xml"] = new OpenApiMediaType() { Schema = schema };
241+
}
242+
return mediaTypes;
243+
}
249244
}
250245
}
251246

test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/twoResponses.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@
7878
}
7979
},
8080
"produces": [
81-
"application/json",
82-
"application/xml"
81+
"application/json"
8382
],
8483
"definitions": {
8584
"Item": {

0 commit comments

Comments
 (0)