Skip to content

Commit 03659f7

Browse files
committed
fix: removes description field from references that do not support it
Signed-off-by: Vincent Biret <[email protected]>
1 parent 33cc238 commit 03659f7

15 files changed

+89
-57
lines changed

src/Microsoft.OpenApi/Models/OpenApiReference.cs renamed to src/Microsoft.OpenApi/Models/BaseOpenApiReference.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,8 @@ namespace Microsoft.OpenApi
1111
/// <summary>
1212
/// A simple object to allow referencing other components in the specification, internally and externally.
1313
/// </summary>
14-
public class BaseOpenApiReference : IOpenApiSerializable, IOpenApiDescribedElement
14+
public class BaseOpenApiReference : IOpenApiSerializable
1515
{
16-
/// <summary>
17-
/// A description which by default SHOULD override that of the referenced component.
18-
/// CommonMark syntax MAY be used for rich text representation.
19-
/// If the referenced object-type does not allow a description field, then this field has no effect.
20-
/// </summary>
21-
public string? Description { get; set; }
22-
23-
24-
2516
/// <summary>
2617
/// External resource in the reference.
2718
/// It maybe:
@@ -147,7 +138,6 @@ public BaseOpenApiReference() { }
147138
public BaseOpenApiReference(BaseOpenApiReference reference)
148139
{
149140
Utils.CheckArgumentNull(reference);
150-
Description = reference.Description;
151141
ExternalResource = reference.ExternalResource;
152142
Type = reference.Type;
153143
Id = reference.Id;
@@ -166,8 +156,7 @@ public virtual void SerializeAsV31(IOpenApiWriter writer)
166156
/// <param name="writer"></param>
167157
protected virtual void SerializeAdditionalV31Properties(IOpenApiWriter writer)
168158
{
169-
// summary and description are in 3.1 but not in 3.0
170-
writer.WriteProperty(OpenApiConstants.Description, Description);
159+
// noop for the base type
171160
}
172161

173162
/// <inheritdoc/>
@@ -305,13 +294,7 @@ internal virtual void SetMetadataFromMapNode(MapNode mapNode)
305294
/// <param name="jsonObject">The object to get the data from</param>
306295
protected virtual void SetAdditional31MetadataFromMapNode(JsonObject jsonObject)
307296
{
308-
// Summary and Description
309-
var description = GetPropertyValueFromNode(jsonObject, OpenApiConstants.Description);
310-
311-
if (!string.IsNullOrEmpty(description))
312-
{
313-
Description = description;
314-
}
297+
// noop for the base type
315298
}
316299

317300
internal void SetJsonPointerPath(string pointer, string nodeLocation)

src/Microsoft.OpenApi/Models/JsonSchemaReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.OpenApi;
1212
/// Schema reference information that includes metadata annotations from JSON Schema 2020-12.
1313
/// This class extends OpenApiReference to provide schema-specific metadata override capabilities.
1414
/// </summary>
15-
public class JsonSchemaReference : BaseOpenApiReference
15+
public class JsonSchemaReference : OpenApiReferenceWithDescription
1616
{
1717
/// <summary>
1818
/// A default value which by default SHOULD override that of the referenced component.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.Text.Json.Nodes;
5+
6+
namespace Microsoft.OpenApi;
7+
8+
/// <summary>
9+
/// OpenApiReferenceWithSummary is a reference to an OpenAPI component that includes a description.
10+
/// </summary>
11+
public class OpenApiReferenceWithDescription : BaseOpenApiReference, IOpenApiDescribedElement
12+
{
13+
/// <summary>
14+
/// A description which by default SHOULD override that of the referenced component.
15+
/// CommonMark syntax MAY be used for rich text representation.
16+
/// If the referenced object-type does not allow a description field, then this field has no effect.
17+
/// </summary>
18+
public string? Description { get; set; }
19+
20+
/// <summary>
21+
/// Parameterless constructor
22+
/// </summary>
23+
public OpenApiReferenceWithDescription() : base() { }
24+
25+
/// <summary>
26+
/// Initializes a copy instance of the <see cref="OpenApiReferenceWithDescription"/> object
27+
/// </summary>
28+
public OpenApiReferenceWithDescription(OpenApiReferenceWithDescription reference) : base(reference)
29+
{
30+
Utils.CheckArgumentNull(reference);
31+
Description = reference.Description;
32+
}
33+
/// <inheritdoc/>
34+
protected override void SerializeAdditionalV31Properties(IOpenApiWriter writer)
35+
{
36+
base.SerializeAdditionalV31Properties(writer);
37+
// summary and description are in 3.1 but not in 3.0
38+
writer.WriteProperty(OpenApiConstants.Description, Description);
39+
}
40+
/// <inheritdoc/>
41+
protected override void SetAdditional31MetadataFromMapNode(JsonObject jsonObject)
42+
{
43+
base.SetAdditional31MetadataFromMapNode(jsonObject);
44+
// Description
45+
var description = GetPropertyValueFromNode(jsonObject, OpenApiConstants.Description);
46+
47+
if (!string.IsNullOrEmpty(description))
48+
{
49+
Description = description;
50+
}
51+
}
52+
}

src/Microsoft.OpenApi/Models/OpenApiReferenceWithSummary.cs renamed to src/Microsoft.OpenApi/Models/OpenApiReferenceWithDescriptionAndSummary.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
using System;
5-
using System.Linq;
64
using System.Text.Json.Nodes;
7-
using Microsoft.OpenApi.Reader;
85

96
namespace Microsoft.OpenApi;
107

118
/// <summary>
129
/// OpenApiReferenceWithSummary is a reference to an OpenAPI component that includes a summary.
1310
/// </summary>
14-
public class OpenApiReferenceWithSummary : BaseOpenApiReference, IOpenApiSummarizedElement
11+
public class OpenApiReferenceWithDescriptionAndSummary : OpenApiReferenceWithDescription, IOpenApiSummarizedElement
1512
{
1613
/// <summary>
1714
/// A short summary which by default SHOULD override that of the referenced component.
@@ -22,12 +19,12 @@ public class OpenApiReferenceWithSummary : BaseOpenApiReference, IOpenApiSummari
2219
/// <summary>
2320
/// Parameterless constructor
2421
/// </summary>
25-
public OpenApiReferenceWithSummary() : base() { }
22+
public OpenApiReferenceWithDescriptionAndSummary() : base() { }
2623

2724
/// <summary>
28-
/// Initializes a copy instance of the <see cref="OpenApiReferenceWithSummary"/> object
25+
/// Initializes a copy instance of the <see cref="OpenApiReferenceWithDescriptionAndSummary"/> object
2926
/// </summary>
30-
public OpenApiReferenceWithSummary(OpenApiReferenceWithSummary reference) : base(reference)
27+
public OpenApiReferenceWithDescriptionAndSummary(OpenApiReferenceWithDescriptionAndSummary reference) : base(reference)
3128
{
3229
Utils.CheckArgumentNull(reference);
3330
Summary = reference.Summary;
@@ -43,7 +40,7 @@ protected override void SerializeAdditionalV31Properties(IOpenApiWriter writer)
4340
protected override void SetAdditional31MetadataFromMapNode(JsonObject jsonObject)
4441
{
4542
base.SetAdditional31MetadataFromMapNode(jsonObject);
46-
// Summary and Description
43+
// Summary
4744
var summary = GetPropertyValueFromNode(jsonObject, OpenApiConstants.Summary);
4845

4946
if (!string.IsNullOrEmpty(summary))

src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Example Object Reference.
1111
/// </summary>
12-
public class OpenApiExampleReference : BaseOpenApiReferenceHolder<OpenApiExample, IOpenApiExample, OpenApiReferenceWithSummary>, IOpenApiExample
12+
public class OpenApiExampleReference : BaseOpenApiReferenceHolder<OpenApiExample, IOpenApiExample, OpenApiReferenceWithDescriptionAndSummary>, IOpenApiExample
1313
{
1414
/// <summary>
1515
/// Constructor initializing the reference object.
@@ -74,9 +74,9 @@ public IOpenApiExample CreateShallowCopy()
7474
return new OpenApiExampleReference(this);
7575
}
7676
/// <inheritdoc/>
77-
protected override OpenApiReferenceWithSummary CopyReference(OpenApiReferenceWithSummary sourceReference)
77+
protected override OpenApiReferenceWithDescriptionAndSummary CopyReference(OpenApiReferenceWithDescriptionAndSummary sourceReference)
7878
{
79-
return new OpenApiReferenceWithSummary(sourceReference);
79+
return new OpenApiReferenceWithDescriptionAndSummary(sourceReference);
8080
}
8181
}
8282
}

src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Header Object Reference.
1111
/// </summary>
12-
public class OpenApiHeaderReference : BaseOpenApiReferenceHolder<OpenApiHeader, IOpenApiHeader, BaseOpenApiReference>, IOpenApiHeader
12+
public class OpenApiHeaderReference : BaseOpenApiReferenceHolder<OpenApiHeader, IOpenApiHeader, OpenApiReferenceWithDescription>, IOpenApiHeader
1313
{
1414
/// <summary>
1515
/// Constructor initializing the reference object.
@@ -85,9 +85,9 @@ public IOpenApiHeader CreateShallowCopy()
8585
return new OpenApiHeaderReference(this);
8686
}
8787
/// <inheritdoc/>
88-
protected override BaseOpenApiReference CopyReference(BaseOpenApiReference sourceReference)
88+
protected override OpenApiReferenceWithDescription CopyReference(OpenApiReferenceWithDescription sourceReference)
8989
{
90-
return new BaseOpenApiReference(sourceReference);
90+
return new OpenApiReferenceWithDescription(sourceReference);
9191
}
9292
}
9393
}

src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.OpenApi
88
/// <summary>
99
/// Link Object Reference.
1010
/// </summary>
11-
public class OpenApiLinkReference : BaseOpenApiReferenceHolder<OpenApiLink, IOpenApiLink, BaseOpenApiReference>, IOpenApiLink
11+
public class OpenApiLinkReference : BaseOpenApiReferenceHolder<OpenApiLink, IOpenApiLink, OpenApiReferenceWithDescription>, IOpenApiLink
1212
{
1313
/// <summary>
1414
/// Constructor initializing the reference object.
@@ -74,9 +74,9 @@ public IOpenApiLink CreateShallowCopy()
7474
return new OpenApiLinkReference(this);
7575
}
7676
/// <inheritdoc/>
77-
protected override BaseOpenApiReference CopyReference(BaseOpenApiReference sourceReference)
77+
protected override OpenApiReferenceWithDescription CopyReference(OpenApiReferenceWithDescription sourceReference)
7878
{
79-
return new BaseOpenApiReference(sourceReference);
79+
return new OpenApiReferenceWithDescription(sourceReference);
8080
}
8181
}
8282
}

src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Parameter Object Reference.
1111
/// </summary>
12-
public class OpenApiParameterReference : BaseOpenApiReferenceHolder<OpenApiParameter, IOpenApiParameter, BaseOpenApiReference>, IOpenApiParameter
12+
public class OpenApiParameterReference : BaseOpenApiReferenceHolder<OpenApiParameter, IOpenApiParameter, OpenApiReferenceWithDescription>, IOpenApiParameter
1313
{
1414
/// <summary>
1515
/// Constructor initializing the reference object.
@@ -92,9 +92,9 @@ public IOpenApiParameter CreateShallowCopy()
9292
}
9393

9494
/// <inheritdoc/>
95-
protected override BaseOpenApiReference CopyReference(BaseOpenApiReference sourceReference)
95+
protected override OpenApiReferenceWithDescription CopyReference(OpenApiReferenceWithDescription sourceReference)
9696
{
97-
return new BaseOpenApiReference(sourceReference);
97+
return new OpenApiReferenceWithDescription(sourceReference);
9898
}
9999
}
100100
}

src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Path Item Object Reference: to describe the operations available on a single path.
1111
/// </summary>
12-
public class OpenApiPathItemReference : BaseOpenApiReferenceHolder<OpenApiPathItem, IOpenApiPathItem, OpenApiReferenceWithSummary>, IOpenApiPathItem
12+
public class OpenApiPathItemReference : BaseOpenApiReferenceHolder<OpenApiPathItem, IOpenApiPathItem, OpenApiReferenceWithDescriptionAndSummary>, IOpenApiPathItem
1313
{
1414

1515
/// <summary>
@@ -79,9 +79,9 @@ public override void SerializeAsV2(IOpenApiWriter writer)
7979
Reference.SerializeAsV2(writer);
8080
}
8181
/// <inheritdoc/>
82-
protected override OpenApiReferenceWithSummary CopyReference(OpenApiReferenceWithSummary sourceReference)
82+
protected override OpenApiReferenceWithDescriptionAndSummary CopyReference(OpenApiReferenceWithDescriptionAndSummary sourceReference)
8383
{
84-
return new OpenApiReferenceWithSummary(sourceReference);
84+
return new OpenApiReferenceWithDescriptionAndSummary(sourceReference);
8585
}
8686
}
8787
}

src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Request Body Object Reference.
1111
/// </summary>
12-
public class OpenApiRequestBodyReference : BaseOpenApiReferenceHolder<OpenApiRequestBody, IOpenApiRequestBody, BaseOpenApiReference>, IOpenApiRequestBody
12+
public class OpenApiRequestBodyReference : BaseOpenApiReferenceHolder<OpenApiRequestBody, IOpenApiRequestBody, OpenApiReferenceWithDescription>, IOpenApiRequestBody
1313
{
1414
/// <summary>
1515
/// Constructor initializing the reference object.
@@ -89,9 +89,9 @@ public IOpenApiRequestBody CreateShallowCopy()
8989
return new OpenApiRequestBodyReference(this);
9090
}
9191
/// <inheritdoc/>
92-
protected override BaseOpenApiReference CopyReference(BaseOpenApiReference sourceReference)
92+
protected override OpenApiReferenceWithDescription CopyReference(OpenApiReferenceWithDescription sourceReference)
9393
{
94-
return new BaseOpenApiReference(sourceReference);
94+
return new OpenApiReferenceWithDescription(sourceReference);
9595
}
9696
}
9797
}

0 commit comments

Comments
 (0)