Skip to content

Commit 7f764af

Browse files
authored
#1547: Make RemoveNullability virtual for extendability (#1548)
This allows to implement different logic e.g. treat JsonSchema.OneOf to have multiple (non nullable) items instead of zero or one.
1 parent 26766ce commit 7f764af

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace NJsonSchema.CodeGeneration.Tests;
2+
3+
public class ApiSurfaceGuard
4+
{
5+
private abstract class TypeResolverBaseApiGuard : TypeResolverBase
6+
{
7+
protected TypeResolverBaseApiGuard(CodeGeneratorSettingsBase settings) : base(settings)
8+
{
9+
}
10+
11+
// dummy implementation making sure this method stays overridable
12+
public override string GetOrGenerateTypeName(JsonSchema schema, string typeNameHint)
13+
{
14+
throw new System.NotImplementedException();
15+
}
16+
17+
// dummy implementation making sure this method stays overridable
18+
public override JsonSchema RemoveNullability(JsonSchema schema)
19+
{
20+
throw new System.NotImplementedException();
21+
}
22+
}
23+
}

src/NJsonSchema.CodeGeneration/TypeResolverBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void RegisterSchemaDefinitions(IDictionary<string, JsonSchema> definition
8484
/// <summary>Removes a nullable oneOf reference if available.</summary>
8585
/// <param name="schema">The schema.</param>
8686
/// <returns>The actually resolvable schema</returns>
87-
public JsonSchema RemoveNullability(JsonSchema schema)
87+
public virtual JsonSchema RemoveNullability(JsonSchema schema)
8888
{
8989
// TODO: Method on JsonSchema4?
9090
return schema.OneOf.FirstOrDefault(o => !o.IsNullable(SchemaType.JsonSchema)) ?? schema;

0 commit comments

Comments
 (0)