Skip to content

Adds a summary property in the info object #1039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions src/Microsoft.OpenApi.Readers/V3/OpenApiInfoDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ internal static partial class OpenApiV3Deserializer
o.Version = n.GetScalarValue();
}
},
{
"summary", (o, n) =>
{
o.Summary = n.GetScalarValue();
}
},
{
"description", (o, n) =>
{
Expand Down
12 changes: 10 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;

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

/// <summary>
/// A short summary of the API.
/// </summary>
public string Summary { get; set; }

/// <summary>
/// A short description of the application.
/// </summary>
public string Description { get; set; }

/// <summary>
/// REQUIRED. The version of the OpenAPI document.
/// </summary>
Expand Down Expand Up @@ -60,6 +64,7 @@ public OpenApiInfo() {}
public OpenApiInfo(OpenApiInfo info)
{
Title = info?.Title ?? Title;
Summary = info?.Summary ?? Summary;
Description = info?.Description ?? Description;
Version = info?.Version ?? Version;
TermsOfService = info?.TermsOfService ?? TermsOfService;
Expand All @@ -83,6 +88,9 @@ public void SerializeAsV3(IOpenApiWriter writer)
// title
writer.WriteProperty(OpenApiConstants.Title, Title);

// summary
writer.WriteProperty(OpenApiConstants.Summary, Summary);

// description
writer.WriteProperty(OpenApiConstants.Description, Description);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void ParseAdvancedInfoShouldSucceed()
new OpenApiInfo
{
Title = "Advanced Info",
Summary = "Sample Summary",
Description = "Sample Description",
Version = "1.0.0",
TermsOfService = new Uri("http://example.org/termsOfService"),
Expand Down Expand Up @@ -101,6 +102,7 @@ public void ParseBasicInfoShouldSucceed()
new OpenApiInfo
{
Title = "Basic Info",
Summary = "Sample Summary",
Description = "Sample Description",
Version = "1.0.1",
TermsOfService = new Uri("http://swagger.io/terms/"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
title: Advanced Info
version: 1.0.0
summary: Sample Summary
description: Sample Description
termsOfService: http://example.org/termsOfService
contact:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Basic Info",
"summary": "Sample Summary",
"description": "Sample Description",
"termsOfService": "http://swagger.io/terms/",
"contact": {
Expand Down
48 changes: 48 additions & 0 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using SharpYaml;
using Xunit;

namespace Microsoft.OpenApi.Tests.Models
Expand All @@ -29,6 +30,14 @@ public class OpenApiInfoTests
}
};

public static OpenApiInfo InfoWithSummary = new()
{
Title = "Sample Pet Store App",
Summary = "This is a sample server for a pet store.",
Description = "This is a sample server for a pet store.",
Version = "1.1.1",
};

public static OpenApiInfo BasicInfo = new OpenApiInfo
{
Title = "Sample Pet Store App",
Expand Down Expand Up @@ -101,6 +110,7 @@ public static IEnumerable<object[]> AdvanceInfoJsonExpect()
specVersion,
@"{
""title"": ""Sample Pet Store App"",
""summary"": ""This is a sample server for a pet store."",
""description"": ""This is a sample server for a pet store."",
""termsOfService"": ""http://example.com/terms/"",
""contact"": {
Expand Down Expand Up @@ -195,5 +205,43 @@ public void InfoVersionShouldAcceptDateStyledAsVersions()
expected = expected.MakeLineBreaksEnvironmentNeutral();
actual.Should().Be(expected);
}

[Fact]
public void SerializeInfoObjectWithSummaryAsV3YamlWorks()
{
// Arrange
var expected = @"title: Sample Pet Store App
summary: This is a sample server for a pet store.
description: This is a sample server for a pet store.
version: '1.1.1'";

// Act
var actual = InfoWithSummary.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);

// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
expected = expected.MakeLineBreaksEnvironmentNeutral();
Assert.Equal(expected, actual);
}

[Fact]
public void SerializeInfoObjectWithSummaryAsV3JsonWorks()
{
// Arrange
var expected = @"{
""title"": ""Sample Pet Store App"",
""summary"": ""This is a sample server for a pet store."",
""description"": ""This is a sample server for a pet store."",
""version"": ""1.1.1""
}";

// Act
var actual = InfoWithSummary.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);

// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
expected = expected.MakeLineBreaksEnvironmentNeutral();
Assert.Equal(expected, actual);
}
}
}