Search in sources :

Example 1 with SchemaCleanUpUtils

use of com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils in project jsonschema-generator by victools.

the class SchemaDefinitionNamingStrategyTest method testExampleStrategy.

@Test
@Parameters
@TestCaseName(value = "{method}({0}, {3} | {4}) [{index}]")
public void testExampleStrategy(String caseTitle, SchemaDefinitionNamingStrategy strategy, ResolvedType type, String expectedUriCompatibleName, String expectedPlainName) {
    Mockito.when(this.key.getType()).thenReturn(type);
    String result = strategy.getDefinitionNameForKey(this.key, this.generationContext);
    // before the produced name is used in an actual schema, the SchemaCleanUpUtils come into play one way or another
    SchemaCleanUpUtils cleanUpUtils = new SchemaCleanUpUtils(null);
    Assert.assertEquals(expectedUriCompatibleName, cleanUpUtils.ensureDefinitionKeyIsUriCompatible(result));
    Assert.assertEquals(expectedPlainName, cleanUpUtils.ensureDefinitionKeyIsPlain(result));
}
Also used : SchemaCleanUpUtils(com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Example 2 with SchemaCleanUpUtils

use of com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils in project jsonschema-generator by victools.

the class SchemaBuilder method performCleanup.

/**
 * Reduce unnecessary structures in the generated schema definitions. Assumption being that this method is being invoked as the very last action
 * of the schema generation.
 *
 * @see SchemaGeneratorConfig#shouldCleanupUnnecessaryAllOfElements()
 * @see SchemaCleanUpUtils#reduceAllOfNodes(List)
 * @see SchemaCleanUpUtils#reduceAnyOfNodes(List)
 */
private void performCleanup() {
    SchemaCleanUpUtils cleanUpUtils = new SchemaCleanUpUtils(this.config);
    if (this.config.shouldCleanupUnnecessaryAllOfElements()) {
        cleanUpUtils.reduceAllOfNodes(this.schemaNodes);
    }
    cleanUpUtils.reduceAnyOfNodes(this.schemaNodes);
}
Also used : SchemaCleanUpUtils(com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils)

Aggregations

SchemaCleanUpUtils (com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils)2 Parameters (junitparams.Parameters)1 TestCaseName (junitparams.naming.TestCaseName)1 Test (org.junit.Test)1