Search in sources :

Example 1 with TypeScope

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TypeScope(com.github.victools.jsonschema.generator.TypeScope)

Example 2 with TypeScope

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TypeScope(com.github.victools.jsonschema.generator.TypeScope)

Example 3 with TypeScope

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);
}
Also used : TypeScope(com.github.victools.jsonschema.generator.TypeScope)

Example 4 with TypeScope

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);
    }
}
Also used : Type(java.lang.reflect.Type) ConfigFunction(com.github.victools.jsonschema.generator.ConfigFunction) TypeScope(com.github.victools.jsonschema.generator.TypeScope) TypeContext(com.github.victools.jsonschema.generator.TypeContext) Parameters(junitparams.Parameters) Test(org.junit.Test) AbstractTypeAwareTest(com.github.victools.jsonschema.generator.AbstractTypeAwareTest)

Example 5 with TypeScope

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);
}
Also used : FieldScope(com.github.victools.jsonschema.generator.FieldScope) ConfigFunction(com.github.victools.jsonschema.generator.ConfigFunction) TypeScope(com.github.victools.jsonschema.generator.TypeScope) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

TypeScope (com.github.victools.jsonschema.generator.TypeScope)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ConfigFunction (com.github.victools.jsonschema.generator.ConfigFunction)2 Parameters (junitparams.Parameters)2 Test (org.junit.Test)2 AbstractTypeAwareTest (com.github.victools.jsonschema.generator.AbstractTypeAwareTest)1 FieldScope (com.github.victools.jsonschema.generator.FieldScope)1 TypeContext (com.github.victools.jsonschema.generator.TypeContext)1 Type (java.lang.reflect.Type)1