diff --git a/CHANGELOG.md b/CHANGELOG.md index 85318f32..c8c57abf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### `jsonschema-generator` #### Added - new `Option.STANDARD_FORMATS` includes standard `"format"` values to some types considered by `Option.ADDITIONAL_FIXED_TYPES` +- new `Option.INLINE_NULLABLE_SCHEMAS` avoids `"-nullable"` entries in the `"definitions"`/`"$defs"` #### Changed - include new `Option.STANDARD_FORMATS` in `OptionPreset.PLAIN_JSON` by default diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/Option.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/Option.java index cb398027..d154891e 100644 --- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/Option.java +++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/Option.java @@ -268,6 +268,14 @@ public enum Option { * @since 4.27.0 */ DEFINITIONS_FOR_MEMBER_SUPERTYPES(null, null), + /** + * Whether the "nullable" variants of a sub-schema should be defined in-line, i.e., avoiding a second "MyType-nullable" entry in the + * "definitions"/"$defs". This takes precedence over {@link #DEFINITIONS_FOR_ALL_OBJECTS} in this specific case. The non-nullable sub-schema is + * unaffected by this setting. + * + * @since 4.33.0 + */ + INLINE_NULLABLE_SCHEMAS(null, null), /** * Whether all sub-schemas should be defined in-line, i.e. including no "definitions"/"$defs". This takes precedence over * {@link #DEFINITIONS_FOR_ALL_OBJECTS} and {@link #DEFINITION_FOR_MAIN_SCHEMA}. @@ -277,7 +285,8 @@ public enum Option { * * @since 4.10.0 */ - INLINE_ALL_SCHEMAS(InlineSchemaModule::new, null, Option.DEFINITIONS_FOR_ALL_OBJECTS, Option.DEFINITION_FOR_MAIN_SCHEMA), + INLINE_ALL_SCHEMAS(InlineSchemaModule::new, null, + Option.DEFINITIONS_FOR_ALL_OBJECTS, Option.DEFINITION_FOR_MAIN_SCHEMA, Option.INLINE_NULLABLE_SCHEMAS), /** * Generally, keys in the collected "definitions"/"$defs" are ensured to be URI compatible but may include parentheses and commas for listing type * parameters. By enabling this option, these parentheses and commas will be removed to conform with a reduced set of characters, e.g. as expected diff --git a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaBuilder.java b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaBuilder.java index 2574309a..c4d568c9 100644 --- a/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaBuilder.java +++ b/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/SchemaBuilder.java @@ -205,17 +205,14 @@ private void performCleanup() { private ObjectNode buildDefinitionsAndResolveReferences(String designatedDefinitionPath, DefinitionKey mainSchemaKey, SchemaGenerationContextImpl generationContext) { final ObjectNode definitionsNode = this.config.createObjectNode(); - final boolean createDefinitionsForAll = this.config.shouldCreateDefinitionsForAllObjects(); - final boolean inlineAllSchemas = this.config.shouldInlineAllSchemas(); final AtomicBoolean considerOnlyDirectReferences = new AtomicBoolean(false); - Predicate shouldProduceDefinition = this.getShouldProduceDefinitionCheck(mainSchemaKey, considerOnlyDirectReferences, - createDefinitionsForAll, inlineAllSchemas); + Predicate shouldProduceDefinition = this.getShouldProduceDefinitionCheck(mainSchemaKey, considerOnlyDirectReferences); Map baseReferenceKeys = this.getReferenceKeys(mainSchemaKey, shouldProduceDefinition, generationContext); considerOnlyDirectReferences.set(true); - for (Map.Entry entry : baseReferenceKeys.entrySet()) { - String definitionName = entry.getValue(); - DefinitionKey definitionKey = entry.getKey(); + for (Map.Entry baseReferenceKey : baseReferenceKeys.entrySet()) { + String definitionName = baseReferenceKey.getValue(); + DefinitionKey definitionKey = baseReferenceKey.getKey(); List references = generationContext.getReferences(definitionKey); List nullableReferences = generationContext.getNullableReferences(definitionKey); final String referenceKey; @@ -242,8 +239,7 @@ private ObjectNode buildDefinitionsAndResolveReferences(String designatedDefinit definition = this.config.createObjectNode().put(this.config.getKeyword(SchemaKeyword.TAG_REF), referenceKey); } generationContext.makeNullable(definition); - if (generationContext.shouldNeverInlineDefinition(definitionKey) - || (!inlineAllSchemas && (createDefinitionsForAll || nullableReferences.size() > 1))) { + if (this.shouldCreateNullableDefinition(generationContext, definitionKey, nullableReferences)) { String nullableDefinitionName = this.definitionNamingStrategy .adjustNullableName(definitionKey, definitionName, generationContext); definitionsNode.set(nullableDefinitionName, definition); @@ -258,6 +254,20 @@ private ObjectNode buildDefinitionsAndResolveReferences(String designatedDefinit return definitionsNode; } + private boolean shouldCreateNullableDefinition(SchemaGenerationContextImpl generationContext, DefinitionKey definitionKey, + List nullableReferences) { + if (this.config.shouldInlineNullableSchemas()) { + return false; + } + if (generationContext.shouldNeverInlineDefinition(definitionKey)) { + return true; + } + if (this.config.shouldInlineAllSchemas()) { + return false; + } + return this.config.shouldCreateDefinitionsForAllObjects() || nullableReferences.size() > 1; + } + private String getReferenceKey(DefinitionKey mainSchemaKey, DefinitionKey definitionKey, Supplier addDefinitionAndReturnReferenceKey) { final String referenceKey; if (definitionKey.equals(mainSchemaKey) && !this.config.shouldCreateDefinitionForMainSchema()) { @@ -275,12 +285,11 @@ private String getReferenceKey(DefinitionKey mainSchemaKey, DefinitionKey defini * * @param mainSchemaKey main type to consider * @param considerOnlyDirectReferences whether to ignore nullable references when determing about definition vs. inlining - * @param createDefinitionsForAll whether to produce definitions for all schemas by default (unless explicitly stated otherwise) - * @param inlineAllSchemas whether to inline all schemas by default (unless explicitly stated otherwise) * @return reusable predicate */ - private Predicate getShouldProduceDefinitionCheck(DefinitionKey mainSchemaKey, AtomicBoolean considerOnlyDirectReferences, - boolean createDefinitionsForAll, boolean inlineAllSchemas) { + private Predicate getShouldProduceDefinitionCheck(DefinitionKey mainSchemaKey, AtomicBoolean considerOnlyDirectReferences) { + final boolean createDefinitionsForAll = this.config.shouldCreateDefinitionsForAllObjects(); + final boolean inlineAllSchemas = this.config.shouldInlineAllSchemas(); return definitionKey -> { if (generationContext.shouldNeverInlineDefinition(definitionKey)) { // e.g. custom definition explicitly marked to always produce a definition 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 d2753fba..842a5c24 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 @@ -85,6 +85,14 @@ public interface SchemaGeneratorConfig extends StatefulConfig { */ boolean shouldInlineAllSchemas(); + /** + * Determine whether nullable sub-schemas should be included in-line, even if they occur multiple times, and not in the schema's + * "definitions"/"$defs". + * + * @return whether to include nullable sub-schemas in-line + */ + boolean shouldInlineNullableSchemas(); + /** * Determine whether the {@link SchemaKeyword#TAG_SCHEMA} attribute with {@link SchemaKeyword#TAG_SCHEMA_VALUE} should be added. * 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 02e82e8c..5a835f32 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 @@ -133,6 +133,11 @@ public boolean shouldInlineAllSchemas() { return this.isOptionEnabled(Option.INLINE_ALL_SCHEMAS); } + @Override + public boolean shouldInlineNullableSchemas() { + return this.isOptionEnabled(Option.INLINE_NULLABLE_SCHEMAS); + } + @Override public boolean shouldUsePlainDefinitionKeys() { return this.isOptionEnabled(Option.PLAIN_DEFINITION_KEYS); diff --git a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorComplexTypesTest.java b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorComplexTypesTest.java index ed4464db..d84ca6ab 100644 --- a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorComplexTypesTest.java +++ b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorComplexTypesTest.java @@ -110,7 +110,7 @@ static Stream parametersForTestGenerateSchema() { return null; }); Module alternativeDefinitionModule = configBuilder -> configBuilder.with(Option.DEFINITION_FOR_MAIN_SCHEMA, - Option.PLAIN_DEFINITION_KEYS, Option.FIELDS_DERIVED_FROM_ARGUMENTFREE_METHODS); + Option.PLAIN_DEFINITION_KEYS, Option.FIELDS_DERIVED_FROM_ARGUMENTFREE_METHODS, Option.INLINE_NULLABLE_SCHEMAS); Module typeInGeneralModule = configBuilder -> populateTypeConfigPart( configBuilder.with(Option.FORBIDDEN_ADDITIONAL_PROPERTIES_BY_DEFAULT).forTypesInGeneral() .withIdResolver(scope -> scope.getType().getTypeName().contains("$Test") ? "id-" + scope.getSimpleTypeDescription() : null) diff --git a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorCustomDefinitionsTest.java b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorCustomDefinitionsTest.java index 05e5bf1f..39f814a8 100644 --- a/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorCustomDefinitionsTest.java +++ b/jsonschema-generator/src/test/java/com/github/victools/jsonschema/generator/SchemaGeneratorCustomDefinitionsTest.java @@ -185,6 +185,7 @@ public void testGenerateSchema_CircularCustomStandardDefinition(SchemaVersion sc .set(accessProperty, context.createDefinitionReference(generic)))); }; SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(schemaVersion); + configBuilder.with(Option.INLINE_NULLABLE_SCHEMAS); configBuilder.forTypesInGeneral() .withCustomDefinitionProvider(customDefinitionProvider); SchemaGenerator generator = new SchemaGenerator(configBuilder.build()); diff --git a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_2019_09.json b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_2019_09.json index f803957a..757d9172 100644 --- a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_2019_09.json +++ b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_2019_09.json @@ -1,26 +1,15 @@ { "$defs": { - "List(TestCircularClass1)-nullable": { - "type": ["object", "null"], - "properties": { - "get(0)": { - "$ref": "#" - } - } - }, - "List(TestCircularClass2)-nullable": { - "type": ["object", "null"], - "properties": { - "get(0)": { - "$ref": "#/$defs/TestCircularClass2" - } - } - }, "TestCircularClass2": { "type": "object", "properties": { "list1": { - "$ref": "#/$defs/List(TestCircularClass1)-nullable" + "type": ["object", "null"], + "properties": { + "get(0)": { + "$ref": "#" + } + } } } } @@ -28,7 +17,12 @@ "type": "object", "properties": { "list2": { - "$ref": "#/$defs/List(TestCircularClass2)-nullable" + "type": ["object", "null"], + "properties": { + "get(0)": { + "$ref": "#/$defs/TestCircularClass2" + } + } } } } diff --git a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_2020_12.json b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_2020_12.json index f803957a..757d9172 100644 --- a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_2020_12.json +++ b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_2020_12.json @@ -1,26 +1,15 @@ { "$defs": { - "List(TestCircularClass1)-nullable": { - "type": ["object", "null"], - "properties": { - "get(0)": { - "$ref": "#" - } - } - }, - "List(TestCircularClass2)-nullable": { - "type": ["object", "null"], - "properties": { - "get(0)": { - "$ref": "#/$defs/TestCircularClass2" - } - } - }, "TestCircularClass2": { "type": "object", "properties": { "list1": { - "$ref": "#/$defs/List(TestCircularClass1)-nullable" + "type": ["object", "null"], + "properties": { + "get(0)": { + "$ref": "#" + } + } } } } @@ -28,7 +17,12 @@ "type": "object", "properties": { "list2": { - "$ref": "#/$defs/List(TestCircularClass2)-nullable" + "type": ["object", "null"], + "properties": { + "get(0)": { + "$ref": "#/$defs/TestCircularClass2" + } + } } } } diff --git a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_6.json b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_6.json index a76e9cdd..d2cf65be 100644 --- a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_6.json +++ b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_6.json @@ -1,26 +1,15 @@ { "definitions": { - "List(TestCircularClass1)-nullable": { - "type": ["object", "null"], - "properties": { - "get(0)": { - "$ref": "#" - } - } - }, - "List(TestCircularClass2)-nullable": { - "type": ["object", "null"], - "properties": { - "get(0)": { - "$ref": "#/definitions/TestCircularClass2" - } - } - }, "TestCircularClass2": { "type": "object", "properties": { "list1": { - "$ref": "#/definitions/List(TestCircularClass1)-nullable" + "type": ["object", "null"], + "properties": { + "get(0)": { + "$ref": "#" + } + } } } } @@ -28,7 +17,12 @@ "type": "object", "properties": { "list2": { - "$ref": "#/definitions/List(TestCircularClass2)-nullable" + "type": ["object", "null"], + "properties": { + "get(0)": { + "$ref": "#/definitions/TestCircularClass2" + } + } } } } diff --git a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_7.json b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_7.json index a76e9cdd..d2cf65be 100644 --- a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_7.json +++ b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/circular-custom-definition-DRAFT_7.json @@ -1,26 +1,15 @@ { "definitions": { - "List(TestCircularClass1)-nullable": { - "type": ["object", "null"], - "properties": { - "get(0)": { - "$ref": "#" - } - } - }, - "List(TestCircularClass2)-nullable": { - "type": ["object", "null"], - "properties": { - "get(0)": { - "$ref": "#/definitions/TestCircularClass2" - } - } - }, "TestCircularClass2": { "type": "object", "properties": { "list1": { - "$ref": "#/definitions/List(TestCircularClass1)-nullable" + "type": ["object", "null"], + "properties": { + "get(0)": { + "$ref": "#" + } + } } } } @@ -28,7 +17,12 @@ "type": "object", "properties": { "list2": { - "$ref": "#/definitions/List(TestCircularClass2)-nullable" + "type": ["object", "null"], + "properties": { + "get(0)": { + "$ref": "#/definitions/TestCircularClass2" + } + } } } } diff --git a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/testclass3-FULL_DOCUMENTATION.json b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/testclass3-FULL_DOCUMENTATION.json index d0d11379..ab6b37c6 100644 --- a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/testclass3-FULL_DOCUMENTATION.json +++ b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/testclass3-FULL_DOCUMENTATION.json @@ -23,13 +23,6 @@ } } }, - "Optional_Integer_-nullable": { - "anyOf": [{ - "type": "null" - }, { - "$ref": "#/definitions/Optional_Integer_" - }] - }, "RoundingMode": { "type": "object", "properties": { @@ -50,10 +43,22 @@ "enum": ["UP", "DOWN", "CEILING", "FLOOR", "HALF_UP", "HALF_DOWN", "HALF_EVEN", "UNNECESSARY"] }, "valueOf(String)": { - "$ref": "#/definitions/RoundingMode-nullable" + "anyOf": [ + { + "type": "null" + }, { + "$ref": "#/definitions/RoundingMode" + } + ] }, "valueOf(int)": { - "$ref": "#/definitions/RoundingMode-nullable" + "anyOf": [ + { + "type": "null" + }, { + "$ref": "#/definitions/RoundingMode" + } + ] }, "values()": { "type": ["array", "null"], @@ -63,21 +68,6 @@ } } }, - "RoundingMode-nullable": { - "anyOf": [{ - "type": "null" - }, { - "$ref": "#/definitions/RoundingMode" - }] - }, - "Supplier_Integer_-nullable": { - "type": ["object", "null"], - "properties": { - "get()": { - "type": ["integer", "null"] - } - } - }, "TestClass1": { "type": "object", "properties": { @@ -120,13 +110,6 @@ } } }, - "TestClass2_Long_-nullable": { - "anyOf": [{ - "type": "null" - }, { - "$ref": "#/definitions/TestClass2_Long_" - }] - }, "TestClass2_String_": { "type": "object", "properties": { @@ -141,58 +124,100 @@ } } }, - "TestClass2_String_-nullable": { - "anyOf": [{ - "type": "null" - }, { - "$ref": "#/definitions/TestClass2_String_" - }] - }, - "TestClass2_TestClass1..._-nullable": { - "type": ["object", "null"], - "properties": { - "genericArray": { - "type": ["array", "null"], - "items": { - "type": "array", - "items": { - "$ref": "#/definitions/TestClass1" - } - } - }, - "genericValue": { - "type": ["array", "null"], - "items": { - "$ref": "#/definitions/TestClass1" - } - } - } - }, - "TestClass2_TestClass2_String__-nullable": { - "type": ["object", "null"], - "properties": { - "genericArray": { - "type": ["array", "null"], - "items": { - "$ref": "#/definitions/TestClass2_String_" - } - }, - "genericValue": { - "$ref": "#/definitions/TestClass2_String_-nullable" - } - } - }, "TestClass3": { "type": "object", "properties": { "class4": { - "$ref": "#/definitions/TestClass4_Integer.String_-nullable" + "type": ["object", "null"], + "properties": { + "DEFAULT_ROUNDING_MODE": { + "allOf": [ + { + "$ref": "#/definitions/RoundingMode" + }, { + "const": "HALF_UP" + } + ] + }, + "class2OfClass2OfT": { + "type": ["object", "null"], + "properties": { + "genericArray": { + "type": ["array", "null"], + "items": { + "$ref": "#/definitions/TestClass2_String_" + } + }, + "genericValue": { + "anyOf": [ + { + "type": "null" + }, { + "$ref": "#/definitions/TestClass2_String_" + } + ] + } + } + }, + "listOfOptionalS": { + "type": ["array", "null"], + "items": { + "$ref": "#/definitions/Optional_Integer_" + } + }, + "optionalS": { + "anyOf": [ + { + "type": "null" + }, { + "$ref": "#/definitions/Optional_Integer_" + } + ] + }, + "setOfStringSupplier": { + "type": ["array", "null"], + "items": { + "$ref": "#/definitions/LazyStringSupplier" + } + }, + "supplierS": { + "type": ["object", "null"], + "properties": { + "get()": { + "type": ["integer", "null"] + } + } + } + } }, "nestedClass1Array": { - "$ref": "#/definitions/TestClass2_TestClass1..._-nullable" + "type": ["object", "null"], + "properties": { + "genericArray": { + "type": ["array", "null"], + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/TestClass1" + } + } + }, + "genericValue": { + "type": ["array", "null"], + "items": { + "$ref": "#/definitions/TestClass1" + } + } + } }, "nestedLong": { - "$ref": "#/definitions/TestClass2_Long_-nullable" + "anyOf": [ + { + "type": "null" + }, { + "$ref": "#/definitions/TestClass2_Long_" + } + ] }, "nestedLongList": { "type": ["array", "null"], @@ -201,39 +226,6 @@ } } } - }, - "TestClass4_Integer.String_-nullable": { - "type": ["object", "null"], - "properties": { - "DEFAULT_ROUNDING_MODE": { - "allOf": [{ - "$ref": "#/definitions/RoundingMode" - }, { - "const": "HALF_UP" - }] - }, - "class2OfClass2OfT": { - "$ref": "#/definitions/TestClass2_TestClass2_String__-nullable" - }, - "listOfOptionalS": { - "type": ["array", "null"], - "items": { - "$ref": "#/definitions/Optional_Integer_" - } - }, - "optionalS": { - "$ref": "#/definitions/Optional_Integer_-nullable" - }, - "setOfStringSupplier": { - "type": ["array", "null"], - "items": { - "$ref": "#/definitions/LazyStringSupplier" - } - }, - "supplierS": { - "$ref": "#/definitions/Supplier_Integer_-nullable" - } - } } } } diff --git a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/testenum-FULL_DOCUMENTATION-default.json b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/testenum-FULL_DOCUMENTATION-default.json index a4bd989e..6a8783d2 100644 --- a/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/testenum-FULL_DOCUMENTATION-default.json +++ b/jsonschema-generator/src/test/resources/com/github/victools/jsonschema/generator/testenum-FULL_DOCUMENTATION-default.json @@ -21,7 +21,13 @@ "type": ["string", "null"] }, "valueOf(String)": { - "$ref": "#/definitions/TestEnum-nullable" + "anyOf": [ + { + "type": "null" + }, { + "$ref": "#/definitions/TestEnum" + } + ] }, "values()": { "type": ["array", "null"], @@ -30,13 +36,6 @@ } } } - }, - "TestEnum-nullable": { - "anyOf": [{ - "type": "null" - }, { - "$ref": "#/definitions/TestEnum" - }] } } } diff --git a/slate-docs/source/includes/_main-generator-options.md b/slate-docs/source/includes/_main-generator-options.md index 37c34890..1c44b677 100644 --- a/slate-docs/source/includes/_main-generator-options.md +++ b/slate-docs/source/includes/_main-generator-options.md @@ -310,6 +310,14 @@ configBuilder.without( #Behavior if includedBehavior if excluded 33 + Option.INLINE_NULLABLE_SCHEMAS + + + Do not include $defs/definitions for a nullable version of a type, but rather define it "inline". The non-nullable type may still be referenced. + Depending on whether DEFINITIONS_FOR_ALL_OBJECTS is included or excluded. + + + 34 Option.PLAIN_DEFINITION_KEYS @@ -317,7 +325,7 @@ configBuilder.without( Ensure that the keys for any $defs/definitions are URI compatible (as expected by the JSON Schema specification). - 34 + 35 Option.ALLOF_CLEANUP_AT_THE_END @@ -325,7 +333,7 @@ configBuilder.without( Do not attempt to reduce allOf wrappers but preserve them as they were generated regardless of them being necessary or not. - 35 + 36 Option.STRICT_TYPE_INFO @@ -375,6 +383,7 @@ Below, you can find the lists of Options included/excluded in the r | 30 | `DEFINITION_FOR_MAIN_SCHEMA` | ⬜️ | ⬜️ | ⬜️ | | 31 | `DEFINITIONS_FOR_MEMBER_SUPERTYPES` | ⬜️ | ⬜️ | ⬜️ | | 32 | `INLINE_ALL_SCHEMAS` | ⬜️ | ⬜️ | ⬜️ | -| 33 | `PLAIN_DEFINITION_KEYS` | ⬜️ | ⬜️ | ⬜️ | -| 34 | `ALLOF_CLEANUP_AT_THE_END` | ✅ | ✅ | ✅ | -| 35 | `STRICT_TYPE_INFO` | ⬜️ | ⬜️ | ⬜️ | \ No newline at end of file +| 33 | `INLINE_NULLABLE_SCHEMAS` | ⬜️ | ⬜️ | ⬜️ | +| 34 | `PLAIN_DEFINITION_KEYS` | ⬜️ | ⬜️ | ⬜️ | +| 35 | `ALLOF_CLEANUP_AT_THE_END` | ✅ | ✅ | ✅ | +| 36 | `STRICT_TYPE_INFO` | ⬜️ | ⬜️ | ⬜️ |