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

Enums in query params #25

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
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
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)
}

Comment on lines +103 to +108
Copy link

@rpiotrow rpiotrow Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work nice for enum values, but example is still not rendered correctly:
Screenshot from 2023-10-18 11-19-58

Copy link

@rpiotrow rpiotrow Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example in the param is rendered incorrectly, while in the schema it is okay:

      - name: role
        in: query
        required: false
        schema:
          type: string
          example: Admin
          enum:
          - Admin
        example: {}

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
Loading