@@ -8,7 +8,11 @@ package io.openapiprocessor.intellij
88import com.intellij.openapi.vfs.VirtualFile
99import com.intellij.openapi.vfs.impl.http.HttpsFileSystem
1010import com.intellij.psi.PsiFile
11+ import com.intellij.util.net.HttpConnectionUtils
1112import com.jetbrains.jsonSchema.extension.ContentAwareJsonSchemaFileProvider
13+ import java.net.HttpURLConnection
14+
15+ const val GITHUB_PREFIX = " raw.githubusercontent.com/openapi-processor/openapi-processor/master/"
1216
1317class TypeMappingSchemaProvider : ContentAwareJsonSchemaFileProvider {
1418
@@ -28,12 +32,26 @@ class TypeMappingSchemaProvider: ContentAwareJsonSchemaFileProvider {
2832
2933 private fun getSchema (type : String , version : String ): VirtualFile ? {
3034 // same as https://openapiprocessor.io/schemas/mapping/$type-$version.json
31- @Suppress(" UnstableApiUsage" )
35+
36+ // first, check if there is a "merged" version without external $refs
37+ val mergedUrl = " ${GITHUB_PREFIX } public/schemas/mapping/$type -$version .merged.json"
38+ if (exists(mergedUrl)) {
39+ return HttpsFileSystem .getHttpsInstance().findFileByPath(mergedUrl)
40+ }
41+
42+ // if there is no merged version try the original json schema
3243 return HttpsFileSystem .getHttpsInstance().findFileByPath(
33- " raw.githubusercontent.com" +
34- " /openapi-processor/openapi-processor" +
35- " /master/public/schemas/mapping/$type -$version .json"
36- )
44+ " ${GITHUB_PREFIX } public/schemas/mapping/$type -$version .json" )
45+ }
46+
47+ private fun exists (url : String ): Boolean {
48+ try {
49+ val connection = HttpConnectionUtils .openHttpConnection(" https://${url} " )
50+ connection.setRequestMethod(" HEAD" )
51+ return connection.responseCode == HttpURLConnection .HTTP_OK
52+ } catch (_: Exception ) {
53+ return false
54+ }
3755 }
3856
3957 private fun isMappingFile (file : PsiFile ): Boolean {
0 commit comments