use of com.github.victools.jsonschema.generator.TypeScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImpl method createStandardDefinitionReference.
@Override
public ObjectNode createStandardDefinitionReference(ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider) {
ObjectNode definition = this.generatorConfig.createObjectNode();
TypeScope scope = this.typeContext.createTypeScope(targetType);
this.traverseGenericType(scope, definition, false, false, ignoredDefinitionProvider);
return definition;
}
use of com.github.victools.jsonschema.generator.TypeScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImpl method createStandardDefinition.
@Override
public ObjectNode createStandardDefinition(ResolvedType targetType, CustomDefinitionProviderV2 ignoredDefinitionProvider) {
ObjectNode definition = this.generatorConfig.createObjectNode();
TypeScope scope = this.typeContext.createTypeScope(targetType);
this.traverseGenericType(scope, definition, false, true, ignoredDefinitionProvider);
return definition;
}
use of com.github.victools.jsonschema.generator.TypeScope in project jsonschema-generator by victools.
the class SchemaGenerationContextImpl method traverseGenericType.
/**
* Preparation Step: add the given targetType.
*
* @param targetType (possibly generic) type to add
* @param targetNode node in the JSON schema that should represent the targetType
* @param isNullable whether the field/method's return value is allowed to be null in the declaringType in this particular scenario
*/
protected void traverseGenericType(ResolvedType targetType, ObjectNode targetNode, boolean isNullable) {
TypeScope scope = this.typeContext.createTypeScope(targetType);
this.traverseGenericType(scope, targetNode, isNullable, false, null);
}
use of com.github.victools.jsonschema.generator.TypeScope in project jsonschema-generator by victools.
the class AdditionalPropertiesModuleTest method testResolveAdditionalProperties.
@Test
@Parameters
@SuppressWarnings("unchecked")
public void testResolveAdditionalProperties(Module moduleInstance, Type expectedAdditionalProperties, Type type, Type[] typeParameters) {
moduleInstance.applyToConfigBuilder(this.builder);
ArgumentCaptor<ConfigFunction<TypeScope, Type>> resolverCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.generalConfigPart).withAdditionalPropertiesResolver(resolverCaptor.capture());
ConfigFunction<TypeScope, Type> additionalPropertiesResolver = resolverCaptor.getValue();
TypeContext typeContext = this.getContext().getTypeContext();
TypeScope scope = typeContext.createTypeScope(typeContext.resolve(type, typeParameters));
Type result = additionalPropertiesResolver.apply(scope);
if (expectedAdditionalProperties == null || expectedAdditionalProperties == Void.class) {
Assert.assertEquals(expectedAdditionalProperties, result);
} else {
Assert.assertEquals(typeContext.resolve(expectedAdditionalProperties), result);
}
}
use of com.github.victools.jsonschema.generator.TypeScope in project jsonschema-generator by victools.
the class SwaggerModuleTest method testDescriptionResolver.
@Test
@Parameters
public void testDescriptionResolver(String fieldName, boolean asContainerItem, String expectedMemberDescription, String expectedTypeDescription) {
new SwaggerModule().applyToConfigBuilder(this.configBuilder);
TestType testType = new TestType(TestClassForDescription.class);
FieldScope field = testType.getMemberField(fieldName);
if (asContainerItem) {
field = field.asFakeContainerItemScope();
}
ArgumentCaptor<ConfigFunction<FieldScope, String>> memberCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.fieldConfigPart).withDescriptionResolver(memberCaptor.capture());
String memberDescription = memberCaptor.getValue().apply(field);
Assert.assertEquals(expectedMemberDescription, memberDescription);
ArgumentCaptor<ConfigFunction<TypeScope, String>> typeCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
Mockito.verify(this.typesInGeneralConfigPart).withDescriptionResolver(typeCaptor.capture());
TypeScope scope = Mockito.mock(TypeScope.class);
Mockito.when(scope.getType()).thenReturn(field.getType());
String typeDescription = typeCaptor.getValue().apply(scope);
Assert.assertEquals(expectedTypeDescription, typeDescription);
}
Aggregations