Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lapis): hint to which regex syntax is used in Swagger docs #907

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions lapis/src/main/kotlin/org/genspectrum/lapis/openApi/OpenApiDocs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,29 @@ private fun filterFieldSchema(fieldType: SequenceFilterFieldType) =
Schema<String>().anyOf(
listOf(
nullableStringSchema(fieldType.openApiType),
nullableStringArraySchema(fieldType.openApiType),
logicalOrArraySchema(nullableStringSchema(fieldType.openApiType)),
),
)

is SequenceFilterFieldType.StringSearch ->
Schema<String>().anyOf(
listOf(
nullableStringRegexSchema(fieldType.associatedField),
logicalOrArraySchema(nullableStringRegexSchema(fieldType.associatedField)),
),
)

else -> nullableStringSchema(fieldType.openApiType)
}

private fun nullableStringSchema(type: String) = Schema<String>().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<String>().type(type).nullable(true)

private fun requestSchemaForCommonSequenceFilters(
requestProperties: Map<SequenceFilterFieldName, Schema<out Any>>,
Expand Down Expand Up @@ -502,7 +515,7 @@ private fun aminoAcidInsertionSchema() =
private fun nucleotideMutations() =
Schema<List<NucleotideMutation>>()
.type("array")
.description(NUCLEOTIDE_MUTATION_DESCRIPTION)
.description("Logical \"and\" concatenation of a list of mutations.")
.items(
Schema<String>()
.type("string")
Expand All @@ -513,6 +526,7 @@ private fun nucleotideMutations() =
private fun aminoAcidMutations() =
Schema<List<AminoAcidMutation>>()
.type("array")
.description("Logical \"and\" concatenation of a list of mutations.")
.items(
Schema<String>()
.type("string")
Expand All @@ -523,6 +537,7 @@ private fun aminoAcidMutations() =
private fun nucleotideInsertions() =
Schema<List<NucleotideInsertion>>()
.type("array")
.description("Logical \"and\" concatenation of a list of insertions.")
.items(
Schema<String>()
.type("string")
Expand All @@ -538,6 +553,7 @@ private fun nucleotideInsertions() =
private fun aminoAcidInsertions() =
Schema<List<AminoAcidInsertion>>()
.type("array")
.description("Logical \"and\" concatenation of a list of insertions.")
.items(
Schema<String>()
.type("string")
Expand Down Expand Up @@ -639,6 +655,10 @@ private fun fieldsEnum(
.type("string")
._enum(databaseConfig.map { it.name } + additionalFields)

private fun logicalOrArraySchema(schema: Schema<Any>) =
arraySchema(schema)
.description("Logical \"or\" concatenation of a list of values.")

private fun arraySchema(schema: Schema<Any>) =
ArraySchema()
.items(schema)