Skip to content

Commit 388d196

Browse files
committed
added support for openapi-processor-spring mapping identifier (openapi-processor/openapi-processor-spring#439)
1 parent e82f579 commit 388d196

5 files changed

Lines changed: 99 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## [Unreleased]
66

7+
- added support for `openapi-processor-spring` mapping.yaml identifier (for `openapi-processor-spring` 2026.3).
78
- updated the minimum platform to 2025.3.
89

910
## [2025.2]

src/main/kotlin/io/openapiprocessor/intellij/TypeMappingFileType.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory
1717
import java.io.IOException
1818
import javax.swing.Icon
1919

20-
val KEY_REGEX = Regex("""^${TypeMappingFileType.KEY}:\s+v\d+\s+""")
20+
val KEY_REGEX = Regex("""^${TypeMappingFileType.PREFIX}-[a-z]+:\s+v\d+\s+""")
2121

2222
class TypeMappingFileType :
2323
LanguageFileType(YAMLLanguage.INSTANCE, true),
@@ -78,5 +78,6 @@ class TypeMappingFileType :
7878
companion object {
7979
const val NAME = "openapi-processor mapping"
8080
const val KEY = "openapi-processor-mapping"
81+
const val PREFIX = "openapi-processor"
8182
}
8283
}

src/main/kotlin/io/openapiprocessor/intellij/TypeMappingSchemaProvider.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@ class TypeMappingSchemaProvider: ContentAwareJsonSchemaFileProvider {
1717
return null
1818

1919
val start = String(file.virtualFile.inputStream.readNBytes(64))
20-
val regex = Regex("""^${TypeMappingFileType.KEY}:\s+(v\d+)\s*$""", RegexOption.MULTILINE)
20+
val regex = Regex("""^${TypeMappingFileType.PREFIX}-([a-z]+):\s+(v\d+)\s*$""", RegexOption.MULTILINE)
2121
val match = regex.find(start) ?: return null
22-
val version = match.groups[1] ?: return null
2322

24-
return getSchema(version.value)
23+
val type = match.groups[1] ?: return null
24+
val version = match.groups[2] ?: return null
25+
26+
return getSchema(type.value, version.value)
2527
}
2628

27-
private fun getSchema(version: String): VirtualFile? {
28-
// same as https://openapiprocessor.io/schemas/mapping/mapping-$version.json
29+
private fun getSchema(type: String, version: String): VirtualFile? {
30+
// same as https://openapiprocessor.io/schemas/mapping/$type-$version.json
2931
@Suppress("UnstableApiUsage")
3032
return HttpsFileSystem.getHttpsInstance().findFileByPath(
3133
"raw.githubusercontent.com" +
3234
"/openapi-processor/openapi-processor" +
33-
"/master/public/schemas/mapping/mapping-$version.json"
35+
"/master/public/schemas/mapping/$type-$version.json"
3436
)
3537
}
3638

src/test/kotlin/io/openapiprocessor/intellij/FileTypeSpec.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ class FileTypeSpec {
4242
package-name: io.openapiprocessor
4343
""".trimIndent())
4444

45+
val springMappingYaml = sourceRoot.virtualFileFixture(
46+
"spring-mapping.yaml", """
47+
openapi-processor-spring: v0
48+
options:
49+
package-name: io.openapiprocessor
50+
""".trimIndent())
51+
4552
val directory = sourceRoot.virtualDirFixture("folder")
4653

4754
val jar = testFixture {
@@ -89,6 +96,18 @@ class FileTypeSpec {
8996
assertTrue(mappingYml.get().fileType is TypeMappingFileType)
9097
}
9198

99+
@Test
100+
fun `detects file type with 'openapi-processor-mapping' identifier`() {
101+
assertEquals(TypeMappingFileType.NAME, mappingYaml.get().fileType.name)
102+
assertTrue(mappingYaml.get().fileType is TypeMappingFileType)
103+
}
104+
105+
@Test
106+
fun `detects file type with 'openapi-processor-spring' identifier`() {
107+
assertEquals(TypeMappingFileType.NAME, springMappingYaml.get().fileType.name)
108+
assertTrue(springMappingYaml.get().fileType is TypeMappingFileType)
109+
}
110+
92111
@Test
93112
fun `ignores directory`() {
94113
assertNotEquals(TypeMappingFileType.NAME, directory.get().fileType.name)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2026 https://github.com/openapi-processor/openapi-processor-intellij
3+
* PDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.openapiprocessor.intellij
7+
8+
import com.intellij.openapi.application.runReadAction
9+
import com.intellij.testFramework.junit5.TestApplication
10+
import com.intellij.testFramework.junit5.fixture.moduleFixture
11+
import com.intellij.testFramework.junit5.fixture.projectFixture
12+
import com.intellij.testFramework.junit5.fixture.sourceRootFixture
13+
import com.intellij.testFramework.junit5.fixture.virtualFileFixture
14+
import com.intellij.testFramework.utils.vfs.getPsiFile
15+
import org.junit.jupiter.api.Assertions.assertEquals
16+
import org.junit.jupiter.api.Test
17+
18+
@TestApplication
19+
class TypeMappingSchemaProviderSpec {
20+
companion object {
21+
val project = projectFixture()
22+
val module = project.moduleFixture("main")
23+
val sourceRoot = module.sourceRootFixture()
24+
25+
val mappingYaml = sourceRoot.virtualFileFixture(
26+
"mapping.yaml", """
27+
openapi-processor-mapping: v18
28+
options:
29+
package-name: io.openapiprocessor
30+
""".trimIndent())
31+
32+
val springMappingYaml = sourceRoot.virtualFileFixture(
33+
"spring-mapping.yaml", """
34+
openapi-processor-spring: v1
35+
options:
36+
package-name: io.openapiprocessor
37+
""".trimIndent())
38+
}
39+
40+
@Test
41+
fun `detects openapi-processor-mapping schema`() {
42+
val provider = TypeMappingSchemaProvider()
43+
44+
runReadAction {
45+
val schema = provider.getSchemaFile(mappingYaml.get().getPsiFile(project.get()))
46+
47+
assertEquals(
48+
"raw.githubusercontent.com" +
49+
"/openapi-processor/openapi-processor" +
50+
"/master/public/schemas/mapping/mapping-v18.json",
51+
schema!!.canonicalPath)
52+
}
53+
}
54+
55+
@Test
56+
fun `detects openapi-processor-spring schema`() {
57+
val provider = TypeMappingSchemaProvider()
58+
59+
runReadAction {
60+
val schema = provider.getSchemaFile(springMappingYaml.get().getPsiFile(project.get()))
61+
62+
assertEquals(
63+
"raw.githubusercontent.com" +
64+
"/openapi-processor/openapi-processor" +
65+
"/master/public/schemas/mapping/spring-v1.json",
66+
schema!!.canonicalPath)
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)