use of com.github.victools.jsonschema.generator.CustomPropertyDefinition in project jsonschema-generator by victools.
the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForField_withCustomPropertyDefinitionExcludingAttributes.
@Test
public void testCreateStandardDefinitionReferenceForField_withCustomPropertyDefinitionExcludingAttributes() {
ObjectNode customNode = this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom property");
Mockito.doReturn(new CustomPropertyDefinition(customNode, CustomDefinition.EXCLUDING_ATTRIBUTES)).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\"}", result.toString());
}
use of com.github.victools.jsonschema.generator.CustomPropertyDefinition in project kogito-runtimes by kiegroup.
the class JsonSchemaGenerator method getInputOutput.
private CustomPropertyDefinition getInputOutput(FieldScope scope, SchemaGenerationContext context) {
UserTaskParam param = scope.getAnnotation(UserTaskParam.class);
if (param != null) {
final ObjectNode refNode = context.createStandardDefinitionReference(scope.getDeclaredType(), null);
ObjectNode rootNode = context.getGeneratorConfig().createObjectNode();
ArrayNode allOfNode = rootNode.withArray(context.getKeyword(SchemaKeyword.TAG_ALLOF));
allOfNode.add(refNode);
allOfNode.addObject().put(param.value().toString().toLowerCase(), true);
return new CustomPropertyDefinition(rootNode, AttributeInclusion.YES);
}
return null;
}
use of com.github.victools.jsonschema.generator.CustomPropertyDefinition in project tigris-client-java by tigrisdata.
the class StandardModelToTigrisJsonSchema method toJsonSchema.
@Override
public JsonNode toJsonSchema(Class<? extends TigrisCollectionType> clazz) {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12, OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES).with(builder -> builder.forFields().withDescriptionResolver(target -> {
TigrisField tigrisField = target.getAnnotation(TigrisField.class);
if (tigrisField != null && !tigrisField.description().isEmpty()) {
return target.getAnnotation(TigrisField.class).description();
}
return null;
}).withCustomDefinitionProvider((scope, context) -> {
// one or multiple dimensional byte array
if (scope.getType().getSignature().endsWith("[B")) {
ObjectNode customProperty = handleMultiDimensionalByteArray(scope.getType().getSignature());
return new CustomPropertyDefinition(customProperty);
}
return null;
})).build();
SchemaGenerator generator = new SchemaGenerator(config);
JsonNode jsonSchema = generator.generateSchema(clazz);
JsonNode result = customizeSchema(jsonSchema, clazz);
log.info("Collection type class: {}, schema: {}", clazz.getName(), result.toPrettyString());
return result;
}
use of com.github.victools.jsonschema.generator.CustomPropertyDefinition 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.CustomPropertyDefinition in project jsonschema-generator by victools.
the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForMethod_withCustomPropertyDefinition.
@Test
public void testCreateStandardDefinitionReferenceForMethod_withCustomPropertyDefinition() {
Mockito.doReturn(new CustomPropertyDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom property"))).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(MethodScope.class), Mockito.any(), Mockito.any());
MethodScope targetMethod = this.getTestClassMethod("isBooleanField");
JsonNode result = this.contextImpl.createStandardDefinitionReference(targetMethod, null);
Assert.assertEquals("{\"$comment\":\"custom property\",\"title\":\"Method Title\",\"description\":\"Type Description\"}", result.toString());
}
Aggregations