@@ -11,21 +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 OpenApiReference : IOpenApiSerializable , IOpenApiDescribedElement , IOpenApiSummarizedElement
14+ public class BaseOpenApiReference : IOpenApiSerializable
1515 {
16- /// <summary>
17- /// A short summary which by default SHOULD override that of the referenced component.
18- /// If the referenced object-type does not allow a summary field, then this field has no effect.
19- /// </summary>
20- public string ? Summary { get ; set ; }
21-
22- /// <summary>
23- /// A description which by default SHOULD override that of the referenced component.
24- /// CommonMark syntax MAY be used for rich text representation.
25- /// If the referenced object-type does not allow a description field, then this field has no effect.
26- /// </summary>
27- public string ? Description { get ; set ; }
28-
2916 /// <summary>
3017 /// External resource in the reference.
3118 /// It maybe:
@@ -143,45 +130,43 @@ public string? ReferenceV2
143130 /// <summary>
144131 /// Parameterless constructor
145132 /// </summary>
146- public OpenApiReference ( ) { }
133+ public BaseOpenApiReference ( ) { }
147134
148135 /// <summary>
149- /// Initializes a copy instance of the <see cref="OpenApiReference "/> object
136+ /// Initializes a copy instance of the <see cref="BaseOpenApiReference "/> object
150137 /// </summary>
151- public OpenApiReference ( OpenApiReference reference )
138+ public BaseOpenApiReference ( BaseOpenApiReference reference )
152139 {
153140 Utils . CheckArgumentNull ( reference ) ;
154- Summary = reference . Summary ;
155- Description = reference . Description ;
156141 ExternalResource = reference . ExternalResource ;
157142 Type = reference . Type ;
158143 Id = reference . Id ;
159144 HostDocument = reference . HostDocument ;
160145 }
161146
162- /// <summary>
163- /// Serialize <see cref="OpenApiReference"/> to Open Api v3.1.
164- /// </summary>
165- public void SerializeAsV31 ( IOpenApiWriter writer )
147+ /// <inheritdoc/>
148+ public virtual void SerializeAsV31 ( IOpenApiWriter writer )
166149 {
167- SerializeInternal ( writer , w =>
168- {
169- // summary and description are in 3.1 but not in 3.0
170- w . WriteProperty ( OpenApiConstants . Summary , Summary ) ;
171- w . WriteProperty ( OpenApiConstants . Description , Description ) ;
172- } ) ;
150+ SerializeInternal ( writer , SerializeAdditionalV31Properties ) ;
173151 }
174152
175153 /// <summary>
176- /// Serialize <see cref="OpenApiReference"/> to Open Api v3.0 .
154+ /// Serialize additional properties for Open Api v3.1 .
177155 /// </summary>
178- public void SerializeAsV3 ( IOpenApiWriter writer )
156+ /// <param name="writer"></param>
157+ protected virtual void SerializeAdditionalV31Properties ( IOpenApiWriter writer )
158+ {
159+ // noop for the base type
160+ }
161+
162+ /// <inheritdoc/>
163+ public virtual void SerializeAsV3 ( IOpenApiWriter writer )
179164 {
180165 SerializeInternal ( writer ) ;
181166 }
182167
183168 /// <summary>
184- /// Serialize <see cref="OpenApiReference "/>
169+ /// Serialize <see cref="BaseOpenApiReference "/>
185170 /// </summary>
186171 private void SerializeInternal ( IOpenApiWriter writer , Action < IOpenApiWriter > ? callback = null )
187172 {
@@ -206,10 +191,8 @@ private void SerializeInternal(IOpenApiWriter writer, Action<IOpenApiWriter>? ca
206191 writer . WriteEndObject ( ) ;
207192 }
208193
209- /// <summary>
210- /// Serialize <see cref="OpenApiReference"/> to Open Api v2.0.
211- /// </summary>
212- public void SerializeAsV2 ( IOpenApiWriter writer )
194+ /// <inheritdoc/>
195+ public virtual void SerializeAsV2 ( IOpenApiWriter writer )
213196 {
214197 Utils . CheckArgumentNull ( writer ) ;
215198
@@ -291,23 +274,27 @@ internal void EnsureHostDocumentIsSet(OpenApiDocument currentDocument)
291274 Utils . CheckArgumentNull ( currentDocument ) ;
292275 hostDocument ??= currentDocument ;
293276 }
294- private static string ? GetPropertyValueFromNode ( JsonObject jsonObject , string key ) =>
277+ /// <summary>
278+ /// Gets the property value from a JsonObject node.
279+ /// </summary>
280+ /// <param name="jsonObject">The object to get the value from</param>
281+ /// <param name="key">The key of the property</param>
282+ /// <returns>The property value</returns>
283+ protected internal static string ? GetPropertyValueFromNode ( JsonObject jsonObject , string key ) =>
295284 jsonObject . TryGetPropertyValue ( key , out var valueNode ) && valueNode is JsonValue valueCast && valueCast . TryGetValue < string > ( out var strValue ) ? strValue : null ;
296- internal void SetSummaryAndDescriptionFromMapNode ( MapNode mapNode )
285+ internal virtual void SetMetadataFromMapNode ( MapNode mapNode )
297286 {
298- var ( description , summary ) = mapNode . JsonNode switch {
299- JsonObject jsonObject => ( GetPropertyValueFromNode ( jsonObject , OpenApiConstants . Description ) ,
300- GetPropertyValueFromNode ( jsonObject , OpenApiConstants . Summary ) ) ,
301- _ => ( null , null )
302- } ;
303- if ( ! string . IsNullOrEmpty ( description ) )
304- {
305- Description = description ;
306- }
307- if ( ! string . IsNullOrEmpty ( summary ) )
308- {
309- Summary = summary ;
310- }
287+ if ( mapNode . JsonNode is not JsonObject jsonObject ) return ;
288+ SetAdditional31MetadataFromMapNode ( jsonObject ) ;
289+ }
290+
291+ /// <summary>
292+ /// Sets additional metadata from the map node.
293+ /// </summary>
294+ /// <param name="jsonObject">The object to get the data from</param>
295+ protected virtual void SetAdditional31MetadataFromMapNode ( JsonObject jsonObject )
296+ {
297+ // noop for the base type
311298 }
312299
313300 internal void SetJsonPointerPath ( string pointer , string nodeLocation )
@@ -319,11 +306,11 @@ internal void SetJsonPointerPath(string pointer, string nodeLocation)
319306 }
320307
321308 // Absolute reference or anchor (e.g. "#/components/schemas/..." or full URL)
322- else if ( ( pointer . Contains ( '#' ) || pointer . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) )
309+ else if ( ( pointer . Contains ( '#' ) || pointer . StartsWith ( "http" , StringComparison . OrdinalIgnoreCase ) )
323310 && ! string . Equals ( ReferenceV3 , pointer , StringComparison . OrdinalIgnoreCase ) )
324311 {
325312 ReferenceV3 = pointer ;
326- }
313+ }
327314 }
328315
329316 private static string ResolveRelativePointer ( string nodeLocation , string relativeRef )
0 commit comments