Search in sources :

Example 21 with FieldScope

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

the class SwaggerModuleTest method testIgnoreCheck.

@Test
@Parameters
public void testIgnoreCheck(String fieldName, boolean expectedResult) {
    new SwaggerModule(SwaggerOption.IGNORING_HIDDEN_PROPERTIES).applyToConfigBuilder(this.configBuilder);
    TestType testType = new TestType(TestClassForIgnoreCheck.class);
    FieldScope field = testType.getMemberField(fieldName);
    ArgumentCaptor<Predicate<FieldScope>> captor = ArgumentCaptor.forClass(Predicate.class);
    Mockito.verify(this.fieldConfigPart).withIgnoreCheck(captor.capture());
    boolean result = captor.getValue().test(field);
    Assert.assertEquals(expectedResult, result);
}
Also used : FieldScope(com.github.victools.jsonschema.generator.FieldScope) Predicate(java.util.function.Predicate) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 22 with FieldScope

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

the class SwaggerModuleTest method testNumberMinMaxResolvers.

@Test
@Parameters
public void testNumberMinMaxResolvers(String fieldName, boolean asContainerItem, BigDecimal expectedMinInclusive, BigDecimal expectedMinExclusive, BigDecimal expectedMaxInclusive, BigDecimal expectedMaxExclusive) throws Exception {
    new SwaggerModule().applyToConfigBuilder(this.configBuilder);
    TestType testType = new TestType(TestClassForNumberMinMax.class);
    FieldScope field = testType.getMemberField(fieldName);
    if (asContainerItem) {
        field = field.asFakeContainerItemScope();
    }
    ArgumentCaptor<ConfigFunction<FieldScope, BigDecimal>> minInclusiveCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withNumberInclusiveMinimumResolver(minInclusiveCaptor.capture());
    BigDecimal minInclusive = minInclusiveCaptor.getValue().apply(field);
    Assert.assertEquals(expectedMinInclusive, minInclusive);
    ArgumentCaptor<ConfigFunction<FieldScope, BigDecimal>> minExclusiveCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withNumberExclusiveMinimumResolver(minExclusiveCaptor.capture());
    BigDecimal minExclusive = minExclusiveCaptor.getValue().apply(field);
    Assert.assertEquals(expectedMinExclusive, minExclusive);
    ArgumentCaptor<ConfigFunction<FieldScope, BigDecimal>> maxInclusiveCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withNumberInclusiveMaximumResolver(maxInclusiveCaptor.capture());
    BigDecimal maxInclusive = maxInclusiveCaptor.getValue().apply(field);
    Assert.assertEquals(expectedMaxInclusive, maxInclusive);
    ArgumentCaptor<ConfigFunction<FieldScope, BigDecimal>> maxExclusiveCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withNumberExclusiveMaximumResolver(maxExclusiveCaptor.capture());
    BigDecimal maxExclusive = maxExclusiveCaptor.getValue().apply(field);
    Assert.assertEquals(expectedMaxExclusive, maxExclusive);
}
Also used : FieldScope(com.github.victools.jsonschema.generator.FieldScope) ConfigFunction(com.github.victools.jsonschema.generator.ConfigFunction) BigDecimal(java.math.BigDecimal) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 23 with FieldScope

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

the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForField_withCustomPropertyAndTypeDefinitions.

@Test
public void testCreateStandardDefinitionReferenceForField_withCustomPropertyAndTypeDefinitions() {
    Mockito.doReturn(new CustomDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom type"), true)).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(ResolvedType.class), Mockito.any(), Mockito.any());
    Mockito.doReturn(new CustomPropertyDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom property"))).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(FieldScope.class), Mockito.any(), Mockito.any());
    FieldScope targetField = this.getTestClassField("booleanField");
    ObjectNode result = this.contextImpl.createStandardDefinitionReference(targetField, null);
    Assert.assertEquals("{\"$comment\":\"custom property\",\"title\":\"Field Title\",\"description\":\"Type Description\"}", result.toString());
}
Also used : CustomDefinition(com.github.victools.jsonschema.generator.CustomDefinition) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FieldScope(com.github.victools.jsonschema.generator.FieldScope) CustomPropertyDefinition(com.github.victools.jsonschema.generator.CustomPropertyDefinition) ResolvedType(com.fasterxml.classmate.ResolvedType) Test(org.junit.Test) AbstractTypeAwareTest(com.github.victools.jsonschema.generator.AbstractTypeAwareTest)

Example 24 with FieldScope

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

the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForField_withCustomTypeDefinition.

@Test
public void testCreateStandardDefinitionReferenceForField_withCustomTypeDefinition() {
    Mockito.doReturn(new CustomDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom type"), true)).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(ResolvedType.class), Mockito.any(), Mockito.any());
    FieldScope targetField = this.getTestClassField("booleanField");
    ObjectNode result = this.contextImpl.createStandardDefinitionReference(targetField, null);
    Assert.assertEquals("{\"allOf\":[{\"$comment\":\"custom type\",\"description\":\"Type Description\"},{\"title\":\"Field Title\"}]}", result.toString());
}
Also used : CustomDefinition(com.github.victools.jsonschema.generator.CustomDefinition) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FieldScope(com.github.victools.jsonschema.generator.FieldScope) ResolvedType(com.fasterxml.classmate.ResolvedType) Test(org.junit.Test) AbstractTypeAwareTest(com.github.victools.jsonschema.generator.AbstractTypeAwareTest)

Example 25 with FieldScope

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

the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForField_withCustomPropertyDefinition.

@Test
public void testCreateStandardDefinitionReferenceForField_withCustomPropertyDefinition() {
    Mockito.doReturn(new CustomPropertyDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom property"))).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(FieldScope.class), Mockito.any(), Mockito.any());
    FieldScope targetField = this.getTestClassField("booleanField");
    ObjectNode result = this.contextImpl.createStandardDefinitionReference(targetField, null);
    Assert.assertEquals("{\"$comment\":\"custom property\",\"title\":\"Field Title\",\"description\":\"Type Description\"}", result.toString());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FieldScope(com.github.victools.jsonschema.generator.FieldScope) CustomPropertyDefinition(com.github.victools.jsonschema.generator.CustomPropertyDefinition) Test(org.junit.Test) AbstractTypeAwareTest(com.github.victools.jsonschema.generator.AbstractTypeAwareTest)

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