Skip to content

Commit

Permalink
Scalafmt changes
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpedromoreno committed Feb 21, 2020
1 parent ac793ab commit b09ef12
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 55 deletions.
8 changes: 2 additions & 6 deletions src/main/scala/higherkindness/skeuomorph/avro/schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,13 @@ object AvroF {
"name" -> Json.fromString(name),
"fields" -> Json.arr(fields.map(field2Obj): _*)
)
val withNamespace = namespace.fold(base) { n =>
base deepMerge Json.obj("namespace" -> Json.fromString(n))
}
val withNamespace = namespace.fold(base)(n => base deepMerge Json.obj("namespace" -> Json.fromString(n)))
val withAliases =
if (aliases.isEmpty)
withNamespace
else
withNamespace deepMerge Json.obj("aliases" -> Json.arr(aliases.map(Json.fromString): _*))
val withDoc = doc.fold(withAliases) { f =>
withAliases deepMerge Json.obj("doc" -> Json.fromString(f))
}
val withDoc = doc.fold(withAliases)(f => withAliases deepMerge Json.obj("doc" -> Json.fromString(f)))
withDoc
case TEnum(_, _, _, _, _) => ???
case TUnion(options) => Json.arr(options.toList: _*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object JsonDecoders {

private def basicJsonSchemaDecoder[A: Embed[JsonSchemaF, ?]]: Decoder[A] = {
import JsonSchemaF._
Decoder.forProduct2[(String, Option[String]), String, Option[String]]("type", "format") { Tuple2.apply }.emap {
Decoder.forProduct2[(String, Option[String]), String, Option[String]]("type", "format")(Tuple2.apply).emap {
case ("integer", Some("int32")) => integer[A].embed.asRight
case ("integer", Some("int64")) => long[A].embed.asRight
case ("integer", _) => integer[A].embed.asRight
Expand Down Expand Up @@ -294,7 +294,7 @@ object JsonDecoders {
servers.getOrElse(List.empty),
parameters.getOrElse(List.empty)
)
)
)
)

implicit def componentsDecoder[A: Decoder]: Decoder[Components[A]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ object JsonEncoders {
Encoder.forProduct2(
"description",
"schema"
) { h =>
(h.description, h.schema)
}
)(h => (h.description, h.schema))

implicit def encodingEncoder[A: Encoder]: Encoder[Encoding[A]] =
Encoder.forProduct5(
Expand All @@ -87,17 +85,13 @@ object JsonEncoders {
"style",
"explode",
"allowReserved"
) { e =>
(e.contentType, e.headers, e.style, e.explode, e.allowReserved)
}
)(e => (e.contentType, e.headers, e.style, e.explode, e.allowReserved))

implicit def mediaTypeEncoder[A: Encoder]: Encoder[MediaType[A]] =
Encoder.forProduct2(
"schema",
"encoding"
) { m =>
(m.schema, m.encoding)
}
)(m => (m.schema, m.encoding))

implicit def requestEncoder[A: Encoder]: Encoder[Request[A]] =
Encoder.forProduct3(
Expand All @@ -111,9 +105,7 @@ object JsonEncoders {
"description",
"headers",
"content"
) { r =>
(r.description, r.headers, r.content)
}
)(r => (r.description, r.headers, r.content))

implicit val locationEncoder: Encoder[Location] = Encoder.encodeString.contramap(_.value)

Expand Down Expand Up @@ -178,7 +170,7 @@ object JsonEncoders {
"trace",
"servers",
"parameters"
) { Path.ItemObject.unapply(_).get }
)(Path.ItemObject.unapply(_).get)

implicit def componentsEncoder[A: Encoder]: Encoder[Components[A]] =
Encoder.forProduct4(
Expand All @@ -197,7 +189,5 @@ object JsonEncoders {
"components",
"tags",
"externalDocs"
) { o =>
(o.openapi, o.info, o.servers, o.paths, o.components, o.tags, o.externalDocs)
}
)(o => (o.openapi, o.info, o.servers, o.paths, o.components, o.tags, o.externalDocs))
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ object JsonSchemaF {

}

implicit def eqProperty[T: Eq]: Eq[Property[T]] = Eq.instance { (p1, p2) =>
p1.name === p2.name && p1.tpe === p2.tpe
}
implicit def eqProperty[T: Eq]: Eq[Property[T]] = Eq.instance((p1, p2) => p1.name === p2.name && p1.tpe === p2.tpe)

implicit def eqJsonSchemaF[T: Eq]: Eq[JsonSchemaF[T]] = Eq.instance {
case (IntegerF(), IntegerF()) => true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ package object circe {
)
case CaseClassCodecs(name, fields) =>
val (default, optionType) = codecsTypes[T](name)
val withFields = un(second(default) { x =>
x -> fields
})
val withFields = un(second(default)(x => x -> fields))
(
packages,
none,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ object print {
(
x.verb,
x.path -> queryParametersFrom(x),
x.requestBody.flatMap { requestOrTuple[T](x.operationId, _) }.map(_.name),
x.requestBody.flatMap(requestOrTuple[T](x.operationId, _)).map(_.name),
headers.headOption.map(_ => headers)
)
}
Expand Down Expand Up @@ -213,9 +213,7 @@ object print {

def expectImpl[T: Basis[JsonSchemaF, ?]](implicit http4sSpecifics: Http4sSpecifics): Printer[Http.Operation[T]] =
(κ("expect[") *< responsesTypes >* κ("]("), requestImpl[T] >* κ(")"))
.contramapN { x =>
(x.operationId -> x.responses, x)
}
.contramapN(x => (x.operationId -> x.responses, x))

def methodImpl[T: Basis[JsonSchemaF, ?]](
implicit codecs: Printer[Codecs],
Expand All @@ -224,9 +222,7 @@ object print {
(
method[T] >* κ(" = client."),
expectImpl[T] >|< fetchImpl[T]
).contramapN { x =>
(x, if (x.responses.size > 1) x.asRight else x.asLeft)
}
).contramapN(x => (x, if (x.responses.size > 1) x.asRight else x.asLeft))

def queryParameter[T]: Printer[Parameter.Query[T]] =
(space *< string >* space, κ("(\"") *< divBy(string, κ("\", "), show[Var]) >* κ(")")).contramapN { q =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ object print {
κ(" def ") *< show[Http.OperationId],
κ("(") *< sepBy(argumentDef, ", "),
κ("): F[") *< responsesTypes >* κ("]")
).contramapN { operationTuple[T] }
).contramapN(operationTuple[T])

private def itemObjectTuple[T](
thePath: String,
Expand Down Expand Up @@ -292,9 +292,7 @@ object print {
typeFromResponse(response).map(schema(innerType.some).print).getOrElse("Unit")
tpe match {
case _ if (tpe === newSchema) =>
un(second(success) { x =>
none -> x
})
un(second(success)(x => none -> x))
case _ if (newSchema.nonEmpty) => (tpe, innerType.some, List(newSchema))
case _ => (tpe, none, Nil)
}
Expand All @@ -312,7 +310,7 @@ object print {
caseClassDef.print(newType -> List("statusCode" -> Tpe[T]("Int"), "value" -> Tpe[T](tpe)))
responseOr.fold(
r => {
val (_, anonymousType, schemas) = typeAndSchemaFor(operationId.some, r, tpe) { tpe -> List.empty }
val (_, anonymousType, schemas) = typeAndSchemaFor(operationId.some, r, tpe)(tpe -> List.empty)
un(second(newType -> schemas) { x =>
anonymousType.getOrElse(tpe) -> (x ++ List(statusCaseClass(anonymousType.getOrElse(tpe))))
})
Expand Down Expand Up @@ -379,7 +377,7 @@ object print {
.toList
.flatMap {
case (response, tpe) =>
typeAndSchemaFor(none, response, tpe) { tpe -> Nil }._3
typeAndSchemaFor(none, response, tpe)(tpe -> Nil)._3
}
.asRight
case _ =>
Expand Down Expand Up @@ -432,9 +430,7 @@ object print {
(optional((space >* space) *< schemaWithName[T])).contramap((requestSchemaTuple[T] _).tupled)

private def parameterSchema[T: Basis[JsonSchemaF, ?]](implicit codecs: Printer[Codecs]): Printer[Parameter[T]] =
schemaWithName[T].contramap { x =>
x.name -> x.schema
}
schemaWithName[T].contramap(x => x.name -> x.schema)

private def clientTypes[T: Basis[JsonSchemaF, ?]](
implicit codecs: Printer[Codecs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ object schema {
private def extractTypesFromMediaType[T: Basis[JsonSchemaF, ?]](
mediaType: MediaType[T]
): NestedTypesState[T, MediaType[T]] =
mediaType.schema.traverse(nestedTypes.apply).map { x =>
mediaType.copy(schema = x)
}
mediaType.schema.traverse(nestedTypes.apply).map(x => mediaType.copy(schema = x))
private def extractTypesFromContent[T: Basis[JsonSchemaF, ?]](
content: Map[String, MediaType[T]]
): NestedTypesState[T, Map[String, MediaType[T]]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,11 @@ object ParseProto {
Protocol.Operation(
name = o.getName,
request = findMessage(o.getInputType, files)
.fold(`null`[A]()) { namedMessage =>
namedType[A](namedMessage.scalaPrefix, namedMessage.name)
}
.fold(`null`[A]())(namedMessage => namedType[A](namedMessage.scalaPrefix, namedMessage.name))
.embed,
requestStreaming = o.getClientStreaming,
response = findMessage(o.getOutputType, files)
.fold(`null`[A]()) { namedMessage =>
namedType[A](namedMessage.scalaPrefix, namedMessage.name)
}
.fold(`null`[A]())(namedMessage => namedType[A](namedMessage.scalaPrefix, namedMessage.name))
.embed,
responseStreaming = o.getServerStreaming
)
Expand Down

0 comments on commit b09ef12

Please sign in to comment.