Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull resources from submodules instead of copying from submodules #139

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
matrix:
os: [ ubuntu-latest ]
steps:
- uses: actions/checkout@v2
- name: Checkout source
uses: actions/checkout@v2
with:
submodules: 'true'
- uses: gradle/wrapper-validation-action@v1
- uses: actions/setup-java@v1
with:
Expand Down
19 changes: 12 additions & 7 deletions protocol/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ dependencies {
testImplementation("com.willowtreeapps.assertk:assertk:0.27.0")
}

tasks {
register("syncSchemas", Sync::class) {
from("../tbdex/hosted/json-schemas")
into("./src/main/resources")
sourceSets {
val test by getting {
val resourceDirs = listOf(
"../tbdex/hosted/test-vectors/protocol/vectors",
)
resources.setSrcDirs(resourceDirs)
}

register("syncTestVectors", Sync::class) {
from("../tbdex/hosted/test-vectors/protocol/vectors")
into("./src/test/resources/test-vectors")
main {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really sure the diff between this vs using val main by getting {.. but this one works! 🤷

val resourceDirs = listOf(
"../tbdex/hosted/json-schemas"
)

resources.setSrcDirs(resourceDirs)
}
}

Expand Down
9 changes: 5 additions & 4 deletions protocol/src/main/kotlin/tbdex/sdk/protocol/Validator.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tbdex.sdk.protocol

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.networknt.schema.JsonSchema
import com.networknt.schema.JsonSchemaFactory
import com.networknt.schema.SchemaValidatorsConfig
Expand Down Expand Up @@ -32,21 +31,23 @@ object Validator {
* Initializes the validator by loading schemas for messages and resources.
*/
init {
val loader = Thread.currentThread().contextClassLoader

// Translate external URIs into internal resource URIs
config.addUriTranslator { uri: URI ->
val uriStr = uri.toString()
val prefix = "https://tbdex.dev/"
if (uriStr.startsWith(prefix)) {
val resourceName = uriStr.substring(prefix.length)
val resourceUri = object {}.javaClass.getResource("/$resourceName")?.toURI()
val resourceUri = loader.getResource(resourceName)?.toURI()
return@addUriTranslator resourceUri
}
return@addUriTranslator uri
}

val factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)

val definitionsStream = object {}.javaClass.getResourceAsStream("/definitions.json")
val definitionsStream = loader.getResourceAsStream("definitions.json")
factory.getSchema(definitionsStream, config)

val schemaNames = listOf("message" to "message.schema.json", "resource" to "resource.schema.json") +
Expand All @@ -55,7 +56,7 @@ object Validator {

for (schemaName in schemaNames) {
val (name, fileName) = schemaName
val schemaStream = object {}.javaClass.getResourceAsStream("/$fileName")
val schemaStream = loader.getResourceAsStream(fileName)
schemaMap[name] = factory.getSchema(schemaStream, config)
}
}
Expand Down
11 changes: 0 additions & 11 deletions protocol/src/main/resources/close.schema.json

This file was deleted.

15 changes: 0 additions & 15 deletions protocol/src/main/resources/definitions.json

This file was deleted.

61 changes: 0 additions & 61 deletions protocol/src/main/resources/message.schema.json

This file was deleted.

83 changes: 0 additions & 83 deletions protocol/src/main/resources/offering.schema.json

This file was deleted.

7 changes: 0 additions & 7 deletions protocol/src/main/resources/order.schema.json

This file was deleted.

14 changes: 0 additions & 14 deletions protocol/src/main/resources/orderstatus.schema.json

This file was deleted.

57 changes: 0 additions & 57 deletions protocol/src/main/resources/quote.schema.json

This file was deleted.

4 changes: 0 additions & 4 deletions protocol/src/main/resources/reputation.schema.json

This file was deleted.

46 changes: 0 additions & 46 deletions protocol/src/main/resources/resource.schema.json

This file was deleted.

Loading
Loading