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

Added (on)SchemaGenerated to JSchemaGenerator #282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions Src/Newtonsoft.Json.Schema/Generation/JSchemaGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public virtual IContractResolver ContractResolver
set => _contractResolver = value;
}

/// <summary>
/// Is called each time a schema is generated.
/// Allows the user to manipulate the schema.
/// </summary>
public Action<Type, JSchema>? SchemaGenerated;

/// <summary>
/// Initializes a new instance of the <see cref="JSchemaGenerator"/> class.
/// </summary>
Expand Down Expand Up @@ -135,5 +141,14 @@ public virtual JSchema Generate(Type type, bool rootSchemaNullable)
JSchemaGeneratorInternal generator = new JSchemaGeneratorInternal(this);
return generator.Generate(type, required);
}

/// <summary>
/// Is called each time a schema is generated.
/// Allows the user to manipulate the schema.
/// </summary>
internal protected virtual void OnSchemaGenerated(Type type, JSchema schema)
{
this.SchemaGenerated?.Invoke(type, schema);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ private JSchema GenerateInternal(Type type, Required? valueRequired, JsonPropert
PopulateSchema(schema, contract, memberProperty, resolvedRequired);
}

_generator.OnSchemaGenerated(type, schema);

return schema;
}

Expand Down