Skip to content

Commit 509d53c

Browse files
Merge pull request #1039 from microsoft/mk/add-summary-to-info-object
Adds a summary property in the info object
2 parents d23ad22 + ca924a9 commit 509d53c

File tree

9 files changed

+69
-11
lines changed

9 files changed

+69
-11
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ private static void ProcessAnyMapFields<T, U>(
113113
{
114114
try
115115
{
116-
var newProperty = new List<IOpenApiAny>();
117-
118116
mapNode.Context.StartObject(anyMapFieldName);
119117

120118
foreach (var propertyMapElement in anyMapFieldMap[anyMapFieldName].PropertyMapGetter(domainObject))

src/Microsoft.OpenApi.Readers/V3/OpenApiInfoDeserializer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ internal static partial class OpenApiV3Deserializer
2929
o.Version = n.GetScalarValue();
3030
}
3131
},
32+
{
33+
"summary", (o, n) =>
34+
{
35+
o.Summary = n.GetScalarValue();
36+
}
37+
},
3238
{
3339
"description", (o, n) =>
3440
{
@@ -63,10 +69,7 @@ internal static partial class OpenApiV3Deserializer
6369
public static OpenApiInfo LoadInfo(ParseNode node)
6470
{
6571
var mapNode = node.CheckMapNode("Info");
66-
6772
var info = new OpenApiInfo();
68-
var required = new List<string> { "title", "version" };
69-
7073
ParseMap(mapNode, info, InfoFixedFields, InfoPatternFields);
7174

7275
return info;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public static OpenApiResponse LoadResponse(ParseNode node)
5858
return mapNode.GetReferencedObject<OpenApiResponse>(ReferenceType.Response, pointer);
5959
}
6060

61-
var requiredFields = new List<string> { "description" };
6261
var response = new OpenApiResponse();
6362
ParseMap(mapNode, response, _responseFixedFields, _responsePatternFields);
6463

src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ private static void ProcessAnyMapFields<T, U>(
108108
foreach (var anyMapFieldName in anyMapFieldMap.Keys.ToList())
109109
{
110110
try
111-
{
112-
var newProperty = new List<IOpenApiAny>();
113-
111+
{
114112
mapNode.Context.StartObject(anyMapFieldName);
115113

116114
foreach (var propertyMapElement in anyMapFieldMap[anyMapFieldName].PropertyMapGetter(domainObject))

src/Microsoft.OpenApi/Models/OpenApiInfo.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using Microsoft.OpenApi.Any;
76
using Microsoft.OpenApi.Interfaces;
87
using Microsoft.OpenApi.Writers;
98

@@ -19,11 +18,16 @@ public class OpenApiInfo : IOpenApiSerializable, IOpenApiExtensible
1918
/// </summary>
2019
public string Title { get; set; }
2120

21+
/// <summary>
22+
/// A short summary of the API.
23+
/// </summary>
24+
public string Summary { get; set; }
25+
2226
/// <summary>
2327
/// A short description of the application.
2428
/// </summary>
2529
public string Description { get; set; }
26-
30+
2731
/// <summary>
2832
/// REQUIRED. The version of the OpenAPI document.
2933
/// </summary>
@@ -60,6 +64,7 @@ public OpenApiInfo() {}
6064
public OpenApiInfo(OpenApiInfo info)
6165
{
6266
Title = info?.Title ?? Title;
67+
Summary = info?.Summary ?? Summary;
6368
Description = info?.Description ?? Description;
6469
Version = info?.Version ?? Version;
6570
TermsOfService = info?.TermsOfService ?? TermsOfService;
@@ -83,6 +88,9 @@ public void SerializeAsV3(IOpenApiWriter writer)
8388
// title
8489
writer.WriteProperty(OpenApiConstants.Title, Title);
8590

91+
// summary
92+
writer.WriteProperty(OpenApiConstants.Summary, Summary);
93+
8694
// description
8795
writer.WriteProperty(OpenApiConstants.Description, Description);
8896

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiInfoTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void ParseAdvancedInfoShouldSucceed()
4141
new OpenApiInfo
4242
{
4343
Title = "Advanced Info",
44+
Summary = "Sample Summary",
4445
Description = "Sample Description",
4546
Version = "1.0.0",
4647
TermsOfService = new Uri("http://example.org/termsOfService"),
@@ -101,6 +102,7 @@ public void ParseBasicInfoShouldSucceed()
101102
new OpenApiInfo
102103
{
103104
Title = "Basic Info",
105+
Summary = "Sample Summary",
104106
Description = "Sample Description",
105107
Version = "1.0.1",
106108
TermsOfService = new Uri("http://swagger.io/terms/"),

test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiInfo/advancedInfo.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
title: Advanced Info
22
version: 1.0.0
3+
summary: Sample Summary
34
description: Sample Description
45
termsOfService: http://example.org/termsOfService
56
contact:

test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiInfo/basicInfo.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"title": "Basic Info",
3+
"summary": "Sample Summary",
34
"description": "Sample Description",
45
"termsOfService": "http://swagger.io/terms/",
56
"contact": {

test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.OpenApi.Extensions;
99
using Microsoft.OpenApi.Interfaces;
1010
using Microsoft.OpenApi.Models;
11+
using SharpYaml;
1112
using Xunit;
1213

1314
namespace Microsoft.OpenApi.Tests.Models
@@ -29,6 +30,14 @@ public class OpenApiInfoTests
2930
}
3031
};
3132

33+
public static OpenApiInfo InfoWithSummary = new()
34+
{
35+
Title = "Sample Pet Store App",
36+
Summary = "This is a sample server for a pet store.",
37+
Description = "This is a sample server for a pet store.",
38+
Version = "1.1.1",
39+
};
40+
3241
public static OpenApiInfo BasicInfo = new OpenApiInfo
3342
{
3443
Title = "Sample Pet Store App",
@@ -101,6 +110,7 @@ public static IEnumerable<object[]> AdvanceInfoJsonExpect()
101110
specVersion,
102111
@"{
103112
""title"": ""Sample Pet Store App"",
113+
""summary"": ""This is a sample server for a pet store."",
104114
""description"": ""This is a sample server for a pet store."",
105115
""termsOfService"": ""http://example.com/terms/"",
106116
""contact"": {
@@ -195,5 +205,43 @@ public void InfoVersionShouldAcceptDateStyledAsVersions()
195205
expected = expected.MakeLineBreaksEnvironmentNeutral();
196206
actual.Should().Be(expected);
197207
}
208+
209+
[Fact]
210+
public void SerializeInfoObjectWithSummaryAsV3YamlWorks()
211+
{
212+
// Arrange
213+
var expected = @"title: Sample Pet Store App
214+
summary: This is a sample server for a pet store.
215+
description: This is a sample server for a pet store.
216+
version: '1.1.1'";
217+
218+
// Act
219+
var actual = InfoWithSummary.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
220+
221+
// Assert
222+
actual = actual.MakeLineBreaksEnvironmentNeutral();
223+
expected = expected.MakeLineBreaksEnvironmentNeutral();
224+
Assert.Equal(expected, actual);
225+
}
226+
227+
[Fact]
228+
public void SerializeInfoObjectWithSummaryAsV3JsonWorks()
229+
{
230+
// Arrange
231+
var expected = @"{
232+
""title"": ""Sample Pet Store App"",
233+
""summary"": ""This is a sample server for a pet store."",
234+
""description"": ""This is a sample server for a pet store."",
235+
""version"": ""1.1.1""
236+
}";
237+
238+
// Act
239+
var actual = InfoWithSummary.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
240+
241+
// Assert
242+
actual = actual.MakeLineBreaksEnvironmentNeutral();
243+
expected = expected.MakeLineBreaksEnvironmentNeutral();
244+
Assert.Equal(expected, actual);
245+
}
198246
}
199247
}

0 commit comments

Comments
 (0)