Skip to content

Commit

Permalink
Fix error when extracting examples (#2789) (#2922)
Browse files Browse the repository at this point in the history
HttpCodec fallback always eliminates HttpCodec.Halt (#2789)
  • Loading branch information
987Nabil authored Jun 24, 2024
1 parent 9e5cd1e commit a98ed32
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
.content[NotFoundError]
.examples("not found" -> NotFoundError("not found")),
)
.examplesOut("other" -> Right(NotFoundError("other")))

val generated = OpenAPIGen.fromEndpoints("Simple Endpoint", "1.0", endpoint)
val json = toJsonAst(generated)
Expand All @@ -727,24 +728,20 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
| "paths" : {
| "/static" : {
| "get" : {
| "requestBody" :
| {
| "requestBody" : {
| "content" : {
| "application/json" : {
| "schema" :
| {
| "schema" : {
| "$ref" : "#/components/schemas/SimpleInputBody"
| },
| "examples" : {
| "john" :
| {
| "john" : {
| "value" : {
| "name" : "John",
| "age" : 42
| }
| },
| "jane" :
| {
| "jane" : {
| "value" : {
| "name" : "Jane",
| "age" : 43
Expand All @@ -756,12 +753,10 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
| "required" : true
| },
| "responses" : {
| "default" :
| {
| "default" : {
| "content" : {
| "application/json" : {
| "schema" :
| {
| "schema" : {
| "anyOf" : [
| {
| "$ref" : "#/components/schemas/SimpleOutputBody"
Expand All @@ -773,22 +768,24 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
| "description" : ""
| },
| "examples" : {
| "john" :
| {
| "john" : {
| "value" : {
| "userName" : "John",
| "score" : 42
| }
| },
| "jane" :
| {
| "jane" : {
| "value" : {
| "userName" : "Jane",
| "score" : 43
| }
| },
| "not found" :
| {
| "other" : {
| "value" : {
| "message" : "other"
| }
| },
| "not found" : {
| "value" : {
| "message" : "not found"
| }
Expand All @@ -803,32 +800,25 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
| },
| "components" : {
| "schemas" : {
| "NotFoundError" :
| {
| "type" :
| "object",
| "NotFoundError" : {
| "type" : "object",
| "properties" : {
| "message" : {
| "type" :
| "string"
| "type" : "string"
| }
| },
| "required" : [
| "message"
| ]
| },
| "SimpleInputBody" :
| {
| "type" :
| "object",
| "SimpleInputBody" : {
| "type" : "object",
| "properties" : {
| "name" : {
| "type" :
| "string"
| "type" : "string"
| },
| "age" : {
| "type" :
| "integer",
| "type" : "integer",
| "format" : "int32"
| }
| },
Expand All @@ -837,18 +827,14 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
| "age"
| ]
| },
| "SimpleOutputBody" :
| {
| "type" :
| "object",
| "SimpleOutputBody" : {
| "type" : "object",
| "properties" : {
| "userName" : {
| "type" :
| "string"
| "type" : "string"
| },
| "score" : {
| "type" :
| "integer",
| "type" : "integer",
| "format" : "int32"
| }
| },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ sealed trait HttpCodec[-AtomTypes, Value] {
that: HttpCodec[AtomTypes1, Value2],
)(implicit alternator: Alternator[Value, Value2]): HttpCodec[AtomTypes1, alternator.Out] = {
if (self eq HttpCodec.Halt) that.asInstanceOf[HttpCodec[AtomTypes1, alternator.Out]]
else if (that eq HttpCodec.Halt) self.asInstanceOf[HttpCodec[AtomTypes1, alternator.Out]]
else {
HttpCodec
.Fallback(self, that, alternator, HttpCodec.Fallback.Condition.IsHttpCodecError)
Expand Down

0 comments on commit a98ed32

Please sign in to comment.