@@ -11,21 +11,8 @@ namespace Microsoft.OpenApi
11
11
/// <summary>
12
12
/// A simple object to allow referencing other components in the specification, internally and externally.
13
13
/// </summary>
14
- public class OpenApiReference : IOpenApiSerializable , IOpenApiDescribedElement , IOpenApiSummarizedElement
14
+ public class BaseOpenApiReference : IOpenApiSerializable
15
15
{
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
-
29
16
/// <summary>
30
17
/// External resource in the reference.
31
18
/// It maybe:
@@ -143,45 +130,43 @@ public string? ReferenceV2
143
130
/// <summary>
144
131
/// Parameterless constructor
145
132
/// </summary>
146
- public OpenApiReference ( ) { }
133
+ public BaseOpenApiReference ( ) { }
147
134
148
135
/// <summary>
149
- /// Initializes a copy instance of the <see cref="OpenApiReference "/> object
136
+ /// Initializes a copy instance of the <see cref="BaseOpenApiReference "/> object
150
137
/// </summary>
151
- public OpenApiReference ( OpenApiReference reference )
138
+ public BaseOpenApiReference ( BaseOpenApiReference reference )
152
139
{
153
140
Utils . CheckArgumentNull ( reference ) ;
154
- Summary = reference . Summary ;
155
- Description = reference . Description ;
156
141
ExternalResource = reference . ExternalResource ;
157
142
Type = reference . Type ;
158
143
Id = reference . Id ;
159
144
HostDocument = reference . HostDocument ;
160
145
}
161
146
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 )
166
149
{
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 ) ;
173
151
}
174
152
175
153
/// <summary>
176
- /// Serialize <see cref="OpenApiReference"/> to Open Api v3.0 .
154
+ /// Serialize additional properties for Open Api v3.1 .
177
155
/// </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 )
179
164
{
180
165
SerializeInternal ( writer ) ;
181
166
}
182
167
183
168
/// <summary>
184
- /// Serialize <see cref="OpenApiReference "/>
169
+ /// Serialize <see cref="BaseOpenApiReference "/>
185
170
/// </summary>
186
171
private void SerializeInternal ( IOpenApiWriter writer , Action < IOpenApiWriter > ? callback = null )
187
172
{
@@ -206,10 +191,8 @@ private void SerializeInternal(IOpenApiWriter writer, Action<IOpenApiWriter>? ca
206
191
writer . WriteEndObject ( ) ;
207
192
}
208
193
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 )
213
196
{
214
197
Utils . CheckArgumentNull ( writer ) ;
215
198
@@ -291,23 +274,27 @@ internal void EnsureHostDocumentIsSet(OpenApiDocument currentDocument)
291
274
Utils . CheckArgumentNull ( currentDocument ) ;
292
275
hostDocument ??= currentDocument ;
293
276
}
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 ) =>
295
284
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 )
297
286
{
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
311
298
}
312
299
313
300
internal void SetJsonPointerPath ( string pointer , string nodeLocation )
@@ -319,11 +306,11 @@ internal void SetJsonPointerPath(string pointer, string nodeLocation)
319
306
}
320
307
321
308
// 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 ) )
323
310
&& ! string . Equals ( ReferenceV3 , pointer , StringComparison . OrdinalIgnoreCase ) )
324
311
{
325
312
ReferenceV3 = pointer ;
326
- }
313
+ }
327
314
}
328
315
329
316
private static string ResolveRelativePointer ( string nodeLocation , string relativeRef )
0 commit comments