Skip to content

Commit

Permalink
Add comments / simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jul 6, 2023
1 parent 398c15a commit 095ebdf
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package circe {
override val openApi30: Boolean = true

implicit val encoderOAuthFlow: Encoder[OAuthFlow] = {
// #79: all OAuth flow object MUST include a scopes field, but it MAY be empty.
import scala.collection.immutable.ListMap
implicit def encodeListMap: Encoder[ListMap[String, String]] = doEncodeListMap(nullWhenEmpty = false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ trait InternalSttpOpenAPICirceDecoders extends JsonSchemaCirceDecoders {
implicit val tagDecoder: Decoder[Tag] = withExtensions(deriveDecoder[Tag])

implicit val oauthFlowDecoder: Decoder[OAuthFlow] = {
// #79: all OAuth flow object MUST include a scopes field, but it MAY be empty.
implicit def listMapDecoder: Decoder[ListMap[String, String]] =
Decoder.decodeOption(Decoder.decodeMapLike[String, String, ListMap]).map(_.getOrElse(ListMap.empty))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import scala.collection.immutable.ListMap

trait InternalSttpOpenAPICirceEncoders extends JsonSchemaCirceEncoders {
implicit val encoderOAuthFlow: Encoder[OAuthFlow] = {
// #79: all OAuth flow object MUST include a scopes field, but it MAY be empty.
implicit def encodeListMap: Encoder[ListMap[String, String]] = doEncodeListMap(nullWhenEmpty = false)

deriveEncoder[OAuthFlow].mapJsonObject(expandExtensions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import scala.collection.immutable.ListMap
class DecoderTest extends AnyFunSuite with ResourcePlatform {
override val basedir = "openapi-circe"

private val tokenUrl = basedir + "-token"

test("petstore deserialize") {
val Right(openapi) = readJson("/petstore/basic-petstore.json").flatMap(_.as[OpenAPI]): @unchecked

Expand Down Expand Up @@ -48,7 +46,7 @@ class DecoderTest extends AnyFunSuite with ResourcePlatform {

test("decode security schema with not empty scopes") {
val expectedScopes = Some(Some(ListMap("example" -> "description")))
val expectedToken = Some(Some(Some(tokenUrl)))
val expectedToken = Some(Some(Some("openapi-circe-token")))

val Right(securityScheme) =
readJson("/securitySchema/security-schema-with-scopes.json").flatMap(_.as[SecurityScheme]): @unchecked
Expand All @@ -59,7 +57,7 @@ class DecoderTest extends AnyFunSuite with ResourcePlatform {

test("decode security schema with empty scopes") {
val expectedScopes = Some(Some(ListMap.empty[String, String]))
val expectedToken = Some(Some(Some(tokenUrl)))
val expectedToken = Some(Some(Some("openapi-circe-token")))

val Right(securityScheme) =
readJson("/securitySchema/security-schema-with-empty-scopes.json").flatMap(_.as[SecurityScheme]): @unchecked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import scala.collection.immutable.ListMap
class EncoderTest extends AnyFunSuite with ResourcePlatform with SttpOpenAPICirceEncoders {
override val basedir = "openapi-circe"

private val tokenUrl = basedir + "-token"

val petstore: OpenAPI = OpenAPI(
openapi = "3.1.0",
info = Info(
title = "Sample Pet Store App",
summary = Some("A pet store manager."),
Expand Down Expand Up @@ -114,7 +111,6 @@ class EncoderTest extends AnyFunSuite with ResourcePlatform with SttpOpenAPICirc
)

val openapi = OpenAPI(
openapi = "3.1.0",
info = Info(title = "API", version = "1.0.0"),
components = Some(components)
)
Expand Down Expand Up @@ -143,7 +139,7 @@ class EncoderTest extends AnyFunSuite with ResourcePlatform with SttpOpenAPICirc
Some(
OAuthFlow(
authorizationUrl = None,
tokenUrl = Some(tokenUrl),
tokenUrl = Some("openapi-circe-token"),
refreshUrl = None,
scopes = scopesRequirement
)
Expand Down Expand Up @@ -176,7 +172,7 @@ class EncoderTest extends AnyFunSuite with ResourcePlatform with SttpOpenAPICirc
Some(
OAuthFlow(
authorizationUrl = None,
tokenUrl = Some(tokenUrl),
tokenUrl = Some("openapi-circe-token"),
refreshUrl = None,
scopes = scopesRequirement
)
Expand Down

0 comments on commit 095ebdf

Please sign in to comment.