Skip to content

Commit ce2fa8f

Browse files
committed
Revert "Clean up code; update tests and public API"
This reverts commit f503757.
1 parent d275b57 commit ce2fa8f

6 files changed

+34
-41
lines changed

src/Microsoft.OpenApi/Extensions/JsonSchemaBuilderExtensions.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,25 @@ public static JsonSchemaBuilder OpenApiExternalDocs(this JsonSchemaBuilder build
112112
return builder;
113113
}
114114

115+
/// <summary>
116+
/// Removes a keyword from the builder instance
117+
/// </summary>
118+
/// <param name="builder"></param>
119+
/// <param name="keyWord"></param>
120+
/// <returns></returns>
121+
public static JsonSchemaBuilder RemoveKeyWord(this JsonSchemaBuilder builder, IJsonSchemaKeyword keyWord)
122+
{
123+
var schema = builder.Build();
124+
var newKeyWords = new List<IJsonSchemaKeyword>();
125+
newKeyWords = schema.Keywords.Where(x => !x.Equals(keyWord)).ToList();
126+
foreach (var item in newKeyWords)
127+
{
128+
builder.Add(item);
129+
}
130+
131+
return builder;
132+
}
133+
115134
/// <summary>
116135
/// Removes a keyword
117136
/// </summary>
@@ -134,6 +153,7 @@ public static JsonSchemaBuilder Remove(this JsonSchemaBuilder builder, string ke
134153
}
135154
}
136155

156+
//_keywords.Remove(keyword);
137157
return schemaBuilder;
138158
}
139159
}

test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.SerializeParameterWithSchemaTypeObjectAsV2JsonWorksAsync_produceTerseOutput=False.verified.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,5 @@
33
"name": "name1",
44
"description": "description1",
55
"required": true,
6-
"type": "string",
7-
"x-examples": {
8-
"test": {
9-
"summary": "summary3",
10-
"description": "description3"
11-
}
12-
}
6+
"type": "string"
137
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"in":"header","name":"name1","description":"description1","required":true,"type":"string","x-examples":{"test":{"summary":"summary3","description":"description3"}}}
1+
{"in":"header","name":"name1","description":"description1","required":true,"type":"string"}

test/Microsoft.OpenApi.Tests/Models/OpenApiParameterTests.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -296,13 +296,7 @@ public void SerializeAdvancedParameterAsV2JsonWorks()
296296
"name": "name1",
297297
"description": "description1",
298298
"required": true,
299-
"format": "double",
300-
"x-examples": {
301-
"test": {
302-
"summary": "summary3",
303-
"description": "description3"
304-
}
305-
}
299+
"format": "double"
306300
}
307301
""";
308302

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,6 @@ namespace Microsoft.OpenApi.Extensions
166166
public const string Name = "extensions";
167167
public void Evaluate(Json.Schema.EvaluationContext context) { }
168168
}
169-
[Json.Schema.SchemaKeyword("externalDocs")]
170-
public class ExternalDocsKeyword : Json.Schema.IJsonSchemaKeyword
171-
{
172-
public const string Name = "externalDocs";
173-
public ExternalDocsKeyword(Microsoft.OpenApi.Models.OpenApiExternalDocs value) { }
174-
public Microsoft.OpenApi.Models.OpenApiExternalDocs Value { get; }
175-
public void Evaluate(Json.Schema.EvaluationContext context) { }
176-
}
177169
public static class JsonSchemaBuilderExtensions
178170
{
179171
public static Json.Schema.JsonSchemaBuilder AdditionalPropertiesAllowed(this Json.Schema.JsonSchemaBuilder builder, bool additionalPropertiesAllowed) { }
@@ -182,8 +174,6 @@ namespace Microsoft.OpenApi.Extensions
182174
public static Json.Schema.JsonSchemaBuilder ExclusiveMinimum(this Json.Schema.JsonSchemaBuilder builder, bool value) { }
183175
public static Json.Schema.JsonSchemaBuilder Extensions(this Json.Schema.JsonSchemaBuilder builder, System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Interfaces.IOpenApiExtension> extensions) { }
184176
public static Json.Schema.JsonSchemaBuilder Nullable(this Json.Schema.JsonSchemaBuilder builder, bool value) { }
185-
public static Json.Schema.JsonSchemaBuilder OpenApiExternalDocs(this Json.Schema.JsonSchemaBuilder builder, Microsoft.OpenApi.Models.OpenApiExternalDocs externalDocs) { }
186-
public static Json.Schema.JsonSchemaBuilder Remove(this Json.Schema.JsonSchemaBuilder builder, string keyword) { }
187177
public static Json.Schema.JsonSchemaBuilder Summary(this Json.Schema.JsonSchemaBuilder builder, string summary) { }
188178
}
189179
public static class JsonSchemaExtensions
@@ -194,7 +184,6 @@ namespace Microsoft.OpenApi.Extensions
194184
public static Microsoft.OpenApi.Extensions.DiscriminatorKeyword GetOpenApiDiscriminator(this Json.Schema.JsonSchema schema) { }
195185
public static bool? GetOpenApiExclusiveMaximum(this Json.Schema.JsonSchema schema) { }
196186
public static bool? GetOpenApiExclusiveMinimum(this Json.Schema.JsonSchema schema) { }
197-
public static Microsoft.OpenApi.Models.OpenApiExternalDocs GetOpenApiExternalDocs(this Json.Schema.JsonSchema schema) { }
198187
public static string GetSummary(this Json.Schema.JsonSchema schema) { }
199188
}
200189
[Json.Schema.SchemaKeyword("nullable")]
@@ -310,7 +299,7 @@ namespace Microsoft.OpenApi.MicrosoftExtensions
310299
public class EnumDescription : Microsoft.OpenApi.Interfaces.IOpenApiElement
311300
{
312301
public EnumDescription() { }
313-
public EnumDescription(System.Text.Json.Nodes.JsonObject source) { }
302+
public EnumDescription(Microsoft.OpenApi.Any.OpenApiObject source) { }
314303
public string Description { get; set; }
315304
public string Name { get; set; }
316305
public string Value { get; set; }
@@ -324,15 +313,15 @@ namespace Microsoft.OpenApi.MicrosoftExtensions
324313
public string Version { get; set; }
325314
public static string Name { get; }
326315
public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { }
327-
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiDeprecationExtension Parse(Microsoft.OpenApi.Any.OpenApiAny source) { }
316+
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiDeprecationExtension Parse(Microsoft.OpenApi.Any.IOpenApiAny source) { }
328317
}
329318
public class OpenApiEnumFlagsExtension : Microsoft.OpenApi.Interfaces.IOpenApiExtension
330319
{
331320
public OpenApiEnumFlagsExtension() { }
332321
public bool IsFlags { get; set; }
333322
public static string Name { get; }
334323
public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { }
335-
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiEnumFlagsExtension Parse(Microsoft.OpenApi.Any.OpenApiAny source) { }
324+
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiEnumFlagsExtension Parse(Microsoft.OpenApi.Any.IOpenApiAny source) { }
336325
}
337326
public class OpenApiEnumValuesDescriptionExtension : Microsoft.OpenApi.Interfaces.IOpenApiExtension
338327
{
@@ -341,7 +330,7 @@ namespace Microsoft.OpenApi.MicrosoftExtensions
341330
public System.Collections.Generic.List<Microsoft.OpenApi.MicrosoftExtensions.EnumDescription> ValuesDescriptions { get; set; }
342331
public static string Name { get; }
343332
public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { }
344-
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiEnumValuesDescriptionExtension Parse(Microsoft.OpenApi.Any.OpenApiAny source) { }
333+
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiEnumValuesDescriptionExtension Parse(Microsoft.OpenApi.Any.IOpenApiAny source) { }
345334
}
346335
public class OpenApiPagingExtension : Microsoft.OpenApi.Interfaces.IOpenApiExtension
347336
{
@@ -351,23 +340,23 @@ namespace Microsoft.OpenApi.MicrosoftExtensions
351340
public string OperationName { get; set; }
352341
public static string Name { get; }
353342
public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { }
354-
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiPagingExtension Parse(Microsoft.OpenApi.Any.OpenApiAny source) { }
343+
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiPagingExtension Parse(Microsoft.OpenApi.Any.IOpenApiAny source) { }
355344
}
356345
public class OpenApiPrimaryErrorMessageExtension : Microsoft.OpenApi.Interfaces.IOpenApiExtension
357346
{
358347
public OpenApiPrimaryErrorMessageExtension() { }
359348
public bool IsPrimaryErrorMessage { get; set; }
360349
public static string Name { get; }
361350
public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { }
362-
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiPrimaryErrorMessageExtension Parse(Microsoft.OpenApi.Any.OpenApiAny source) { }
351+
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiPrimaryErrorMessageExtension Parse(Microsoft.OpenApi.Any.IOpenApiAny source) { }
363352
}
364353
public class OpenApiReservedParameterExtension : Microsoft.OpenApi.Interfaces.IOpenApiExtension
365354
{
366355
public OpenApiReservedParameterExtension() { }
367356
public bool? IsReserved { get; set; }
368357
public static string Name { get; }
369358
public void Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) { }
370-
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiReservedParameterExtension Parse(Microsoft.OpenApi.Any.OpenApiAny source) { }
359+
public static Microsoft.OpenApi.MicrosoftExtensions.OpenApiReservedParameterExtension Parse(Microsoft.OpenApi.Any.IOpenApiAny source) { }
371360
}
372361
}
373362
namespace Microsoft.OpenApi.Models
@@ -1490,7 +1479,6 @@ namespace Microsoft.OpenApi.Writers
14901479
void WriteRaw(string value);
14911480
void WriteStartArray();
14921481
void WriteStartObject();
1493-
void WriteV2Examples(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.Models.OpenApiExample example, Microsoft.OpenApi.OpenApiSpecVersion version);
14941482
void WriteValue(bool value);
14951483
void WriteValue(decimal value);
14961484
void WriteValue(int value);
@@ -1554,7 +1542,6 @@ namespace Microsoft.OpenApi.Writers
15541542
public abstract void WriteRaw(string value);
15551543
public abstract void WriteStartArray();
15561544
public abstract void WriteStartObject();
1557-
public void WriteV2Examples(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.Models.OpenApiExample example, Microsoft.OpenApi.OpenApiSpecVersion version) { }
15581545
public virtual void WriteValue(bool value) { }
15591546
public virtual void WriteValue(System.DateTime value) { }
15601547
public virtual void WriteValue(System.DateTimeOffset value) { }
@@ -1585,8 +1572,6 @@ namespace Microsoft.OpenApi.Writers
15851572
where T : struct { }
15861573
public static void WriteProperty<T>(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, T? value)
15871574
where T : struct { }
1588-
public static void WriteRequiredCollection<T>(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IEnumerable<T> elements, System.Action<Microsoft.OpenApi.Writers.IOpenApiWriter, T> action)
1589-
where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { }
15901575
public static void WriteRequiredMap(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary<string, string> elements, System.Action<Microsoft.OpenApi.Writers.IOpenApiWriter, string> action) { }
15911576
public static void WriteRequiredMap<T>(this Microsoft.OpenApi.Writers.IOpenApiWriter writer, string name, System.Collections.Generic.IDictionary<string, T> elements, System.Action<Microsoft.OpenApi.Writers.IOpenApiWriter, T> action)
15921577
where T : Microsoft.OpenApi.Interfaces.IOpenApiElement { }

test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -52,8 +52,8 @@ public void RuleSetConstructorsReturnsTheCorrectRules()
5252
Assert.Empty(ruleSet_4.Rules);
5353

5454
// Update the number if you add new default rule(s).
55-
Assert.Equal(23, ruleSet_1.Rules.Count);
56-
Assert.Equal(23, ruleSet_2.Rules.Count);
55+
Assert.Equal(22, ruleSet_1.Rules.Count);
56+
Assert.Equal(22, ruleSet_2.Rules.Count);
5757
Assert.Equal(3, ruleSet_3.Rules.Count);
5858
}
5959

0 commit comments

Comments
 (0)