Skip to content

Commit

Permalink
#1547: Make RemoveNullability virtual for extendability
Browse files Browse the repository at this point in the history
This allows to implement different logic e.g. treat JsonSchema.OneOf
to have multiple (non nullable) items instead of zero or one.
  • Loading branch information
SamuelBerger committed Aug 7, 2022
1 parent 5476815 commit e678a7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/NJsonSchema.CodeGeneration.Tests/ApiSurfaceGuard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace NJsonSchema.CodeGeneration.Tests;

public class ApiSurfaceGuard
{
private abstract class TypeResolverBaseApiGuard : TypeResolverBase
{
protected TypeResolverBaseApiGuard(CodeGeneratorSettingsBase settings) : base(settings)
{
}

// dummy implementation making sure this method stays overridable
public override string GetOrGenerateTypeName(JsonSchema schema, string typeNameHint)
{
throw new System.NotImplementedException();
}

// dummy implementation making sure this method stays overridable
public override JsonSchema RemoveNullability(JsonSchema schema)
{
throw new System.NotImplementedException();
}
}
}
2 changes: 1 addition & 1 deletion src/NJsonSchema.CodeGeneration/TypeResolverBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void RegisterSchemaDefinitions(IDictionary<string, JsonSchema> definition
/// <summary>Removes a nullable oneOf reference if available.</summary>
/// <param name="schema">The schema.</param>
/// <returns>The actually resolvable schema</returns>
public JsonSchema RemoveNullability(JsonSchema schema)
public virtual JsonSchema RemoveNullability(JsonSchema schema)
{
// TODO: Method on JsonSchema4?
return schema.OneOf.FirstOrDefault(o => !o.IsNullable(SchemaType.JsonSchema)) ?? schema;
Expand Down

0 comments on commit e678a7e

Please sign in to comment.