From ec7d04f5da23089264fc03e40355c11bcc1d11a1 Mon Sep 17 00:00:00 2001 From: Fabian Engelniederhammer Date: Thu, 22 Aug 2024 09:00:15 +0200 Subject: [PATCH] feat(lapis): hint to which regex syntax is used in Swagger docs closes #903 --- .../genspectrum/lapis/openApi/OpenApiDocs.kt | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) 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..c411c454 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 close to 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)