-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AnySchema.Encoding is a json encoding issue
- Loading branch information
Showing
10 changed files
with
129 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
openapi-circe/src/main/scala/sttp/apispec/openapi/circe/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
openapi-circe/src/test/resources/spec/3.1/any_and_nothing1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"title": "API", | ||
"version": "1.0.0" | ||
}, | ||
"components": { | ||
"schemas": { | ||
"anything_boolean": true, | ||
"nothing_boolean": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
openapi-circe/src/test/scala/sttp/apispec/openapi/circe/overridden/EncoderTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package sttp.apispec.openapi.circe.overridden | ||
|
||
import io.circe.syntax._ | ||
import sttp.apispec._ | ||
import sttp.apispec.openapi._ | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import scala.collection.immutable.ListMap | ||
import sttp.apispec.openapi.circe.ResourcePlatform | ||
|
||
class EncoderTest extends AnyFunSuite with ResourcePlatform { | ||
def refOr[A](a: A): ReferenceOr[A] = Right(a) | ||
|
||
test("any boolean") { | ||
import sttp.apispec.openapi.circe._ | ||
|
||
val components = Components( | ||
schemas = ListMap( | ||
"anything_boolean" -> refOr(AnySchema.Anything), | ||
"nothing_boolean" -> refOr(AnySchema.Nothing), | ||
) | ||
) | ||
|
||
val openapi = OpenAPI( | ||
info = Info(title = "API", version = "1.0.0"), | ||
components = Some(components) | ||
) | ||
|
||
val openApiJson = openapi.asJson | ||
val Right(json) = readJson("/spec/3.1/any_and_nothing1.json") | ||
|
||
assert(openApiJson.spaces2SortKeys == json.spaces2SortKeys) | ||
} | ||
|
||
test("any object") { | ||
object obj extends sttp.apispec.openapi.circe.SttpOpenAPICirceEncoders { | ||
val anyObjectEncoding: AnySchema.Encoding = AnySchema.Encoding.Object | ||
} | ||
|
||
import obj._ | ||
|
||
val components = Components( | ||
schemas = ListMap( | ||
"anything_object" -> refOr(AnySchema.Anything), | ||
"nothing_object" -> refOr(AnySchema.Nothing), | ||
) | ||
) | ||
|
||
val openapi = OpenAPI( | ||
info = Info(title = "API", version = "1.0.0"), | ||
components = Some(components) | ||
) | ||
|
||
val openApiJson = openapi.asJson | ||
val Right(json) = readJson("/spec/3.1/any_and_nothing2.json") | ||
|
||
assert(openApiJson.spaces2SortKeys == json.spaces2SortKeys) | ||
} | ||
|
||
} |