@@ -74,7 +74,9 @@ public static void Serialize<T>(
74
74
throw new OpenApiException ( string . Format ( SRResource . OpenApiFormatNotSupported , format ) ) ;
75
75
}
76
76
77
- element . Serialize ( writer , specVersion ) ;
77
+ writer . Settings . SpecVersion = specVersion ;
78
+
79
+ element . Serialize ( writer ) ;
78
80
}
79
81
80
82
/// <summary>
@@ -86,6 +88,19 @@ public static void Serialize<T>(
86
88
/// <param name="specVersion">The Open API specification version.</param>
87
89
public static void Serialize < T > ( this T element , IOpenApiWriter writer , OpenApiSpecVersion specVersion )
88
90
where T : IOpenApiSerializable
91
+ {
92
+ writer . Settings . SpecVersion = specVersion ;
93
+ element . Serialize ( writer ) ;
94
+ }
95
+
96
+ /// <summary>
97
+ /// Serializes the <see cref="IOpenApiSerializable"/> to Open API document using the given specification version and writer.
98
+ /// </summary>
99
+ /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
100
+ /// <param name="element">The Open API element.</param>
101
+ /// <param name="writer">The output writer.</param>
102
+ public static void Serialize < T > ( this T element , IOpenApiWriter writer )
103
+ where T : IOpenApiSerializable
89
104
{
90
105
if ( element == null )
91
106
{
@@ -97,7 +112,7 @@ public static void Serialize<T>(this T element, IOpenApiWriter writer, OpenApiSp
97
112
throw Error . ArgumentNull ( nameof ( writer ) ) ;
98
113
}
99
114
100
- switch ( specVersion )
115
+ switch ( writer . Settings . SpecVersion )
101
116
{
102
117
case OpenApiSpecVersion . OpenApi3_0 :
103
118
element . SerializeAsV3 ( writer ) ;
@@ -108,24 +123,12 @@ public static void Serialize<T>(this T element, IOpenApiWriter writer, OpenApiSp
108
123
break ;
109
124
110
125
default :
111
- throw new OpenApiException ( string . Format ( SRResource . OpenApiSpecVersionNotSupported , specVersion ) ) ;
126
+ throw new OpenApiException ( string . Format ( SRResource . OpenApiSpecVersionNotSupported , writer . Settings . SpecVersion ) ) ;
112
127
}
113
128
114
129
writer . Flush ( ) ;
115
130
}
116
131
117
- /// <summary>
118
- /// Serializes the <see cref="IOpenApiSerializable"/> to Open API document using the given specification version and writer.
119
- /// </summary>
120
- /// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
121
- /// <param name="element">The Open API element.</param>
122
- /// <param name="writer">The output writer.</param>
123
- public static void Serialize < T > ( this T element , IOpenApiWriter writer )
124
- where T : IOpenApiSerializable
125
- {
126
- element . Serialize ( writer , writer . Settings . SpecVersion ) ;
127
- }
128
-
129
132
/// <summary>
130
133
/// Serializes the <see cref="IOpenApiSerializable"/> to the Open API document as a string in JSON format.
131
134
/// </summary>
0 commit comments