@@ -13,51 +13,55 @@ import org.genspectrum.lapis.controller.REQUEST_SCHEMA_WITH_MIN_PROPORTION
13
13
import org.genspectrum.lapis.controller.RESPONSE_SCHEMA_AGGREGATED
14
14
15
15
fun buildOpenApiSchema (sequenceFilterFields : SequenceFilterFields , databaseConfig : DatabaseConfig ): OpenAPI {
16
- var properties = sequenceFilterFields.fields
16
+ val filterProperties = sequenceFilterFields.fields
17
17
.map { (fieldName, fieldType) -> fieldName to Schema <String >().type(fieldType.openApiType) }
18
18
.toMap()
19
19
20
- if (databaseConfig.schema.opennessLevel == OpennessLevel .PROTECTED ) {
21
- properties = properties + (" accessKey" to accessKeySchema)
20
+ val requestProperties = when (databaseConfig.schema.opennessLevel) {
21
+ OpennessLevel .PROTECTED -> filterProperties + (" accessKey" to accessKeySchema)
22
+ else -> filterProperties
22
23
}
23
24
25
+ val responseProperties = filterProperties + mapOf (
26
+ " count" to Schema <String >().type(" number" ),
27
+ )
28
+
24
29
return OpenAPI ()
25
30
.components(
26
31
Components ().addSchemas(
27
32
REQUEST_SCHEMA ,
28
33
Schema <String >()
29
34
.type(" object" )
30
35
.description(" valid filters for sequence data" )
31
- .properties(properties ),
36
+ .properties(requestProperties ),
32
37
).addSchemas(
33
38
REQUEST_SCHEMA_WITH_MIN_PROPORTION ,
34
39
Schema <String >()
35
40
.type(" object" )
36
41
.description(" valid filters for sequence data" )
37
- .properties(properties + Pair (MIN_PROPORTION_PROPERTY , Schema <String >().type(" number" ))),
42
+ .properties(requestProperties + Pair (MIN_PROPORTION_PROPERTY , Schema <String >().type(" number" ))),
38
43
).addSchemas(
39
44
REQUEST_SCHEMA_WITH_GROUP_BY_FIELDS ,
40
45
Schema <String >()
41
46
.type(" object" )
42
47
.description(" valid filters for sequence data" )
43
48
.properties(
44
- properties + Pair (
49
+ requestProperties + Pair (
45
50
" fields" ,
46
- Schema < String >().type( " array " ).items( Schema < String >().type( " string " )) ,
51
+ fieldsSchema ,
47
52
),
48
53
),
49
54
).addSchemas(
50
55
RESPONSE_SCHEMA_AGGREGATED ,
51
56
Schema <String >()
52
57
.type(" object" )
53
- .description(" aggregated sequence data" )
58
+ .description(
59
+ " Aggregated sequence data. " +
60
+ " If fields are specified, then these fields are also keys in the result. " +
61
+ " The key 'count' is always present." ,
62
+ )
54
63
.required(listOf (" count" ))
55
- .properties(
56
- properties +
57
- mapOf (
58
- " count" to Schema <String >().type(" number" ),
59
- ),
60
- ),
64
+ .properties(responseProperties),
61
65
),
62
66
)
63
67
}
@@ -69,3 +73,11 @@ private val accessKeySchema = Schema<String>()
69
73
" There are two types or access keys: One only grants access to aggregated data, " +
70
74
" the other also grants access to detailed data." ,
71
75
)
76
+
77
+ private val fieldsSchema = Schema <String >()
78
+ .type(" array" )
79
+ .items(Schema <String >().type(" string" ))
80
+ .description(
81
+ " The fields to stratify the result by. " +
82
+ " The response will contain the fields specified here with their respective values." ,
83
+ )
0 commit comments