Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal static partial class OpenApiV3Deserializer
{
"examples", (o, n) =>
{
o.Examples = ((ListNode)n).Select(s => LoadExample(s)).ToList();
o.Examples = n.CreateMap(LoadExample);
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class OpenApiParameter : IOpenApiSerializable, IOpenApiReferenceable, IOp
/// Furthermore, if referencing a schema which contains an example,
/// the examples value SHALL override the example provided by the schema.
/// </summary>
public IList<OpenApiExample> Examples { get; set; } = new List<OpenApiExample>();
public IDictionary<string,OpenApiExample> Examples { get; set; } = new Dictionary<string,OpenApiExample>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure this change follows up the v3.x spec.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I triple checked that examples is a map, not a list. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#fixed-fields-10

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


/// <summary>
/// Example of the media type. The example SHOULD match the specified schema and encoding properties
Expand Down Expand Up @@ -189,7 +189,7 @@ public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
writer.WriteOptionalObject(OpenApiConstants.Example, Example, (w, s) => w.WriteAny(s));

// examples
writer.WriteOptionalCollection(OpenApiConstants.Examples, Examples, (w, e) => e.SerializeAsV3(w));
writer.WriteOptionalMap(OpenApiConstants.Examples, Examples, (w, e) => e.SerializeAsV3(w));

// content
writer.WriteOptionalMap(OpenApiConstants.Content, Content, (w, c) => c.SerializeAsV3(w));
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.OpenApi/Services/OpenApiWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ internal void Walk(OpenApiParameter parameter)
_visitor.Visit(parameter);
Walk(OpenApiConstants.Schema, () => Walk(parameter.Schema));
Walk(OpenApiConstants.Content, () => Walk(parameter.Content));
Walk(OpenApiConstants.Examples, () => Walk(parameter.Examples));

Walk(parameter as IOpenApiExtensible);
}

Expand Down
10 changes: 5 additions & 5 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public class OpenApiParameterTests
Title = "title2",
Description = "description2"
},
Examples = new List<OpenApiExample>
Examples = new Dictionary<string,OpenApiExample>
{
new OpenApiExample
["test"] = new OpenApiExample
{
Summary = "summary3",
Description = "description3"
Expand Down Expand Up @@ -97,12 +97,12 @@ public void SerializeAdvancedParameterAsV3JsonWorks()
""title"": ""title2"",
""description"": ""description2""
},
""examples"": [
{
""examples"": {
""test"": {
""summary"": ""summary3"",
""description"": ""description3""
}
]
}
}";

// Act
Expand Down