Skip to content

Commit

Permalink
Pass entire ContextualType to SchemaProcessorContext (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardelean-vlad committed May 15, 2022
1 parent f782bbb commit 5a5ceb6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/NJsonSchema/Generation/JsonSchemaGenerator.cs
Expand Up @@ -798,7 +798,7 @@ private void ApplyAdditionalProperties<TSchemaType>(TSchemaType schema, Type typ

private void ApplySchemaProcessors(JsonSchema schema, ContextualType contextualType, JsonSchemaResolver schemaResolver)
{
var context = new SchemaProcessorContext(contextualType.OriginalType, schema, schemaResolver, this, Settings);
var context = new SchemaProcessorContext(contextualType, schema, schemaResolver, this, Settings);
foreach (var processor in Settings.SchemaProcessors)
{
processor.Process(context);
Expand Down
13 changes: 9 additions & 4 deletions src/NJsonSchema/Generation/SchemaProcessorContext.cs
Expand Up @@ -6,6 +6,7 @@
// <author>Rico Suter, mail@rsuter.com</author>
//-----------------------------------------------------------------------

using Namotion.Reflection;
using System;

namespace NJsonSchema.Generation
Expand All @@ -14,22 +15,26 @@ namespace NJsonSchema.Generation
public class SchemaProcessorContext
{
/// <summary>Initializes a new instance of the <see cref="SchemaProcessorContext" /> class.</summary>
/// <param name="type">The source type.</param>
/// <param name="contextualType">The source contextual type.</param>
/// <param name="schema">The JSON Schema.</param>
/// <param name="resolver">The resolver.</param>
/// <param name="generator">The generator.</param>
/// <param name="settings">The settings.</param>
public SchemaProcessorContext(Type type, JsonSchema schema, JsonSchemaResolver resolver, JsonSchemaGenerator generator, JsonSchemaGeneratorSettings settings)
public SchemaProcessorContext(ContextualType contextualType, JsonSchema schema, JsonSchemaResolver resolver, JsonSchemaGenerator generator, JsonSchemaGeneratorSettings settings)
{
Type = type;
ContextualType = contextualType;
Schema = schema;
Resolver = resolver;
Generator = generator;
Settings = settings;
}

/// <summary>The source type.</summary>
public Type Type { get; }
[Obsolete("Use ContextualType to obtain this instead.")]
public Type Type { get => ContextualType.OriginalType; }

/// <summary>The source contextual type.</summary>
public ContextualType ContextualType { get; }

/// <summary>The JSON Schema to process.</summary>
public JsonSchema Schema { get; }
Expand Down
Expand Up @@ -7,7 +7,6 @@
//-----------------------------------------------------------------------

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
using NJsonSchema.Converters;
using System;

Expand All @@ -32,7 +31,7 @@ public DiscriminatorSchemaProcessor(Type baseType, string discriminator)

public void Process(SchemaProcessorContext context)
{
if (context.Type == BaseType)
if (context.ContextualType.OriginalType == BaseType)
{
var schema = context.Schema;
schema.Discriminator = Discriminator;
Expand Down

0 comments on commit 5a5ceb6

Please sign in to comment.