Skip to content

Commit 49c97d5

Browse files
committed
refactor: clean up CCTokensService
As far as I could tell testing locally, not HTTP calls are performed towards the Draft 4 schema, so we can safely remove it.
1 parent 4540d88 commit 49c97d5

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

src/main/kotlin/com/github/lppedd/cc/configuration/CCTokensService.kt

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.github.lppedd.cc.configuration
22

33
import com.github.erosb.jsonsKema.*
4-
import com.github.erosb.jsonsKema.FormatValidationPolicy.ALWAYS
54
import com.github.lppedd.cc.*
65
import com.intellij.openapi.application.WriteAction
76
import com.intellij.openapi.components.Service
@@ -11,8 +10,6 @@ import com.intellij.openapi.vfs.LocalFileSystem
1110
import com.intellij.openapi.vfs.VirtualFile
1211
import org.codehaus.jettison.json.JSONArray
1312
import org.codehaus.jettison.json.JSONObject
14-
import java.io.Reader
15-
import java.net.URI
1613

1714
/**
1815
* Manages bundled and custom commit message tokens.
@@ -30,27 +27,12 @@ internal class CCTokensService(private val project: Project) {
3027
* JSON Schema used to validate the default commit types and scopes JSON file.
3128
*/
3229
private val tokensSchema: Schema by lazy {
33-
// See https://github.com/erosb/json-sKema/tree/master/src/main/resources/json-meta-schemas
34-
val draft04Reader = getResourceAsStream("/json-meta-schemas/draft04/schema.json").bufferedReader()
35-
val draft04Str = draft04Reader.use(Reader::readText)
36-
3730
val schemaReader = getResourceAsStream("/defaults/${CC.File.Schema}").bufferedReader()
3831
val schemaJson = schemaReader.use {
3932
JsonParser(schemaReader).parse()
4033
}
4134

42-
// Pre-populate additional Draft 4 schemas to avoid network calls.
43-
// I'm not sure whether all of these are needed, but let's play on the safe side.
44-
val config = SchemaLoaderConfig.createDefaultConfig(
45-
mapOf(
46-
URI("http://json-schema.org/draft-04/schema") to draft04Str,
47-
URI("http://json-schema.org/draft-04/schema#") to draft04Str,
48-
URI("https://json-schema.org/draft-04/schema") to draft04Str,
49-
URI("https://json-schema.org/draft-04/schema#") to draft04Str,
50-
)
51-
)
52-
53-
return@lazy SchemaLoader(schemaJson, config).load()
35+
return@lazy SchemaLoader(schemaJson).load()
5436
}
5537

5638
/**
@@ -337,7 +319,7 @@ internal class CCTokensService(private val project: Project) {
337319

338320
private fun Schema.validateJson(content: String): ValidationFailure? {
339321
val jsonValue = JsonParser(content).parse()
340-
val validator = Validator.create(this, ValidatorConfig(ALWAYS))
322+
val validator = Validator.create(this, ValidatorConfig(FormatValidationPolicy.ALWAYS))
341323
return validator.validate(jsonValue)
342324
}
343325
}

0 commit comments

Comments
 (0)