Skip to content

Commit 37c097e

Browse files
committed
Fetch the examples from storage and append them to the resulting body parameter object
1 parent 7c17a09 commit 37c097e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Security.Cryptography.X509Certificates;
7+
using System.Xml.Linq;
78
using Microsoft.OpenApi.Any;
89
using Microsoft.OpenApi.Extensions;
910
using Microsoft.OpenApi.Models;
@@ -194,7 +195,8 @@ internal static OpenApiRequestBody CreateRequestBody(
194195
k => k,
195196
_ => new OpenApiMediaType
196197
{
197-
Schema = bodyParameter.Schema
198+
Schema = bodyParameter.Schema,
199+
Examples = bodyParameter.Examples
198200
}),
199201
Extensions = bodyParameter.Extensions
200202
};

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -261,6 +261,14 @@ public static OpenApiParameter LoadParameter(ParseNode node, bool loadRequestBod
261261
node.Context.SetTempStorage("schema", null);
262262
}
263263

264+
// load examples from storage and add them to the parameter
265+
var examples = node.Context.GetFromTempStorage<Dictionary<string, OpenApiExample>>(TempStorageKeys.Examples, parameter);
266+
if (examples != null)
267+
{
268+
parameter.Examples = examples;
269+
node.Context.SetTempStorage("examples", null);
270+
}
271+
264272
var isBodyOrFormData = (bool)node.Context.GetFromTempStorage<object>(TempStorageKeys.ParameterIsBodyOrFormData);
265273
if (isBodyOrFormData && !loadRequestBody)
266274
{

0 commit comments

Comments
 (0)