From 48fb6ccd8fce5bb280d609b856001a9ccf3fa094 Mon Sep 17 00:00:00 2001 From: Krzysztof Palcowski Date: Tue, 17 Oct 2023 16:21:09 +0200 Subject: [PATCH] Enums in query params --- .../core/model/RouteParameterRepresentation.scala | 5 ++++- .../formatter/openapi/OpenApiFormatterWorker.scala | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/pl/iterators/baklava/core/model/RouteParameterRepresentation.scala b/core/src/main/scala/pl/iterators/baklava/core/model/RouteParameterRepresentation.scala index caaee6d..76842c9 100644 --- a/core/src/main/scala/pl/iterators/baklava/core/model/RouteParameterRepresentation.scala +++ b/core/src/main/scala/pl/iterators/baklava/core/model/RouteParameterRepresentation.scala @@ -6,10 +6,13 @@ case class RouteParameterRepresentation[T]( name: String, required: Boolean, sampleValue: T, - marshaller: T => String + marshaller: T => String, + enumValues: Option[Seq[T]] = None )(implicit typeTag: TypeTag[T]) { lazy val marshall: String = marshaller(sampleValue) + lazy val enums: Option[Seq[String]] = enumValues.map(values => values.map(marshaller)) + lazy val scalaType: String = typeTag.tpe.toString } diff --git a/formatter-openapi/src/main/scala/pl/iterators/baklava/formatter/openapi/OpenApiFormatterWorker.scala b/formatter-openapi/src/main/scala/pl/iterators/baklava/formatter/openapi/OpenApiFormatterWorker.scala index 84b4c56..d6c3da6 100644 --- a/formatter-openapi/src/main/scala/pl/iterators/baklava/formatter/openapi/OpenApiFormatterWorker.scala +++ b/formatter-openapi/src/main/scala/pl/iterators/baklava/formatter/openapi/OpenApiFormatterWorker.scala @@ -10,6 +10,7 @@ import io.swagger.v3.oas.models.security.{SecurityRequirement, SecurityScheme} import pl.iterators.baklava.core.model._ import pl.iterators.baklava.formatter.openapi.builders.{OpenApiBuilder, OperationBuilder, PathItemBuilder} import pl.iterators.kebs.jsonschema.JsonSchemaWrapper +import scala.jdk.CollectionConverters._ class OpenApiFormatterWorker(jsonSchemaToSwaggerSchemaWorker: JsonSchemaToSwaggerSchemaWorker) { @@ -99,12 +100,18 @@ class OpenApiFormatterWorker(jsonSchemaToSwaggerSchemaWorker: JsonSchemaToSwagge private def queryParamsToParams(parameters: List[RouteParameterRepresentation[_]]): List[Parameter] = { parameters.map { param => + val schema = new StringSchema + schema.setExample(param.sampleValue) + param.enums.foreach { values => + schema.setEnum(values.toList.asJava) + } + val p = new Parameter() p.setName(param.name) p.setIn("query") p.setExample(param.sampleValue) p.setRequired(param.required) - p.setSchema(new StringSchema) + p.setSchema(schema) p } }