Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
987Nabil committed Oct 21, 2023
1 parent a5f1e4d commit 63de2ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package zio.http.endpoint.openapi

import java.util.UUID

import scala.annotation.tailrec
import scala.collection.{immutable, mutable}

import zio.Chunk
import zio.json.EncoderOps
import zio.json.ast.Json

import zio.schema.Schema.Record
import zio.schema.codec.JsonCodec
import zio.schema.{Schema, TypeId}

import zio.http._
import zio.http.codec.HttpCodec.Metadata
import zio.http.codec._
import zio.http.endpoint.openapi.JsonSchema.SchemaStyle
import zio.http.endpoint._
import zio.http.endpoint.openapi.JsonSchema.SchemaStyle

object OpenAPIGen {
private val PathWildcard = "pathWildcard"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
private val simpleEndpoint =
Endpoint(
(GET / "static" / int("id") / uuid("uuid") ?? Doc.p("user id") / string("name")) ?? Doc.p("get path"),
)
)
.in[SimpleInputBody](Doc.p("input body"))
.out[SimpleOutputBody](Doc.p("output body"))
.outError[NotFoundError](Status.NotFound, Doc.p("not found"))
Expand All @@ -49,11 +49,10 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
.inCodec(
(HttpCodec.content[OtherSimpleInputBody] ?? Doc.p("other input") | HttpCodec
.content[SimpleInputBody] ?? Doc.p("simple input")) ?? Doc.p("takes either of the two input bodies"),
)
)
.out[SimpleOutputBody]
.outError[NotFoundError](Status.NotFound)


def minify(str: String): String =
Json.encoder.encodeJson(Json.decoder.decodeJson(str).toOption.get, None).toString
override def spec: Spec[TestEnvironment with Scope, Any] =
Expand Down Expand Up @@ -794,21 +793,21 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
|}""".stripMargin
assertTrue(json == minify(expectedJson))
},
test("with query parameter, alternative input, alternative output and examples"){
test("with query parameter, alternative input, alternative output and examples") {
val endpoint =
Endpoint(GET / "static")
.inCodec(
HttpCodec
.content[OtherSimpleInputBody] ?? Doc.p("other input") |
HttpCodec
.content[SimpleInputBody] ?? Doc.p("simple input")
.content[SimpleInputBody] ?? Doc.p("simple input"),
)
.query(QueryCodec.paramStr("query"))
.outCodec(
HttpCodec
.content[SimpleOutputBody] ?? Doc.p("simple output") |
HttpCodec
.content[NotFoundError] ?? Doc.p("not found")
.content[NotFoundError] ?? Doc.p("not found"),
)

val generated = OpenAPIGen.fromEndpoints("Simple Endpoint", "1.0", endpoint)
Expand Down Expand Up @@ -1104,7 +1103,7 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
"1.0",
simpleEndpoint,
queryParamEndpoint,
alternativeInputEndpoint
alternativeInputEndpoint,
)
val json = generated.toJson
val expected =
Expand Down Expand Up @@ -1409,7 +1408,7 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
| }
|}""".stripMargin
assertTrue(json == minify(expected))
}
},
)

}

0 comments on commit 63de2ea

Please sign in to comment.