Skip to content
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 @@ -34,4 +34,4 @@ components:
- blue
- red
shapeType:
type: string
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
openapi: 3.0.3
info:
title: Enums
version: '1.0'
paths:
/:
get:
operationId: getRoot
responses:
'200':
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/Square'
components:
schemas:
CornerStyle:
type: string
enum:
- rounded
- straight
Square:
type: object
properties:
cornerStyle:
$ref: '#/components/schemas/CornerStyle'
tags:
type: array
items:
$ref: '#/components/schemas/Tag'
Tag:
type: string
enum:
- tag1
- tag2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import enumeratum.{EnumEntry, _}
import io.circe.generic.auto._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import sttp.tapir.Schema.SName
import sttp.tapir.docs.openapi.VerifyYamlEnumerationTest._
import sttp.tapir.generic.auto._
import sttp.tapir.json.circe._
Expand Down Expand Up @@ -82,6 +83,16 @@ class VerifyYamlEnumerationTest extends AnyFunSuite with Matchers {

noIndentation(actualYaml) shouldBe expectedYaml
}

test("should support optional enums and sequences of enums") {
implicit val shapeCodec: io.circe.Codec[Square] = null
val e = endpoint.get.out(jsonBody[Square])

val expectedYaml = load("enum/expected_enum_collections.yml")
val actualYaml = OpenAPIDocsInterpreter().toOpenAPI(e, "Enums", "1.0").toYaml

noIndentation(actualYaml) shouldBe expectedYaml
}
}

object VerifyYamlEnumerationTest {
Expand Down Expand Up @@ -122,4 +133,26 @@ object VerifyYamlEnumerationTest {

case class Error1Response(error: ErrorCode)
case class Error2Response(error: ErrorCode)

object CornerStyle extends Enumeration {
type CornerStyle = Value

val Rounded = Value("rounded")
val Straight = Value("straight")

implicit def schemaForEnum: Schema[Value] =
Schema.string.validate(Validator.enumeration(values.toList, v => Option(v), Some(SName("CornerStyle"))))
}

object Tag extends Enumeration {
type Tag = Value

val Tag1 = Value("tag1")
val Tag2 = Value("tag2")

implicit def schemaForEnum: Schema[Value] =
Schema.string.validate(Validator.enumeration(values.toList, v => Option(v), Some(SName("Tag"))))
}

case class Square(cornerStyle: Option[CornerStyle.Value], tags: Seq[Tag.Value])
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class VerifyYamlCoproductTest extends AnyFunSuite with Matchers {
val endpoint = sttp.tapir.endpoint.get.out(jsonBody[Shape])

val expectedYaml = load("coproduct/expected_coproduct_discriminator_with_enum_circe.yml")
val actualYaml = OpenAPIDocsInterpreter().toOpenAPI(endpoint, "My Bookshop", "1.0").toYaml

val actualYaml =
OpenAPIDocsInterpreter()
.toOpenAPI(endpoint, "My Bookshop", "1.0")
.toYaml
noIndentation(actualYaml) shouldBe expectedYaml
}

Expand Down