Skip to content

Commit 87c075d

Browse files
MarcelBochtlersschuberth
authored andcommitted
fix(schema): Fix JSON schema for package-configuration
[1] introduced `sourceCodeOrigin` field. Add this missing field and specify the requirements and restrictions for the three mutually exclusive fields in the schema. [1]: #10375 Signed-off-by: Marcel Bochtler <[email protected]>
1 parent e69cbbe commit 87c075d

File tree

2 files changed

+154
-12
lines changed

2 files changed

+154
-12
lines changed

integrations/schemas/package-configuration-schema.json

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
},
4141
"source_artifact_url": {
4242
"type": "string"
43+
},
44+
"source_code_origin": {
45+
"enum": [
46+
"VCS",
47+
"ARTIFACT"
48+
]
4349
}
4450
},
4551
"definitions": {
@@ -143,16 +149,27 @@
143149
"required": [
144150
"id"
145151
],
146-
"oneOf": [
147-
{
148-
"required": [
149-
"vcs"
150-
]
151-
},
152-
{
153-
"required": [
154-
"source_artifact_url"
155-
]
156-
}
157-
]
152+
"not": {
153+
"description": "A package configuration must contain at most one of 'vcs', 'source_artifact_url', or 'source_code_origin'.",
154+
"anyOf": [
155+
{
156+
"allOf": [
157+
{ "required": ["vcs"] },
158+
{ "required": ["source_artifact_url"] }
159+
]
160+
},
161+
{
162+
"allOf": [
163+
{ "required": ["vcs"] },
164+
{ "required": ["source_code_origin"] }
165+
]
166+
},
167+
{
168+
"allOf": [
169+
{ "required": ["source_artifact_url"] },
170+
{ "required": ["source_code_origin"] }
171+
]
172+
}
173+
]
174+
}
158175
}

model/src/test/kotlin/JsonSchemaTest.kt

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import io.kotest.core.spec.style.StringSpec
2727
import io.kotest.inspectors.forAll
2828
import io.kotest.matchers.collections.beEmpty
2929
import io.kotest.matchers.should
30+
import io.kotest.matchers.shouldNot
3031

3132
import java.io.File
3233

@@ -138,6 +139,130 @@ class JsonSchemaTest : StringSpec({
138139

139140
errors should beEmpty()
140141
}
142+
143+
"Package configuration with no matchers validates successfully" {
144+
val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI()
145+
val schema = schemaV7.getSchema(packageConfigurationSchema)
146+
147+
val configWithNoMatchers = """
148+
id: "Pip::example-package:0.0.1"
149+
""".trimIndent()
150+
151+
val errors = schema.validate(configWithNoMatchers, InputFormat.YAML)
152+
153+
errors should beEmpty()
154+
}
155+
156+
"Package configuration with only vcs validates successfully" {
157+
val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI()
158+
val schema = schemaV7.getSchema(packageConfigurationSchema)
159+
160+
val configWithVcs = """
161+
id: "Pip::example-package:0.0.1"
162+
vcs:
163+
type: "Git"
164+
url: "https://github.com/example/repo.git"
165+
""".trimIndent()
166+
167+
val errors = schema.validate(configWithVcs, InputFormat.YAML)
168+
169+
errors should beEmpty()
170+
}
171+
172+
"Package configuration with only source_artifact_url validates successfully" {
173+
val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI()
174+
val schema = schemaV7.getSchema(packageConfigurationSchema)
175+
176+
val configWithSourceArtifact = """
177+
id: "Pip::example-package:0.0.1"
178+
source_artifact_url: "https://example.com/package.tar.gz"
179+
""".trimIndent()
180+
181+
val errors = schema.validate(configWithSourceArtifact, InputFormat.YAML)
182+
183+
errors should beEmpty()
184+
}
185+
186+
"Package configuration with only source_code_origin validates successfully" {
187+
val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI()
188+
val schema = schemaV7.getSchema(packageConfigurationSchema)
189+
190+
val configWithSourceCodeOrigin = """
191+
id: "Pip::example-package:0.0.1"
192+
source_code_origin: "VCS"
193+
""".trimIndent()
194+
195+
val errors = schema.validate(configWithSourceCodeOrigin, InputFormat.YAML)
196+
197+
errors should beEmpty()
198+
}
199+
200+
"Package configuration with vcs and source_artifact_url fails validation" {
201+
val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI()
202+
val schema = schemaV7.getSchema(packageConfigurationSchema)
203+
204+
val configWithVcsAndSourceArtifact = """
205+
id: "Pip::example-package:0.0.1"
206+
vcs:
207+
type: "Git"
208+
url: "https://github.com/example/repo.git"
209+
source_artifact_url: "https://example.com/package.tar.gz"
210+
""".trimIndent()
211+
212+
val errors = schema.validate(configWithVcsAndSourceArtifact, InputFormat.YAML)
213+
214+
errors shouldNot beEmpty()
215+
}
216+
217+
"Package configuration with vcs and source_code_origin fails validation" {
218+
val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI()
219+
val schema = schemaV7.getSchema(packageConfigurationSchema)
220+
221+
val configWithVcsAndSourceCodeOrigin = """
222+
id: "Pip::example-package:0.0.1"
223+
vcs:
224+
type: "Git"
225+
url: "https://github.com/example/repo.git"
226+
source_code_origin: "VCS"
227+
""".trimIndent()
228+
229+
val errors = schema.validate(configWithVcsAndSourceCodeOrigin, InputFormat.YAML)
230+
231+
errors shouldNot beEmpty()
232+
}
233+
234+
"Package configuration with source_artifact_url and source_code_origin fails validation" {
235+
val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI()
236+
val schema = schemaV7.getSchema(packageConfigurationSchema)
237+
238+
val configWithSourceArtifactAndSourceCodeOrigin = """
239+
id: "Pip::example-package:0.0.1"
240+
source_artifact_url: "https://example.com/package.tar.gz"
241+
source_code_origin: "ARTIFACT"
242+
""".trimIndent()
243+
244+
val errors = schema.validate(configWithSourceArtifactAndSourceCodeOrigin, InputFormat.YAML)
245+
246+
errors shouldNot beEmpty()
247+
}
248+
249+
"Package configuration with all three matchers fails validation" {
250+
val packageConfigurationSchema = File("../integrations/schemas/package-configuration-schema.json").toURI()
251+
val schema = schemaV7.getSchema(packageConfigurationSchema)
252+
253+
val configWithAllMatchers = """
254+
id: "Pip::example-package:0.0.1"
255+
vcs:
256+
type: "Git"
257+
url: "https://github.com/example/repo.git"
258+
source_artifact_url: "https://example.com/package.tar.gz"
259+
source_code_origin: "VCS"
260+
""".trimIndent()
261+
262+
val errors = schema.validate(configWithAllMatchers, InputFormat.YAML)
263+
264+
errors shouldNot beEmpty()
265+
}
141266
})
142267

143268
private val schemaV7 = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)

0 commit comments

Comments
 (0)