diff --git a/lapis/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt b/lapis/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt index b7836ebf..7cd5a9d9 100644 --- a/lapis/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt +++ b/lapis/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt @@ -347,16 +347,29 @@ private fun filterFieldSchema(fieldType: SequenceFilterFieldType) = Schema().anyOf( listOf( nullableStringSchema(fieldType.openApiType), - nullableStringArraySchema(fieldType.openApiType), + logicalOrArraySchema(nullableStringSchema(fieldType.openApiType)), + ), + ) + + is SequenceFilterFieldType.StringSearch -> + Schema().anyOf( + listOf( + nullableStringRegexSchema(fieldType.associatedField), + logicalOrArraySchema(nullableStringRegexSchema(fieldType.associatedField)), ), ) else -> nullableStringSchema(fieldType.openApiType) } -private fun nullableStringSchema(type: String) = Schema().type(type).nullable(true) +private fun nullableStringRegexSchema(associatedField: SequenceFilterFieldName) = + nullableStringSchema("string") + .description( + "A regex pattern (subset of PCRE) for filtering '$associatedField'. " + + "For details on the syntax, see https://github.com/google/re2/wiki/Syntax.", + ) -private fun nullableStringArraySchema(type: String) = arraySchema(nullableStringSchema(type)) +private fun nullableStringSchema(type: String) = Schema().type(type).nullable(true) private fun requestSchemaForCommonSequenceFilters( requestProperties: Map>, @@ -502,7 +515,7 @@ private fun aminoAcidInsertionSchema() = private fun nucleotideMutations() = Schema>() .type("array") - .description(NUCLEOTIDE_MUTATION_DESCRIPTION) + .description("Logical \"and\" concatenation of a list of mutations.") .items( Schema() .type("string") @@ -513,6 +526,7 @@ private fun nucleotideMutations() = private fun aminoAcidMutations() = Schema>() .type("array") + .description("Logical \"and\" concatenation of a list of mutations.") .items( Schema() .type("string") @@ -523,6 +537,7 @@ private fun aminoAcidMutations() = private fun nucleotideInsertions() = Schema>() .type("array") + .description("Logical \"and\" concatenation of a list of insertions.") .items( Schema() .type("string") @@ -538,6 +553,7 @@ private fun nucleotideInsertions() = private fun aminoAcidInsertions() = Schema>() .type("array") + .description("Logical \"and\" concatenation of a list of insertions.") .items( Schema() .type("string") @@ -639,6 +655,10 @@ private fun fieldsEnum( .type("string") ._enum(databaseConfig.map { it.name } + additionalFields) +private fun logicalOrArraySchema(schema: Schema) = + arraySchema(schema) + .description("Logical \"or\" concatenation of a list of values.") + private fun arraySchema(schema: Schema) = ArraySchema() .items(schema)