Skip to content

Commit 6011cba

Browse files
committed
Revert "Preserve examples in v2 files and write them out as extensions"
This reverts commit b004ba6.
1 parent ce2fa8f commit 6011cba

File tree

4 files changed

+5
-42
lines changed

4 files changed

+5
-42
lines changed

src/Microsoft.OpenApi/Models/OpenApiParameter.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,20 +433,6 @@ public void SerializeAsV2WithoutReference(IOpenApiWriter writer)
433433
}
434434
}
435435

436-
//examples
437-
if (Examples != null && Examples.Any())
438-
{
439-
writer.WritePropertyName("x-examples");
440-
writer.WriteStartObject();
441-
442-
foreach (var example in Examples)
443-
{
444-
writer.WritePropertyName(example.Key);
445-
writer.WriteV2Examples(writer, example.Value, OpenApiSpecVersion.OpenApi2_0);
446-
}
447-
writer.WriteEndObject();
448-
}
449-
450436
// extensions
451437
writer.WriteExtensions(extensionsClone, OpenApiSpecVersion.OpenApi2_0);
452438

src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs

Lines changed: 3 additions & 5 deletions
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;
@@ -185,8 +185,7 @@ internal OpenApiBodyParameter ConvertToBodyParameter()
185185
// V2 spec actually allows the body to have custom name.
186186
// To allow round-tripping we use an extension to hold the name
187187
Name = "body",
188-
Schema = Content.Values.FirstOrDefault()?.Schema ?? new JsonSchemaBuilder().Build(),
189-
Examples = Content.Values.FirstOrDefault()?.Examples,
188+
Schema = Content.Values.FirstOrDefault()?.Schema ?? new OpenApiSchema(),
190189
Required = Required,
191190
Extensions = Extensions.ToDictionary(static k => k.Key, static v => v.Value) // Clone extensions so we can remove the x-bodyName extensions from the output V2 model.
192191
};
@@ -220,8 +219,7 @@ internal IEnumerable<OpenApiFormDataParameter> ConvertToFormDataParameters()
220219
Description = property.Value.GetDescription(),
221220
Name = property.Key,
222221
Schema = property.Value,
223-
Examples = Content.Values.FirstOrDefault()?.Examples,
224-
Required = Content.First().Value.Schema.GetRequired()?.Contains(property.Key) ?? false
222+
Required = Content.First().Value.Schema.Required.Contains(property.Key)
225223
};
226224
}
227225
}

src/Microsoft.OpenApi/Models/OpenApiResponse.cs

Lines changed: 1 addition & 22 deletions
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;
@@ -231,27 +231,6 @@ public void SerializeAsV2WithoutReference(IOpenApiWriter writer)
231231
writer.WriteEndObject();
232232
}
233233

234-
if (Content.Values.Any(m => m.Examples != null && m.Examples.Any()))
235-
{
236-
writer.WritePropertyName("x-examples");
237-
writer.WriteStartObject();
238-
239-
foreach (var mediaTypePair in Content)
240-
{
241-
var examples = mediaTypePair.Value.Examples;
242-
if (examples != null && examples.Any())
243-
{
244-
foreach (var example in examples)
245-
{
246-
writer.WritePropertyName(example.Key);
247-
writer.WriteV2Examples(writer, example.Value, OpenApiSpecVersion.OpenApi2_0);
248-
}
249-
}
250-
}
251-
252-
writer.WriteEndObject();
253-
}
254-
255234
writer.WriteExtensions(mediatype.Value.Extensions, OpenApiSpecVersion.OpenApi2_0);
256235

257236
foreach (var key in mediatype.Value.Extensions.Keys)

src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs

Lines changed: 1 addition & 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;

0 commit comments

Comments
 (0)