use of com.github.victools.jsonschema.generator.CustomDefinitionProviderV2 in project jsonschema-generator by victools.
the class SchemaGeneratorConfigImplTest method testGetCustomDefinition_withMappingReturningNull.
@Test
public void testGetCustomDefinition_withMappingReturningNull() {
CustomDefinitionProviderV2 provider = Mockito.mock(CustomDefinitionProviderV2.class);
Mockito.when(this.typesInGeneralConfigPart.getCustomDefinitionProviders()).thenReturn(Collections.singletonList(provider));
ResolvedType javaType = Mockito.mock(ResolvedType.class);
Assert.assertNull(this.instance.getCustomDefinition(javaType, this.getContext(), null));
// ensure that the provider has been called and the given java type and type variable context were forward accordingly
Mockito.verify(provider).provideCustomSchemaDefinition(javaType, this.getContext());
}
use of com.github.victools.jsonschema.generator.CustomDefinitionProviderV2 in project jsonschema-generator by victools.
the class SchemaGenerationContextImplTest method testReference_DifferentIgnoredDefinitionProvider.
@Test
public void testReference_DifferentIgnoredDefinitionProvider() {
ResolvedType javaType = Mockito.mock(ResolvedType.class);
CustomDefinitionProviderV2 providerOne = null;
CustomDefinitionProviderV2 providerTwo = Mockito.mock(CustomDefinitionProviderV2.class);
DefinitionKey keyOne = new DefinitionKey(javaType, providerOne);
DefinitionKey keyTwo = new DefinitionKey(javaType, providerTwo);
// adding an entry creates the "references" list for that type
ObjectNode referenceInputOne = Mockito.mock(ObjectNode.class);
this.contextImpl.addReference(javaType, referenceInputOne, providerOne, false);
Assert.assertEquals(Collections.singletonList(referenceInputOne), this.contextImpl.getReferences(keyOne));
Assert.assertEquals(Collections.<ObjectNode>emptyList(), this.contextImpl.getReferences(keyTwo));
// adding an entry for the same type but other ignored definition provider creates a separate "references" list for this other type
ObjectNode referenceInputTwo = Mockito.mock(ObjectNode.class);
this.contextImpl.addReference(javaType, referenceInputTwo, providerTwo, false);
Assert.assertEquals(Collections.singletonList(referenceInputOne), this.contextImpl.getReferences(keyOne));
Assert.assertEquals(Collections.singletonList(referenceInputTwo), this.contextImpl.getReferences(keyTwo));
}
use of com.github.victools.jsonschema.generator.CustomDefinitionProviderV2 in project jsonschema-generator by victools.
the class EnumModuleTest method testCustomSchemaDefinition_asStrings.
@Test
@Parameters
public void testCustomSchemaDefinition_asStrings(SchemaVersion schemaVersion, EnumModule instance, String value1, String value2, String value3) {
this.initConfigBuilder(schemaVersion);
instance.applyToConfigBuilder(this.builder);
ArgumentCaptor<CustomDefinitionProviderV2> captor = ArgumentCaptor.forClass(CustomDefinitionProviderV2.class);
Mockito.verify(this.typeConfigPart).withCustomDefinitionProvider(captor.capture());
ResolvedType testEnumType = this.getContext().getTypeContext().resolve(TestEnum.class);
CustomDefinition schemaDefinition = captor.getValue().provideCustomSchemaDefinition(testEnumType, this.getContext());
Assert.assertFalse(schemaDefinition.isMeantToBeInline());
ObjectNode node = schemaDefinition.getValue();
Assert.assertEquals(2, node.size());
JsonNode typeNode = node.get(SchemaKeyword.TAG_TYPE.forVersion(schemaVersion));
Assert.assertEquals(JsonNodeType.STRING, typeNode.getNodeType());
Assert.assertEquals(SchemaKeyword.TAG_TYPE_STRING.forVersion(schemaVersion), typeNode.textValue());
JsonNode enumNode = node.get(SchemaKeyword.TAG_ENUM.forVersion(schemaVersion));
Assert.assertEquals(JsonNodeType.ARRAY, enumNode.getNodeType());
Assert.assertEquals(3, ((ArrayNode) enumNode).size());
Assert.assertEquals(JsonNodeType.STRING, enumNode.get(0).getNodeType());
Assert.assertEquals(value1, enumNode.get(0).textValue());
Assert.assertEquals(JsonNodeType.STRING, enumNode.get(1).getNodeType());
Assert.assertEquals(value2, enumNode.get(1).textValue());
Assert.assertEquals(JsonNodeType.STRING, enumNode.get(2).getNodeType());
Assert.assertEquals(value3, enumNode.get(2).textValue());
}
Aggregations