Skip to content

Commit f0802e5

Browse files
committed
fix: makes reference serialization object generic
Signed-off-by: Vincent Biret <[email protected]>
1 parent ddf17fe commit f0802e5

14 files changed

+52
-73
lines changed

src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace Microsoft.OpenApi
88
/// </summary>
99
/// <typeparam name="T">The type of the target being referenced</typeparam>
1010
/// <typeparam name="V">The type of the interface implemented by both the target and the reference type</typeparam>
11-
public interface IOpenApiReferenceHolder<out T, V> : IOpenApiReferenceHolder where T : IOpenApiReferenceable, V
11+
/// <typeparam name="U">The type for the reference holding the additional fields and annotations</typeparam>
12+
public interface IOpenApiReferenceHolder<out T, V, U> : IOpenApiReferenceHolder<U> where T : IOpenApiReferenceable, V where U : OpenApiReference
1213
{
1314
/// <summary>
1415
/// Gets the resolved target object.
@@ -28,7 +29,7 @@ public interface IOpenApiReferenceHolder<out T, V> : IOpenApiReferenceHolder whe
2829
/// <summary>
2930
/// A generic interface for OpenApiReferenceable objects that have a target.
3031
/// </summary>
31-
public interface IOpenApiReferenceHolder : IOpenApiSerializable
32+
public interface IOpenApiReferenceHolder<U> : IOpenApiSerializable where U : OpenApiReference
3233
{
3334
/// <summary>
3435
/// Indicates if object is populated with data or is just a reference to the data
@@ -38,6 +39,6 @@ public interface IOpenApiReferenceHolder : IOpenApiSerializable
3839
/// <summary>
3940
/// Reference object.
4041
/// </summary>
41-
OpenApiReference Reference { get; init; }
42+
U Reference { get; init; }
4243
}
4344
}

src/Microsoft.OpenApi/Models/OpenApiSchemaReferenceInformation.cs renamed to src/Microsoft.OpenApi/Models/JsonSchemaReference.cs

Lines changed: 5 additions & 5 deletions
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 OpenApiSchemaReferenceInformation : OpenApiReference
15+
public class JsonSchemaReference : OpenApiReference
1616
{
1717
/// <summary>
1818
/// A default value which by default SHOULD override that of the referenced component.
@@ -53,12 +53,12 @@ public class OpenApiSchemaReferenceInformation : OpenApiReference
5353
/// <summary>
5454
/// Parameterless constructor
5555
/// </summary>
56-
public OpenApiSchemaReferenceInformation() { }
56+
public JsonSchemaReference() { }
5757

5858
/// <summary>
59-
/// Initializes a copy instance of the <see cref="OpenApiSchemaReferenceInformation"/> object
59+
/// Initializes a copy instance of the <see cref="JsonSchemaReference"/> object
6060
/// </summary>
61-
public OpenApiSchemaReferenceInformation(OpenApiSchemaReferenceInformation reference) : base(reference)
61+
public JsonSchemaReference(JsonSchemaReference reference) : base(reference)
6262
{
6363
Utils.CheckArgumentNull(reference);
6464
Default = reference.Default;
@@ -70,7 +70,7 @@ public OpenApiSchemaReferenceInformation(OpenApiSchemaReferenceInformation refer
7070
}
7171

7272
/// <summary>
73-
/// Serialize <see cref="OpenApiSchemaReferenceInformation"/> to Open Api v3.1.
73+
/// Serialize <see cref="JsonSchemaReference"/> to Open Api v3.1.
7474
/// </summary>
7575
public override void SerializeAsV31(IOpenApiWriter writer)
7676
{

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace Microsoft.OpenApi;
66
/// </summary>
77
/// <typeparam name="T">The concrete class implementation type for the model.</typeparam>
88
/// <typeparam name="V">The interface type for the model.</typeparam>
9-
public abstract class BaseOpenApiReferenceHolder<T, V> : IOpenApiReferenceHolder<T, V> where T : class, IOpenApiReferenceable, V where V : IOpenApiReferenceable, IOpenApiSerializable
9+
/// <typeparam name="U">The type for the reference holding the additional fields and annotations</typeparam>
10+
public abstract class BaseOpenApiReferenceHolder<T, V, U> : IOpenApiReferenceHolder<T, V, U> where T : class, IOpenApiReferenceable, V where V : IOpenApiReferenceable, IOpenApiSerializable where U : OpenApiReference, new()
1011
{
1112
/// <inheritdoc/>
1213
public virtual V? Target
@@ -23,7 +24,7 @@ public T? RecursiveTarget
2324
get
2425
{
2526
return Target switch {
26-
BaseOpenApiReferenceHolder<T, V> recursiveTarget => recursiveTarget.RecursiveTarget,
27+
BaseOpenApiReferenceHolder<T, V, U> recursiveTarget => recursiveTarget.RecursiveTarget,
2728
T concrete => concrete,
2829
_ => null
2930
};
@@ -34,7 +35,7 @@ public T? RecursiveTarget
3435
/// Copy constructor
3536
/// </summary>
3637
/// <param name="source">The parameter reference to copy</param>
37-
protected BaseOpenApiReferenceHolder(BaseOpenApiReferenceHolder<T, V> source)
38+
protected BaseOpenApiReferenceHolder(BaseOpenApiReferenceHolder<T, V, U> source)
3839
{
3940
Utils.CheckArgumentNull(source);
4041
Reference = new(source.Reference);
@@ -58,7 +59,7 @@ protected BaseOpenApiReferenceHolder(string referenceId, OpenApiDocument? hostDo
5859
// we're not checking for null hostDocument as it's optional and can be set via additional methods by a walker
5960
// this way object initialization of a whole document is supported
6061

61-
Reference = new OpenApiReference()
62+
Reference = new U()
6263
{
6364
Id = referenceId,
6465
HostDocument = hostDocument,
@@ -71,10 +72,10 @@ protected BaseOpenApiReferenceHolder(string referenceId, OpenApiDocument? hostDo
7172

7273
#if NETSTANDARD2_1_OR_GREATER
7374
/// <inheritdoc/>
74-
public required OpenApiReference Reference { get; init; }
75+
public required U Reference { get; init; }
7576
#else
7677
/// <inheritdoc/>
77-
public OpenApiReference Reference { get; init; }
78+
public U Reference { get; init; }
7879
#endif
7980
/// <inheritdoc/>
8081
public abstract V CopyReferenceAsTargetElementWithOverrides(V source);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.OpenApi
88
/// <summary>
99
/// Callback Object Reference: A reference to a map of possible out-of band callbacks related to the parent operation.
1010
/// </summary>
11-
public class OpenApiCallbackReference : BaseOpenApiReferenceHolder<OpenApiCallback, IOpenApiCallback>, IOpenApiCallback
11+
public class OpenApiCallbackReference : BaseOpenApiReferenceHolder<OpenApiCallback, IOpenApiCallback, OpenApiReference>, IOpenApiCallback
1212
{
1313
/// <summary>
1414
/// Constructor initializing the reference object.

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

Lines changed: 1 addition & 1 deletion
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>, IOpenApiExample
12+
public class OpenApiExampleReference : BaseOpenApiReferenceHolder<OpenApiExample, IOpenApiExample, OpenApiReference>, IOpenApiExample
1313
{
1414
/// <summary>
1515
/// Constructor initializing the reference object.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Header Object Reference.
1111
/// </summary>
12-
public class OpenApiHeaderReference : BaseOpenApiReferenceHolder<OpenApiHeader, IOpenApiHeader>, IOpenApiHeader
13-
{
12+
public class OpenApiHeaderReference : BaseOpenApiReferenceHolder<OpenApiHeader, IOpenApiHeader, OpenApiReference>, IOpenApiHeader
13+
{ //TODO switch to the non summary version
1414
/// <summary>
1515
/// Constructor initializing the reference object.
1616
/// </summary>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace Microsoft.OpenApi
88
/// <summary>
99
/// Link Object Reference.
1010
/// </summary>
11-
public class OpenApiLinkReference : BaseOpenApiReferenceHolder<OpenApiLink, IOpenApiLink>, IOpenApiLink
12-
{
11+
public class OpenApiLinkReference : BaseOpenApiReferenceHolder<OpenApiLink, IOpenApiLink, OpenApiReference>, IOpenApiLink
12+
{//TODO switch to the non summary version
1313
/// <summary>
1414
/// Constructor initializing the reference object.
1515
/// </summary>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Parameter Object Reference.
1111
/// </summary>
12-
public class OpenApiParameterReference : BaseOpenApiReferenceHolder<OpenApiParameter, IOpenApiParameter>, IOpenApiParameter
13-
{
12+
public class OpenApiParameterReference : BaseOpenApiReferenceHolder<OpenApiParameter, IOpenApiParameter, OpenApiReference>, IOpenApiParameter
13+
{//TODO switch to the non summary version
1414
/// <summary>
1515
/// Constructor initializing the reference object.
1616
/// </summary>

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

Lines changed: 1 addition & 1 deletion
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>, IOpenApiPathItem
12+
public class OpenApiPathItemReference : BaseOpenApiReferenceHolder<OpenApiPathItem, IOpenApiPathItem, OpenApiReference>, IOpenApiPathItem
1313
{
1414

1515
/// <summary>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace Microsoft.OpenApi
99
/// <summary>
1010
/// Request Body Object Reference.
1111
/// </summary>
12-
public class OpenApiRequestBodyReference : BaseOpenApiReferenceHolder<OpenApiRequestBody, IOpenApiRequestBody>, IOpenApiRequestBody
13-
{
12+
public class OpenApiRequestBodyReference : BaseOpenApiReferenceHolder<OpenApiRequestBody, IOpenApiRequestBody, OpenApiReference>, IOpenApiRequestBody
13+
{//TODO switch to the non summary version
1414
/// <summary>
1515
/// Constructor initializing the reference object.
1616
/// </summary>

0 commit comments

Comments
 (0)