Skip to content

Commit

Permalink
Enums in query params (#25)
Browse files Browse the repository at this point in the history
* Enums in query params
  • Loading branch information
kristerr authored Oct 31, 2023
1 parent f89f7e1 commit c926c53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -99,12 +100,17 @@ 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
}
}
Expand Down

0 comments on commit c926c53

Please sign in to comment.