Search in sources :

Example 1 with Required

use of org.alfresco.event.sdk.model.v1.model.schema.Required in project alfresco-java-sdk by Alfresco.

the class JsonSchemaGeneratorTest method getConfigBuilder.

private SchemaGeneratorConfigBuilder getConfigBuilder(final EventEntry entry) {
    final JacksonModule module = new JacksonModule(JacksonOption.RESPECT_JSONPROPERTY_ORDER);
    final SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON).with(module);
    configBuilder.forTypesInGeneral().withSubtypeResolver((declaredType, generationContext) -> {
        if (declaredType.getErasedType() == Resource.class) {
            final TypeContext typeContext = generationContext.getTypeContext();
            switch(entry) {
                case NODE_ENTRY:
                    return List.of(typeContext.resolveSubtype(declaredType, NodeResource.class));
                case CHILD_ASSOC_ENTRY:
                    return List.of(typeContext.resolveSubtype(declaredType, ChildAssociationResource.class));
                case PEER_ASSOC_ENTRY:
                    return List.of(typeContext.resolveSubtype(declaredType, PeerAssociationResource.class));
            }
        }
        if (declaredType.getErasedType() == DataAttributes.class) {
            final TypeContext typeContext = generationContext.getTypeContext();
            if (entry == EventEntry.NODE_UPDATED_ENTRY) {
                return List.of(typeContext.resolveSubtype(declaredType, EventDataWithResourceBefore.class));
            } else {
                return List.of(typeContext.resolveSubtype(declaredType, EventDataWithoutResourceBefore.class));
            }
        }
        return null;
    });
    configBuilder.forFields().withTargetTypeOverridesResolver(field -> {
        if (field.getDeclaredType().getErasedType() == URI.class) {
            return Stream.of(String.class).map(specificSubtype -> field.getContext().resolve(String.class)).collect(Collectors.toList());
        }
        return null;
    });
    configBuilder.forFields().withRequiredCheck(field -> {
        final Required annotation = field.getAnnotation(Required.class);
        return (annotation != null);
    });
    return configBuilder;
}
Also used : NodeResource(org.alfresco.event.sdk.model.v1.model.schema.NodeResource) TypeContext(com.github.victools.jsonschema.generator.TypeContext) Required(org.alfresco.event.sdk.model.v1.model.schema.Required) SchemaGeneratorConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder) SchemaVersion(com.github.victools.jsonschema.generator.SchemaVersion) NodeResource(org.alfresco.event.sdk.model.v1.model.schema.NodeResource) RepoEvent(org.alfresco.event.sdk.model.v1.model.schema.RepoEvent) OutputStreamWriter(java.io.OutputStreamWriter) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) PrintWriter(java.io.PrintWriter) DataAttributes(org.alfresco.event.sdk.model.v1.model.DataAttributes) OptionPreset(com.github.victools.jsonschema.generator.OptionPreset) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Test(org.junit.Test) SchemaGenerator(com.github.victools.jsonschema.generator.SchemaGenerator) EventDataWithResourceBefore(org.alfresco.event.sdk.model.v1.model.schema.EventDataWithResourceBefore) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) EventDataWithoutResourceBefore(org.alfresco.event.sdk.model.v1.model.schema.EventDataWithoutResourceBefore) List(java.util.List) Stream(java.util.stream.Stream) JacksonOption(com.github.victools.jsonschema.module.jackson.JacksonOption) SchemaGeneratorConfig(com.github.victools.jsonschema.generator.SchemaGeneratorConfig) ChildAssociationResource(org.alfresco.event.sdk.model.v1.model.schema.ChildAssociationResource) Resource(org.alfresco.event.sdk.model.v1.model.Resource) PeerAssociationResource(org.alfresco.event.sdk.model.v1.model.schema.PeerAssociationResource) JacksonModule(com.github.victools.jsonschema.module.jackson.JacksonModule) PeerAssociationResource(org.alfresco.event.sdk.model.v1.model.schema.PeerAssociationResource) Required(org.alfresco.event.sdk.model.v1.model.schema.Required) SchemaGeneratorConfigBuilder(com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder) ChildAssociationResource(org.alfresco.event.sdk.model.v1.model.schema.ChildAssociationResource) EventDataWithoutResourceBefore(org.alfresco.event.sdk.model.v1.model.schema.EventDataWithoutResourceBefore) TypeContext(com.github.victools.jsonschema.generator.TypeContext) JacksonModule(com.github.victools.jsonschema.module.jackson.JacksonModule) EventDataWithResourceBefore(org.alfresco.event.sdk.model.v1.model.schema.EventDataWithResourceBefore)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 OptionPreset (com.github.victools.jsonschema.generator.OptionPreset)1 SchemaGenerator (com.github.victools.jsonschema.generator.SchemaGenerator)1 SchemaGeneratorConfig (com.github.victools.jsonschema.generator.SchemaGeneratorConfig)1 SchemaGeneratorConfigBuilder (com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder)1 SchemaVersion (com.github.victools.jsonschema.generator.SchemaVersion)1 TypeContext (com.github.victools.jsonschema.generator.TypeContext)1 JacksonModule (com.github.victools.jsonschema.module.jackson.JacksonModule)1 JacksonOption (com.github.victools.jsonschema.module.jackson.JacksonOption)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 URI (java.net.URI)1 StandardCharsets (java.nio.charset.StandardCharsets)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 DataAttributes (org.alfresco.event.sdk.model.v1.model.DataAttributes)1