Created
July 19, 2024 20:24
-
-
Save ntngel1/61ecc1787441f3e0b2a76af47a44d240 to your computer and use it in GitHub Desktop.
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
package routing | |
import Readers._ | |
import cats.implicits._ | |
import errors.internal.base.AppError | |
import play.api.libs.json.{Json, OWrites} | |
sealed trait PathSegment | |
object PathSegment { | |
final case class Literal(value: String) extends PathSegment | |
final case object Trailing extends PathSegment | |
final case class Parameter[T : PathParameter]( | |
name: String, | |
description: Option[String] | |
) extends PathSegment | |
} | |
trait PathParameter[T] { | |
def read(value: String): Either[AppError, T] | |
} | |
object Readers { | |
implicit val stringReader: PathParameter[String] = (value: String) => value.asRight[AppError] | |
} | |
case class Endpoint[I, O]( | |
path: Seq[PathSegment], | |
queryParams: Seq[QueryParameter[_]], | |
) | |
final case class QueryParameter[T]( | |
name: String, | |
description: Option[String], | |
defaultValue: Option[T] | |
) | |
object Main { | |
def main(args: Array[String]): Unit = { | |
val endpoint = Endpoint( | |
path = Seq(PathSegment.Literal("api"), PathSegment.Literal("cinema"), PathSegment.Parameter[String]("id", description = None), PathSegment.Trailing), | |
queryParams = Seq.empty | |
) | |
println(OpenAPI(version = "3.1.0", info = OpenAPI.Info("Hello World,"))) | |
} | |
} | |
case class OpenAPI( | |
version: String, | |
info: OpenAPI.Info, | |
) | |
trait OpenAPIJson { | |
implicit val writes: OWrites[OpenAPI] = Json.writes[OpenAPI] | |
} | |
object OpenAPI { | |
case class Info( | |
title: String, | |
summary: Option[String], | |
description: Option[String], | |
termsOfServiceUrl: Option[String], | |
version: String | |
) | |
trait InfoJson { | |
implicit val writes: OWrites[Info] = Json.writes[Info] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment