Repository: victools/jsonschema-generator
Pull request #69 (2020-04-06 19:47:12)

Provide generation context to attribute overrides
- Offering also `SchemaGenerationContext.createStandardDefinition(FieldScope, CustomPropertyDefinitionProvider)`
- Offering also `SchemaGenerationContext.createStandardDefinition(MethodScope, CustomPropertyDefinitionProvider)`
- Alternative `SchemaGenerationConfigPart.withInstanceAttributeOverride(InstanceAttributeOverrideV2)` with access to `SchemaGenerationContext`
- Providing access to the `SchemaGenerationContext` when invoking `TypeAttributeOverrideV2` (potentially BREAKING change in case of lambda usage)


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b51dc49..162b1a3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,9 +8,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### `jsonschema-generator`
 #### Added
 - New `Option.INLINE_ALL_SCHEMAS` to enforce no `definitions`/`$defs` to be produced (throwing exception if there is at least one circular reference)
+- Offering also `SchemaGenerationContext.createStandardDefinition(FieldScope, CustomPropertyDefinitionProvider)`
+- Offering also `SchemaGenerationContext.createStandardDefinition(MethodScope, CustomPropertyDefinitionProvider)`
+- Alternative `SchemaGenerationConfigPart.withInstanceAttributeOverride(InstanceAttributeOverrideV2)` with access to `SchemaGenerationContext`
 
 #### Changed
 - Enhance `Option.ALLOF_CLEANUP_AT_THE_END` to also reduce `allOf` if multiple parts have the same attributes but with equal values
+- Providing access to the `SchemaGenerationContext` when invoking `TypeAttributeOverrideV2` (potentially BREAKING change in case of lambda usage)
+
+#### Deprecated
+- `SchemaGenerationConfigPart.withInstanceAttributeOverride(InstanceAttributeOverride)` without access to SchemaGenerationContext`
+- `InstanceAttributeOverride` interface without access to `SchemaGenerationContext`
+- `TypeAttributeOverride` interface with only access to `SchemaGenerationConfig` and not `SchemaGenerationContext`
+- Ambiguous `SchemaGeneratorConfigBuilder.with(CustomDefinitionProviderV2)`
+- Ambiguous `SchemaGeneratorConfigBuilder.with(TypeAttributeOverrideV2)`
 
 ### `jsonschema-module-jackson`
 #### Added
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/InstanceAttributeOverride.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/InstanceAttributeOverride.java
index 35a847a..0aece2a 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/InstanceAttributeOverride.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/InstanceAttributeOverride.java
@@ -22,8 +22,10 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
  * Entry point for customising a JSON Schema being generated for a certain kind of reference/context.
  *
  * @param <M> type of the reference/context to modify
+ * @deprecated use {@link InstanceAttributeOverrideV2} instead
  */
-public interface InstanceAttributeOverride<M extends MemberScope<?, ?>> {
+@Deprecated
+public interface InstanceAttributeOverride<M extends MemberScope<?, ?>> extends InstanceAttributeOverrideV2<M> {
 
     /**
      * Add/remove attributes on the given JSON Schema node – this is specifically intended for attributes relating to a particular instance.
@@ -34,4 +36,9 @@ public interface InstanceAttributeOverride<M extends MemberScope<?, ?>> {
      * @param member reference/context to which the collected attributes in the JSON Schema node are referring
      */
     void overrideInstanceAttributes(ObjectNode jsonSchemaAttributesNode, M member);
+
+    @Override
+    default void overrideInstanceAttributes(ObjectNode jsonSchemaAttributesNode, M member, SchemaGenerationContext context) {
+        this.overrideInstanceAttributes(jsonSchemaAttributesNode, member);
+    }
 }
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/InstanceAttributeOverrideV2.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/InstanceAttributeOverrideV2.java
new file mode 100644
index 0000000..04d6c79
--- /dev/null
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/InstanceAttributeOverrideV2.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2020 VicTools.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.github.victools.jsonschema.generator;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * Entry point for customising the JSON Schema attributes being collected for a property.
+ *
+ * @param <M> type of the reference/context to modify
+ */
+public interface InstanceAttributeOverrideV2<M extends MemberScope<?, ?>> {
+
+    /**
+     * Add/remove attributes on the given JSON Schema node – this is specifically intended for attributes relating to a particular instance.
+     * <br>
+     * E.g. {@link SchemaKeyword#TAG_DESCRIPTION}, {@link SchemaKeyword#TAG_MINIMUM}, {@link SchemaKeyword#TAG_MAXIMUM_EXCLUSIVE}
+     *
+     * @param collectedMemberAttributes node to modify
+     * @param member reference/context to which the collected attributes in the JSON Schema node are referring
+     * @param context generation context
+     */
+    void overrideInstanceAttributes(ObjectNode collectedMemberAttributes, M member, SchemaGenerationContext context);
+}
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGenerationContext.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGenerationContext.java
index 33e8034..c45bc14 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGenerationContext.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGenerationContext.java
@@ -89,6 +89,38 @@ public interface SchemaGenerationContext {
      */
     ObjectNode createStandardDefinition(ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider);
 
+    /**
+     * Create a standard definition for the given property. Ignoring custom definitions up to the given one, but respecting others.
+     * <br>
+     * The returned schema will be inlined and fully populated, i.e. it may be further manipulated - at the risk of an endless loop in case of a
+     * circular reference.
+     *
+     * @param targetScope property to create definition node for
+     * @param ignoredDefinitionProvider custom definition provider to ignore
+     * @return inline definition for the given field
+     *
+     * @see #createDefinitionReference(ResolvedType)
+     * @see #createStandardDefinitionReference(FieldScope, CustomPropertyDefinitionProvider)
+     */
+    ObjectNode createStandardDefinition(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider);
+
+    /**
+     * Create a standard definition for the given property. Ignoring custom definitions up to the given one, but respecting others.
+     * <br>
+     * The returned schema will be inlined and fully populated, i.e. it may be further manipulated - at the risk of an endless loop in case of a
+     * circular reference.
+     * <br>
+     * The returned type is always an {@link ObjectNode} unless the given method is {@code void}, which will result in a {@link BooleanNode#FALSE}.
+     *
+     * @param targetScope property to create definition node for
+     * @param ignoredDefinitionProvider custom definition provider to ignore
+     * @return inline definition for the given method
+     *
+     * @see #createDefinition(ResolvedType)
+     * @see #createStandardDefinitionReference(MethodScope, CustomPropertyDefinitionProvider)
+     */
+    JsonNode createStandardDefinition(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider);
+
     /**
      * Create a standard definition for the given targetType. Ignoring custom definitions up to the given one, but respecting others.
      * <br>
@@ -115,6 +147,7 @@ public interface SchemaGenerationContext {
      *         at the very end of the schema generation
      *
      * @see #createDefinitionReference(ResolvedType)
+     * @see #createStandardDefinition(FieldScope, CustomPropertyDefinitionProvider)
      */
     ObjectNode createStandardDefinitionReference(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider);
 
@@ -132,6 +165,7 @@ public interface SchemaGenerationContext {
      *         at the very end of the schema generation
      *
      * @see #createDefinitionReference(ResolvedType)
+     * @see #createStandardDefinition(MethodScope, CustomPropertyDefinitionProvider)
      */
     JsonNode createStandardDefinitionReference(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider);
 
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfig.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfig.java
index d90eec4..557ef29 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfig.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfig.java
@@ -154,21 +154,21 @@ public interface SchemaGeneratorConfig {
      *
      * @return overrides of a given JSON Schema node's type attributes
      */
-    List<TypeAttributeOverride> getTypeAttributeOverrides();
+    List<TypeAttributeOverrideV2> getTypeAttributeOverrides();
 
     /**
      * Getter for the applicable instance attribute overrides for fields.
      *
      * @return overrides of a given JSON Schema node's instance attributes
      */
-    List<InstanceAttributeOverride<FieldScope>> getFieldAttributeOverrides();
+    List<InstanceAttributeOverrideV2<FieldScope>> getFieldAttributeOverrides();
 
     /**
      * Getter for the applicable instance attribute overrides for methods.
      *
      * @return overrides of a given JSON Schema node's instance attributes
      */
-    List<InstanceAttributeOverride<MethodScope>> getMethodAttributeOverrides();
+    List<InstanceAttributeOverrideV2<MethodScope>> getMethodAttributeOverrides();
 
     /**
      * Check whether a field/property is nullable.
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigBuilder.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigBuilder.java
index 2aa6692..c13f449 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigBuilder.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigBuilder.java
@@ -210,7 +210,9 @@ public class SchemaGeneratorConfigBuilder {
      *
      * @param definitionProvider provider of a custom definition to register, which may return null
      * @return this builder instance (for chaining)
+     * @deprecated use {@link SchemaGeneratorGeneralConfigPart#withCustomDefinitionProvider(CustomDefinitionProviderV2)} instead
      */
+    @Deprecated
     public SchemaGeneratorConfigBuilder with(CustomDefinitionProviderV2 definitionProvider) {
         this.typesInGeneralConfigPart.withCustomDefinitionProvider(definitionProvider);
         return this;
@@ -221,7 +223,9 @@ public class SchemaGeneratorConfigBuilder {
      *
      * @param override adding/removing attributes on a JSON Schema node – specifically intended for attributes relating to the type in general.
      * @return this builder instance (for chaining)
+     * @deprecated use {@link SchemaGeneratorGeneralConfigPart#withTypeAttributeOverride(TypeAttributeOverrideV2)} instead
      */
+    @Deprecated
     public SchemaGeneratorConfigBuilder with(TypeAttributeOverride override) {
         this.typesInGeneralConfigPart.withTypeAttributeOverride(override);
         return this;
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigPart.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigPart.java
index eb9ba10..94d98a9 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigPart.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigPart.java
@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
 public class SchemaGeneratorConfigPart<M extends MemberScope<?, ?>> extends SchemaGeneratorTypeConfigPart<M> {
 
     private final List<CustomPropertyDefinitionProvider<M>> customDefinitionProviders = new ArrayList<>();
-    private final List<InstanceAttributeOverride<M>> instanceAttributeOverrides = new ArrayList<>();
+    private final List<InstanceAttributeOverrideV2<M>> instanceAttributeOverrides = new ArrayList<>();
 
     /*
      * Customising options for properties in a schema with "type": object;
@@ -81,8 +81,20 @@ public class SchemaGeneratorConfigPart<M extends MemberScope<?, ?>> extends Sche
      *
      * @param override override of a given JSON Schema node's instance attributes
      * @return this config part (for chaining)
+     * @deprecated use {@link #withInstanceAttributeOverride(InstanceAttributeOverrideV2)} instead
      */
+    @Deprecated
     public SchemaGeneratorConfigPart<M> withInstanceAttributeOverride(InstanceAttributeOverride<M> override) {
+        return this.withInstanceAttributeOverride((InstanceAttributeOverrideV2<M>) override);
+    }
+
+    /**
+     * Setter for override of attributes on a given JSON Schema node in the respective member.
+     *
+     * @param override override of a given JSON Schema node's instance attributes
+     * @return this config part (for chaining)
+     */
+    public SchemaGeneratorConfigPart<M> withInstanceAttributeOverride(InstanceAttributeOverrideV2<M> override) {
         this.instanceAttributeOverrides.add(override);
         return this;
     }
@@ -92,7 +104,7 @@ public class SchemaGeneratorConfigPart<M extends MemberScope<?, ?>> extends Sche
      *
      * @return overrides of a given JSON Schema node's instance attributes
      */
-    public List<InstanceAttributeOverride<M>> getInstanceAttributeOverrides() {
+    public List<InstanceAttributeOverrideV2<M>> getInstanceAttributeOverrides() {
         return Collections.unmodifiableList(this.instanceAttributeOverrides);
     }
 
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorGeneralConfigPart.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorGeneralConfigPart.java
index a2bb2ee..1842c5e 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorGeneralConfigPart.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaGeneratorGeneralConfigPart.java
@@ -31,7 +31,7 @@ public class SchemaGeneratorGeneralConfigPart extends SchemaGeneratorTypeConfigP
 
     private final List<CustomDefinitionProviderV2> customDefinitionProviders = new ArrayList<>();
     private final List<SubtypeResolver> subtypeResolvers = new ArrayList<>();
-    private final List<TypeAttributeOverride> typeAttributeOverrides = new ArrayList<>();
+    private final List<TypeAttributeOverrideV2> typeAttributeOverrides = new ArrayList<>();
 
     private final List<ConfigFunction<TypeScope, String>> idResolvers = new ArrayList<>();
     private final List<ConfigFunction<TypeScope, String>> anchorResolvers = new ArrayList<>();
@@ -86,7 +86,7 @@ public class SchemaGeneratorGeneralConfigPart extends SchemaGeneratorTypeConfigP
      * @param override adding/removing attributes on a JSON Schema node – specifically intended for attributes relating to the type in general.
      * @return this builder instance (for chaining)
      */
-    public SchemaGeneratorGeneralConfigPart withTypeAttributeOverride(TypeAttributeOverride override) {
+    public SchemaGeneratorGeneralConfigPart withTypeAttributeOverride(TypeAttributeOverrideV2 override) {
         this.typeAttributeOverrides.add(override);
         return this;
     }
@@ -96,7 +96,7 @@ public class SchemaGeneratorGeneralConfigPart extends SchemaGeneratorTypeConfigP
      *
      * @return registered overrides to be applied in the given order
      */
-    public List<TypeAttributeOverride> getTypeAttributeOverrides() {
+    public List<TypeAttributeOverrideV2> getTypeAttributeOverrides() {
         return Collections.unmodifiableList(this.typeAttributeOverrides);
     }
 
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SubtypeResolver.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SubtypeResolver.java
index c77509d..feb048b 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SubtypeResolver.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SubtypeResolver.java
@@ -32,7 +32,7 @@ public interface SubtypeResolver {
     /**
      * Look-up the subtypes for a given type, that should be listed independently.
      * <br>
-     * If it returns null, the next subtype resolver is expected to be applied.An empty list will result only in the originally declared type to be
+     * If it returns null, the next subtype resolver is expected to be applied. An empty list will result only in the originally declared type to be
      * considered.
      * <br>
      * Returning a list with a single entry will treat the declared type as one-to-one alias for the returned type. Alternatively, you may want to
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeAttributeOverride.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeAttributeOverride.java
index 1e72c2c..ba62c85 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeAttributeOverride.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeAttributeOverride.java
@@ -16,13 +16,15 @@
 
 package com.github.victools.jsonschema.generator;
 
-import com.fasterxml.jackson.databind.JavaType;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 
 /**
- * Entry point for customising a JSON Schema being generated for a particular {@link JavaType}, i.e. the part that may be referenced multiple times.
+ * Entry point for customising a JSON Schema being generated for a particular java type, i.e. the part that may be referenced multiple times.
+ *
+ * @deprecated use {@link TypeAttributeOverrideV2} instead
  */
-public interface TypeAttributeOverride {
+@Deprecated
+public interface TypeAttributeOverride extends TypeAttributeOverrideV2 {
 
     /**
      * Add/remove attributes on the given JSON Schema node – this is specifically intended for attributes relating to the type in general.
@@ -35,4 +37,8 @@ public interface TypeAttributeOverride {
      */
     void overrideTypeAttributes(ObjectNode jsonSchemaTypeNode, TypeScope scope, SchemaGeneratorConfig config);
 
+    @Override
+    default void overrideTypeAttributes(ObjectNode collectedTypeAttributes, TypeScope scope, SchemaGenerationContext context) {
+        this.overrideTypeAttributes(collectedTypeAttributes, scope, context.getGeneratorConfig());
+    }
 }
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeAttributeOverrideV2.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeAttributeOverrideV2.java
new file mode 100644
index 0000000..55485fb
--- /dev/null
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeAttributeOverrideV2.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2020 VicTools.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.github.victools.jsonschema.generator;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * Entry point for customising the JSON Schema attributes being collected for a type in general, i.e. the part that may be referenced multiple times.
+ */
+public interface TypeAttributeOverrideV2 {
+
+    /**
+     * Add/remove attributes on the given JSON Schema node – this is specifically intended for attributes relating to the type in general.
+     * <br>
+     * E.g. {@link SchemaKeyword#TAG_FORMAT}, {@link SchemaKeyword#TAG_PATTERN}, {@link SchemaKeyword#TAG_REQUIRED}
+     *
+     * @param collectedTypeAttributes node to modify (the part that may be referenced multiple times)
+     * @param scope the type representation associated with the JSON Schema node
+     * @param context generation context
+     */
+    void overrideTypeAttributes(ObjectNode collectedTypeAttributes, TypeScope scope, SchemaGenerationContext context);
+}
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
index dc272b3..cdaa873 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/AttributeCollector.java
@@ -89,7 +89,7 @@ public class AttributeCollector {
         collector.setArrayMaxItems(node, config.resolveArrayMaxItems(field), generationContext);
         collector.setArrayUniqueItems(node, config.resolveArrayUniqueItems(field), generationContext);
         config.getFieldAttributeOverrides()
-                .forEach(override -> override.overrideInstanceAttributes(node, field));
+                .forEach(override -> override.overrideInstanceAttributes(node, field, generationContext));
         return node;
     }
 
@@ -123,7 +123,7 @@ public class AttributeCollector {
         collector.setArrayMaxItems(node, config.resolveArrayMaxItems(method), generationContext);
         collector.setArrayUniqueItems(node, config.resolveArrayUniqueItems(method), generationContext);
         config.getMethodAttributeOverrides()
-                .forEach(override -> override.overrideInstanceAttributes(node, method));
+                .forEach(override -> override.overrideInstanceAttributes(node, method, generationContext));
         return node;
     }
 
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java
index 04b3a30..8fae6a8 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGenerationContextImpl.java
@@ -206,6 +206,16 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
         return definition;
     }
 
+    @Override
+    public ObjectNode createStandardDefinition(FieldScope targetScope, CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider) {
+        return this.createFieldSchema(targetScope, false, true, ignoredDefinitionProvider);
+    }
+
+    @Override
+    public JsonNode createStandardDefinition(MethodScope targetScope, CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider) {
+        return this.createMethodSchema(targetScope, false, true, ignoredDefinitionProvider);
+    }
+
     @Override
     public ObjectNode createStandardDefinitionReference(ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider) {
         ObjectNode definition = this.generatorConfig.createObjectNode();
@@ -217,13 +227,13 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
     @Override
     public ObjectNode createStandardDefinitionReference(FieldScope targetScope,
             CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider) {
-        return this.createFieldSchema(targetScope, false, ignoredDefinitionProvider);
+        return this.createFieldSchema(targetScope, false, false, ignoredDefinitionProvider);
     }
 
     @Override
     public JsonNode createStandardDefinitionReference(MethodScope targetScope,
             CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider) {
-        return this.createMethodSchema(targetScope, false, ignoredDefinitionProvider);
+        return this.createMethodSchema(targetScope, false, false, ignoredDefinitionProvider);
     }
 
     /**
@@ -310,7 +320,7 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
         }
         // apply overrides as the very last step
         this.generatorConfig.getTypeAttributeOverrides()
-                .forEach(override -> override.overrideTypeAttributes(definition, scope, this.generatorConfig));
+                .forEach(override -> override.overrideTypeAttributes(definition, scope, this));
     }
 
     /**
@@ -540,7 +550,7 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
         // consider declared type (instead of overridden one) for determining null-ability
         boolean isNullable = !field.getRawMember().isEnumConstant() && !field.isFakeContainerItemScope() && this.generatorConfig.isNullable(field);
         if (fieldOptions.size() == 1) {
-            collectedFields.put(propertyName, this.createFieldSchema(fieldOptions.get(0), isNullable, null));
+            collectedFields.put(propertyName, this.createFieldSchema(fieldOptions.get(0), isNullable, false, null));
         } else {
             ObjectNode subSchema = this.generatorConfig.createObjectNode();
             collectedFields.put(propertyName, subSchema);
@@ -549,7 +559,7 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
                 anyOfArray.addObject()
                         .put(this.getKeyword(SchemaKeyword.TAG_TYPE), this.getKeyword(SchemaKeyword.TAG_TYPE_NULL));
             }
-            fieldOptions.forEach(option -> anyOfArray.add(this.createFieldSchema(option, false, null)));
+            fieldOptions.forEach(option -> anyOfArray.add(this.createFieldSchema(option, false, false, null)));
         }
     }
 
@@ -558,14 +568,15 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
      *
      * @param field field/property to populate the schema node for
      * @param isNullable whether the field/property's value may be null
+     * @param forceInlineDefinition whether to generate an inline definition without registering it in this context
      * @param ignoredDefinitionProvider first custom definition provider to ignore
      * @return schema node representing the given field/property
      */
-    private ObjectNode createFieldSchema(FieldScope field, boolean isNullable,
+    private ObjectNode createFieldSchema(FieldScope field, boolean isNullable, boolean forceInlineDefinition,
             CustomPropertyDefinitionProvider<FieldScope> ignoredDefinitionProvider) {
         ObjectNode subSchema = this.generatorConfig.createObjectNode();
         ObjectNode fieldAttributes = AttributeCollector.collectFieldAttributes(field, this);
-        this.populateMemberSchema(field, subSchema, isNullable, fieldAttributes, ignoredDefinitionProvider);
+        this.populateMemberSchema(field, subSchema, isNullable, forceInlineDefinition, fieldAttributes, ignoredDefinitionProvider);
         return subSchema;
     }
 
@@ -611,7 +622,7 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
         boolean isNullable = methodWithNameOverride.isVoid()
                 || !method.isFakeContainerItemScope() && this.generatorConfig.isNullable(methodWithNameOverride);
         if (methodOptions.size() == 1) {
-            collectedMethods.put(propertyName, this.createMethodSchema(methodOptions.get(0), isNullable, null));
+            collectedMethods.put(propertyName, this.createMethodSchema(methodOptions.get(0), isNullable, false, null));
         } else {
             ObjectNode subSchema = this.generatorConfig.createObjectNode();
             collectedMethods.put(propertyName, subSchema);
@@ -620,7 +631,7 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
                 anyOfArray.add(this.generatorConfig.createObjectNode()
                         .put(this.getKeyword(SchemaKeyword.TAG_TYPE), this.getKeyword(SchemaKeyword.TAG_TYPE_NULL)));
             }
-            methodOptions.forEach(option -> anyOfArray.add(this.createMethodSchema(option, false, null)));
+            methodOptions.forEach(option -> anyOfArray.add(this.createMethodSchema(option, false, false, null)));
         }
     }
 
@@ -629,17 +640,18 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
      *
      * @param method method to populate the schema node for
      * @param isNullable whether the method's return value may be null
+     * @param forceInlineDefinition whether to generate an inline definition without registering it in this context
      * @param ignoredDefinitionProvider first custom definition provider to ignore
      * @return schema node representing the given method's return type
      */
-    private JsonNode createMethodSchema(MethodScope method, boolean isNullable,
+    private JsonNode createMethodSchema(MethodScope method, boolean isNullable, boolean forceInlineDefinition,
             CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider) {
         if (method.isVoid()) {
             return BooleanNode.FALSE;
         }
         ObjectNode subSchema = this.generatorConfig.createObjectNode();
         ObjectNode methodAttributes = AttributeCollector.collectMethodAttributes(method, this);
-        this.populateMemberSchema(method, subSchema, isNullable, methodAttributes, ignoredDefinitionProvider);
+        this.populateMemberSchema(method, subSchema, isNullable, forceInlineDefinition, methodAttributes, ignoredDefinitionProvider);
         return subSchema;
     }
 
@@ -650,12 +662,13 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
      * @param scope field's type or method return value's type that should be represented by the given targetNode
      * @param targetNode node in the JSON schema that should represent the associated javaType and include the separately collected attributes
      * @param isNullable whether the field/method's return value the javaType refers to is allowed to be null in the declaringType
+     * @param forceInlineDefinition whether to generate an inline definition without registering it in this context
      * @param collectedAttributes separately collected attribute for the field/method in their respective declaring type
      * @param ignoredDefinitionProvider first custom definition provider to ignore
      * @see #populateField(FieldScope, Map, Set)
      * @see #populateMethod(MethodScope, Map, Set)
      */
-    private <M extends MemberScope<?, ?>> void populateMemberSchema(M scope, ObjectNode targetNode, boolean isNullable,
+    private <M extends MemberScope<?, ?>> void populateMemberSchema(M scope, ObjectNode targetNode, boolean isNullable, boolean forceInlineDefinition,
             ObjectNode collectedAttributes, CustomPropertyDefinitionProvider<M> ignoredDefinitionProvider) {
         final CustomDefinition customDefinition = this.generatorConfig.getCustomDefinition(scope, this, ignoredDefinitionProvider);
         if (customDefinition != null && customDefinition.isMeantToBeInline()) {
@@ -690,7 +703,7 @@ public class SchemaGenerationContextImpl implements SchemaGenerationContext {
             }
             // only add reference for separate definition if it is not a fixed type that should be in-lined
             try {
-                this.traverseGenericType(scope, referenceContainer, isNullable, false, null);
+                this.traverseGenericType(scope, referenceContainer, isNullable, forceInlineDefinition, null);
             } catch (UnsupportedOperationException ex) {
                 logger.warn("Skipping type definition due to error", ex);
             }
diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java
index 6b8a6b8..d04cdcf 100644
--- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java
+++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImpl.java
@@ -25,7 +25,7 @@ import com.github.victools.jsonschema.generator.CustomDefinitionProviderV2;
 import com.github.victools.jsonschema.generator.CustomPropertyDefinition;
 import com.github.victools.jsonschema.generator.CustomPropertyDefinitionProvider;
 import com.github.victools.jsonschema.generator.FieldScope;
-import com.github.victools.jsonschema.generator.InstanceAttributeOverride;
+import com.github.victools.jsonschema.generator.InstanceAttributeOverrideV2;
 import com.github.victools.jsonschema.generator.MemberScope;
 import com.github.victools.jsonschema.generator.MethodScope;
 import com.github.victools.jsonschema.generator.Option;
@@ -35,7 +35,7 @@ import com.github.victools.jsonschema.generator.SchemaGeneratorConfigPart;
 import com.github.victools.jsonschema.generator.SchemaGeneratorGeneralConfigPart;
 import com.github.victools.jsonschema.generator.SchemaKeyword;
 import com.github.victools.jsonschema.generator.SchemaVersion;
-import com.github.victools.jsonschema.generator.TypeAttributeOverride;
+import com.github.victools.jsonschema.generator.TypeAttributeOverrideV2;
 import com.github.victools.jsonschema.generator.TypeScope;
 import java.lang.reflect.Type;
 import java.math.BigDecimal;
@@ -220,17 +220,17 @@ public class SchemaGeneratorConfigImpl implements SchemaGeneratorConfig {
     }
 
     @Override
-    public List<TypeAttributeOverride> getTypeAttributeOverrides() {
+    public List<TypeAttributeOverrideV2> getTypeAttributeOverrides() {
         return this.typesInGeneralConfigPart.getTypeAttributeOverrides();
     }
 
     @Override
-    public List<InstanceAttributeOverride<FieldScope>> getFieldAttributeOverrides() {
+    public List<InstanceAttributeOverrideV2<FieldScope>> getFieldAttributeOverrides() {
         return this.fieldConfigPart.getInstanceAttributeOverrides();
     }
 
     @Override
-    public List<InstanceAttributeOverride<MethodScope>> getMethodAttributeOverrides() {
+    public List<InstanceAttributeOverrideV2<MethodScope>> getMethodAttributeOverrides() {
         return this.methodConfigPart.getInstanceAttributeOverrides();
     }
 


Test patch:
diff --git a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigPartTest.java b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigPartTest.java
index b18d0b1..dd9a819 100644
--- a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigPartTest.java
+++ b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorConfigPartTest.java
@@ -48,10 +48,10 @@ public class SchemaGeneratorConfigPartTest {
 
     @Test
     public void testInstanceAttributeOverride() {
-        InstanceAttributeOverride<FieldScope> instanceOverride = (node, field) -> node.put("$comment", "test");
+        InstanceAttributeOverrideV2<FieldScope> instanceOverride = (node, _field, _context) -> node.put("$comment", "test");
         Assert.assertSame(this.instance, this.instance.withInstanceAttributeOverride(instanceOverride));
 
-        List<InstanceAttributeOverride<FieldScope>> instanceOverrideList = this.instance.getInstanceAttributeOverrides();
+        List<InstanceAttributeOverrideV2<FieldScope>> instanceOverrideList = this.instance.getInstanceAttributeOverrides();
         Assert.assertEquals(1, instanceOverrideList.size());
         Assert.assertSame(instanceOverride, instanceOverrideList.get(0));
     }
diff --git a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImplTest.java b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImplTest.java
index 06f64ba..cbb9dad 100644
--- a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImplTest.java
+++ b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/impl/SchemaGeneratorConfigImplTest.java
@@ -24,13 +24,13 @@ import com.github.victools.jsonschema.generator.AbstractTypeAwareTest;
 import com.github.victools.jsonschema.generator.CustomDefinition;
 import com.github.victools.jsonschema.generator.CustomDefinitionProviderV2;
 import com.github.victools.jsonschema.generator.FieldScope;
-import com.github.victools.jsonschema.generator.InstanceAttributeOverride;
+import com.github.victools.jsonschema.generator.InstanceAttributeOverrideV2;
 import com.github.victools.jsonschema.generator.MethodScope;
 import com.github.victools.jsonschema.generator.Option;
 import com.github.victools.jsonschema.generator.SchemaGeneratorConfigPart;
 import com.github.victools.jsonschema.generator.SchemaGeneratorGeneralConfigPart;
 import com.github.victools.jsonschema.generator.SchemaVersion;
-import com.github.victools.jsonschema.generator.TypeAttributeOverride;
+import com.github.victools.jsonschema.generator.TypeAttributeOverrideV2;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
@@ -195,30 +195,30 @@ public class SchemaGeneratorConfigImplTest extends AbstractTypeAwareTest {
 
     @Test
     public void testGetTypeAttributeOverrides() {
-        TypeAttributeOverride typeOverride = (typeNode, type, c) -> typeNode.put("$comment", type.getSimpleTypeDescription());
+        TypeAttributeOverrideV2 typeOverride = (typeNode, type, c) -> typeNode.put("$comment", type.getSimpleTypeDescription());
         Mockito.when(this.typesInGeneralConfigPart.getTypeAttributeOverrides()).thenReturn(Collections.singletonList(typeOverride));
 
-        List<TypeAttributeOverride> result = this.instance.getTypeAttributeOverrides();
+        List<TypeAttributeOverrideV2> result = this.instance.getTypeAttributeOverrides();
         Assert.assertEquals(1, result.size());
         Assert.assertSame(typeOverride, result.get(0));
     }
 
     @Test
     public void testGetFieldAttributeOverrides() {
-        InstanceAttributeOverride<FieldScope> instanceOverride = (node, field) -> node.put("$comment", field.getName());
+        InstanceAttributeOverrideV2<FieldScope> instanceOverride = (node, field, _context) -> node.put("$comment", field.getName());
         Mockito.when(this.fieldConfigPart.getInstanceAttributeOverrides()).thenReturn(Collections.singletonList(instanceOverride));
 
-        List<InstanceAttributeOverride<FieldScope>> result = this.instance.getFieldAttributeOverrides();
+        List<InstanceAttributeOverrideV2<FieldScope>> result = this.instance.getFieldAttributeOverrides();
         Assert.assertEquals(1, result.size());
         Assert.assertSame(instanceOverride, result.get(0));
     }
 
     @Test
     public void testGetMethodAttributeOverrides() {
-        InstanceAttributeOverride<MethodScope> instanceOverride = (node, method) -> node.put("$comment", method.getName() + "()");
+        InstanceAttributeOverrideV2<MethodScope> instanceOverride = (node, method, _context) -> node.put("$comment", method.getName() + "()");
         Mockito.when(this.methodConfigPart.getInstanceAttributeOverrides()).thenReturn(Collections.singletonList(instanceOverride));
 
-        List<InstanceAttributeOverride<MethodScope>> result = this.instance.getMethodAttributeOverrides();
+        List<InstanceAttributeOverrideV2<MethodScope>> result = this.instance.getMethodAttributeOverrides();
         Assert.assertEquals(1, result.size());
         Assert.assertSame(instanceOverride, result.get(0));
     }