Skip to content

Commit e3c80a3

Browse files
committed
chore: cleans up temporary interface structure for references migration
Signed-off-by: Vincent Biret <[email protected]>
1 parent e147e72 commit e3c80a3

File tree

5 files changed

+10
-26
lines changed

5 files changed

+10
-26
lines changed

src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceHolder.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,14 @@ namespace Microsoft.OpenApi.Interfaces
88
/// <summary>
99
/// A generic interface for OpenApiReferenceable objects that have a target.
1010
/// </summary>
11-
/// <typeparam name="T">Type of the target being referenced</typeparam>
12-
public interface IOpenApiReferenceHolder<out T> : IOpenApiReferenceHolder where T : IOpenApiReferenceable
11+
/// <typeparam name="T">The type of the target being referenced</typeparam>
12+
/// <typeparam name="V">The type of the interface implemented by both the target and the reference type</typeparam>
13+
public interface IOpenApiReferenceHolder<out T, V> : IOpenApiReferenceHolder where T : IOpenApiReferenceable, V
1314
{
1415
/// <summary>
1516
/// Gets the resolved target object.
1617
/// </summary>
1718
T Target { get; }
18-
}
19-
/// <summary>
20-
/// A generic interface for OpenApiReferenceable objects that have a target.
21-
/// </summary>
22-
/// <typeparam name="T">The type of the target being referenced</typeparam>
23-
/// <typeparam name="V">The type of the interface implemented by both the target and the reference type</typeparam>
24-
public interface IOpenApiReferenceHolder<out T, V> : IOpenApiReferenceHolder<T> where T : IOpenApiReferenceable, V
25-
{
26-
//TODO merge this interface with the previous once all implementations are updated
2719
/// <summary>
2820
/// Copy the reference as a target element with overrides.
2921
/// </summary>
@@ -37,8 +29,7 @@ public interface IOpenApiReferenceHolder : IOpenApiSerializable
3729
/// <summary>
3830
/// Indicates if object is populated with data or is just a reference to the data
3931
/// </summary>
40-
bool UnresolvedReference { get; set; }
41-
//TODO the UnresolvedReference property setter should be removed and a default implementation that checks whether the target is null for the getter should be provided instead
32+
bool UnresolvedReference { get; }
4233

4334
/// <summary>
4435
/// Reference object.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ protected BaseOpenApiReferenceHolder(BaseOpenApiReferenceHolder<T, V> source)
3131
{
3232
Utils.CheckArgumentNull(source);
3333
Reference = source.Reference != null ? new(source.Reference) : null;
34-
UnresolvedReference = source.UnresolvedReference;
3534
//no need to copy summary and description as if they are not overridden, they will be fetched from the target
3635
//if they are, the reference copy will handle it
3736
}
@@ -69,7 +68,7 @@ protected BaseOpenApiReferenceHolder(string referenceId, OpenApiDocument hostDoc
6968
};
7069
}
7170
/// <inheritdoc/>
72-
public bool UnresolvedReference { get; set; }
71+
public bool UnresolvedReference { get => Reference is null || Target is null; }
7372
/// <inheritdoc/>
7473
public OpenApiReference Reference { get; set; }
7574
/// <inheritdoc/>

src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public T GetReferencedObject<T>(ReferenceType referenceType, string referenceId,
124124
{
125125
return new()
126126
{
127-
UnresolvedReference = true,
128127
Reference = Context.VersionService.ConvertToOpenApiReference(referenceId, referenceType, summary, description)
129128
};
130129
}

test/Microsoft.OpenApi.Readers.Tests/OpenApiWorkspaceTests/OpenApiWorkspaceStreamTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public async Task LoadingDocumentWithResolveAllReferencesShouldLoadDocumentIntoW
3030
BaseUrl = new("file://c:\\")
3131
};
3232

33-
// Todo: this should be ReadAsync
3433
var stream = new MemoryStream();
3534
var doc = """
3635
openapi: 3.0.0

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,12 @@ namespace Microsoft.OpenApi.Interfaces
225225
public interface IOpenApiReferenceHolder : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
226226
{
227227
Microsoft.OpenApi.Models.OpenApiReference Reference { get; set; }
228-
bool UnresolvedReference { get; set; }
228+
bool UnresolvedReference { get; }
229229
}
230-
public interface IOpenApiReferenceHolder<out T> : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
231-
where out T : Microsoft.OpenApi.Interfaces.IOpenApiReferenceable
232-
{
233-
T Target { get; }
234-
}
235-
public interface IOpenApiReferenceHolder<out T, V> : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder<T>, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
230+
public interface IOpenApiReferenceHolder<out T, V> : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
236231
where out T : Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, V
237232
{
233+
T Target { get; }
238234
V CopyReferenceAsTargetElementWithOverrides(V source);
239235
}
240236
public interface IOpenApiReferenceable : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { }
@@ -1238,7 +1234,7 @@ namespace Microsoft.OpenApi.Models
12381234
}
12391235
namespace Microsoft.OpenApi.Models.References
12401236
{
1241-
public abstract class BaseOpenApiReferenceHolder<T, V> : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder<T>, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder<T, V>, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
1237+
public abstract class BaseOpenApiReferenceHolder<T, V> : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder, Microsoft.OpenApi.Interfaces.IOpenApiReferenceHolder<T, V>, Microsoft.OpenApi.Interfaces.IOpenApiSerializable
12421238
where T : class, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, V
12431239
where V : Microsoft.OpenApi.Interfaces.IOpenApiSerializable
12441240
{
@@ -1247,7 +1243,7 @@ namespace Microsoft.OpenApi.Models.References
12471243
protected BaseOpenApiReferenceHolder(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, Microsoft.OpenApi.Models.ReferenceType referenceType, string externalResource = null) { }
12481244
public Microsoft.OpenApi.Models.OpenApiReference Reference { get; set; }
12491245
public virtual T Target { get; }
1250-
public bool UnresolvedReference { get; set; }
1246+
public bool UnresolvedReference { get; }
12511247
public abstract V CopyReferenceAsTargetElementWithOverrides(V source);
12521248
public virtual void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { }
12531249
public virtual void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { }

0 commit comments

Comments
 (0)