Skip to content

Commit a493c1b

Browse files
authored
Allow containers with a single variant (#4853) (#4859)
(cherry picked from commit c3e323a) # Conflicts: # output/schema/validation-errors.json
1 parent e03eeba commit a493c1b

File tree

2 files changed

+5
-34
lines changed

2 files changed

+5
-34
lines changed

compiler/src/steps/validate-model.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -584,17 +584,10 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
584584

585585
if (typeDef.variants?.kind === 'container') {
586586
const variants = typeDef.properties.filter(prop => !(prop.containerProperty ?? false))
587-
if (variants.length === 1) {
588-
// Single-variant containers must have a required property
589-
if (!variants[0].required) {
590-
modelError(`Property ${variants[0].name} is a single-variant and must be required`)
591-
}
592-
} else {
593-
// Multiple variants must all be optional
594-
for (const v of variants) {
595-
if (v.required) {
596-
modelError(`Variant ${variants[0].name} must be optional`)
597-
}
587+
// Variants must all be optional
588+
for (const v of variants) {
589+
if (v.required) {
590+
modelError(`Variant ${variants[0].name} must be optional`)
598591
}
599592
}
600593
}

output/schema/validation-errors.json

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"endpointErrors": {
33
"async_search.submit": {
44
"request": [
5-
"Request: query parameter 'min_compatible_shard_node' does not exist in the json spec",
6-
"interface definition _types:QueryVectorBuilder - Property text_embedding is a single-variant and must be required"
5+
"Request: query parameter 'min_compatible_shard_node' does not exist in the json spec"
76
],
87
"response": []
98
},
@@ -281,12 +280,6 @@
281280
],
282281
"response": []
283282
},
284-
"search": {
285-
"request": [
286-
"interface definition _types:RankContainer - Property rrf is a single-variant and must be required"
287-
],
288-
"response": []
289-
},
290283
"search_mvt": {
291284
"request": [
292285
"Request: query parameter 'grid_agg' does not exist in the json spec",
@@ -326,21 +319,6 @@
326319
],
327320
"response": []
328321
},
329-
"transform.get_transform": {
330-
"request": [],
331-
"response": [
332-
"interface definition transform._types:RetentionPolicyContainer - Property time is a single-variant and must be required",
333-
"interface definition transform._types:SyncContainer - Property time is a single-variant and must be required"
334-
]
335-
},
336-
"watcher.execute_watch": {
337-
"request": [
338-
"interface definition watcher._types:TriggerContainer - Property schedule is a single-variant and must be required"
339-
],
340-
"response": [
341-
"interface definition watcher._types:TriggerEventContainer - Property schedule is a single-variant and must be required"
342-
]
343-
},
344322
"xpack.info": {
345323
"request": [
346324
"request definition xpack.info:Request / query - Property 'human' is already defined in an ancestor class"

0 commit comments

Comments
 (0)