From 5f9fb1da8850df31f86ab3d78e28fe096d63c8a9 Mon Sep 17 00:00:00 2001 From: Era Dorta Date: Fri, 6 Mar 2026 23:29:29 +0100 Subject: [PATCH] Fix generator for JsonUnwrapped files --- build.gradle.kts | 53 +++++++-- .../asamk/signal/json/JsonSchemaCatalog.java | 56 --------- .../schemas/sync-data-message.schema.json | 111 ++++++++++++++++++ .../META-INF/schemas/sync-message.schema.json | 40 +++++++ .../schemas/sync-story-message.schema.json | 57 +++++++++ 5 files changed, 250 insertions(+), 67 deletions(-) delete mode 100644 src/main/java/org/asamk/signal/json/JsonSchemaCatalog.java create mode 100644 src/main/resources/META-INF/schemas/sync-data-message.schema.json create mode 100644 src/main/resources/META-INF/schemas/sync-message.schema.json create mode 100644 src/main/resources/META-INF/schemas/sync-story-message.schema.json diff --git a/build.gradle.kts b/build.gradle.kts index 357fb3b0..fb27dfe4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -72,6 +72,11 @@ val excludePatterns = mapOf( ) ) +val schemaAnnotationProcessor by configurations.creating { + isCanBeConsumed = false + isCanBeResolved = true +} + dependencies { registerTransform(JarFileExcluder::class) { from.attribute(minified, false).attribute(artifactType, "jar") @@ -82,8 +87,8 @@ dependencies { } } - annotationProcessor(libs.micronaut.json.schema.processor) - annotationProcessor(libs.micronaut.inject.java) + schemaAnnotationProcessor(libs.micronaut.json.schema.processor) + schemaAnnotationProcessor(libs.micronaut.inject.java) implementation(libs.bouncycastle) implementation(libs.jackson.databind) @@ -112,14 +117,6 @@ tasks.withType().configureEach { tasks.withType().configureEach { options.encoding = "UTF-8" - options.compilerArgs.addAll( - listOf( - "-Amicronaut.processing.group=org.asamk", - "-Amicronaut.processing.module=signal-cli", - "-Amicronaut.processing.annotations=org.asamk.signal.json.*", - "-Amicronaut.jsonschema.baseUri=https://example.com/schemas", - ) - ) } tasks.withType { @@ -152,8 +149,42 @@ tasks.register("fatJar", type = Jar::class) { with(tasks.jar.get()) } +val compileJsonSchemas by tasks.registering(JavaCompile::class) { + dependsOn(tasks.compileJava) + + source = sourceSets.main.get().java + include("org/asamk/signal/json/**/*.java") + + // Exclude files with @JsonUnwrapped and files that reference them + exclude("org/asamk/signal/json/JsonSyncDataMessage.java") + exclude("org/asamk/signal/json/JsonSyncStoryMessage.java") + exclude("org/asamk/signal/json/JsonSyncMessage.java") + + classpath = sourceSets.main.get().compileClasspath + files(sourceSets.main.get().java.destinationDirectory) + destinationDirectory.set(layout.buildDirectory.dir("classes/java/schemas")) + + options.annotationProcessorPath = schemaAnnotationProcessor + options.compilerArgs.addAll( + listOf( + "-Amicronaut.processing.group=org.asamk", + "-Amicronaut.processing.module=signal-cli", + "-Amicronaut.processing.annotations=org.asamk.signal.json.*", + "-Amicronaut.jsonschema.baseUri=https://example.com/schemas", + ) + ) + + doLast { + // Copy manual schemas for classes with @JsonUnwrapped + copy { + from("src/main/resources/META-INF/schemas") + into(destinationDirectory.get().dir("META-INF/schemas")) + include("*.schema.json") + } + } +} + tasks.register("genJsonSchemas") { group = "application" description = "Generate JSON schemas using annotation processing" - dependsOn(tasks.compileJava) + dependsOn(compileJsonSchemas) } diff --git a/src/main/java/org/asamk/signal/json/JsonSchemaCatalog.java b/src/main/java/org/asamk/signal/json/JsonSchemaCatalog.java deleted file mode 100644 index 8f711f8b..00000000 --- a/src/main/java/org/asamk/signal/json/JsonSchemaCatalog.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.asamk.signal.json; - -import io.micronaut.jsonschema.JsonSchema; - -import java.util.List; - -@JsonSchema(title = "SchemaCatalog") -public class JsonSchemaCatalog { - - public JsonAdminDelete adminDelete; - public JsonAttachment attachment; - public JsonAttachmentData attachmentData; - public JsonCallMessage callMessage; - public JsonContact contact; - public JsonContactAddress contactAddress; - public JsonContactAvatar contactAvatar; - public JsonContactEmail contactEmail; - public JsonContactName contactName; - public JsonContactPhone contactPhone; - public JsonDataMessage dataMessage; - public JsonEditMessage editMessage; - public JsonError error; - public JsonGroupInfo groupInfo; - public JsonMention mention; - public JsonMessageEnvelope messageEnvelope; - public JsonPayment payment; - public JsonPinMessage pinMessage; - public JsonPollCreate pollCreate; - public JsonPollTerminate pollTerminate; - public JsonPollVote pollVote; - public JsonPreview preview; - public JsonQuote quote; - public JsonQuotedAttachment quotedAttachment; - public JsonReaction reaction; - public JsonReceiptMessage receiptMessage; - public JsonRecipientAddress recipientAddress; - public JsonRemoteDelete remoteDelete; - public JsonSendMessageResult sendMessageResult; - public JsonSharedContact sharedContact; - public JsonSticker sticker; - public JsonStoryContext storyContext; - public JsonStoryMessage storyMessage; - public JsonSyncDataMessage syncDataMessage; - public JsonSyncMessage syncMessage; - public JsonSyncReadMessage syncReadMessage; - public JsonSyncStoryMessage syncStoryMessage; - public JsonTextStyle textStyle; - public JsonTypingMessage typingMessage; - public JsonUnpinMessage unpinMessage; - - public List attachments; - public List mentions; - public List previews; - public List contacts; - public List textStyles; -} diff --git a/src/main/resources/META-INF/schemas/sync-data-message.schema.json b/src/main/resources/META-INF/schemas/sync-data-message.schema.json new file mode 100644 index 00000000..d3cb4a50 --- /dev/null +++ b/src/main/resources/META-INF/schemas/sync-data-message.schema.json @@ -0,0 +1,111 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/schemas/sync-data-message.schema.json", + "title": "SyncDataMessage", + "type": "object", + "properties": { + "adminDelete": { + "$ref": "https://example.com/schemas/admin-delete.schema.json" + }, + "attachments": { + "type": "array", + "items": { + "$ref": "https://example.com/schemas/attachment.schema.json" + } + }, + "contacts": { + "type": "array", + "items": { + "$ref": "https://example.com/schemas/shared-contact.schema.json" + } + }, + "destination": { + "type": "string" + }, + "destinationNumber": { + "type": "string" + }, + "destinationUuid": { + "type": "string" + }, + "editMessage": { + "$ref": "https://example.com/schemas/edit-message.schema.json" + }, + "expiresInSeconds": { + "type": "integer" + }, + "groupInfo": { + "$ref": "https://example.com/schemas/group-info.schema.json" + }, + "isExpirationUpdate": { + "type": "boolean" + }, + "mentions": { + "type": "array", + "items": { + "$ref": "https://example.com/schemas/mention.schema.json" + } + }, + "message": { + "type": "string" + }, + "payment": { + "$ref": "https://example.com/schemas/payment.schema.json" + }, + "pinMessage": { + "$ref": "https://example.com/schemas/pin-message.schema.json" + }, + "pollCreate": { + "$ref": "https://example.com/schemas/poll-create.schema.json" + }, + "pollTerminate": { + "$ref": "https://example.com/schemas/poll-terminate.schema.json" + }, + "pollVote": { + "$ref": "https://example.com/schemas/poll-vote.schema.json" + }, + "previews": { + "type": "array", + "items": { + "$ref": "https://example.com/schemas/preview.schema.json" + } + }, + "quote": { + "$ref": "https://example.com/schemas/quote.schema.json" + }, + "reaction": { + "$ref": "https://example.com/schemas/reaction.schema.json" + }, + "remoteDelete": { + "$ref": "https://example.com/schemas/remote-delete.schema.json" + }, + "sticker": { + "$ref": "https://example.com/schemas/sticker.schema.json" + }, + "storyContext": { + "$ref": "https://example.com/schemas/story-context.schema.json" + }, + "textStyles": { + "type": "array", + "items": { + "$ref": "https://example.com/schemas/text-style.schema.json" + } + }, + "timestamp": { + "type": "integer" + }, + "unpinMessage": { + "$ref": "https://example.com/schemas/unpin-message.schema.json" + }, + "viewOnce": { + "type": "boolean" + } + }, + "required": [ + "destinationNumber", + "destinationUuid", + "message", + "expiresInSeconds", + "timestamp" + ] +} diff --git a/src/main/resources/META-INF/schemas/sync-message.schema.json b/src/main/resources/META-INF/schemas/sync-message.schema.json new file mode 100644 index 00000000..26b2a1c7 --- /dev/null +++ b/src/main/resources/META-INF/schemas/sync-message.schema.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/schemas/sync-message.schema.json", + "title": "SyncMessage", + "type": "object", + "properties": { + "blockedGroupIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "blockedNumbers": { + "type": "array", + "items": { + "type": "string" + } + }, + "readMessages": { + "type": "array", + "items": { + "$ref": "https://example.com/schemas/sync-read-message.schema.json" + } + }, + "sentMessage": { + "$ref": "https://example.com/schemas/sync-data-message.schema.json" + }, + "sentStoryMessage": { + "$ref": "https://example.com/schemas/sync-story-message.schema.json" + }, + "type": { + "type": "string", + "enum": [ + "CONTACTS_SYNC", + "GROUPS_SYNC", + "REQUEST_SYNC" + ] + } + } +} diff --git a/src/main/resources/META-INF/schemas/sync-story-message.schema.json b/src/main/resources/META-INF/schemas/sync-story-message.schema.json new file mode 100644 index 00000000..d17a775c --- /dev/null +++ b/src/main/resources/META-INF/schemas/sync-story-message.schema.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/schemas/sync-story-message.schema.json", + "title": "SyncStoryMessage", + "type": "object", + "properties": { + "allowsReplies": { + "type": "boolean" + }, + "destinationNumber": { + "type": "string" + }, + "destinationUuid": { + "type": "string" + }, + "fileAttachment": { + "$ref": "https://example.com/schemas/attachment.schema.json" + }, + "groupId": { + "type": "string" + }, + "textAttachment": { + "type": "object", + "properties": { + "backgroundColor": { + "type": "string" + }, + "backgroundGradient": { + "type": "object" + }, + "preview": { + "$ref": "https://example.com/schemas/preview.schema.json" + }, + "style": { + "type": "string" + }, + "text": { + "type": "string" + }, + "textBackgroundColor": { + "type": "string" + }, + "textForegroundColor": { + "type": "string" + } + }, + "required": [ + "text" + ] + } + }, + "required": [ + "destinationNumber", + "destinationUuid", + "allowsReplies" + ] +}