Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #1547: Make RemoveNullability virtual for extendability #1548

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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