Search in sources :

Example 41 with FieldScope

use of com.github.victools.jsonschema.generator.FieldScope 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

FieldScope (com.github.victools.jsonschema.generator.FieldScope)41 Test (org.junit.Test)25 ConfigFunction (com.github.victools.jsonschema.generator.ConfigFunction)20 Parameters (junitparams.Parameters)19 AbstractTypeAwareTest (com.github.victools.jsonschema.generator.AbstractTypeAwareTest)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 MethodScope (com.github.victools.jsonschema.generator.MethodScope)5 ResolvedType (com.fasterxml.classmate.ResolvedType)4 CustomDefinition (com.github.victools.jsonschema.generator.CustomDefinition)4 CustomPropertyDefinition (com.github.victools.jsonschema.generator.CustomPropertyDefinition)4 BigInteger (java.math.BigInteger)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 BigDecimal (java.math.BigDecimal)3 TestCaseName (junitparams.naming.TestCaseName)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 MemberScope (com.github.victools.jsonschema.generator.MemberScope)2 SchemaGeneratorGeneralConfigPart (com.github.victools.jsonschema.generator.SchemaGeneratorGeneralConfigPart)2 TypeScope (com.github.victools.jsonschema.generator.TypeScope)2 JsonClassDescription (com.fasterxml.jackson.annotation.JsonClassDescription)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1