Skip to content

Commit f2f866a

Browse files
committed
Implement PR feedback
1 parent a6a68c2 commit f2f866a

37 files changed

+148
-146
lines changed

src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface IOpenApiReferenceable : IOpenApiSerializable
2525
/// <summary>
2626
/// Serialize to OpenAPI V3 document without using reference.
2727
/// </summary>
28-
void SerializeAsV3WithoutReference(IOpenApiWriter writer);
28+
void SerializeAsV3WithoutReference(IOpenApiWriter writer, OpenApiSpecVersion version);
2929

3030
/// <summary>
3131
/// Serialize to OpenAPI V2 document without using reference.

src/Microsoft.OpenApi/Models/OpenApiCallback.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,23 @@ public void AddPathItem(RuntimeExpression expression, OpenApiPathItem pathItem)
8383
/// <exception cref="System.NotImplementedException"></exception>
8484
public void SerializeAsV31(IOpenApiWriter writer)
8585
{
86-
Serialize(writer);
86+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1);
8787
}
8888

8989
/// <summary>
9090
/// Serialize <see cref="OpenApiCallback"/> to Open Api v3.0
9191
/// </summary>
9292
public void SerializeAsV3(IOpenApiWriter writer)
9393
{
94-
Serialize(writer);
94+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0);
9595
}
9696

9797
/// <summary>
9898
/// Serialize <see cref="OpenApiCallback"/>
9999
/// </summary>
100100
/// <param name="writer"></param>
101-
public void Serialize(IOpenApiWriter writer)
101+
/// <param name="version"></param>
102+
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version)
102103
{
103104
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
104105

@@ -116,7 +117,7 @@ public void Serialize(IOpenApiWriter writer)
116117
target = GetEffective(Reference.HostDocument);
117118
}
118119
}
119-
target.SerializeAsV3WithoutReference(writer);
120+
target.SerializeAsV3WithoutReference(writer, version);
120121
}
121122

122123
/// <summary>
@@ -141,7 +142,7 @@ public OpenApiCallback GetEffective(OpenApiDocument doc)
141142
/// Serialize to OpenAPI V3 document without using reference.
142143
/// </summary>
143144

144-
public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
145+
public void SerializeAsV3WithoutReference(IOpenApiWriter writer, OpenApiSpecVersion version)
145146
{
146147
writer.WriteStartObject();
147148

@@ -152,7 +153,7 @@ public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
152153
}
153154

154155
// extensions
155-
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0);
156+
writer.WriteExtensions(Extensions, version);
156157

157158
writer.WriteEndObject();
158159
}

src/Microsoft.OpenApi/Models/OpenApiComponents.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public OpenApiComponents(OpenApiComponents components)
101101
/// <param name="writer"></param>
102102
public void SerializeAsV31(IOpenApiWriter writer)
103103
{
104-
Serialize(writer);
104+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1);
105105

106106
// pathItems - only present in v3.1
107107
writer.WriteOptionalMap(
@@ -113,7 +113,7 @@ public void SerializeAsV31(IOpenApiWriter writer)
113113
component.Reference.Type == ReferenceType.Schema &&
114114
component.Reference.Id == key)
115115
{
116-
component.SerializeAsV3WithoutReference(w);
116+
component.SerializeAsV3WithoutReference(w, OpenApiSpecVersion.OpenApi3_1);
117117
}
118118
else
119119
{
@@ -130,14 +130,14 @@ public void SerializeAsV31(IOpenApiWriter writer)
130130
/// <param name="writer"></param>
131131
public void SerializeAsV3(IOpenApiWriter writer)
132132
{
133-
Serialize(writer);
133+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0);
134134
writer.WriteEndObject();
135135
}
136136

137137
/// <summary>
138138
/// Serialize <see cref="OpenApiComponents"/>.
139139
/// </summary>
140-
public void Serialize(IOpenApiWriter writer)
140+
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version)
141141
{
142142
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
143143

@@ -156,7 +156,7 @@ public void Serialize(IOpenApiWriter writer)
156156
OpenApiConstants.Schemas,
157157
Schemas,
158158
(w, key, component) => {
159-
component.SerializeAsV3WithoutReference(w);
159+
component.SerializeAsV3WithoutReference(w, version);
160160
});
161161
}
162162
writer.WriteEndObject();
@@ -178,7 +178,7 @@ public void Serialize(IOpenApiWriter writer)
178178
component.Reference.Type == ReferenceType.Schema &&
179179
component.Reference.Id == key)
180180
{
181-
component.SerializeAsV3WithoutReference(w);
181+
component.SerializeAsV3WithoutReference(w, version);
182182
}
183183
else
184184
{
@@ -196,7 +196,7 @@ public void Serialize(IOpenApiWriter writer)
196196
component.Reference.Type == ReferenceType.Response &&
197197
component.Reference.Id == key)
198198
{
199-
component.SerializeAsV3WithoutReference(w);
199+
component.SerializeAsV3WithoutReference(w, version);
200200
}
201201
else
202202
{
@@ -214,7 +214,7 @@ public void Serialize(IOpenApiWriter writer)
214214
component.Reference.Type == ReferenceType.Parameter &&
215215
component.Reference.Id == key)
216216
{
217-
component.SerializeAsV3WithoutReference(w);
217+
component.SerializeAsV3WithoutReference(w, version);
218218
}
219219
else
220220
{
@@ -232,7 +232,7 @@ public void Serialize(IOpenApiWriter writer)
232232
component.Reference.Type == ReferenceType.Example &&
233233
component.Reference.Id == key)
234234
{
235-
component.SerializeAsV3WithoutReference(w);
235+
component.SerializeAsV3WithoutReference(w, version);
236236
}
237237
else
238238
{
@@ -250,7 +250,7 @@ public void Serialize(IOpenApiWriter writer)
250250
component.Reference.Type == ReferenceType.RequestBody &&
251251
component.Reference.Id == key)
252252
{
253-
component.SerializeAsV3WithoutReference(w);
253+
component.SerializeAsV3WithoutReference(w, version);
254254
}
255255
else
256256
{
@@ -268,7 +268,7 @@ public void Serialize(IOpenApiWriter writer)
268268
component.Reference.Type == ReferenceType.Header &&
269269
component.Reference.Id == key)
270270
{
271-
component.SerializeAsV3WithoutReference(w);
271+
component.SerializeAsV3WithoutReference(w, version);
272272
}
273273
else
274274
{
@@ -286,7 +286,7 @@ public void Serialize(IOpenApiWriter writer)
286286
component.Reference.Type == ReferenceType.SecurityScheme &&
287287
component.Reference.Id == key)
288288
{
289-
component.SerializeAsV3WithoutReference(w);
289+
component.SerializeAsV3WithoutReference(w, version);
290290
}
291291
else
292292
{
@@ -304,7 +304,7 @@ public void Serialize(IOpenApiWriter writer)
304304
component.Reference.Type == ReferenceType.Link &&
305305
component.Reference.Id == key)
306306
{
307-
component.SerializeAsV3WithoutReference(w);
307+
component.SerializeAsV3WithoutReference(w, version);
308308
}
309309
else
310310
{
@@ -322,7 +322,7 @@ public void Serialize(IOpenApiWriter writer)
322322
component.Reference.Type == ReferenceType.Callback &&
323323
component.Reference.Id == key)
324324
{
325-
component.SerializeAsV3WithoutReference(w);
325+
component.SerializeAsV3WithoutReference(w, version);
326326
}
327327
else
328328
{
@@ -331,7 +331,7 @@ public void Serialize(IOpenApiWriter writer)
331331
});
332332

333333
// extensions
334-
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0);
334+
writer.WriteExtensions(Extensions, version);
335335
}
336336

337337
/// <summary>

src/Microsoft.OpenApi/Models/OpenApiDiscriminator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ public OpenApiDiscriminator(OpenApiDiscriminator discriminator)
4242
/// <param name="writer"></param>
4343
public void SerializeAsV31(IOpenApiWriter writer)
4444
{
45-
Serialize(writer);
45+
SerializeInternal(writer);
4646
}
4747

4848
/// <summary>
4949
/// Serialize <see cref="OpenApiDiscriminator"/> to Open Api v3.0
5050
/// </summary>
5151
public void SerializeAsV3(IOpenApiWriter writer)
5252
{
53-
Serialize(writer);
53+
SerializeInternal(writer);
5454
}
5555

5656
/// <summary>
5757
/// Serialize <see cref="OpenApiDiscriminator"/> to Open Api v3.0
5858
/// </summary>
5959
/// <param name="writer"></param>
60-
public void Serialize(IOpenApiWriter writer)
60+
private void SerializeInternal(IOpenApiWriter writer)
6161
{
6262
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
6363

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void SerializeAsV31(IOpenApiWriter writer)
121121
// jsonSchemaDialect
122122
writer.WriteProperty(OpenApiConstants.JsonSchemaDialect, JsonSchemaDialect);
123123

124-
Serialize(writer);
124+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1);
125125

126126
// webhooks
127127
writer.WriteOptionalMap(
@@ -133,7 +133,7 @@ public void SerializeAsV31(IOpenApiWriter writer)
133133
component.Reference.Type == ReferenceType.PathItem &&
134134
component.Reference.Id == key)
135135
{
136-
component.SerializeAsV3WithoutReference(w);
136+
component.SerializeAsV3WithoutReference(w, OpenApiSpecVersion.OpenApi3_1);
137137
}
138138
else
139139
{
@@ -156,15 +156,16 @@ public void SerializeAsV3(IOpenApiWriter writer)
156156

157157
// openapi
158158
writer.WriteProperty(OpenApiConstants.OpenApi, "3.0.1");
159-
Serialize(writer);
159+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0);
160160
writer.WriteEndObject();
161161
}
162162

163163
/// <summary>
164164
/// Serialize <see cref="OpenApiDocument"/>
165165
/// </summary>
166166
/// <param name="writer"></param>
167-
public void Serialize(IOpenApiWriter writer)
167+
/// <param name="version"></param>
168+
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version)
168169
{
169170
// info
170171
writer.WriteRequiredObject(OpenApiConstants.Info, Info, (w, i) => i.SerializeAsV3(w));
@@ -185,7 +186,7 @@ public void Serialize(IOpenApiWriter writer)
185186
(w, s) => s.SerializeAsV3(w));
186187

187188
// tags
188-
writer.WriteOptionalCollection(OpenApiConstants.Tags, Tags, (w, t) => t.SerializeAsV3WithoutReference(w));
189+
writer.WriteOptionalCollection(OpenApiConstants.Tags, Tags, (w, t) => t.SerializeAsV3WithoutReference(w, version));
189190

190191
// external docs
191192
writer.WriteOptionalObject(OpenApiConstants.ExternalDocs, ExternalDocs, (w, e) => e.SerializeAsV3(w));

src/Microsoft.OpenApi/Models/OpenApiEncoding.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public OpenApiEncoding(OpenApiEncoding encoding)
7777
/// <param name="writer"></param>
7878
public void SerializeAsV31(IOpenApiWriter writer)
7979
{
80-
Serialize(writer);
80+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1);
8181
}
8282

8383
/// <summary>
@@ -86,13 +86,13 @@ public void SerializeAsV31(IOpenApiWriter writer)
8686
/// <param name="writer"></param>
8787
public void SerializeAsV3(IOpenApiWriter writer)
8888
{
89-
Serialize(writer);
89+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0);
9090
}
9191

9292
/// <summary>
9393
/// Serialize <see cref="OpenApiExternalDocs"/> to Open Api v3.0.
9494
/// </summary>
95-
public void Serialize(IOpenApiWriter writer)
95+
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version)
9696
{
9797
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
9898

@@ -114,7 +114,7 @@ public void Serialize(IOpenApiWriter writer)
114114
writer.WriteProperty(OpenApiConstants.AllowReserved, AllowReserved, false);
115115

116116
// extensions
117-
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0);
117+
writer.WriteExtensions(Extensions, version);
118118

119119
writer.WriteEndObject();
120120
}

src/Microsoft.OpenApi/Models/OpenApiExample.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public OpenApiExample(OpenApiExample example)
7979
/// <param name="writer"></param>
8080
public void SerializeAsV31(IOpenApiWriter writer)
8181
{
82-
Serialize(writer);
82+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1);
8383
}
8484

8585
/// <summary>
@@ -88,13 +88,13 @@ public void SerializeAsV31(IOpenApiWriter writer)
8888
/// <param name="writer"></param>
8989
public void SerializeAsV3(IOpenApiWriter writer)
9090
{
91-
Serialize(writer);
91+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0);
9292
}
9393

9494
/// <summary>
9595
/// Serialize <see cref="OpenApiExample"/> to Open Api v3.0
9696
/// </summary>
97-
public void Serialize(IOpenApiWriter writer)
97+
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version)
9898
{
9999
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
100100

@@ -112,7 +112,7 @@ public void Serialize(IOpenApiWriter writer)
112112
target = GetEffective(Reference.HostDocument);
113113
}
114114
}
115-
target.SerializeAsV3WithoutReference(writer);
115+
target.SerializeAsV3WithoutReference(writer, version);
116116
}
117117

118118
/// <summary>
@@ -135,7 +135,7 @@ public OpenApiExample GetEffective(OpenApiDocument doc)
135135
/// <summary>
136136
/// Serialize to OpenAPI V3 document without using reference.
137137
/// </summary>
138-
public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
138+
public void SerializeAsV3WithoutReference(IOpenApiWriter writer, OpenApiSpecVersion version)
139139
{
140140
writer.WriteStartObject();
141141

@@ -152,7 +152,7 @@ public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
152152
writer.WriteProperty(OpenApiConstants.ExternalValue, ExternalValue);
153153

154154
// extensions
155-
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0);
155+
writer.WriteExtensions(Extensions, version);
156156

157157
writer.WriteEndObject();
158158
}

src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected OpenApiExtensibleDictionary(
4545
/// <param name="writer"></param>
4646
public void SerializeAsV31(IOpenApiWriter writer)
4747
{
48-
Serialize(writer);
48+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1);
4949
}
5050

5151
/// <summary>
@@ -54,13 +54,13 @@ public void SerializeAsV31(IOpenApiWriter writer)
5454
/// <param name="writer"></param>
5555
public void SerializeAsV3(IOpenApiWriter writer)
5656
{
57-
Serialize(writer);
57+
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0);
5858
}
5959

6060
/// <summary>
6161
/// Serialize to Open Api v3.0
6262
/// </summary>
63-
public void Serialize(IOpenApiWriter writer)
63+
private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version)
6464
{
6565
writer = writer ?? throw Error.ArgumentNull(nameof(writer));
6666

@@ -71,7 +71,7 @@ public void Serialize(IOpenApiWriter writer)
7171
writer.WriteRequiredObject(item.Key, item.Value, (w, p) => p.SerializeAsV3(w));
7272
}
7373

74-
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi3_0);
74+
writer.WriteExtensions(Extensions, version);
7575

7676
writer.WriteEndObject();
7777
}

0 commit comments

Comments
 (0)