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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations